GameLogic - Merged with gamelogic

This commit is contained in:
dean11 2014-02-27 09:11:00 +01:00
commit ca715dbe05
6 changed files with 65 additions and 26 deletions

View File

@ -154,6 +154,11 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa
//this->privData->camera.UpdateOrientation(); //this->privData->camera.UpdateOrientation();
} }
} }
else
{
int i = 0;
// some error loading model
}
} }
GameClientState::ClientState GameState::Update( float deltaTime ) GameClientState::ClientState GameState::Update( float deltaTime )
@ -743,11 +748,20 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
{ {
//Remove the disconnected player //Remove the disconnected player
Protocol_ObjectDisconnectPlayer decoded(data); Protocol_ObjectDisconnectPlayer decoded(data);
auto object = this->privData->dynamicObjects->find( decoded.objectID ); C_Player *player;
if( object != this->privData->dynamicObjects->end() ) player = (this->privData->players)[decoded.objectID];
if( player )
{ {
object->second = nullptr; if( this->privData->myId == decoded.objectID )
this->privData->dynamicObjects->erase( object ); {
// dont delete my player
}
if( player )
{
player->SetVisible(false);
(this->privData->players)[decoded.objectID].Release();
}
} }
} }
return GameClientState::event_processed; return GameClientState::event_processed;

View File

@ -170,6 +170,10 @@ void GamingUI::ReadKeyInput()
{ {
this->nextState = GameStateUI::UIState_shut_down; this->nextState = GameStateUI::UIState_shut_down;
} }
if( this->sharedData->keyboardDevice->IsKeyDown(::Input::Enum::SAKI_M) )
{
this->nextState = GameStateUI::UIState_main_menu;
}
} }
void GamingUI::OnMousePress ( Input::Enum::SAMI key, Input::Mouse* sender ) void GamingUI::OnMousePress ( Input::Enum::SAMI key, Input::Mouse* sender )

View File

@ -368,6 +368,9 @@ void Level::AddPlayerToTeam(Player *player, int teamID)
} }
void Level::AddPlayerToGame(Player *player) void Level::AddPlayerToGame(Player *player)
{ {
int i = rand() % spawnPoints.Size();
Float3 spawnPoint = spawnPoints[i];
player->ResetPlayer(spawnPoint);
for(int i = 0; i < (int)this->playerObjects.Size(); i++) for(int i = 0; i < (int)this->playerObjects.Size(); i++)
{ {
if (!this->playerObjects[i]) if (!this->playerObjects[i])
@ -408,6 +411,8 @@ void Level::Update(float deltaTime)
for(int i = 0; i < (int)this->playerObjects.Size(); i++) for(int i = 0; i < (int)this->playerObjects.Size(); i++)
{
if(this->playerObjects[i])
{ {
if(this->playerObjects[i]->getAffectingPlayer() != NULL) if(this->playerObjects[i]->getAffectingPlayer() != NULL)
{ {
@ -433,6 +438,7 @@ void Level::Update(float deltaTime)
((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID
} }
} }
}
for(int i = 0; i < dynamicObjects.Size(); i++) for(int i = 0; i < dynamicObjects.Size(); i++)
{ {

View File

@ -15,6 +15,8 @@ Player::Player()
Player::initPlayerData(); Player::initPlayerData();
this->weapon = NULL; this->weapon = NULL;
this->teamID = -1; this->teamID = -1;
this->playerScore.killScore = 0;
this->playerScore.deathScore = 0;
} }
Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID)
@ -23,6 +25,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)
this->weapon = new Weapon(2,this); this->weapon = new Weapon(2,this);
Player::initPlayerData(); Player::initPlayerData();
this->teamID = teamID; this->teamID = teamID;
this->playerScore.killScore = 0;
this->playerScore.deathScore = 0;
} }
Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID)
@ -31,6 +35,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom
this->weapon = new Weapon(2,this); this->weapon = new Weapon(2,this);
Player::initPlayerData(); Player::initPlayerData();
this->teamID = teamID; this->teamID = teamID;
this->playerScore.killScore = 0;
this->playerScore.deathScore = 0;
} }
Player::~Player(void) Player::~Player(void)
@ -45,8 +51,6 @@ void Player::initPlayerData()
{ {
this->playerStats.hp = MAX_HP; this->playerStats.hp = MAX_HP;
this->playerStats.movementSpeed = BASIC_SPEED; this->playerStats.movementSpeed = BASIC_SPEED;
this->playerScore.killScore = 0;
this->playerScore.deathScore = 0;
this->playerState = PLAYER_STATE_IDLE; this->playerState = PLAYER_STATE_IDLE;
this->lookDir = Oyster::Math::Float3(0,0,-1); this->lookDir = Oyster::Math::Float3(0,0,-1);
@ -308,7 +312,13 @@ void Player::Inactivate()
{ {
//this-> //this->
} }
void Player::ResetPlayer( Oyster::Math::Float3 spawnPos)
{
Player::initPlayerData();
this->rigidBody->SetPosition(spawnPos);
this->playerScore.killScore = 0;
this->playerScore.deathScore = 0;
}
Oyster::Math::Float3 Player::GetPosition() const Oyster::Math::Float3 Player::GetPosition() const
{ {
return (Oyster::Math::Float3) this->rigidBody->GetState().centerPos; return (Oyster::Math::Float3) this->rigidBody->GetState().centerPos;

View File

@ -82,6 +82,7 @@ namespace GameLogic
bool IsIdle(); bool IsIdle();
void Inactivate(); void Inactivate();
void ResetPlayer( Oyster::Math::Float3 spawnPos);
Oyster::Math::Float3 GetPosition() const; Oyster::Math::Float3 GetPosition() const;
Oyster::Math::Float3 GetLookDir() const; Oyster::Math::Float3 GetLookDir() const;

View File

@ -25,6 +25,10 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::Net
} }
GameClient::~GameClient() GameClient::~GameClient()
{ {
if(this->player)
{
this->player->Inactivate();
}
this->isReady = false; this->isReady = false;
this->character = L"char_orca.dan"; this->character = L"char_orca.dan";
this->alias = L"Unknown"; this->alias = L"Unknown";