Health pickups is now working!
This commit is contained in:
parent
9ec3fc6fa4
commit
925f05b3b0
|
@ -142,8 +142,8 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa
|
|||
this->privData->camera.SetPosition( p->getPos() );
|
||||
Float3 offset = Float3( 0.0f );
|
||||
// DEBUG position of camera so we can see the player model
|
||||
offset.y = p->getScale().y * 5.0f;
|
||||
offset.z = p->getScale().z * -5.0f;
|
||||
//offset.y = p->getScale().y * 5.0f;
|
||||
//offset.z = p->getScale().z * -5.0f;
|
||||
// !DEBUG
|
||||
this->privData->camera.SetHeadOffset( offset );
|
||||
this->privData->camera.UpdateOrientation();
|
||||
|
@ -187,7 +187,7 @@ bool GameState::Render()
|
|||
{
|
||||
if(playerObject->second)
|
||||
{
|
||||
//if( this->privData->myId != playerObject->second->GetId() )
|
||||
if( this->privData->myId != playerObject->second->GetId() )
|
||||
{
|
||||
playerObject->second->Render();
|
||||
}
|
||||
|
@ -596,6 +596,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
|
|||
{
|
||||
// if it is not a player
|
||||
object = (*this->privData->dynamicObjects)[decoded.objectID];
|
||||
|
||||
if(!object)
|
||||
{
|
||||
//If it is a static object
|
||||
object = (*this->privData->staticObjects)[decoded.objectID];
|
||||
}
|
||||
}
|
||||
|
||||
if( object )
|
||||
|
@ -613,6 +619,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
|
|||
{
|
||||
// if it is not a player
|
||||
object = (*this->privData->dynamicObjects)[decoded.objectID];
|
||||
|
||||
if(!object)
|
||||
{
|
||||
//If it is a static object
|
||||
object = (*this->privData->staticObjects)[decoded.objectID];
|
||||
}
|
||||
}
|
||||
|
||||
if( object )
|
||||
|
|
|
@ -44,7 +44,6 @@ using namespace GameLogic;
|
|||
realObjB = realObjA;
|
||||
}
|
||||
|
||||
|
||||
switch (realObjB->GetObjectType())
|
||||
{
|
||||
case ObjectSpecialType::ObjectSpecialType_Generic:
|
||||
|
@ -375,7 +374,12 @@ using namespace GameLogic;
|
|||
|
||||
if(b->GetObjectType() == ObjectSpecialType_Player)
|
||||
{
|
||||
((Pickup*)a)->OnCollision((Player*)(b));
|
||||
//Only update if it is active. And if the player is alive
|
||||
if(((Pickup*)a)->IsActive() && ((Player*)b)->GetState() != PLAYER_STATE_DEAD && ((Player*)b)->GetState() != PLAYER_STATE_DIED)
|
||||
{
|
||||
((Pickup*)a)->OnCollision((Player*)(b));
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if(a->GetObjectType() != ObjectSpecialType_Player)
|
||||
{
|
||||
|
@ -384,5 +388,9 @@ using namespace GameLogic;
|
|||
return;
|
||||
}
|
||||
|
||||
((Pickup*)b)->OnCollision((Player*)a);
|
||||
//Only update if it is active. And if the player is alive
|
||||
if(((Pickup*)b)->IsActive() && ((Player*)a)->GetState() != PLAYER_STATE_DEAD && ((Player*)a)->GetState() != PLAYER_STATE_DIED)
|
||||
{
|
||||
((Pickup*)b)->OnCollision((Player*)a);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisi
|
|||
this->active = true;
|
||||
this->spawnTime = spawnTime;
|
||||
timer.reset();
|
||||
this->GetRigidBody()->MoveToLimbo();
|
||||
}
|
||||
|
||||
Pickup::~Pickup()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "PickupHealth.h"
|
||||
#include "../Game.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
|
||||
|
@ -14,5 +15,8 @@ PickupHealth::~PickupHealth()
|
|||
void PickupHealth::OnCollision(Player *player)
|
||||
{
|
||||
timer.reset();
|
||||
((Game*)&Game::Instance())->onDisableFnc(this);
|
||||
|
||||
this->active = false;
|
||||
player->DamageLife(-hpValue);
|
||||
}
|
|
@ -345,16 +345,22 @@ PLAYER_STATE Player::GetState() const
|
|||
|
||||
void Player::DamageLife(int damage)
|
||||
{
|
||||
this->playerStats.hp -= damage;
|
||||
// send hp to client
|
||||
this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp);
|
||||
|
||||
if(this->playerStats.hp <= 0)
|
||||
if(damage != 0)
|
||||
{
|
||||
this->playerStats.hp = 0;
|
||||
this->playerState = PLAYER_STATE_DIED;
|
||||
}
|
||||
this->playerStats.hp -= damage;
|
||||
|
||||
if(this->playerStats.hp > 100)
|
||||
this->playerStats.hp = 100;
|
||||
|
||||
// send hp to client
|
||||
this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp);
|
||||
|
||||
if(this->playerStats.hp <= 0)
|
||||
{
|
||||
this->playerStats.hp = 0;
|
||||
this->playerState = PLAYER_STATE_DIED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::AddAffectedObject(DynamicObject &AffectedObject)
|
||||
|
|
|
@ -152,7 +152,7 @@ using namespace DanBias;
|
|||
}
|
||||
void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject )
|
||||
{
|
||||
GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol());
|
||||
GameSession::gameSession->Send(Protocol_ObjectEnable(movedObject->GetID()).GetProtocol());
|
||||
}
|
||||
void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp )
|
||||
{
|
||||
|
|
|
@ -168,6 +168,14 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
|
|||
ParseObject(&buffer[counter], &header->healthValue, 4);
|
||||
counter += 4;
|
||||
|
||||
// DEBUG
|
||||
header->position[1] = 150;
|
||||
header->spawnTime = 5;
|
||||
header->boundingVolume.box.mass = 0;
|
||||
header->typeID = ObjectType_Static;
|
||||
header->healthValue = 50;
|
||||
// !DEBUG
|
||||
|
||||
objects.push_back(header);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue