From d87e643777655dbe189b20026aed4547e7c7a2e8 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 26 Nov 2013 11:30:49 +0100 Subject: [PATCH] =?UTF-8?q?lite=20saker=20+=20debug=20f=C3=B6nster?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/GameLogic/CollisionManager.cpp | 35 ++++++++++++++++ Code/GameLogic/CollisionManager.h | 5 ++- Code/GameLogic/Object.cpp | 5 +++ Code/GameLogic/Object.h | 14 ++++++- Code/GameLogic/Player.cpp | 65 ++--------------------------- Code/GameLogic/Player.h | 4 +- Code/GameLogic/RefManager.h | 8 ++-- 7 files changed, 62 insertions(+), 74 deletions(-) diff --git a/Code/GameLogic/CollisionManager.cpp b/Code/GameLogic/CollisionManager.cpp index 35b497d1..5994dc89 100644 --- a/Code/GameLogic/CollisionManager.cpp +++ b/Code/GameLogic/CollisionManager.cpp @@ -4,9 +4,44 @@ using namespace GameLogic; CollisionManager::CollisionManager(void) { + refManager = new RefManager(); } CollisionManager::~CollisionManager(void) { + SAFE_DELETE(refManager); } + +void CollisionManager::ColisionEvent(Oyster::Physics::ICustomBody &obj1, Oyster::Physics::ICustomBody &obj2) +{ + Object *realObj1 = refManager->GetMap(obj1); + Object *realObj2 = refManager->GetMap(obj2); + + + switch(realObj1->GetType()) + { + case Object::OBJECT_TYPE_PLAYER: + + if (realObj2->GetType() == Object::OBJECT_TYPE_BOX ) + { + PlayerVBox(*((Player*)realObj1),*((DynamicObject*)realObj2)); + } + + break; + case Object::OBJECT_TYPE_BOX: + + if (realObj2->GetType() == Object::OBJECT_TYPE_PLAYER) + { + PlayerVBox(*((Player*)realObj2),*((DynamicObject*)realObj1)); + } + + break; + } + +} + +void CollisionManager::PlayerVBox(Player &player, DynamicObject &box) +{ + //spela ljud? ta skada? etc etc +} \ No newline at end of file diff --git a/Code/GameLogic/CollisionManager.h b/Code/GameLogic/CollisionManager.h index f4418b3d..8bbc06c7 100644 --- a/Code/GameLogic/CollisionManager.h +++ b/Code/GameLogic/CollisionManager.h @@ -17,11 +17,12 @@ namespace GameLogic CollisionManager(void); ~CollisionManager(void); + private: void ColisionEvent(Oyster::Physics::ICustomBody &obj1, Oyster::Physics::ICustomBody &obj2); void PlayerVBox(Player &player, DynamicObject &box); - + private: - + RefManager *refManager; }; diff --git a/Code/GameLogic/Object.cpp b/Code/GameLogic/Object.cpp index 18c7f1c0..e9c8db7a 100644 --- a/Code/GameLogic/Object.cpp +++ b/Code/GameLogic/Object.cpp @@ -59,3 +59,8 @@ void Object::Render() model->info->Vertices.Apply(0); Oyster::Graphics::Core::deviceContext->Draw(model->info->VertexCount,0); } + +Object::OBJECT_TYPE Object::GetType() +{ + return this->type; +} diff --git a/Code/GameLogic/Object.h b/Code/GameLogic/Object.h index 193be4db..6ee07df5 100644 --- a/Code/GameLogic/Object.h +++ b/Code/GameLogic/Object.h @@ -4,23 +4,33 @@ #include "Model/Model.h" #include "Render/Rendering/Render.h" #include "Utilities.h" - #include "PhysicsAPI.h" namespace GameLogic { + class Object { + + public: Object(void); virtual ~Object(void); - + + enum OBJECT_TYPE + { + OBJECT_TYPE_PLAYER, + OBJECT_TYPE_BOX, + }; void Render(); + OBJECT_TYPE GetType(); + private: + OBJECT_TYPE type; protected: //either a model pointer or an ID to an arraypos filled with models that are to be rendered diff --git a/Code/GameLogic/Player.cpp b/Code/GameLogic/Player.cpp index bfd41757..b67c889a 100644 --- a/Code/GameLogic/Player.cpp +++ b/Code/GameLogic/Player.cpp @@ -7,73 +7,15 @@ using namespace Oyster::Physics; using namespace Utility::DynamicMemory; -//void ColisionEvent(unsigned int obj1Ref, unsigned int obj2Ref) -//{ -// const ICustomBody *body1 = &API::Instance().Peek( obj1Ref ); -// const ICustomBody *body2 = &API::Instance().Peek( obj2Ref ); -// if( body1 != &Error::nobody ) -// { -// Object *obj1 = (Object*) const_cast(body1); -// -// Object *obj2 = (Object*) const_cast(body2); -// -// //switch( obj1->type ) -// //{ -// //case Player: -// // switch (obj2->type) -// // { -// // case låda: -// // //action -// // //soud -// // //particle effect -// -// // } -// -// //case låda : -// -// -// //} -// } -// -//} -void DestructionEvent(unsigned int obj1, ::Utility::DynamicMemory::UniquePointer obj2) -{ -} Player::Player(void) :Object() { - life = 10; + life = 100; - UniquePointer rigidBody = API::Instance().CreateSimpleRigidBody(); + rigidBody = API::Instance().CreateSimpleRigidBody(); API::Instance().AddObject(rigidBody); - - ////ref = API::Instance().AddObject(API::Instance().CreateSimpleRigidBody()); - //const ICustomBody* rB; - - ////rB = &API::Instance().Peek(ref); - ////if( rB == &Error::nobody) - ////{ - //// //error - ////} - - //API::Instance().SetCenter(ref, Oyster::Math::Float3::null); - //API::Instance().SetMass_KeepMomentum(ref, 20); - //// get Tensor matrix (tröghetsmonent) - ////API::Instance().SetMomentOfInertiaTensor_KeepMomentum(ref, tensorMatrix ) - // - ////Oyster::Math::Float3 ve = rB->GetCenter(); - //API::Instance().SetDeltaTime(0.01f); - - ////API::Instance().ApplyForceAt(ref, rB->GetCenter(), Oyster::Math::Float3::null); - // - ////API::Instance().SetAction(ColisionEvent); - - ////API::Instance().Update(); - - - } @@ -83,8 +25,7 @@ Player::~Player(void) } void Player::Update() { - //API::Instance().API::Update(); - //API::Instance().API::ApplyForceAt(ref, ) + } void Player::Move() diff --git a/Code/GameLogic/Player.h b/Code/GameLogic/Player.h index 3747e9fe..39deb4b2 100644 --- a/Code/GameLogic/Player.h +++ b/Code/GameLogic/Player.h @@ -7,9 +7,7 @@ namespace GameLogic { - //void ColisionEvent(unsigned int obj1, unsigned int obj2); - void DestructionEvent(unsigned int obj1, ::Utility::DynamicMemory::UniquePointer obj2); - + class Player : public Object { diff --git a/Code/GameLogic/RefManager.h b/Code/GameLogic/RefManager.h index 2e1e9498..1aa51dc8 100644 --- a/Code/GameLogic/RefManager.h +++ b/Code/GameLogic/RefManager.h @@ -8,20 +8,18 @@ namespace GameLogic { - - class RefManager { public: RefManager(void); ~RefManager(void); - Object* GetMap(Oyster::Physics::ICustomBody &body); - void AddMapping(Oyster::Physics::ICustomBody &body, Object &obj); + 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 private: - std::map mapper; //shall be pointer from physics that map to an object + std::map mapper; //mapper points a rigidBody to an actual game object }; }