From 8173f3818dcbddea9d87515f9ce8d51120a97ab7 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Wed, 18 Dec 2013 08:30:58 +0100 Subject: [PATCH] gamelogic update and added some level design elements teammanager, team, --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 2 +- Code/Game/GameLogic/AttatchmentMassDriver.h | 15 ++++ Code/Game/GameLogic/AttatchmentSocket.cpp | 4 + Code/Game/GameLogic/GameLogic.vcxproj | 4 + Code/Game/GameLogic/Level.cpp | 22 ++++- Code/Game/GameLogic/Level.h | 27 ++++++ Code/Game/GameLogic/Player.cpp | 40 +++------ Code/Game/GameLogic/Player.h | 28 ++++-- Code/Game/GameLogic/Team.cpp | 59 +++++++++++++ Code/Game/GameLogic/Team.h | 35 ++++++++ Code/Game/GameLogic/TeamManager.cpp | 96 +++++++++++++++++++++ Code/Game/GameLogic/TeamManager.h | 63 ++++++++++++++ Code/Game/GameLogic/Weapon.cpp | 12 ++- Code/Network/NetworkAPI/CustomNetProtocol.h | 2 +- Code/Network/NetworkAPI/NetworkClient.h | 2 +- 15 files changed, 372 insertions(+), 39 deletions(-) create mode 100644 Code/Game/GameLogic/Team.cpp create mode 100644 Code/Game/GameLogic/Team.h create mode 100644 Code/Game/GameLogic/TeamManager.cpp create mode 100644 Code/Game/GameLogic/TeamManager.h diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 15e799bf..cd2842e6 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -9,7 +9,7 @@ #include "NetworkClient.h" #include "L_inputClass.h" -#include "vld.h" +//#include "vld.h" namespace DanBias { diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h index 2fac7be4..4c4fc124 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.h +++ b/Code/Game/GameLogic/AttatchmentMassDriver.h @@ -18,9 +18,24 @@ namespace GameLogic void UseAttatchment(const WEAPON_FIRE &fireInput); private: + /******************************************************** + * Pushes objects and players in a cone in front of the player + * @param fireInput: allows switching on different functionality in this specific function + ********************************************************/ void ForcePush(const WEAPON_FIRE &fireInput); + + /******************************************************** + * Pulls the player forward, this is a movement tool + * @param fireInput: allows switching on different functionality in this specific function + ********************************************************/ void ForcePull(const WEAPON_FIRE &fireInput); + /******************************************************** + * Sucks objects towards the player, the player can then pick up an object and throw it as a projectile + * @param fireInput: allows switching on different functionality in this specific function + ********************************************************/ + void ForceSuck(const WEAPON_FIRE &fireInput); + private: struct PrivateData; PrivateData *myData; diff --git a/Code/Game/GameLogic/AttatchmentSocket.cpp b/Code/Game/GameLogic/AttatchmentSocket.cpp index 288a1a4e..5d997a45 100644 --- a/Code/Game/GameLogic/AttatchmentSocket.cpp +++ b/Code/Game/GameLogic/AttatchmentSocket.cpp @@ -26,6 +26,10 @@ AttatchmentSocket::AttatchmentSocket(void) AttatchmentSocket::~AttatchmentSocket(void) { + if (myData->attatchment) + { + delete myData->attatchment; + } } IAttatchment* AttatchmentSocket::GetAttatchment() diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index e0614e29..11ba6e82 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -180,6 +180,8 @@ + + @@ -193,6 +195,8 @@ + + diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 835062c1..f0d1b935 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -3,6 +3,8 @@ #include "DynamicObject.h" #include "GameMode.h" #include "Player.h" +#include "PhysicsAPI.h" +#include "TeamManager.h" using namespace GameLogic; @@ -16,8 +18,7 @@ struct Level::PrivateData { } - Player *players; - int nrOfPlayers; + TeamManager *teamManager; StaticObject** staticObjects; int nrOfStaticObjects; @@ -27,6 +28,8 @@ struct Level::PrivateData GameMode* gameMode; + Oyster::Physics::ICustomBody *rigidBodyLevel; + }myData; Level::Level(void) @@ -45,4 +48,19 @@ void Level::InitiateLevel(std::string levelPath) } +void Level::AddPlayerToTeam(Player *player, int teamID) +{ + myData->teamManager->AddPlayerToTeam(player,teamID); +} + +void Level::CreateTeam(int teamSize) +{ + myData->teamManager->CreateTeam(teamSize); +} + +void Level::RespawnPlayer(Player *player) +{ + myData->teamManager->RespawnPlayerRandom(player); +} + diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 7177531b..fa450dc4 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -4,6 +4,7 @@ #ifndef LEVEL_H #define LEVEL_H #include +#include "Player.h" namespace GameLogic { @@ -15,8 +16,34 @@ namespace GameLogic Level(void); ~Level(void); + /******************************************************** + * Initiates a level for players to play on + * @param levelPath: Path to a file that contains all information on the level + ********************************************************/ void InitiateLevel(std::string levelPath); + /******************************************************** + * Creates a team in the level + * @param teamSize: The size of the team you want to create + ********************************************************/ + void CreateTeam(int teamSize); + + /******************************************************** + * Adds a player to a team + * @param player: The player you want to add to the team + * @param teamID: ArrayPos of the team you want to add the player to + ********************************************************/ + void AddPlayerToTeam(Player *player, int teamID); + + + /******************************************************** + * Respawns a player on a random teammate + * @param player: The player you want to respawn + ********************************************************/ + void RespawnPlayer(Player *player); + + private: + private: struct PrivateData; PrivateData *myData; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index bae54e9a..b17a1b5b 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -13,6 +13,7 @@ struct Player::PrivateData weapon = new Weapon(); life = 100; + teamID = -1; playerState = PLAYER_STATE_IDLE; lookDir = Oyster::Math::Float3(1,0,0); @@ -27,6 +28,7 @@ struct Player::PrivateData } int life; + int teamID; Weapon *weapon; PLAYER_STATE playerState; Oyster::Math::Float3 lookDir; @@ -44,20 +46,7 @@ Player::~Player(void) delete myData; } -/******************************************************** -* Updates the player(is this function needed?) -********************************************************/ -void Player::Update() -{ - -} - -/******************************************************** -* Moves the player based on client input -* Uses the physics to move the player by adding a force in the chosen direction -* Uses the Jump() function if the player is to jump, this is becuase jumping requires additional logic compared to normal movement -********************************************************/ void Player::Move(const PLAYER_MOVEMENT &movement) { Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity(); @@ -83,18 +72,20 @@ void Player::Move(const PLAYER_MOVEMENT &movement) break; } } -/******************************************************** -* Uses the players weapon based on user input -********************************************************/ + void Player::UseWeapon(const WEAPON_FIRE &fireInput) { myData->weapon->Use(fireInput); } -/******************************************************** -* Jumps if the player is currently not in a state of jumping -* Applies a force upwards(current upwards) -********************************************************/ +void Player::Respawn(Oyster::Math::Float3 spawnPoint) +{ + API::Instance().SetCenter(rigidBody,spawnPoint); + myData->life = 100; + myData->playerState = PLAYER_STATE_IDLE; + myData->lookDir = Oyster::Math::Float3(1,0,0); +} + void Player::Jump() { API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100); @@ -123,16 +114,11 @@ Oyster::Math::Float3 Player::GetLookDir() return myData->lookDir; } -/******************************************************** -* Respawns the player on a new chosen position -* This resets a set of variables such as life, ammo etcetc -********************************************************/ -void Player::Respawn() +int Player::GetTeamID() { - + return myData->teamID; } - void Player::DamageLife(int damage) { myData->life -= damage; diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index af0bff50..f6e61fa5 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -16,23 +16,39 @@ namespace GameLogic public: Player(void); ~Player(void); - - void Update(); + + /******************************************************** + * Moves the player based on input + * @param movement: enum value on what kind of action is to be taken + ********************************************************/ void Move(const PLAYER_MOVEMENT &movement); - void UseWeapon(const WEAPON_FIRE &fireInput); - void Jump(); + /******************************************************** + * Uses the weapon based on input + * @param fireInput: enum value on what kind of action is to be taken + ********************************************************/ + void UseWeapon(const WEAPON_FIRE &fireInput); + + /******************************************************** + * Respawns the player, this resets several stats and settings on the player + * @param spawnPoint: the coordinate in the world where the player is to spawn + ********************************************************/ + void Respawn(Oyster::Math::Float3 spawnPoint); + + bool IsWalking(); bool IsJumping(); bool IsIdle(); Oyster::Math::Float3 GetPos(); Oyster::Math::Float3 GetLookDir(); - - void Respawn(); + int GetTeamID(); void DamageLife(int damage); + private: + + void Jump(); private: struct PrivateData; PrivateData *myData; diff --git a/Code/Game/GameLogic/Team.cpp b/Code/Game/GameLogic/Team.cpp new file mode 100644 index 00000000..b0c28785 --- /dev/null +++ b/Code/Game/GameLogic/Team.cpp @@ -0,0 +1,59 @@ +#include "Team.h" +#include "Player.h" + +using namespace GameLogic; + +struct Team::PrivateData +{ + PrivateData() + { + players = 0; + nrOfPlayers = 0; + teamSize = 0; + } + ~PrivateData() + { + + } + + Player **players; + int nrOfPlayers; + + int teamSize; + +}myData; + +Team::Team(void) +{ + myData = new PrivateData(); +} + +Team::Team(int teamSize) +{ + myData = new PrivateData(); + myData->teamSize = teamSize; +} + + +Team::~Team(void) +{ + delete myData; +} + +Player* Team::GetPlayer(int playerID) +{ + return myData->players[playerID]; +} + +bool Team::AddPlayer(Player *player) +{ + if (myData->nrOfPlayers >= myData->teamSize) + { + return false; + } + else + { + myData->players[myData->nrOfPlayers] = player; + myData->nrOfPlayers++; + } +} diff --git a/Code/Game/GameLogic/Team.h b/Code/Game/GameLogic/Team.h new file mode 100644 index 00000000..ff0d5941 --- /dev/null +++ b/Code/Game/GameLogic/Team.h @@ -0,0 +1,35 @@ +////////////////////////////////////////////////// +//Created by Erik of the GameLogic team +////////////////////////////////////////////////// + +#ifndef TEAM_H +#define TEAM_H +namespace GameLogic +{ + + class Team + { + public: + Team(void); + Team(int teamSize); + ~Team(void); + + /******************************************************** + * Gets a player in the team + * @param playerID: Arrayposition of the player you want to get + ********************************************************/ + Player* GetPlayer(int playerID); + + /******************************************************** + * Adds a player to the team + * @param player: Player that are to be added + ********************************************************/ + bool AddPlayer(Player *player); + + private: + struct PrivateData; + PrivateData *myData; + }; +} +#endif + diff --git a/Code/Game/GameLogic/TeamManager.cpp b/Code/Game/GameLogic/TeamManager.cpp new file mode 100644 index 00000000..21a68394 --- /dev/null +++ b/Code/Game/GameLogic/TeamManager.cpp @@ -0,0 +1,96 @@ +#include "TeamManager.h" +#include "Team.h" + + +using namespace GameLogic; + +struct TeamManager::PrivateData +{ + PrivateData() + { + teams = 0; + nrOfTeams = 0; + } + ~PrivateData() + { + } + + Team **teams; + int nrOfTeams; + int maxNrOfTeams; + +}myData; + +TeamManager::TeamManager(void) +{ + myData = new PrivateData(); + myData->maxNrOfTeams = 10; + myData->teams = new Team*[myData->maxNrOfTeams]; +} + +TeamManager::TeamManager(int maxNrOfTeams) +{ + myData = new PrivateData(); + myData->maxNrOfTeams = maxNrOfTeams; + + myData->teams = new Team*[myData->maxNrOfTeams]; + for (int i = 0; i < myData->maxNrOfTeams; i++) + { + myData->teams[i] = 0; + } + +} + + +TeamManager::~TeamManager(void) +{ + delete myData; +} + +void TeamManager::RespawnPlayerRandom(Player *player) +{ + + int teamID = player->GetTeamID(); + + Player *respawnOnThis = myData->teams[teamID]->GetPlayer(0); + + player->Respawn(respawnOnThis->GetPos()); +} + +void TeamManager::CreateTeam(int teamSize) +{ + if (myData->nrOfTeams < myData->maxNrOfTeams) + { + myData->teams[myData->nrOfTeams] = new Team(teamSize); + myData->nrOfTeams++; + } +} + +void TeamManager::RemoveTeam(int teamID) +{ + +} + +bool TeamManager::AddPlayerToTeam(Player *player,int teamID) +{ + if (IsValidTeam(teamID)) + { + return myData->teams[teamID]->AddPlayer(player); + } + return false; +} + +bool TeamManager::AddPlayerToTeam(Player *player) +{ + +} + +bool TeamManager::IsValidTeam(int teamID) +{ + if (teamID < myData->nrOfTeams && teamID > 0 && myData->teams[teamID] != NULL) + { + return true; + } + + return false; +} \ No newline at end of file diff --git a/Code/Game/GameLogic/TeamManager.h b/Code/Game/GameLogic/TeamManager.h new file mode 100644 index 00000000..80715210 --- /dev/null +++ b/Code/Game/GameLogic/TeamManager.h @@ -0,0 +1,63 @@ +////////////////////////////////////////////////// +//Created by Erik of the GameLogic team +////////////////////////////////////////////////// + +#ifndef TEAMMANAGER_H +#define TEAMMANAGER_H +#include "Player.h" + +namespace GameLogic +{ + + class TeamManager + { + public: + TeamManager(void); + TeamManager(int maxNrOfTeams); + ~TeamManager(void); + + /******************************************************** + * Respawns the chosen player on a random teammember + * @param player: Pointer to the player you want to respawn + ********************************************************/ + void RespawnPlayerRandom(Player *player); + + /******************************************************** + * Creates a team that can hold players + * @param teamSize: The number of players that can fit in this team + ********************************************************/ + void CreateTeam(int teamSize); + + + /******************************************************** + * Removes the chosen team + * @param teamID: This is the array ID of the team you want to remove + ********************************************************/ + void RemoveTeam(int teamID); + + + /******************************************************** + * Adds a player to the teamID given + * @param player: Player that you want to add to a team + * @param teamID: The team you want to place the player in + ********************************************************/ + bool AddPlayerToTeam(Player *player ,int teamID); + + /******************************************************** + * Adds a player to the team with the least amount players + * @param player: Player that you want to add to a team + ********************************************************/ + bool AddPlayerToTeam(Player *player); + + /******************************************************** + * Checks if the team exists or not, returns true if yes + * @param teamID: ID of the team that are to exist or not + ********************************************************/ + bool IsValidTeam(int teamID); + + private: + struct PrivateData; + PrivateData *myData; + }; +} +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index e620e0d6..b2359ec7 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -49,6 +49,12 @@ Weapon::Weapon(int MaxNrOfSockets) Weapon::~Weapon(void) { + for (int i = 0; i < myData->currentNrOfAttatchments; i++) + { + delete myData->attatchmentSockets[i]; + } + delete[] myData->attatchmentSockets; + delete myData; } @@ -57,7 +63,11 @@ Weapon::~Weapon(void) ********************************************************/ void Weapon::Use(const WEAPON_FIRE &fireInput) { - myData->selectedAttatchment->UseAttatchment(fireInput); + if (myData->selectedAttatchment) + { + myData->selectedAttatchment->UseAttatchment(fireInput); + } + } /******************************************************** diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.h b/Code/Network/NetworkAPI/CustomNetProtocol.h index d25c23e5..82d92c99 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.h +++ b/Code/Network/NetworkAPI/CustomNetProtocol.h @@ -5,7 +5,7 @@ #define NETWORK_CUSTOM_NETWORK_PROTOCOL_H #include -#include +//#include #ifdef CUSTOM_NET_PROTOCOL_EXPORT #define NET_PROTOCOL_EXPORT __declspec(dllexport) diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index 95463d1c..e77667a8 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -12,7 +12,7 @@ #endif #include "NetworkCallbackHelper.h" -#include +//#include namespace Oyster {