diff --git a/Klock_Trials_Of_time/Klock_Trials_Of_time/Game.cpp b/Klock_Trials_Of_time/Klock_Trials_Of_time/Game.cpp index d7ac348..fcde55f 100644 --- a/Klock_Trials_Of_time/Klock_Trials_Of_time/Game.cpp +++ b/Klock_Trials_Of_time/Klock_Trials_Of_time/Game.cpp @@ -101,6 +101,19 @@ void Game::Update() //Updates the active scene m_activeScene->Update(); + for (b2ContactEdge* ce = m_register->get(1).GetBody()->GetContactList(); ce; ce = ce->next) + { + b2Contact* c = ce->contact; + + if (c->IsTouching()) + { + std::cout << "bruh theres a collision\n"; + } + + } + + + } void Game::GUI() @@ -209,11 +222,9 @@ void Game::GamepadTrigger(XInputController * con) void Game::KeyboardHold() { - auto& tempPhysBod = ECS::GetComponent(0); //Grabs the ECS's physics body for the player - //auto& groundPhysBod = ECS::GetComponent(0); //Grabs the ECS's physics Body for the ground - //Change this to main player once the physics works properly + auto& tempPhysBod = ECS::GetComponent(1); //Grabs the ECS's physics body for the player b2Body* playerBody = tempPhysBod.GetBody(); @@ -225,12 +236,16 @@ void Game::KeyboardHold() bool isColliding = false; - if (playerBody->GetContactList() != 0) + for (b2ContactEdge* ce = m_register->get(1).GetBody()->GetContactList(); ce; ce = ce->next) { - isColliding = true; - } + b2Contact* c = ce->contact; + if (c->IsTouching()) + { + isColliding = true; + } + } if (Input::GetKey(Key::S)) { @@ -270,16 +285,21 @@ void Game::KeyboardDown() b2Body* playerBody = tempPhysBod.GetBody(); - - if (playerBody->GetContactList() != 0) + for (b2ContactEdge* ce = m_register->get(1).GetBody()->GetContactList(); ce; ce = ce->next) { - isColliding = true; + b2Contact* c = ce->contact; + + if (c->IsTouching()) + { + isColliding = true; + } + } if (Input::GetKeyDown(Key::W)) { if (isColliding == true) - playerBody->ApplyLinearImpulse(b2Vec2(0.f, 55555.f), b2Vec2(playerBody->GetPosition()), true) ; + playerBody->ApplyLinearImpulse(b2Vec2(0.f, 555000000055.f), b2Vec2(playerBody->GetPosition()), true) ; } m_activeScene->KeyboardDown(); diff --git a/Klock_Trials_Of_time/Klock_Trials_Of_time/Klock_Trials_Of_time.vcxproj b/Klock_Trials_Of_time/Klock_Trials_Of_time/Klock_Trials_Of_time.vcxproj index a0388f9..5cd0372 100644 --- a/Klock_Trials_Of_time/Klock_Trials_Of_time/Klock_Trials_Of_time.vcxproj +++ b/Klock_Trials_Of_time/Klock_Trials_Of_time/Klock_Trials_Of_time.vcxproj @@ -162,7 +162,6 @@ - diff --git a/Klock_Trials_Of_time/Klock_Trials_Of_time/Klock_Trials_Of_time.vcxproj.filters b/Klock_Trials_Of_time/Klock_Trials_Of_time/Klock_Trials_Of_time.vcxproj.filters index 46cbb75..8cc0b11 100644 --- a/Klock_Trials_Of_time/Klock_Trials_Of_time/Klock_Trials_Of_time.vcxproj.filters +++ b/Klock_Trials_Of_time/Klock_Trials_Of_time/Klock_Trials_Of_time.vcxproj.filters @@ -162,9 +162,6 @@ Header Files - - Header Files - diff --git a/Klock_Trials_Of_time/Klock_Trials_Of_time/Level1Scene.cpp b/Klock_Trials_Of_time/Klock_Trials_Of_time/Level1Scene.cpp index 309cf1e..50d4406 100644 --- a/Klock_Trials_Of_time/Klock_Trials_Of_time/Level1Scene.cpp +++ b/Klock_Trials_Of_time/Klock_Trials_Of_time/Level1Scene.cpp @@ -19,50 +19,8 @@ void Level1Scene::InitScene(float windowWidth, float windowHeight) //Sets up aspect ratio for the camera float aspectRatio = windowWidth / windowHeight; - //Setup box #1, entity 0 - { - //Create new Entity - auto entity = ECS::CreateEntity(); - //EntityIdentifier::MainPlayer(entity); - - //Add components - ECS::AttachComponent(entity); - ECS::AttachComponent(entity); - ECS::AttachComponent(entity); - //Sets up components - std::string fileName = "Klock_Png.png"; - ECS::GetComponent(entity).LoadSprite(fileName, 30, 50); - ECS::GetComponent(entity).SetPosition(vec3(0.f, 0.f, 99.f)); - //Grabs reference to various components - auto& tempSpr = ECS::GetComponent(entity); - auto& tempPhysBody = ECS::GetComponent(entity); - - //Physics body covers the entire sprite - float shrinkX = tempSpr.GetWidth() / 2.f; - float shrinkY = tempSpr.GetHeight() / 2.f; - - b2Body* tempBody; - b2BodyDef tempDef; - tempDef.type = b2_dynamicBody; - tempDef.fixedRotation = true; - tempDef.position.Set(float32(26.f), float32(50.f)); - - - tempBody = m_physicsWorld->CreateBody(&tempDef); - - tempPhysBody = PhysicsBody(tempBody, float(tempSpr.GetWidth()), float(tempSpr.GetHeight()), - vec2(0.f, 0.f), true); - - - //Sets up the identifier - ECS::SetIsMainPlayer(entity, true); - unsigned int bitHolder = EntityIdentifier::SpriteBit() | EntityIdentifier::TransformBit() | EntityIdentifier::PhysicsBit(); - ECS::SetUpIdentifier(entity, bitHolder, "Box1"); - } - - - //Background and Ground Object entity 1 + //Background and Ground Object entity 0 { //Create new entity auto entity = ECS::CreateEntity(); @@ -98,25 +56,62 @@ void Level1Scene::InitScene(float windowWidth, float windowHeight) vec2(0.f, (-tempSpr.GetHeight() / 16.f) * 6.f), false); - - //fixture definition - b2PolygonShape polygonShape; - b2FixtureDef myFixtureDef; - myFixtureDef.shape = &polygonShape; - myFixtureDef.density = 1; - myFixtureDef.friction = 1.f; - //Adds a fixture the size of the body - polygonShape.SetAsBox(tempSpr.GetWidth(), tempSpr.GetHeight() / 2.f, b2Vec2(0, 0), 0); - myFixtureDef.isSensor = true; - b2Fixture* footSensorFixture = tempPhysBody.GetBody()->CreateFixture(&myFixtureDef); - footSensorFixture->SetUserData((void*)3); - //Sets up the Identifier unsigned int bitHolder = EntityIdentifier::SpriteBit() | EntityIdentifier::TransformBit() | EntityIdentifier::PhysicsBit(); ECS::SetUpIdentifier(entity, bitHolder, "BackGround"); } - + //Setup klock, entity 1 + { + //Create new Entity + auto entity = ECS::CreateEntity(); + EntityIdentifier::MainPlayer(entity); + + //Add components + ECS::AttachComponent(entity); + ECS::AttachComponent(entity); + + ECS::AttachComponent(entity); + //Sets up components + std::string fileName = "Klock_png.png"; + ECS::GetComponent(entity).LoadSprite(fileName, 25, 25); + ECS::GetComponent(entity).SetPosition(vec3(0.f, 0.f, 97.f)); + //Grabs reference to various components + auto& tempSpr = ECS::GetComponent(entity); + auto& tempPhysBody = ECS::GetComponent(entity); + + //Physics body covers the entire sprite + float shrinkX = tempSpr.GetWidth() / 2.f; + float shrinkY = tempSpr.GetHeight() / 2.f; + + b2Body* tempBody; + b2BodyDef tempDef; + tempDef.type = b2_dynamicBody; + tempDef.position.Set(float32(26.f), float32(50.f)); + tempDef.fixedRotation = true; + + tempBody = m_physicsWorld->CreateBody(&tempDef); + + tempPhysBody = PhysicsBody(tempBody, float(tempSpr.GetWidth()), float(tempSpr.GetHeight()), + vec2(0.f, 0.f), true); + + //fixture definition + b2PolygonShape polygonShape; + b2FixtureDef myFixtureDef; + myFixtureDef.shape = &polygonShape; + myFixtureDef.density = 1; + myFixtureDef.friction = 1.f; + //Adds a fixture the size of the body + polygonShape.SetAsBox(tempSpr.GetWidth(), tempSpr.GetHeight() / 2.f, b2Vec2(0, 0), 0); + myFixtureDef.isSensor = true; + b2Fixture* footSensorFixture = tempPhysBody.GetBody()->CreateFixture(&myFixtureDef); + footSensorFixture->SetUserData((void*)3); + + + //Sets up the identifier + unsigned int bitHolder = EntityIdentifier::SpriteBit() | EntityIdentifier::TransformBit() | EntityIdentifier::PhysicsBit(); + ECS::SetUpIdentifier(entity, bitHolder, "Box1"); + } //Main Camera diff --git a/Klock_Trials_Of_time/Klock_Trials_Of_time/PhysicsBody.h b/Klock_Trials_Of_time/Klock_Trials_Of_time/PhysicsBody.h index 606f104..95c2894 100644 --- a/Klock_Trials_Of_time/Klock_Trials_Of_time/PhysicsBody.h +++ b/Klock_Trials_Of_time/Klock_Trials_Of_time/PhysicsBody.h @@ -61,7 +61,7 @@ class PhysicsBody void AddCollideID(unsigned int collideID); //Getters - b2FixtureDef* GetFixture() const; + //b2FixtureDef* GetFixture() const; //Get the Box2D physics body b2Body* GetBody() const;