Health pickups is now working!

This commit is contained in:
Pontus Fransson 2014-02-26 10:23:38 +01:00
parent 9ec3fc6fa4
commit 925f05b3b0
7 changed files with 57 additions and 18 deletions

View File

@ -142,8 +142,8 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa
this->privData->camera.SetPosition( p->getPos() ); this->privData->camera.SetPosition( p->getPos() );
Float3 offset = Float3( 0.0f ); Float3 offset = Float3( 0.0f );
// DEBUG position of camera so we can see the player model // DEBUG position of camera so we can see the player model
offset.y = p->getScale().y * 5.0f; //offset.y = p->getScale().y * 5.0f;
offset.z = p->getScale().z * -5.0f; //offset.z = p->getScale().z * -5.0f;
// !DEBUG // !DEBUG
this->privData->camera.SetHeadOffset( offset ); this->privData->camera.SetHeadOffset( offset );
this->privData->camera.UpdateOrientation(); this->privData->camera.UpdateOrientation();
@ -187,7 +187,7 @@ bool GameState::Render()
{ {
if(playerObject->second) if(playerObject->second)
{ {
//if( this->privData->myId != playerObject->second->GetId() ) if( this->privData->myId != playerObject->second->GetId() )
{ {
playerObject->second->Render(); playerObject->second->Render();
} }
@ -596,6 +596,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
{ {
// if it is not a player // if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID]; object = (*this->privData->dynamicObjects)[decoded.objectID];
if(!object)
{
//If it is a static object
object = (*this->privData->staticObjects)[decoded.objectID];
}
} }
if( object ) if( object )
@ -613,6 +619,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
{ {
// if it is not a player // if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID]; object = (*this->privData->dynamicObjects)[decoded.objectID];
if(!object)
{
//If it is a static object
object = (*this->privData->staticObjects)[decoded.objectID];
}
} }
if( object ) if( object )

View File

@ -44,7 +44,6 @@ using namespace GameLogic;
realObjB = realObjA; realObjB = realObjA;
} }
switch (realObjB->GetObjectType()) switch (realObjB->GetObjectType())
{ {
case ObjectSpecialType::ObjectSpecialType_Generic: case ObjectSpecialType::ObjectSpecialType_Generic:
@ -375,7 +374,12 @@ using namespace GameLogic;
if(b->GetObjectType() == ObjectSpecialType_Player) 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) else if(a->GetObjectType() != ObjectSpecialType_Player)
{ {
@ -384,5 +388,9 @@ using namespace GameLogic;
return; 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);
}
} }

View File

@ -9,6 +9,7 @@ Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisi
this->active = true; this->active = true;
this->spawnTime = spawnTime; this->spawnTime = spawnTime;
timer.reset(); timer.reset();
this->GetRigidBody()->MoveToLimbo();
} }
Pickup::~Pickup() Pickup::~Pickup()

View File

@ -1,4 +1,5 @@
#include "PickupHealth.h" #include "PickupHealth.h"
#include "../Game.h"
using namespace GameLogic; using namespace GameLogic;
@ -14,5 +15,8 @@ PickupHealth::~PickupHealth()
void PickupHealth::OnCollision(Player *player) void PickupHealth::OnCollision(Player *player)
{ {
timer.reset(); timer.reset();
((Game*)&Game::Instance())->onDisableFnc(this);
this->active = false;
player->DamageLife(-hpValue); player->DamageLife(-hpValue);
} }

View File

@ -345,16 +345,22 @@ PLAYER_STATE Player::GetState() const
void Player::DamageLife(int damage) void Player::DamageLife(int damage)
{ {
this->playerStats.hp -= damage; if(damage != 0)
// send hp to client
this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp);
if(this->playerStats.hp <= 0)
{ {
this->playerStats.hp = 0; this->playerStats.hp -= damage;
this->playerState = PLAYER_STATE_DIED;
}
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) void Player::AddAffectedObject(DynamicObject &AffectedObject)

View File

@ -152,7 +152,7 @@ using namespace DanBias;
} }
void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject ) 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 ) void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp )
{ {

View File

@ -168,6 +168,14 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
ParseObject(&buffer[counter], &header->healthValue, 4); ParseObject(&buffer[counter], &header->healthValue, 4);
counter += 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); objects.push_back(header);
break; break;
} }