diff --git a/Code/GameLogic/CollisionManager.cpp b/Code/GameLogic/CollisionManager.cpp index f7868b79..52eaa4f3 100644 --- a/Code/GameLogic/CollisionManager.cpp +++ b/Code/GameLogic/CollisionManager.cpp @@ -1,6 +1,6 @@ #include "CollisionManager.h" - +using namespace Oyster; namespace GameLogic { @@ -8,10 +8,10 @@ namespace GameLogic namespace CollisionManager { - void PlayerCollision(Oyster::Physics::ICustomBody &rigidBodyPlayer,Oyster::Physics::ICustomBody &obj) + Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj) { - Player *player = ((Player*)GameLogic::RefManager::getInstance()->GetMap(rigidBodyPlayer)); - Object *realObj = GameLogic::RefManager::getInstance()->GetMap(obj); + Player *player = ((Player*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyPlayer)); + Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj); switch (realObj->GetType()) { @@ -24,6 +24,7 @@ namespace GameLogic } //spela ljud? ta skada? etc etc + return Physics::ICustomBody::SubscriptMessage_none; } void PlayerVBox(Player &player, DynamicObject &box) @@ -31,10 +32,10 @@ namespace GameLogic //spela ljud? ta skada? etc etc } - void BoxCollision(Oyster::Physics::ICustomBody &rigidBodyBox, Oyster::Physics::ICustomBody &obj) + Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj) { - DynamicObject *box = ((DynamicObject*)GameLogic::RefManager::getInstance()->GetMap(rigidBodyBox)); - Object *realObj = GameLogic::RefManager::getInstance()->GetMap(obj); + DynamicObject *box = ((DynamicObject*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyBox)); + Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj); switch (realObj->GetType()) { @@ -45,6 +46,8 @@ namespace GameLogic PlayerVBox(*(Player*)realObj,*box); break; } + + return Physics::ICustomBody::SubscriptMessage_none; } } } \ No newline at end of file diff --git a/Code/GameLogic/CollisionManager.h b/Code/GameLogic/CollisionManager.h index a650f595..f88404cc 100644 --- a/Code/GameLogic/CollisionManager.h +++ b/Code/GameLogic/CollisionManager.h @@ -13,8 +13,9 @@ namespace GameLogic namespace CollisionManager { //these are the main collision functions - void PlayerCollision(Oyster::Physics::ICustomBody &rigidBodyPlayer,Oyster::Physics::ICustomBody &obj); - void BoxCollision(Oyster::Physics::ICustomBody &rigidBodyBox, Oyster::Physics::ICustomBody &obj); + //typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); + Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj); + Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj); //these are the specific collision case functions void PlayerVBox(Player &player, DynamicObject &box); diff --git a/Code/GameLogic/DynamicObject.cpp b/Code/GameLogic/DynamicObject.cpp index 14e0518d..3c7cfe21 100644 --- a/Code/GameLogic/DynamicObject.cpp +++ b/Code/GameLogic/DynamicObject.cpp @@ -1,12 +1,14 @@ #include "DynamicObject.h" +#include "CollisionManager.h" using namespace GameLogic; using namespace Oyster::Physics; using namespace Utility::DynamicMemory; -DynamicObject::DynamicObject(void) - :Object() +DynamicObject::DynamicObject(std::wstring objFile) + :Object(objFile) { + rigidBody->SetSubscription(CollisionManager::BoxCollision); } diff --git a/Code/GameLogic/DynamicObject.h b/Code/GameLogic/DynamicObject.h index 2d6ffdc8..7daf7345 100644 --- a/Code/GameLogic/DynamicObject.h +++ b/Code/GameLogic/DynamicObject.h @@ -16,7 +16,7 @@ namespace GameLogic { public: - DynamicObject(void); + DynamicObject(std::wstring objFile); ~DynamicObject(void); void Update(); diff --git a/Code/GameLogic/Game.cpp b/Code/GameLogic/Game.cpp index b4095130..7e54fcee 100644 --- a/Code/GameLogic/Game.cpp +++ b/Code/GameLogic/Game.cpp @@ -1,4 +1,5 @@ #include "Game.h" + using namespace GameLogic; Game::Game(void) @@ -26,7 +27,13 @@ Game::~Game(void) void Game::Init() { - player = new Player(); + //Oyster::Physics::API::SetSubscription("remove object"); + + player = new Player(L"worldDummy"); + + box = new DynamicObject(L"crate"); + //poi + //box = new physcTestObj("box"); camera = new Camera(); } void Game::StartGame() @@ -60,9 +67,11 @@ void Game::Update(keyInput keyPressed, float pitch, float yaw) camera->Walk(0.1); } camera->UpdateViewMatrix(); + //poi Oyster::Physics::API::Update(); } void Game::Render() { Oyster::Graphics::API::NewFrame(camera->View(), camera->Proj()); player->Render(); + box->Render(); } \ No newline at end of file diff --git a/Code/GameLogic/Game.h b/Code/GameLogic/Game.h index 0a8a031a..b3ac07c3 100644 --- a/Code/GameLogic/Game.h +++ b/Code/GameLogic/Game.h @@ -21,6 +21,7 @@ namespace GameLogic private: Level* level; + DynamicObject* box; Player* player; Camera* camera; }; diff --git a/Code/GameLogic/Object.cpp b/Code/GameLogic/Object.cpp index 33679058..a1f03da3 100644 --- a/Code/GameLogic/Object.cpp +++ b/Code/GameLogic/Object.cpp @@ -12,15 +12,16 @@ using namespace Oyster::Graphics::Model; using namespace Utility::DynamicMemory; using namespace Oyster::Physics; -Object::Object(void) +Object::Object(std::wstring objFile) { - model = new Model(); - model = Oyster::Graphics::API::CreateModel(L"orca"); + //model = new Model(); + model = Oyster::Graphics::API::CreateModel(objFile); API::SimpleBodyDescription sbDesc; //sbDesc.centerPosition = + //poi ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this); diff --git a/Code/GameLogic/Object.h b/Code/GameLogic/Object.h index 767edb1f..1c1c2830 100644 --- a/Code/GameLogic/Object.h +++ b/Code/GameLogic/Object.h @@ -25,7 +25,7 @@ namespace GameLogic OBJECT_TYPE_PLAYER, OBJECT_TYPE_BOX, }; - Object(void); + Object(std::wstring objFile ); virtual ~Object(void); void Render(); diff --git a/Code/GameLogic/Player.cpp b/Code/GameLogic/Player.cpp index 93a83506..a7b80805 100644 --- a/Code/GameLogic/Player.cpp +++ b/Code/GameLogic/Player.cpp @@ -1,13 +1,15 @@ #include "Player.h" #include "OysterMath.h" +#include "CollisionManager.h" using namespace GameLogic; using namespace Oyster::Physics; -Player::Player(void) - :Object() +Player::Player(std::wstring objFile) + :Object( objFile ) { life = 100; + rigidBody->SetSubscription(CollisionManager::PlayerCollision); } Player::~Player(void) { @@ -16,6 +18,7 @@ Player::~Player(void) void Player::Update(keyInput keyPressed) { + if(keyPressed != keyInput_none) { Move(keyPressed); @@ -24,6 +27,7 @@ void Player::Update(keyInput keyPressed) void Player::Move(keyInput keyPressed) { + if(keyPressed == keyInput_A) { Oyster::Math::Float3 pos = this->rigidBody->GetCenter(); diff --git a/Code/GameLogic/Player.h b/Code/GameLogic/Player.h index 7c4045e3..a15319b3 100644 --- a/Code/GameLogic/Player.h +++ b/Code/GameLogic/Player.h @@ -17,7 +17,7 @@ namespace GameLogic { public: - Player(void); + Player(std::wstring objFile); ~Player(void); /******************************************************** diff --git a/Code/GameLogic/RefManager.cpp b/Code/GameLogic/RefManager.cpp index a119898c..cb3d099f 100644 --- a/Code/GameLogic/RefManager.cpp +++ b/Code/GameLogic/RefManager.cpp @@ -2,7 +2,7 @@ using namespace GameLogic; -typedef std::pair mapData; +typedef std::pair mapData; RefManager* RefManager::instance = 0; @@ -34,12 +34,12 @@ RefManager* RefManager::getInstance( ) return instance; } -Object* RefManager::GetMap(Oyster::Physics::ICustomBody &body) +Object* RefManager::GetMap(const Oyster::Physics::ICustomBody &body) { return mapper[&body]; } -void RefManager::AddMapping(Oyster::Physics::ICustomBody &body, Object &obj) +void RefManager::AddMapping( const Oyster::Physics::ICustomBody &body, Object &obj) { mapper.insert(mapData(&body,&obj)); } diff --git a/Code/GameLogic/RefManager.h b/Code/GameLogic/RefManager.h index b5fd91d2..a184e220 100644 --- a/Code/GameLogic/RefManager.h +++ b/Code/GameLogic/RefManager.h @@ -23,13 +23,13 @@ namespace GameLogic void Release(); - Object* GetMap(Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler - void AddMapping(Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value + Object* GetMap(const Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler + void AddMapping(const Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value private: static RefManager* instance; - std::map mapper; //mapper points a rigidBody to an actual game object + std::map mapper; //mapper points a rigidBody to an actual game object }; diff --git a/Code/GameLogic/StaticObject.cpp b/Code/GameLogic/StaticObject.cpp index 855ef645..da30a54e 100644 --- a/Code/GameLogic/StaticObject.cpp +++ b/Code/GameLogic/StaticObject.cpp @@ -2,7 +2,8 @@ using namespace GameLogic; -StaticObject::StaticObject(void) +StaticObject::StaticObject(std::wstring objFile) + :Object(objFile) { } diff --git a/Code/GameLogic/StaticObject.h b/Code/GameLogic/StaticObject.h index 07d23311..73ed30f1 100644 --- a/Code/GameLogic/StaticObject.h +++ b/Code/GameLogic/StaticObject.h @@ -15,7 +15,7 @@ namespace GameLogic { public: - StaticObject(void); + StaticObject(std::wstring objFile); ~StaticObject(void); }; diff --git a/Code/GameLogic/Weapon.cpp b/Code/GameLogic/Weapon.cpp index 2cbd4e71..1bbc5618 100644 --- a/Code/GameLogic/Weapon.cpp +++ b/Code/GameLogic/Weapon.cpp @@ -2,7 +2,8 @@ using namespace GameLogic; -Weapon::Weapon(void) +Weapon::Weapon(std::wstring objFile) + :Object(objFile) { } diff --git a/Code/GameLogic/Weapon.h b/Code/GameLogic/Weapon.h index e8d37a15..dcac1d02 100644 --- a/Code/GameLogic/Weapon.h +++ b/Code/GameLogic/Weapon.h @@ -15,7 +15,7 @@ namespace GameLogic { public: - Weapon(void); + Weapon(std::wstring objFile); ~Weapon(void); private: