diff --git a/Code/GameLogic/CollisionManager.cpp b/Code/GameLogic/CollisionManager.cpp new file mode 100644 index 00000000..5994dc89 --- /dev/null +++ b/Code/GameLogic/CollisionManager.cpp @@ -0,0 +1,47 @@ +#include "CollisionManager.h" + +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 new file mode 100644 index 00000000..8bbc06c7 --- /dev/null +++ b/Code/GameLogic/CollisionManager.h @@ -0,0 +1,31 @@ +#ifndef COLLISIONMANAGER_H +#define COLLISIONMANAGER_H + +#include "Object.h" +#include "PhysicsAPI.h" +#include "RefManager.h" +#include "DynamicObject.h" +#include "Player.h" + +namespace GameLogic +{ + + class CollisionManager + { + + public: + CollisionManager(void); + ~CollisionManager(void); + + private: + void ColisionEvent(Oyster::Physics::ICustomBody &obj1, Oyster::Physics::ICustomBody &obj2); + void PlayerVBox(Player &player, DynamicObject &box); + + private: + RefManager *refManager; + + }; + +} + +#endif \ No newline at end of file diff --git a/Code/GameLogic/DynamicObject.cpp b/Code/GameLogic/DynamicObject.cpp index bdb5be0c..303f9e7d 100644 --- a/Code/GameLogic/DynamicObject.cpp +++ b/Code/GameLogic/DynamicObject.cpp @@ -1,9 +1,13 @@ #include "DynamicObject.h" using namespace GameLogic; +using namespace Oyster::Physics; +using namespace Utility::DynamicMemory; DynamicObject::DynamicObject(void) { + rigidBody = API::Instance().CreateSimpleRigidBody(); + API::Instance().AddObject(rigidBody); } diff --git a/Code/GameLogic/DynamicObject.h b/Code/GameLogic/DynamicObject.h index 445b2e7b..5aa47d97 100644 --- a/Code/GameLogic/DynamicObject.h +++ b/Code/GameLogic/DynamicObject.h @@ -6,6 +6,7 @@ namespace GameLogic { + class DynamicObject : public Object { diff --git a/Code/GameLogic/Game.h b/Code/GameLogic/Game.h index 0b452b30..2d808388 100644 --- a/Code/GameLogic/Game.h +++ b/Code/GameLogic/Game.h @@ -8,21 +8,21 @@ namespace GameLogic { class Game { - private: + public: + Game(); + ~Game(); + + void Init(); + void StartGame(); + void Update(); + void Render(); private: Level* level; Player* player; - public: - Game(); - ~Game(); - void Init(); - void StartGame(); - void Update(); - void Render(); }; } #endif \ No newline at end of file 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 a3c9fa2e..6ee07df5 100644 --- a/Code/GameLogic/Object.h +++ b/Code/GameLogic/Object.h @@ -4,30 +4,40 @@ #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); - - Utility::DynamicMemory::UniquePointer model; + + 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 //rigidBody - unsigned int ref; - ::Utility::DynamicMemory::UniquePointer rigidBody; + Utility::DynamicMemory::UniquePointer rigidBody; + Utility::DynamicMemory::UniquePointer model; }; } diff --git a/Code/GameLogic/Player.cpp b/Code/GameLogic/Player.cpp index 131fb456..b67c889a 100644 --- a/Code/GameLogic/Player.cpp +++ b/Code/GameLogic/Player.cpp @@ -7,72 +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(); - - - } @@ -82,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.cpp b/Code/GameLogic/RefManager.cpp index 852cb6b1..022ec6bb 100644 --- a/Code/GameLogic/RefManager.cpp +++ b/Code/GameLogic/RefManager.cpp @@ -13,14 +13,14 @@ RefManager::~RefManager(void) { } -Object* RefManager::GetMap(Oyster::Physics::ICustomBody *body) +Object* RefManager::GetMap(Oyster::Physics::ICustomBody &body) { - return mapper[body]; + return mapper[&body]; } -void RefManager::AddMapping(Oyster::Physics::ICustomBody *body, Object *obj) +void RefManager::AddMapping(Oyster::Physics::ICustomBody &body, Object &obj) { - mapper.insert(mapData(body,obj)); + mapper.insert(mapData(&body,&obj)); } diff --git a/Code/GameLogic/RefManager.h b/Code/GameLogic/RefManager.h index 1d49af78..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 }; } diff --git a/Code/GameLogic/TestGLMain.cpp b/Code/GameLogic/TestGLMain.cpp index 5ca1ac1d..4bff2956 100644 --- a/Code/GameLogic/TestGLMain.cpp +++ b/Code/GameLogic/TestGLMain.cpp @@ -10,8 +10,16 @@ #include "Core/Core.h" #include "Render\Preparations\Preparations.h" #include "IGame.h" + #include "L_inputClass.h" +// debug window include +#include +#include +#include +#include + + //-------------------------------------------------------------------------------------- @@ -41,6 +49,34 @@ HRESULT CleanUp(); // Entry point to the program. Initializes everything and goes into a message processing // loop. Idle time is used to render the scene. //-------------------------------------------------------------------------------------- + +void SetStdOutToNewConsole() +{ + // allocate a console for this app + AllocConsole(); + + // redirect unbuffered STDOUT to the console + HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); + int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT); + FILE *fp = _fdopen( fileDescriptor, "w" ); + *stdout = *fp; + setvbuf( stdout, NULL, _IONBF, 0 ); + + // give the console window a nicer title + + SetConsoleTitle(L"Debug Output"); + + // give the console window a bigger buffer size + CONSOLE_SCREEN_BUFFER_INFO csbi; + if ( GetConsoleScreenBufferInfo(consoleHandle, &csbi) ) + { + COORD bufferSize; + bufferSize.X = csbi.dwSize.X; + bufferSize.Y = 50; + SetConsoleScreenBufferSize(consoleHandle, bufferSize); + } +} + int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ) { if( FAILED( InitWindow( hInstance, nCmdShow ) ) ) @@ -58,7 +94,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL __int64 prevTimeStamp = 0; QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp); - + SetStdOutToNewConsole(); // Main message loop MSG msg = {0}; while(WM_QUIT != msg.message) @@ -194,8 +230,28 @@ HRESULT InitGame() } HRESULT Update(float deltaTime) { - game->Update(); inputObj->Update(); + GameLogic::keyInput key = GameLogic::keyInput_none; + + if(inputObj->IsKeyPressed(DIK_W)) + { + key = GameLogic::keyInput_W; + } + else if(inputObj->IsKeyPressed(DIK_A)) + { + key = GameLogic::keyInput_A; + } + else if(inputObj->IsKeyPressed(DIK_S)) + { + key = GameLogic::keyInput_S; + } + else if(inputObj->IsKeyPressed(DIK_D)) + { + key = GameLogic::keyInput_D; + } + + game->Update(key); + return S_OK; } @@ -205,6 +261,7 @@ HRESULT Render(float deltaTime) if(inputObj->IsKeyPressed(DIK_A)) { isPressed = 1; + std::cout<<"knon"; } //Oyster::Graphics::Render::Rendering::Basic::NewFrame(); Oyster::Graphics::Render::Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,1,1));