GL - merge stuff

This commit is contained in:
Erik Persson 2014-02-26 12:00:30 +01:00 committed by Dander7BD
parent 7d7d475499
commit 977920b360
5 changed files with 58 additions and 52 deletions

View File

@ -255,16 +255,18 @@ using namespace GameLogic;
{ {
//realobjA is the affectedObject, transfer this to realobjB //realobjA is the affectedObject, transfer this to realobjB
realObjB->SetAffectedBy(*realObjA->getAffectingPlayer()); realObjB->SetAffectedBy(*realObjA->getAffectingPlayer());
return;
} }
if(realObjB->getAffectingPlayer() != NULL && realObjA->getAffectingPlayer() == NULL) if(realObjB->getAffectingPlayer() != NULL && realObjA->getAffectingPlayer() == NULL)
{ {
//realobjB is the affectedObject, transfer this to realobjA //realobjB is the affectedObject, transfer this to realobjA
realObjA->SetAffectedBy(*realObjB->getAffectingPlayer()); realObjA->SetAffectedBy(*realObjB->getAffectingPlayer());
return;
} }
if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL) if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL && ( realObjA->getAffectingPlayer()->GetID() != realObjB->getAffectingPlayer()->GetID()))
{ {
//Both objects have a player affecting them, now use the special case //Both objects have a player affecting them, now use the special case
if(realObjA->GetRigidBody()->GetState().previousVelocity.GetMagnitude() > realObjB->GetRigidBody()->GetState().previousVelocity.GetMagnitude() ) if(realObjA->GetRigidBody()->GetState().previousVelocity.GetMagnitude() > realObjB->GetRigidBody()->GetState().previousVelocity.GetMagnitude() )

View File

@ -90,11 +90,6 @@ void DynamicObject::Activate()
void DynamicObject::SetAffectedBy(Player &player) void DynamicObject::SetAffectedBy(Player &player)
{ {
this->affectedBy = &player; this->affectedBy = &player;
if(this->type != ObjectSpecialType::ObjectSpecialType_Player) //should not add itself to its own list if its a player
{
player.AddAffectedObject(*this);
}
} }
Player* DynamicObject::getAffectingPlayer() Player* DynamicObject::getAffectingPlayer()

View File

@ -369,10 +369,15 @@ void Level::RespawnPlayer(Player *player)
void Level::Update(float deltaTime) void Level::Update(float deltaTime)
{ {
// update lvl-things // update lvl-things
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]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD)
{ {
// true when timer reaches 0 // true when timer reaches 0
@ -383,9 +388,40 @@ void Level::Update(float deltaTime)
{ {
this->playerObjects[i]->setDeathTimer(DEATH_TIMER); this->playerObjects[i]->setDeathTimer(DEATH_TIMER);
// HACK to avoid crasch. affected by tag is NULL // 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(); Player* killer = this->playerObjects[i]->getAffectingPlayer();
((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID if(!killer) //if there is no killer then you commited suicide
//((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID {
killer = this->playerObjects[i];
}
((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID
}
}
for(int i = 0; i < dynamicObjects.Size(); i++)
{
if(dynamicObjects[i]->getAffectingPlayer() != NULL)
{
Oyster::Math::Float vel = dynamicObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude();
if(vel <= 0.1f) // is bearly moving
{
//set the tag AffectedBy to NULL
dynamicObjects[i]->RemoveAffectedBy();
}
}
}
for(int i = 0; i < playerObjects.Size(); i++)
{
if(playerObjects[i]->getAffectingPlayer() != NULL)
{
Oyster::Math::Float vel = playerObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude();
if(vel <= 0.1f) // is bearly moving
{
//set the tag AffectedBy to NULL
playerObjects[i]->RemoveAffectedBy();
} }
} }
} }

View File

@ -8,11 +8,11 @@ using namespace GameLogic;
using namespace Oyster::Physics; using namespace Oyster::Physics;
const float MOVE_FORCE = 30; const float MOVE_FORCE = 30;
const float KEY_TIMER = 0.03f; const float KEY_TIMER = 0.03f;
const float AFFECTED_TIMER = 1.0f;
Player::Player() Player::Player()
:DynamicObject() :DynamicObject()
{ {
Player::initPlayerData(); Player::initPlayerData();
AffectedObjects.Reserve(15);
this->weapon = NULL; this->weapon = NULL;
this->teamID = -1; this->teamID = -1;
} }
@ -22,7 +22,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)
{ {
this->weapon = new Weapon(2,this); this->weapon = new Weapon(2,this);
Player::initPlayerData(); Player::initPlayerData();
AffectedObjects.Reserve(15);
this->teamID = teamID; this->teamID = teamID;
} }
@ -31,7 +30,6 @@ 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();
AffectedObjects.Reserve(15);
this->teamID = teamID; this->teamID = teamID;
} }
@ -57,7 +55,7 @@ void Player::initPlayerData()
this->key_strafeRight = 0; this->key_strafeRight = 0;
this->key_strafeLeft = 0; this->key_strafeLeft = 0;
this->key_jump = 0; this->key_jump = 0;
this->invincibleCooldown = 0; this->RecentlyAffected = 0;
this->deathTimer = 0; this->deathTimer = 0;
this->rotationUp = 0; this->rotationUp = 0;
@ -69,6 +67,9 @@ void Player::BeginFrame()
{ {
weapon->Update(0.002f); weapon->Update(0.002f);
Oyster::Math::Float maxSpeed = 30; Oyster::Math::Float maxSpeed = 30;
// Rotate player accordingly // Rotate player accordingly
@ -217,16 +218,6 @@ void Player::BeginFrame()
void Player::EndFrame() void Player::EndFrame()
{ {
//check if there are any objects that can be removed from the AffectedObjects list
for(int i = 0; i < this->AffectedObjects.Size(); i++)
{
if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f)
{
this->AffectedObjects[i]->RemoveAffectedBy();
this->AffectedObjects.Remove(i);
}
}
} }
void Player::Move(const PLAYER_MOVEMENT &movement) void Player::Move(const PLAYER_MOVEMENT &movement)
@ -363,20 +354,6 @@ void Player::DamageLife(int damage)
} }
} }
void Player::AddAffectedObject(DynamicObject &AffectedObject)
{
//check if object already exists in the list, if so then do not add
for(int i = 0; i < AffectedObjects.Size(); i++)
{
if(AffectedObjects[i]->GetID() == AffectedObject.GetID())
{
//object already exists, exit function
return;
}
}
//else you add the object to the stack
AffectedObjects.Push(&AffectedObject);
}
bool Player::deathTimerTick(float dt) bool Player::deathTimerTick(float dt)
{ {
this->deathTimer -= dt; this->deathTimer -= dt;

View File

@ -68,8 +68,6 @@ namespace GameLogic
void TurnLeft(Oyster::Math3D::Float deltaRadians); void TurnLeft(Oyster::Math3D::Float deltaRadians);
void AddAffectedObject(DynamicObject &AffectedObject);
/******************************************************** /********************************************************
* Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody
* Will be called when the physics detect a collision * Will be called when the physics detect a collision
@ -90,6 +88,7 @@ namespace GameLogic
Oyster::Math::Float4x4 GetOrientation() const; Oyster::Math::Float4x4 GetOrientation() const;
int GetTeamID() const; int GetTeamID() const;
PLAYER_STATE GetState() const; PLAYER_STATE GetState() const;
Oyster::Math::Float GetRecentlyAffected();
void DamageLife(int damage); void DamageLife(int damage);
void setDeathTimer(float deathTimer); void setDeathTimer(float deathTimer);
@ -99,14 +98,11 @@ namespace GameLogic
void EndFrame(); void EndFrame();
static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
private: private:
void Jump(); void Jump();
void initPlayerData(); void initPlayerData();
private: private:
int teamID; int teamID;
Weapon *weapon; Weapon *weapon;
PLAYER_STATE playerState; PLAYER_STATE playerState;
@ -123,7 +119,7 @@ namespace GameLogic
float deathTimer; float deathTimer;
bool hasTakenDamage; bool hasTakenDamage;
float invincibleCooldown; Oyster::Math::Float RecentlyAffected;
PlayerStats playerStats; PlayerStats playerStats;
PlayerScore playerScore; PlayerScore playerScore;