gamelogic update and added some level design elements

teammanager, team,
This commit is contained in:
Erik Persson 2013-12-18 08:30:58 +01:00
parent 77bc6050fc
commit 8173f3818d
15 changed files with 372 additions and 39 deletions

View File

@ -9,7 +9,7 @@
#include "NetworkClient.h"
#include "L_inputClass.h"
#include "vld.h"
//#include "vld.h"
namespace DanBias
{

View File

@ -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;

View File

@ -26,6 +26,10 @@ AttatchmentSocket::AttatchmentSocket(void)
AttatchmentSocket::~AttatchmentSocket(void)
{
if (myData->attatchment)
{
delete myData->attatchment;
}
}
IAttatchment* AttatchmentSocket::GetAttatchment()

View File

@ -180,6 +180,8 @@
<ClInclude Include="Object.h" />
<ClInclude Include="Player.h" />
<ClInclude Include="StaticObject.h" />
<ClInclude Include="Team.h" />
<ClInclude Include="TeamManager.h" />
<ClInclude Include="Weapon.h" />
</ItemGroup>
<ItemGroup>
@ -193,6 +195,8 @@
<ClCompile Include="Object.cpp" />
<ClCompile Include="Player.cpp" />
<ClCompile Include="StaticObject.cpp" />
<ClCompile Include="Team.cpp" />
<ClCompile Include="TeamManager.cpp" />
<ClCompile Include="Weapon.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -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);
}

View File

@ -4,6 +4,7 @@
#ifndef LEVEL_H
#define LEVEL_H
#include <string>
#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;

View File

@ -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;

View File

@ -17,10 +17,24 @@ namespace GameLogic
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);
/********************************************************
* 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);
void Jump();
/********************************************************
* 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();
@ -28,11 +42,13 @@ namespace GameLogic
Oyster::Math::Float3 GetPos();
Oyster::Math::Float3 GetLookDir();
void Respawn();
int GetTeamID();
void DamageLife(int damage);
private:
void Jump();
private:
struct PrivateData;
PrivateData *myData;

View File

@ -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++;
}
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}
@ -56,10 +62,14 @@ Weapon::~Weapon(void)
* Uses the weapon based on the input given and the current chosen attatchment
********************************************************/
void Weapon::Use(const WEAPON_FIRE &fireInput)
{
if (myData->selectedAttatchment)
{
myData->selectedAttatchment->UseAttatchment(fireInput);
}
}
/********************************************************
* Specific weapon usage implementation
********************************************************/

View File

@ -5,7 +5,7 @@
#define NETWORK_CUSTOM_NETWORK_PROTOCOL_H
#include <string>
#include <vld.h>
//#include <vld.h>
#ifdef CUSTOM_NET_PROTOCOL_EXPORT
#define NET_PROTOCOL_EXPORT __declspec(dllexport)

View File

@ -12,7 +12,7 @@
#endif
#include "NetworkCallbackHelper.h"
#include <vld.h>
//#include <vld.h>
namespace Oyster
{