From 13d6a062fc58cc9c801bfd94fa133bed4f11ce08 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 10:05:07 +0100 Subject: [PATCH 1/8] Added collision and weapon events and send them to client --- .../GameClient/GameClientState/GameState.cpp | 31 +++++++++++++ Code/Game/GameLogic/AttatchmentMassDriver.cpp | 10 ++++- Code/Game/GameLogic/CollisionManager.cpp | 3 +- Code/Game/GameLogic/Game.cpp | 4 ++ Code/Game/GameLogic/Game.h | 2 + Code/Game/GameLogic/GameAPI.h | 3 +- Code/Game/GameLogic/Level.cpp | 42 ++++++++++++------ Code/Game/GameProtocols/ObjectProtocols.h | 44 ++++++++++++++++++- .../GameProtocols/ProtocolIdentificationID.h | 1 + Code/Game/GameServer/GameSession.h | 1 + .../Implementation/GameSession_Gameplay.cpp | 5 +++ .../Implementation/GameSession_General.cpp | 1 + Code/Game/LevelLoader/ObjectDefines.h | 20 ++++++--- 13 files changed, 143 insertions(+), 24 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 7e8a0ee7..c5dd45c5 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -750,6 +750,15 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case GameLogic::PlayerAction::PlayerAction_Idle: player->playAnimation(L"idle", true); break; + + case GameLogic::WeaponAction::WeaponAction_PrimaryShoot: + break; + case GameLogic::WeaponAction::WeaponAction_SecondaryShoot: + break; + case GameLogic::WeaponAction::WeaponAction_Reload: + break; + + default: break; } @@ -757,6 +766,28 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } } return GameClientState::event_processed; + case protocol_Gameplay_ObjectCollision: + { + Protocol_ObjectCollision decoded(data); + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } + if( object ) + { + switch (decoded.collisionID) + { + case GameLogic::CollisionEvent::CollisionEvent_BasicCollision: + break; + default: + break; + } + } + } + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 62f3599e..13ef8fef 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -1,7 +1,7 @@ #include "AttatchmentMassDriver.h" #include "PhysicsAPI.h" #include "GameLogicStates.h" - +#include "Game.h" using namespace GameLogic; @@ -48,6 +48,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, { currentEnergy -= 90.0f; ForcePush(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_PrimaryShoot); } break; @@ -55,7 +57,9 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, if(currentEnergy >= 1.0f) { currentEnergy -= 1.0f; - ForcePull(usage,dt); + ForcePull(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot); } break; @@ -64,6 +68,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, { currentEnergy -= 90.0f; ForceZip(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_UtilityActivate); } break; } diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 3e931f8e..72057e2b 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -69,7 +69,8 @@ using namespace GameLogic; //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; } - + // send collision event message + ((Game*)&Game::Instance())->onCollisionEventFnc(player, CollisionEvent::CollisionEvent_BasicCollision); //return Physics::ICustomBody::SubscriptMessage_none; } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 5879bd86..87216b3b 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -188,6 +188,10 @@ void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) { this->onPickupEventFnc = functionPointer; } +void Game::SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) +{ + this->onCollisionEventFnc = functionPointer; +} bool Game::Initiate() { API::Instance().Init(); diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index abef28f4..28ad9772 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -87,6 +87,7 @@ namespace GameLogic void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override; void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override; + void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) override; bool Initiate() override; float GetFrameTime() const; @@ -108,6 +109,7 @@ namespace GameLogic GameEvent::ObjectDeadFunction onDeadFnc; GameEvent::AnimationEventFunction onActionEventFnc; GameEvent::PickupEventFunction onPickupEventFnc; + GameEvent::CollisionEventFunction onCollisionEventFnc; }; } diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 653fc26b..80b255bd 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -33,6 +33,7 @@ namespace GameLogic typedef void(*ObjectDeadFunction)(IObjectData* victim, IObjectData* killer, float seconds); // Callback method that sends killer and death timer typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer + typedef void(*CollisionEventFunction)(IObjectData*object, int collisionID); //etc... }; @@ -188,7 +189,7 @@ namespace GameLogic virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0; virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0; virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0; - + virtual void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) = 0; }; } diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 0f0ab632..40a2b55a 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -16,6 +16,7 @@ using namespace Oyster::Math; Level::Level(void) { + srand (time(NULL)); objID = 100; } Level::~Level(void) @@ -405,6 +406,15 @@ void Level::AddPlayerToTeam(Player *player, int teamID) } void Level::AddPlayerToGame(Player *player) { + for(int i = 0; i < (int)this->playerObjects.Size(); i++) + { + if (!this->playerObjects[i]) + { + this->playerObjects[i] = player; + return; + } + } + // if no free space, allocate a new spot this->playerObjects.Push(player); } void Level::RemovePlayerFromGame(Player *player) @@ -413,7 +423,7 @@ void Level::RemovePlayerFromGame(Player *player) { if ((Player*)this->playerObjects[i] == player) { - //this->playerObjects[i]. + this->playerObjects[i] = nullptr; } } } @@ -426,7 +436,8 @@ void Level::RespawnPlayer(Player *player) { //this->teamManager.RespawnPlayerRandom(player); - Float3 spawnPoint = spawnPoints[0]; + int i = rand() % spawnPoints.Size(); + Float3 spawnPoint = spawnPoints[i]; player->Respawn(spawnPoint); } void Level::Update(float deltaTime) @@ -434,19 +445,22 @@ void Level::Update(float deltaTime) // update lvl-things for(int i = 0; i < (int)this->playerObjects.Size(); i++) { - if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + if(this->playerObjects[i]) { - // 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 - 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 + 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 + 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 + } } } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 48fa71f7..9b469bbc 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -969,7 +969,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; } -//#define protocol_Gameplay_ObjectAction 369 + //#define protocol_Gameplay_ObjectAction 369 struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject { short objectID; @@ -1010,4 +1010,46 @@ namespace GameLogic private: Oyster::Network::CustomNetProtocol protocol; }; + //#define protocol_Gameplay_ObjectCollision 370 + struct Protocol_ObjectCollision :public Oyster::Network::CustomProtocolObject + { + short objectID; + int collisionID; + // TODO: maybe position, impact, and velocity + + Protocol_ObjectCollision() + { + this->protocol[0].value = protocol_Gameplay_ObjectCollision; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + + this->objectID = -1; + this->collisionID = -1; + } + Protocol_ObjectCollision(Oyster::Network::CustomNetProtocol& p) + { + this->objectID = p[1].value.netShort; + this->collisionID = p[2].value.netInt; + } + Protocol_ObjectCollision( int id, int collisionID) + { + this->protocol[0].value = protocol_Gameplay_ObjectCollision; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + + this->objectID = id; + this->collisionID = collisionID; + } + Oyster::Network::CustomNetProtocol GetProtocol() override + { + this->protocol[1].value = objectID; + this->protocol[2].value = collisionID; + return protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 95e10ba1..f4f2b136 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -72,6 +72,7 @@ #define protocol_Gameplay_ObjectDie 367 #define protocol_Gameplay_ObjectDisconnectPlayer 368 #define protocol_Gameplay_ObjectAction 369 +#define protocol_Gameplay_ObjectCollision 370 #define protocol_GameplayMAX 399 diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 79b50395..d449ff2d 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -105,6 +105,7 @@ namespace DanBias static void ObjectDead ( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds ); static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID ); static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID ); + static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID ); //Private member variables private: Utility::DynamicMemory::DynamicArray gClients; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index fd000a0c..218721be 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -176,6 +176,11 @@ using namespace DanBias; // send action protocol GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol()); } + void GameSession::CollisionEvent( GameLogic::IObjectData* movedObject , int collisionID ) + { + // send action protocol + GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol()); + } //*****************************************************// //****************** Protocol methods *****************// //******************************************************************************************************************// diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index ca869fb7..d19fcecf 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -114,6 +114,7 @@ bool GameSession::Create(GameDescription& desc, bool forceStart) this->gameInstance.SetDeadSubscription(GameSession::ObjectDead); this->gameInstance.SetActionSubscription(GameSession::ActionEvent); this->gameInstance.SetPickupSubscription(GameSession::PickupEvent); + this->gameInstance.SetCollisionSubscription(GameSession::CollisionEvent); this->gameInstance.SetFPS(60); this->description.clients.Clear(); diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index 3eae71a5..e77174f7 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -95,16 +95,26 @@ namespace GameLogic enum PlayerAction { - PlayerAction_Jump, - PlayerAction_Walk, - PlayerAction_Idle, + PlayerAction_Jump = 0, + PlayerAction_Walk = 1, + PlayerAction_Idle = 2, }; + // continue ID counting from playerAction enum WeaponAction { - WeaponAtcion_PrimaryShoot, - WeaponAction_SecondaryShoot + WeaponAction_PrimaryShoot = 3, + WeaponAction_SecondaryShoot = 4, + WeaponAction_UtilityActivate = 5, + WeaponAction_Reload = 6, + WeaponAction_EnergyDepleted = 7, + }; + // TODO: add more collision Events + enum CollisionEvent + { + CollisionEvent_BasicCollision, + }; enum PickupType { PickupType_Health, From 8798fc90068c19ed4fe5b76a98f567b87f912edf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:22:08 +0100 Subject: [PATCH 2/8] Fixed static id not matching on client/server. --- Code/Game/GameLogic/Level.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 0f0ab632..e22c11b6 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -238,7 +238,11 @@ bool Level::InitiateLevel(std::wstring levelPath) { LevelMetaData* LevelObjData = ((LevelMetaData*)obj); std::string levelName = LevelObjData->levelName; + // LevelObjData->worldSize; + + //LevelMetaData is not an object. + --this->objID; } break; case ObjectType::ObjectType_Static: From 9ec3fc6fa40ead95f7f0cacb30eecdab87ce72cf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:22:43 +0100 Subject: [PATCH 3/8] Does not render non visible models anymore. --- Code/Game/GameClient/GameClientState/C_Object.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index b168b92c..8e84da8e 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -91,7 +91,10 @@ void C_Object::Render() { if( this->model ) { - Oyster::Graphics::API::RenderModel(model); + if(this->model->Visible) + { + Oyster::Graphics::API::RenderModel(model); + } } } void C_Object::Release() From 925f05b3b05d49be201c153f88bc77c4594c129a Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:23:38 +0100 Subject: [PATCH 4/8] Health pickups is now working! --- .../GameClient/GameClientState/GameState.cpp | 18 ++++++++++++--- Code/Game/GameLogic/CollisionManager.cpp | 20 ++++++++++++----- Code/Game/GameLogic/PickupSystem/Pickup.cpp | 1 + .../GameLogic/PickupSystem/PickupHealth.cpp | 4 ++++ Code/Game/GameLogic/Player.cpp | 22 ++++++++++++------- .../Implementation/GameSession_Gameplay.cpp | 2 +- Code/Game/LevelLoader/LevelParser.cpp | 8 +++++++ 7 files changed, 57 insertions(+), 18 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 7e8a0ee7..28c65b12 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -142,8 +142,8 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa this->privData->camera.SetPosition( p->getPos() ); Float3 offset = Float3( 0.0f ); // DEBUG position of camera so we can see the player model - offset.y = p->getScale().y * 5.0f; - offset.z = p->getScale().z * -5.0f; + //offset.y = p->getScale().y * 5.0f; + //offset.z = p->getScale().z * -5.0f; // !DEBUG this->privData->camera.SetHeadOffset( offset ); this->privData->camera.UpdateOrientation(); @@ -187,7 +187,7 @@ bool GameState::Render() { if(playerObject->second) { - //if( this->privData->myId != playerObject->second->GetId() ) + if( this->privData->myId != playerObject->second->GetId() ) { playerObject->second->Render(); } @@ -596,6 +596,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { // if it is not a player object = (*this->privData->dynamicObjects)[decoded.objectID]; + + if(!object) + { + //If it is a static object + object = (*this->privData->staticObjects)[decoded.objectID]; + } } if( object ) @@ -613,6 +619,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { // if it is not a player object = (*this->privData->dynamicObjects)[decoded.objectID]; + + if(!object) + { + //If it is a static object + object = (*this->privData->staticObjects)[decoded.objectID]; + } } if( object ) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 3e931f8e..187d592c 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -44,7 +44,6 @@ using namespace GameLogic; realObjB = realObjA; } - switch (realObjB->GetObjectType()) { case ObjectSpecialType::ObjectSpecialType_Generic: @@ -368,14 +367,19 @@ using namespace GameLogic; Object* a = (Object*)objA->GetCustomTag(); Object* b = (Object*)objB->GetCustomTag(); - if(!a) + if(!a) return; - if(!b) + if(!b) return; if(b->GetObjectType() == ObjectSpecialType_Player) { - ((Pickup*)a)->OnCollision((Player*)(b)); + //Only update if it is active. And if the player is alive + if(((Pickup*)a)->IsActive() && ((Player*)b)->GetState() != PLAYER_STATE_DEAD && ((Player*)b)->GetState() != PLAYER_STATE_DIED) + { + ((Pickup*)a)->OnCollision((Player*)(b)); + } + return; } else if(a->GetObjectType() != ObjectSpecialType_Player) { @@ -383,6 +387,10 @@ using namespace GameLogic; //Do nothing. return; } - - ((Pickup*)b)->OnCollision((Player*)a); + + //Only update if it is active. And if the player is alive + if(((Pickup*)b)->IsActive() && ((Player*)a)->GetState() != PLAYER_STATE_DEAD && ((Player*)a)->GetState() != PLAYER_STATE_DIED) + { + ((Pickup*)b)->OnCollision((Player*)a); + } } \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.cpp b/Code/Game/GameLogic/PickupSystem/Pickup.cpp index 73a319f8..a7bcaf14 100644 --- a/Code/Game/GameLogic/PickupSystem/Pickup.cpp +++ b/Code/Game/GameLogic/PickupSystem/Pickup.cpp @@ -9,6 +9,7 @@ Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisi this->active = true; this->spawnTime = spawnTime; timer.reset(); + this->GetRigidBody()->MoveToLimbo(); } Pickup::~Pickup() diff --git a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp index 56cbef1e..5473c44c 100644 --- a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp +++ b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp @@ -1,4 +1,5 @@ #include "PickupHealth.h" +#include "../Game.h" using namespace GameLogic; @@ -14,5 +15,8 @@ PickupHealth::~PickupHealth() void PickupHealth::OnCollision(Player *player) { timer.reset(); + ((Game*)&Game::Instance())->onDisableFnc(this); + + this->active = false; player->DamageLife(-hpValue); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index ddacf25b..9a440b2d 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -345,16 +345,22 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { - this->playerStats.hp -= damage; - // send hp to client - this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); - - if(this->playerStats.hp <= 0) + if(damage != 0) { - this->playerStats.hp = 0; - this->playerState = PLAYER_STATE_DIED; - } + this->playerStats.hp -= damage; + if(this->playerStats.hp > 100) + this->playerStats.hp = 100; + + // send hp to client + this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); + + if(this->playerStats.hp <= 0) + { + this->playerStats.hp = 0; + this->playerState = PLAYER_STATE_DIED; + } + } } void Player::AddAffectedObject(DynamicObject &AffectedObject) diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index fd000a0c..7887e858 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -152,7 +152,7 @@ using namespace DanBias; } void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject ) { - GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); + GameSession::gameSession->Send(Protocol_ObjectEnable(movedObject->GetID()).GetProtocol()); } void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp ) { diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp index 680b0358..f94513b0 100644 --- a/Code/Game/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -167,6 +167,14 @@ std::vector> LevelParser::Parse(std::string filen ParseObject(&buffer[counter], &header->healthValue, 4); counter += 4; + + // DEBUG + header->position[1] = 150; + header->spawnTime = 5; + header->boundingVolume.box.mass = 0; + header->typeID = ObjectType_Static; + header->healthValue = 50; + // !DEBUG objects.push_back(header); break; From 16ca665311e35090a95144c945b8db5eb7dc4bd0 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 11:09:24 +0100 Subject: [PATCH 5/8] Fixed deleting problems when shuting down --- Code/Game/GameLogic/Level.cpp | 116 +++--------------- Code/Game/GameLogic/Level.h | 11 +- Code/Game/GameLogic/Player.cpp | 6 +- .../GameServer/Implementation/GameClient.cpp | 3 - 4 files changed, 27 insertions(+), 109 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index d785a082..233e73da 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -17,12 +17,10 @@ using namespace Oyster::Math; Level::Level(void) { srand (time(NULL)); - objID = 100; + objIDCounter = 100; } Level::~Level(void) { - delete this->levelObj; - this->levelObj = NULL; } Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { @@ -32,7 +30,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { case ObjectSpecialType_None: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; @@ -50,22 +48,22 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float worldSize = ((WorldAttributes*)obj)->worldSize; float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize; - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Building: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Stone: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_StandardBox: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_RedExplosiveBox: @@ -73,7 +71,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) Oyster::Math::Float dmg = 120; Oyster::Math::Float force = 500; Oyster::Math::Float radie = 3; - gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); + gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter++, dmg, force, radie); } break; //case ObjectSpecialType_BlueExplosiveBox: @@ -82,24 +80,24 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) // break; case ObjectSpecialType_SpikeBox: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Spike: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_CrystalFormation: { int dmg = 50; //gameObj = new Crystal(rigidBody); - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_CrystalShard: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_JumpPad: @@ -107,39 +105,28 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float power = 500; //((JumpPadAttributes*)obj)->power; Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction; Oyster::Math::Float3 pushForce = dir * power; - gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID , pushForce); + gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter , pushForce); } break; case ObjectSpecialType_Portal: { Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination; - gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID, destination); - } - break; - //case ObjectSpecialType_SpawnPoint: - //{ - // save - - //} - break; - case ObjectSpecialType_Player: - { - // should not be read from the lvl format + gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter, destination); } break; case ObjectSpecialType_Generic: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_PickupHealth: { - gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objID, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue); + gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objIDCounter, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue); } break; default: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; } @@ -231,7 +218,7 @@ bool Level::InitiateLevel(std::wstring levelPath) for (int i = 0; i < objCount; i++) { - ++this->objID; + ++this->objIDCounter; ObjectTypeHeader* obj = objects.at(i); switch (obj->typeID) { @@ -243,7 +230,7 @@ bool Level::InitiateLevel(std::wstring levelPath) // LevelObjData->worldSize; //LevelMetaData is not an object. - --this->objID; + --this->objIDCounter; } break; case ObjectType::ObjectType_Static: @@ -338,71 +325,6 @@ bool Level::InitiateLevel(std::wstring levelPath) return true; } -bool Level::InitiateLevel(float radius) -{ - API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0)); - API::Instance().SetGravity(200); - int idCount = 100; - // add level sphere - ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - - levelObj = new StaticObject(rigidBody, LevelCollisionAfter, ObjectSpecialType_World, idCount++); - - //this->levelObj->objectID = idCount++; - rigidBody->SetCustomTag(levelObj); - - - ICustomBody* rigidBody_TestBox; - - int nrOfBoxex = 5; - int offset = 0; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(0.0f, 605.0f + i*5.0f, 10.0f), 5.0f, 0.5f, 0.8f, 0.6f); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++)); - } - /*offset += nrOfBoxex; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0,5, -605 -( i*5)), 5); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]); - - } - offset += nrOfBoxex; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(200, 620 + ( i*7), 0), 5); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]); - } - offset += nrOfBoxex; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(5, 605 + i*5, 0), 5); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); - - }*/ - - // add crystal - ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(10.0f, 605.0f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++)); - - // add house - ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20.0f, 20.0f, 20.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(-50.0f, 590.0f, 0.0f), 0.0f, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultOnCollision, ObjectSpecialType_Generic, idCount++)); - - // add jumppad - - ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1.0f, 1.0f, 1.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(4.0f, 600.3f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0))); - return true; -} void Level::AddPlayerToTeam(Player *player, int teamID) { @@ -490,7 +412,7 @@ void Level::PhysicsOnMoveLevel(const ICustomBody *object) Object* temp = (Object*)object->GetCustomTag(); ((Game*)&Game::Instance())->onMoveFnc(temp); } -Utility::DynamicMemory::DynamicArray> Level::GetPlayers() +Utility::DynamicMemory::DynamicArray Level::GetPlayers() { return this->playerObjects; } diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 7d6c25c9..876fd034 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -35,7 +35,6 @@ namespace GameLogic * @param levelPath: Path to a file that contains all information on the level ********************************************************/ bool InitiateLevel(std::wstring levelPath); - bool InitiateLevel(float radius); Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj); Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj); @@ -77,19 +76,19 @@ namespace GameLogic static void PlayerDied( Player* player ); static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object); - Utility::DynamicMemory::DynamicArray> GetPlayers(); + Utility::DynamicMemory::DynamicArray GetPlayers(); Utility::DynamicMemory::DynamicArray> GetStaticObjects(); Utility::DynamicMemory::DynamicArray> GetDynamicObject(); private: - Utility::DynamicMemory::DynamicArray> playerObjects; + Utility::DynamicMemory::DynamicArray playerObjects; TeamManager teamManager; Utility::DynamicMemory::DynamicArray> staticObjects; Utility::DynamicMemory::DynamicArray> dynamicObjects; GameModeType gameMode; - Utility::DynamicMemory::SmartPointer rigidBodyLevel; - StaticObject *levelObj; - int objID; + //Utility::DynamicMemory::SmartPointer rigidBodyLevel; +// //StaticObject *levelObj; + int objIDCounter; Utility::DynamicMemory::DynamicArray spawnPoints; PickupSystem pickupSystem; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 040e70be..550488bd 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -37,10 +37,10 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom Player::~Player(void) { - if(weapon) + if(this->weapon) { - delete weapon; - weapon = NULL; + delete this->weapon; + this->weapon = NULL; } } void Player::initPlayerData() diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 90b412ef..74795ce6 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -25,9 +25,6 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointerplayer) - this->player->Inactivate(); - this->isReady = false; this->character = L"char_orca.dan"; this->alias = L"Unknown"; From 934bc80b6212244e419f35547178dbd50c0c9953 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 11:53:33 +0100 Subject: [PATCH 6/8] InGame keys: Go to mainMenu with M. Exit client with ESC. Fix drop in drop out correctly. --- .../GameClient/GameClientState/GameState.cpp | 19 ++++++++++++++----- .../GameClient/GameClientState/GamingUI.cpp | 6 ++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 556ddf03..c65aa7b4 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -153,19 +153,28 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa GameClientState::ClientState GameState::Update( float deltaTime ) { - GameStateUI::UIState UIstate = this->currGameUI->Update( deltaTime ); + GameStateUI::UIState UIstate = this->gameUI->Update( deltaTime ); switch (UIstate) { + case DanBias::Client::GameStateUI::UIState_shut_down: + { + this->privData->nextState = ClientState_Quit; + // disconnect + } + + break; case DanBias::Client::GameStateUI::UIState_same: break; case DanBias::Client::GameStateUI::UIState_gaming: break; case DanBias::Client::GameStateUI::UIState_main_menu: - //this->privData->nextState = - break; - case DanBias::Client::GameStateUI::UIState_shut_down: - this->privData->nextState = ClientState_Quit; + { + this->privData->nextState = ClientState_Main; + // disconnect + } + break; + default: break; } diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 1486fdda..d12dfdb3 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -17,6 +17,7 @@ GamingUI::GamingUI() : this->camera = nullptr; this->plane = nullptr; this->text = nullptr; + this->nextState = GameStateUI::UIState_same; } GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *camera ) : @@ -25,6 +26,7 @@ GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 * this->input = input; this->netClient = connection; this->camera = camera; + this->nextState = GameStateUI::UIState_same; } GamingUI::~GamingUI() { /* Do nothing */ } @@ -169,6 +171,10 @@ void GamingUI::ReadKeyInput() { this->nextState = GameStateUI::UIState_shut_down; } + if( this->input->IsKeyPressed(DIK_M) ) + { + this->nextState = GameStateUI::UIState_main_menu; + } // !DEGUG KEYS // TODO: implement sub-menu } From 15df481dd30afe5dabc2ef9d5fa1c5851b25c8b8 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Wed, 26 Feb 2014 12:00:30 +0100 Subject: [PATCH 7/8] GL - merge stuff --- Code/Game/GameLogic/CollisionManager.cpp | 4 +- Code/Game/GameLogic/DynamicObject.cpp | 5 -- Code/Game/GameLogic/Level.cpp | 58 +++++++++++++++++++----- Code/Game/GameLogic/Player.cpp | 35 +++----------- Code/Game/GameLogic/Player.h | 7 +-- 5 files changed, 58 insertions(+), 51 deletions(-) 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 550488bd..e8787a1b 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 && this->playerState != PLAYER_STATE_DIED) { - weapon->Update(0.002f); + weapon->Update(0.002f); + + + Oyster::Math::Float maxSpeed = 30; @@ -214,16 +215,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) @@ -360,20 +351,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 c64ba066..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); @@ -104,8 +103,6 @@ namespace GameLogic void initPlayerData(); private: - - Utility::DynamicMemory::DynamicArray AffectedObjects; int teamID; Weapon *weapon; PLAYER_STATE playerState; @@ -122,7 +119,7 @@ namespace GameLogic float deathTimer; bool hasTakenDamage; - float invincibleCooldown; + Oyster::Math::Float RecentlyAffected; PlayerStats playerStats; PlayerScore playerScore; From 4cd91fadad7767b6fabd6b913646fbb4fe4fec0e Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 13:59:06 +0100 Subject: [PATCH 8/8] Found bug. Explosive box was increasing the ID. --- Code/Game/GameLogic/Level.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 56c0e21c..3fa39829 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -71,7 +71,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) Oyster::Math::Float dmg = 120; Oyster::Math::Float force = 500; Oyster::Math::Float radie = 3; - gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter++, dmg, force, radie); + gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter, dmg, force, radie); } break; //case ObjectSpecialType_BlueExplosiveBox: @@ -228,9 +228,6 @@ bool Level::InitiateLevel(std::wstring levelPath) std::string levelName = LevelObjData->levelName; // LevelObjData->worldSize; - - //LevelMetaData is not an object. - --this->objIDCounter; } break; case ObjectType::ObjectType_Static: