Sending dmg, respawn and dead from player to client
This commit is contained in:
parent
b0aa6acdd6
commit
22f52150d5
|
@ -33,7 +33,7 @@ bool GamingUI::Init()
|
|||
// z value should be between 0.5 - 0.9 so that it will be behind other states
|
||||
// add textures and text
|
||||
this->plane = new Plane_UI(L"box_tex.png", Float3(0.5f, 0.0f, 0.5f), Float2(0.3f, 0.1f));
|
||||
this->text = new Text_UI(L"hej", Float3(0.5f,0.0f,0.1f), Float2(0.1f,0.1f));
|
||||
this->text = new Text_UI(L"hej", Float3(0.3f,0.0f,0.1f), Float2(0.1f,0.1f));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ Game::Game(void)
|
|||
: initiated(false)
|
||||
, onMoveFnc(0)
|
||||
, onDisableFnc(0)
|
||||
, onDamageTakenFnc(0)
|
||||
, onRespawnFnc(0)
|
||||
, onDeadFnc(0)
|
||||
, frameTime(1.0f/120.0f)
|
||||
{}
|
||||
|
||||
|
@ -156,7 +159,18 @@ void Game::SetSubscription(GameEvent::ObjectMovedFunction functionPointer)
|
|||
void Game::SetSubscription(GameEvent::ObjectDisabledFunction functionPointer)
|
||||
{
|
||||
this->onDisableFnc = functionPointer;
|
||||
|
||||
}
|
||||
void Game::SetHpSubscription(GameEvent::ObjectHpFunction functionPointer)
|
||||
{
|
||||
this->onDamageTakenFnc = functionPointer;
|
||||
}
|
||||
void Game::SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer)
|
||||
{
|
||||
this->onRespawnFnc = functionPointer;
|
||||
}
|
||||
void Game::SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer)
|
||||
{
|
||||
this->onDeadFnc = functionPointer;
|
||||
}
|
||||
|
||||
bool Game::Initiate()
|
||||
|
|
|
@ -80,6 +80,10 @@ namespace GameLogic
|
|||
void SetFrameTimeLength( float seconds ) override;
|
||||
void SetSubscription(GameEvent::ObjectMovedFunction functionPointer) override;
|
||||
void SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) override;
|
||||
void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) override;
|
||||
void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) override;
|
||||
void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override;
|
||||
|
||||
bool Initiate() override;
|
||||
|
||||
float GetFrameTime() const;
|
||||
|
@ -93,7 +97,9 @@ namespace GameLogic
|
|||
bool initiated;
|
||||
GameEvent::ObjectDisabledFunction onDisableFnc;
|
||||
GameEvent::ObjectMovedFunction onMoveFnc;
|
||||
|
||||
GameEvent::ObjectHpFunction onDamageTakenFnc;
|
||||
GameEvent::ObjectRespawnedFunction onRespawnFnc;
|
||||
GameEvent::ObjectDeadFunction onDeadFnc;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,9 @@ namespace GameLogic
|
|||
{
|
||||
typedef void(*ObjectMovedFunction)(IObjectData* object); // Callback method that recieves and object
|
||||
typedef void(*ObjectDisabledFunction)(IObjectData* object, float seconds); // Callback method that recieves and object
|
||||
typedef void(*ObjectHpFunction)(IObjectData* object, float hp); // Callback method that sends obj HP
|
||||
typedef void(*ObjectRespawnedFunction)(IObjectData* object, Oyster::Math::Float3 spawnPos ); // Callback method that sends spawnPos
|
||||
typedef void(*ObjectDeadFunction)(IObjectData* object, float seconds); // Callback method that sends death timer
|
||||
//etc...
|
||||
};
|
||||
|
||||
|
@ -178,6 +181,9 @@ namespace GameLogic
|
|||
* @param
|
||||
*/
|
||||
virtual void SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) = 0;
|
||||
virtual void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) = 0;
|
||||
virtual void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) = 0;
|
||||
virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -422,5 +422,5 @@ void Level::PhysicsOnMoveLevel(const ICustomBody *object)
|
|||
// function call from physics update when object was moved
|
||||
Object* temp = (Object*)object->GetCustomTag();
|
||||
((Game*)&Game::Instance())->onMoveFnc(temp);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ namespace GameLogic
|
|||
|
||||
int getNrOfDynamicObj();
|
||||
Object* GetObj( int ID ) const;
|
||||
|
||||
static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object);
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)
|
|||
key_strafeLeft = 0;
|
||||
key_jump = 0;
|
||||
invincibleCooldown = 0;
|
||||
this->deathTimeLeft = 0;
|
||||
this->deathTime = 1;
|
||||
|
||||
this->previousPosition = Oyster::Math::Float3(0,0,0);
|
||||
|
||||
|
@ -54,7 +56,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom
|
|||
key_strafeLeft = 0;
|
||||
key_jump = 0;
|
||||
invincibleCooldown = 0;
|
||||
|
||||
this->deathTimeLeft = 0;
|
||||
this->deathTime = 1;
|
||||
this->previousPosition = Oyster::Math::Float3(0,0,0);
|
||||
this->moveDir = Oyster::Math::Float3(0,0,0);
|
||||
this->moveSpeed = 20;
|
||||
|
@ -73,9 +76,10 @@ Player::~Player(void)
|
|||
}
|
||||
|
||||
void Player::BeginFrame()
|
||||
{
|
||||
if( this->playerState != PLAYER_STATE_DEAD)
|
||||
{
|
||||
weapon->Update(0.002f);
|
||||
//Object::BeginFrame();
|
||||
|
||||
Oyster::Math::Float maxSpeed = 30;
|
||||
|
||||
|
@ -194,18 +198,22 @@ void Player::BeginFrame()
|
|||
this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//this->weapon->Update(0.01f);
|
||||
}
|
||||
else
|
||||
{
|
||||
// player is dead
|
||||
// TODO move this logic to lvl
|
||||
this->deathTimeLeft -= gameInstance->GetFrameTime();
|
||||
if( this->deathTimeLeft <= 0)
|
||||
{
|
||||
Respawn( Oyster::Math::Float3( -50, 180, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::EndFrame()
|
||||
{
|
||||
|
||||
//Object::EndFrame();
|
||||
|
||||
}
|
||||
|
||||
void Player::Move(const PLAYER_MOVEMENT &movement)
|
||||
|
@ -257,11 +265,16 @@ void Player::UseWeapon(const WEAPON_FIRE &usage)
|
|||
}
|
||||
|
||||
void Player::Respawn(Oyster::Math::Float3 spawnPoint)
|
||||
{
|
||||
if( this->playerState == PLAYER_STATE_DEAD)
|
||||
{
|
||||
this->life = 100;
|
||||
this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
|
||||
this->lookDir = Oyster::Math::Float4(1,0,0);
|
||||
//this->lookDir = Oyster::Math::Float4(1,0,0);
|
||||
this->rigidBody->SetPosition(spawnPoint);
|
||||
this->gameInstance->onRespawnFnc( this, spawnPoint);
|
||||
this->gameInstance->onDamageTakenFnc( this, this->life);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::SetLookDir(const Oyster::Math3D::Float3& lookDir)
|
||||
|
@ -320,14 +333,18 @@ PLAYER_STATE Player::GetState() const
|
|||
}
|
||||
|
||||
void Player::DamageLife(int damage)
|
||||
{
|
||||
if( this->playerState != PLAYER_STATE_DEAD)
|
||||
{
|
||||
this->life -= damage;
|
||||
this->life = 0;
|
||||
this->gameInstance->onDamageTakenFnc( this, this->life);
|
||||
|
||||
if(this->life <= 0)
|
||||
{
|
||||
this->life = 0;
|
||||
playerState = PLAYER_STATE_DEAD;
|
||||
this->gameInstance->onDisableFnc(this, 0.0f);
|
||||
this->deathTimeLeft = this->deathTime;
|
||||
this->gameInstance->onDeadFnc(this, this->deathTimeLeft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,6 +100,8 @@ namespace GameLogic
|
|||
|
||||
Oyster::Math::Float rotationUp;
|
||||
|
||||
float deathTime;
|
||||
float deathTimeLeft;
|
||||
|
||||
bool hasTakenDamage;
|
||||
float invincibleCooldown;
|
||||
|
|
|
@ -75,13 +75,15 @@ namespace GameLogic
|
|||
}
|
||||
Protocol_ObjectDamage(Oyster::Network::CustomNetProtocol& p)
|
||||
{
|
||||
|
||||
this->object_ID = p[1].value.netInt;
|
||||
this->healthLost = p[2].value.netFloat;
|
||||
}
|
||||
Protocol_ObjectDamage(int id, float hp)
|
||||
{
|
||||
this->protocol[0].value = protocol_Gameplay_ObjectDamage;
|
||||
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
||||
|
||||
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
|
||||
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
|
||||
|
||||
object_ID = id;
|
||||
|
|
|
@ -99,6 +99,9 @@ namespace DanBias
|
|||
//Callback method recieving from gamelogic
|
||||
static void ObjectMove ( GameLogic::IObjectData* movedObject );
|
||||
static void ObjectDisabled ( GameLogic::IObjectData* movedObject, float seconds );
|
||||
static void ObjectDamaged ( GameLogic::IObjectData* movedObject, float hp );
|
||||
static void ObjectRespawned ( GameLogic::IObjectData* movedObject, Oyster::Math::Float3 spawnPos );
|
||||
static void ObjectDead ( GameLogic::IObjectData* movedObject, float seconds );
|
||||
|
||||
//Private member variables
|
||||
private:
|
||||
|
|
|
@ -150,7 +150,18 @@ using namespace DanBias;
|
|||
{
|
||||
GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID(), seconds).GetProtocol());
|
||||
}
|
||||
|
||||
void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp )
|
||||
{
|
||||
GameSession::gameSession->Send(Protocol_ObjectDamage(movedObject->GetID(), hp).GetProtocol());
|
||||
}
|
||||
void GameSession::ObjectRespawned( GameLogic::IObjectData* movedObject, Oyster::Math::Float3 spawnPos )
|
||||
{
|
||||
GameSession::gameSession->Send(Protocol_ObjectRespawn(movedObject->GetID(), spawnPos).GetProtocol());
|
||||
}
|
||||
void GameSession::ObjectDead( GameLogic::IObjectData* movedObject, float seconds )
|
||||
{
|
||||
GameSession::gameSession->Send(Protocol_ObjectDie(movedObject->GetID(), seconds).GetProtocol());
|
||||
}
|
||||
//*****************************************************//
|
||||
//****************** Protocol methods *****************//
|
||||
//******************************************************************************************************************//
|
||||
|
|
|
@ -108,6 +108,9 @@ bool GameSession::Create(GameDescription& desc, bool forceStart)
|
|||
/* Set some game instance data options */
|
||||
this->gameInstance.SetSubscription(GameSession::ObjectMove);
|
||||
this->gameInstance.SetSubscription(GameSession::ObjectDisabled);
|
||||
this->gameInstance.SetHpSubscription(GameSession::ObjectDamaged);
|
||||
this->gameInstance.SetRespawnSubscription(GameSession::ObjectRespawned);
|
||||
this->gameInstance.SetDeadSubscription(GameSession::ObjectDead);
|
||||
this->gameInstance.SetFPS(60);
|
||||
|
||||
this->description.clients.Clear();
|
||||
|
|
Loading…
Reference in New Issue