Spawning players on rand spawnpoint when they connect
This commit is contained in:
parent
15df481dd3
commit
74456a4d80
|
@ -149,6 +149,11 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa
|
|||
this->privData->camera.UpdateOrientation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = 0;
|
||||
// some error loading model
|
||||
}
|
||||
}
|
||||
|
||||
GameClientState::ClientState GameState::Update( float deltaTime )
|
||||
|
@ -736,11 +741,20 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
|
|||
{
|
||||
//Remove the disconnected player
|
||||
Protocol_ObjectDisconnectPlayer decoded(data);
|
||||
auto object = this->privData->dynamicObjects->find( decoded.objectID );
|
||||
if( object != this->privData->dynamicObjects->end() )
|
||||
C_Player *player;
|
||||
player = (this->privData->players)[decoded.objectID];
|
||||
|
||||
if( player )
|
||||
{
|
||||
object->second = nullptr;
|
||||
this->privData->dynamicObjects->erase( object );
|
||||
if( this->privData->myId == decoded.objectID )
|
||||
{
|
||||
// dont delete my player
|
||||
}
|
||||
if( player )
|
||||
{
|
||||
player->SetVisible(false);
|
||||
(this->privData->players)[decoded.objectID].Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
return GameClientState::event_processed;
|
||||
|
|
|
@ -332,6 +332,9 @@ void Level::AddPlayerToTeam(Player *player, int teamID)
|
|||
}
|
||||
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++)
|
||||
{
|
||||
if (!this->playerObjects[i])
|
||||
|
@ -373,28 +376,31 @@ void Level::Update(float deltaTime)
|
|||
|
||||
for(int i = 0; i < (int)this->playerObjects.Size(); i++)
|
||||
{
|
||||
if(this->playerObjects[i]->getAffectingPlayer() != NULL)
|
||||
if(this->playerObjects[i])
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD)
|
||||
{
|
||||
// true when timer reaches 0
|
||||
if(this->playerObjects[i]->deathTimerTick(deltaTime))
|
||||
RespawnPlayer(this->playerObjects[i]);
|
||||
}
|
||||
else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED)
|
||||
{
|
||||
this->playerObjects[i]->setDeathTimer(DEATH_TIMER);
|
||||
// HACK to avoid crasch. affected by tag is NULL
|
||||
//((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID
|
||||
Player* killer = this->playerObjects[i]->getAffectingPlayer();
|
||||
if(!killer) //if there is no killer then you commited suicide
|
||||
if(this->playerObjects[i]->getAffectingPlayer() != NULL)
|
||||
{
|
||||
killer = this->playerObjects[i];
|
||||
|
||||
}
|
||||
|
||||
if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD)
|
||||
{
|
||||
// true when timer reaches 0
|
||||
if(this->playerObjects[i]->deathTimerTick(deltaTime))
|
||||
RespawnPlayer(this->playerObjects[i]);
|
||||
}
|
||||
else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED)
|
||||
{
|
||||
this->playerObjects[i]->setDeathTimer(DEATH_TIMER);
|
||||
// HACK to avoid crasch. affected by tag is NULL
|
||||
//((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID
|
||||
Player* killer = this->playerObjects[i]->getAffectingPlayer();
|
||||
if(!killer) //if there is no killer then you commited suicide
|
||||
{
|
||||
killer = this->playerObjects[i];
|
||||
}
|
||||
((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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ Player::Player()
|
|||
Player::initPlayerData();
|
||||
this->weapon = NULL;
|
||||
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)
|
||||
|
@ -23,6 +25,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)
|
|||
this->weapon = new Weapon(2,this);
|
||||
Player::initPlayerData();
|
||||
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)
|
||||
|
@ -31,6 +35,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom
|
|||
this->weapon = new Weapon(2,this);
|
||||
Player::initPlayerData();
|
||||
this->teamID = teamID;
|
||||
this->playerScore.killScore = 0;
|
||||
this->playerScore.deathScore = 0;
|
||||
}
|
||||
|
||||
Player::~Player(void)
|
||||
|
@ -45,8 +51,6 @@ void Player::initPlayerData()
|
|||
{
|
||||
this->playerStats.hp = MAX_HP;
|
||||
this->playerStats.movementSpeed = BASIC_SPEED;
|
||||
this->playerScore.killScore = 0;
|
||||
this->playerScore.deathScore = 0;
|
||||
this->playerState = PLAYER_STATE_IDLE;
|
||||
this->lookDir = Oyster::Math::Float3(0,0,-1);
|
||||
|
||||
|
@ -309,7 +313,13 @@ void Player::Inactivate()
|
|||
{
|
||||
//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
|
||||
{
|
||||
return (Oyster::Math::Float3) this->rigidBody->GetState().centerPos;
|
||||
|
|
|
@ -82,6 +82,7 @@ namespace GameLogic
|
|||
bool IsIdle();
|
||||
|
||||
void Inactivate();
|
||||
void ResetPlayer( Oyster::Math::Float3 spawnPos);
|
||||
|
||||
Oyster::Math::Float3 GetPosition() const;
|
||||
Oyster::Math::Float3 GetLookDir() const;
|
||||
|
|
|
@ -25,6 +25,10 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::Net
|
|||
}
|
||||
GameClient::~GameClient()
|
||||
{
|
||||
if(this->player)
|
||||
{
|
||||
this->player->Inactivate();
|
||||
}
|
||||
this->isReady = false;
|
||||
this->character = L"char_orca.dan";
|
||||
this->alias = L"Unknown";
|
||||
|
|
Loading…
Reference in New Issue