From 63addde51ed0bee33ddb4857e8f78e202ba8eee1 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 5 Dec 2013 11:50:39 +0100 Subject: [PATCH] made "interfaces" of most classes --- Code/Game/GameLogic/DynamicObject.cpp | 29 +++++++----- Code/Game/GameLogic/DynamicObject.h | 9 ++-- Code/Game/GameLogic/GameMode.cpp | 19 +++++++- Code/Game/GameLogic/GameMode.h | 3 +- Code/Game/GameLogic/Level.cpp | 30 +++++++++++++ Code/Game/GameLogic/Level.h | 17 +------- Code/Game/GameLogic/Player.cpp | 63 ++++++++++++--------------- Code/Game/GameLogic/Player.h | 20 +++------ Code/Game/GameLogic/StaticObject.cpp | 20 ++++++++- Code/Game/GameLogic/StaticObject.h | 9 ++-- Code/Game/GameLogic/Weapon.cpp | 19 +++++++- Code/Game/GameLogic/Weapon.h | 11 ++--- 12 files changed, 152 insertions(+), 97 deletions(-) diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 3c7cfe21..8786255c 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -1,22 +1,29 @@ #include "DynamicObject.h" -#include "CollisionManager.h" using namespace GameLogic; -using namespace Oyster::Physics; -using namespace Utility::DynamicMemory; -DynamicObject::DynamicObject(std::wstring objFile) - :Object(objFile) +struct DynamicObject::PrivateData { - rigidBody->SetSubscription(CollisionManager::BoxCollision); + PrivateData() + { + + } + + ~PrivateData() + { + + } + +}myData; + + +DynamicObject::DynamicObject() +{ + myData = new PrivateData(); } DynamicObject::~DynamicObject(void) { -} - -void DynamicObject::Update() -{ - //update object + delete myData; } \ No newline at end of file diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index 7daf7345..ecf1e905 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -6,21 +6,22 @@ #ifndef DYNAMICOBJECT_H #define DYNAMICOBJECT_H -#include "Object.h" - namespace GameLogic { - class DynamicObject : public Object + class DynamicObject { public: - DynamicObject(std::wstring objFile); + DynamicObject(); ~DynamicObject(void); void Update(); + private: + struct PrivateData; + PrivateData *myData; }; } diff --git a/Code/Game/GameLogic/GameMode.cpp b/Code/Game/GameLogic/GameMode.cpp index 0eddb7f9..bcd87de5 100644 --- a/Code/Game/GameLogic/GameMode.cpp +++ b/Code/Game/GameLogic/GameMode.cpp @@ -3,13 +3,28 @@ using namespace GameLogic; -GameMode::GameMode(void) +struct GameMode::PrivateData { + PrivateData() + { + } + + ~PrivateData() + { + + } + +}myData; + + +GameMode::GameMode() +{ + myData = new PrivateData(); } GameMode::~GameMode(void) { - + delete myData; } diff --git a/Code/Game/GameLogic/GameMode.h b/Code/Game/GameLogic/GameMode.h index 42273946..865f07c3 100644 --- a/Code/Game/GameLogic/GameMode.h +++ b/Code/Game/GameLogic/GameMode.h @@ -15,7 +15,8 @@ namespace GameLogic GameMode(void); ~GameMode(void); private: - //variabels that control what game rules the level runs on + struct PrivateData; + PrivateData *myData; }; } diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 32fbe2d5..c83056c6 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -1,12 +1,42 @@ #include "Level.h" +#include "StaticObject.h" +#include "DynamicObject.h" +#include "GameMode.h" using namespace GameLogic; +struct Level::PrivateData +{ + PrivateData() + { + gameMode = new GameMode(); + } + ~PrivateData() + { + if (gameMode) + { + delete gameMode; + } + } + + + StaticObject** staticObjects; + int nrOfStaticObjects; + + DynamicObject** dynamicObjects; + int nrOfDynamicObjects; + + GameMode* gameMode; + +}myData; + Level::Level(void) { + myData = new PrivateData(); } Level::~Level(void) { + delete myData; } diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index b43f193d..217a60e4 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -1,15 +1,9 @@ ////////////////////////////////////////////////// //Created by Erik and Linda of the GameLogic team ////////////////////////////////////////////////// - - #ifndef LEVEL_H #define LEVEL_H -#include "StaticObject.h" -#include "DynamicObject.h" -#include "GameMode.h" - namespace GameLogic { @@ -21,15 +15,8 @@ namespace GameLogic ~Level(void); private: - StaticObject** staticObjects; - int nrOfStaticObjects; - - DynamicObject** dynamicObjects; - int nrOfDynamicObjects; - - GameMode* gameMode; - - + struct PrivateData; + PrivateData *myData; }; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index a7b80805..6c514634 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -1,57 +1,48 @@ #include "Player.h" #include "OysterMath.h" #include "CollisionManager.h" +#include "Weapon.h" using namespace GameLogic; using namespace Oyster::Physics; -Player::Player(std::wstring objFile) - :Object( objFile ) +struct Player::PrivateData { - life = 100; - rigidBody->SetSubscription(CollisionManager::PlayerCollision); + PrivateData() + { + weapon = new Weapon(); + } + ~PrivateData() + { + if (weapon) + { + delete weapon; + } + } + + int life; + Weapon *weapon; + +}myData; + +Player::Player() +{ + myData = new PrivateData(); + } Player::~Player(void) { - delete this->rigidBody; + delete myData; } -void Player::Update(keyInput keyPressed) +void Player::Update() { - - if(keyPressed != keyInput_none) - { - Move(keyPressed); - } + } -void Player::Move(keyInput keyPressed) +void Player::Move() { - if(keyPressed == keyInput_A) - { - Oyster::Math::Float3 pos = this->rigidBody->GetCenter(); - pos.x -= 0.1; - rigidBody->SetCenter(pos); - } - if(keyPressed == keyInput_D) - { - Oyster::Math::Float3 pos = this->rigidBody->GetCenter(); - pos.x += 0.1; - rigidBody->SetCenter(pos); - } - if(keyPressed == keyInput_S) - { - Oyster::Math::Float3 pos = this->rigidBody->GetCenter(); - pos.y -= 0.1; - rigidBody->SetCenter(pos); - } - if(keyPressed == keyInput_W) - { - Oyster::Math::Float3 pos = this->rigidBody->GetCenter(); - pos.y += 0.1; - rigidBody->SetCenter(pos); - } } void Player::Shoot() { diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index a15319b3..439bbcd9 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -1,37 +1,29 @@ ////////////////////////////////////////////////// //Created by Erik and Linda of the GameLogic team ////////////////////////////////////////////////// - - #ifndef PLAYER_H #define PLAYER_H -#include "Object.h" -#include "Weapon.h" -#include "IGame.h" - - namespace GameLogic { - class Player : public Object + class Player { public: - Player(std::wstring objFile); + Player(void); ~Player(void); /******************************************************** * Update the position of the rigid body * This will be done with physics later ********************************************************/ - void Update(keyInput keyPressed); - - void Move(keyInput keyPressed); + void Update(); + void Move(); void Shoot(); private: - int life; - Weapon *weapon; + struct PrivateData; + PrivateData *myData; }; } #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp index da30a54e..c58fb83c 100644 --- a/Code/Game/GameLogic/StaticObject.cpp +++ b/Code/Game/GameLogic/StaticObject.cpp @@ -2,12 +2,28 @@ using namespace GameLogic; -StaticObject::StaticObject(std::wstring objFile) - :Object(objFile) +struct StaticObject::PrivateData { + PrivateData() + { + + } + + ~PrivateData() + { + + } + +}myData; + + +StaticObject::StaticObject() +{ + myData = new PrivateData(); } StaticObject::~StaticObject(void) { + delete myData; } diff --git a/Code/Game/GameLogic/StaticObject.h b/Code/Game/GameLogic/StaticObject.h index 73ed30f1..2f292795 100644 --- a/Code/Game/GameLogic/StaticObject.h +++ b/Code/Game/GameLogic/StaticObject.h @@ -11,13 +11,16 @@ namespace GameLogic { - class StaticObject : public Object + class StaticObject { public: - StaticObject(std::wstring objFile); + StaticObject(); ~StaticObject(void); - + + private: + struct PrivateData; + PrivateData *myData; }; } diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index 1bbc5618..c335ae7b 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -2,12 +2,27 @@ using namespace GameLogic; -Weapon::Weapon(std::wstring objFile) - :Object(objFile) +struct Weapon::PrivateData { + PrivateData() + { + + } + + ~PrivateData() + { + + } + +}myData; + +Weapon::Weapon() +{ + myData = new PrivateData(); } Weapon::~Weapon(void) { + delete myData; } diff --git a/Code/Game/GameLogic/Weapon.h b/Code/Game/GameLogic/Weapon.h index dcac1d02..527b0b73 100644 --- a/Code/Game/GameLogic/Weapon.h +++ b/Code/Game/GameLogic/Weapon.h @@ -1,25 +1,22 @@ ////////////////////////////////////////////////// //Created by Erik and Linda of the GameLogic team ////////////////////////////////////////////////// - - #ifndef WEAPON_H #define WEAPON_H -#include "Object.h" - namespace GameLogic { - class Weapon : public Object + class Weapon { public: - Weapon(std::wstring objFile); + Weapon(void); ~Weapon(void); private: - + struct PrivateData; + PrivateData *myData; }; }