GL - players created with unique ids
This commit is contained in:
parent
af15157283
commit
c2ef8350cf
|
@ -68,12 +68,33 @@ void Game::GetAllPlayerPositions() const
|
||||||
Game::PlayerData* Game::CreatePlayer()
|
Game::PlayerData* Game::CreatePlayer()
|
||||||
{
|
{
|
||||||
// Find a free space in array or insert at end
|
// Find a free space in array or insert at end
|
||||||
int i = InsertObject(this->players, (PlayerData*)0);
|
int insert = InsertObject(this->players, (PlayerData*)0);
|
||||||
|
int freeID = 0;
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
this->players[i] = new PlayerData();
|
for(int i = 0; i < 100; i++)
|
||||||
this->players[i]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove);
|
{
|
||||||
|
found = true;
|
||||||
|
freeID = i;
|
||||||
|
|
||||||
return this->players[i];
|
for(int j = 0; j < players.Size(); j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(this->players[j] && this->players[j]->GetID() == freeID)
|
||||||
|
{
|
||||||
|
found = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!found) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(found) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->players[insert] = new PlayerData(freeID, 0); // user constructor with objectID and teamID
|
||||||
|
this->players[insert]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove);
|
||||||
|
|
||||||
|
return this->players[insert];
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::LevelData* Game::CreateLevel(const wchar_t mapName[255])
|
Game::LevelData* Game::CreateLevel(const wchar_t mapName[255])
|
||||||
|
@ -95,21 +116,15 @@ bool Game::NewFrame()
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < this->players.Size(); i++)
|
for (unsigned int i = 0; i < this->players.Size(); i++)
|
||||||
{
|
{
|
||||||
if(this->players[i]->player) this->players[i]->player->BeginFrame();
|
if(this->players[i] && this->players[i]->player) this->players[i]->player->BeginFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
API::Instance().UpdateWorld();
|
API::Instance().UpdateWorld();
|
||||||
|
|
||||||
for (unsigned int i = 0; i < this->players.Size(); i++)
|
for (unsigned int i = 0; i < this->players.Size(); i++)
|
||||||
{
|
{
|
||||||
if(this->players[i]->player) this->players[i]->player->EndFrame();
|
if(this->players[i] && this->players[i]->player) this->players[i]->player->EndFrame();
|
||||||
gameInstance.onMoveFnc(this->players[i]);
|
|
||||||
}
|
}
|
||||||
for (unsigned int i = 0; i < this->level->level->dynamicObjects.Size(); i++)
|
|
||||||
{
|
|
||||||
gameInstance.onMoveFnc(this->level->level->dynamicObjects[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,23 @@ Game::PlayerData::PlayerData()
|
||||||
rigidBody->SetAngularFactor(0.0f);
|
rigidBody->SetAngularFactor(0.0f);
|
||||||
//create player with this rigid body
|
//create player with this rigid body
|
||||||
this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player,0,0);
|
this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player,0,0);
|
||||||
|
|
||||||
//this->player->GetRigidBody()->SetCustomTag(this);
|
|
||||||
player->EndFrame();
|
|
||||||
}
|
}
|
||||||
Game::PlayerData::PlayerData(int playerID,int teamID)
|
Game::PlayerData::PlayerData(int playerID,int teamID)
|
||||||
{
|
{
|
||||||
this->player = new Player();
|
Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(50,130,0);
|
||||||
|
|
||||||
|
Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,2.0f,0.5f);
|
||||||
|
Oyster::Math::Float mass = 60;
|
||||||
|
Oyster::Math::Float restitutionCoeff = 0.5f;
|
||||||
|
Oyster::Math::Float frictionCoeff_Static = 0.4f;
|
||||||
|
Oyster::Math::Float frictionCoeff_Dynamic = 0.3f;
|
||||||
|
//sbDesc.quaternion = Oyster::Math::Float3(0, Oyster::Math::pi, 0);
|
||||||
|
|
||||||
|
//create rigid body
|
||||||
|
Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f );
|
||||||
|
rigidBody->SetAngularFactor(0.0f);
|
||||||
|
//create player with this rigid body
|
||||||
|
this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player,playerID,teamID);
|
||||||
}
|
}
|
||||||
Game::PlayerData::~PlayerData()
|
Game::PlayerData::~PlayerData()
|
||||||
{
|
{
|
||||||
|
|
|
@ -337,11 +337,7 @@ namespace Utility
|
||||||
|
|
||||||
template<typename ValueType>
|
template<typename ValueType>
|
||||||
inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max )
|
inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max )
|
||||||
{
|
{ return value < min ? Max( value, max ) : min; }
|
||||||
if( value < min ) return min;
|
|
||||||
if( value > max ) return max;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename ValueType>
|
template<typename ValueType>
|
||||||
inline ValueType Average( const ValueType &valueA, const ValueType &valueB )
|
inline ValueType Average( const ValueType &valueA, const ValueType &valueB )
|
||||||
|
|
Loading…
Reference in New Issue