diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 32f5bdc5..c355fd04 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -255,16 +255,18 @@ using namespace GameLogic; { //realobjA is the affectedObject, transfer this to realobjB realObjB->SetAffectedBy(*realObjA->getAffectingPlayer()); + return; } if(realObjB->getAffectingPlayer() != NULL && realObjA->getAffectingPlayer() == NULL) { //realobjB is the affectedObject, transfer this to realobjA 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 if(realObjA->GetRigidBody()->GetState().previousVelocity.GetMagnitude() > realObjB->GetRigidBody()->GetState().previousVelocity.GetMagnitude() ) diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 844deaf2..d785b4d4 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -90,11 +90,6 @@ void DynamicObject::Activate() void DynamicObject::SetAffectedBy(Player &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() diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 233e73da..56c0e21c 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -369,23 +369,59 @@ void Level::RespawnPlayer(Player *player) void Level::Update(float deltaTime) { // update lvl-things + + 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 + 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 { - // true when timer reaches 0 - if(this->playerObjects[i]->deathTimerTick(deltaTime)) - RespawnPlayer(this->playerObjects[i]); + killer = this->playerObjects[i]; } - else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + ((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 { - this->playerObjects[i]->setDeathTimer(DEATH_TIMER); - // HACK to avoid crasch. affected by tag is NULL - Player* killer = this->playerObjects[i]->getAffectingPlayer(); - ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID - //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID + //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(); } } } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 6682237f..1d95a83b 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -8,11 +8,11 @@ using namespace GameLogic; using namespace Oyster::Physics; const float MOVE_FORCE = 30; const float KEY_TIMER = 0.03f; +const float AFFECTED_TIMER = 1.0f; Player::Player() :DynamicObject() { Player::initPlayerData(); - AffectedObjects.Reserve(15); this->weapon = NULL; this->teamID = -1; } @@ -22,7 +22,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) { this->weapon = new Weapon(2,this); Player::initPlayerData(); - AffectedObjects.Reserve(15); this->teamID = teamID; } @@ -31,7 +30,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom { this->weapon = new Weapon(2,this); Player::initPlayerData(); - AffectedObjects.Reserve(15); this->teamID = teamID; } @@ -57,7 +55,7 @@ void Player::initPlayerData() this->key_strafeRight = 0; this->key_strafeLeft = 0; this->key_jump = 0; - this->invincibleCooldown = 0; + this->RecentlyAffected = 0; this->deathTimer = 0; this->rotationUp = 0; @@ -67,7 +65,10 @@ void Player::BeginFrame() { if( this->playerState != PLAYER_STATE_DEAD && PLAYER_STATE_DIED) { - weapon->Update(0.002f); + weapon->Update(0.002f); + + + Oyster::Math::Float maxSpeed = 30; @@ -217,16 +218,6 @@ void Player::BeginFrame() 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) @@ -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) { this->deathTimer -= dt; diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 2d6f0a35..edb4cc79 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -67,8 +67,6 @@ namespace GameLogic void SetLookDir(const Oyster::Math3D::Float3& lookDir); 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 @@ -90,6 +88,7 @@ namespace GameLogic Oyster::Math::Float4x4 GetOrientation() const; int GetTeamID() const; PLAYER_STATE GetState() const; + Oyster::Math::Float GetRecentlyAffected(); void DamageLife(int damage); void setDeathTimer(float deathTimer); @@ -99,14 +98,11 @@ namespace GameLogic void EndFrame(); static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); - private: void Jump(); void initPlayerData(); private: - - int teamID; Weapon *weapon; PLAYER_STATE playerState; @@ -123,7 +119,7 @@ namespace GameLogic float deathTimer; bool hasTakenDamage; - float invincibleCooldown; + Oyster::Math::Float RecentlyAffected; PlayerStats playerStats; PlayerScore playerScore;