Skip to content

Commit

Permalink
FIXED BALLS SHIT ASS COLLISION
Browse files Browse the repository at this point in the history
Collision no longer makes me want to die and now it just fucking CUMS
  • Loading branch information
noah-glassford committed Jan 30, 2020
1 parent 1ab902a commit a50ec5c
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 72 deletions.
40 changes: 30 additions & 10 deletions Klock_Trials_Of_time/Klock_Trials_Of_time/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ void Game::Update()
//Updates the active scene
m_activeScene->Update();

for (b2ContactEdge* ce = m_register->get<PhysicsBody>(1).GetBody()->GetContactList(); ce; ce = ce->next)
{
b2Contact* c = ce->contact;

if (c->IsTouching())
{
std::cout << "bruh theres a collision\n";
}

}



}

void Game::GUI()
Expand Down Expand Up @@ -209,11 +222,9 @@ void Game::GamepadTrigger(XInputController * con)
void Game::KeyboardHold()
{

auto& tempPhysBod = ECS::GetComponent<PhysicsBody>(0); //Grabs the ECS's physics body for the player


//auto& groundPhysBod = ECS::GetComponent<PhysicsBody>(0); //Grabs the ECS's physics Body for the ground
//Change this to main player once the physics works properly
auto& tempPhysBod = ECS::GetComponent<PhysicsBody>(1); //Grabs the ECS's physics body for the player

b2Body* playerBody = tempPhysBod.GetBody();

Expand All @@ -225,12 +236,16 @@ void Game::KeyboardHold()

bool isColliding = false;

if (playerBody->GetContactList() != 0)
for (b2ContactEdge* ce = m_register->get<PhysicsBody>(1).GetBody()->GetContactList(); ce; ce = ce->next)
{
isColliding = true;
}
b2Contact* c = ce->contact;

if (c->IsTouching())
{
isColliding = true;
}

}

if (Input::GetKey(Key::S))
{
Expand Down Expand Up @@ -270,16 +285,21 @@ void Game::KeyboardDown()

b2Body* playerBody = tempPhysBod.GetBody();


if (playerBody->GetContactList() != 0)
for (b2ContactEdge* ce = m_register->get<PhysicsBody>(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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@
<ClInclude Include="include\imgui\imstb_truetype.h" />
<ClInclude Include="Input.h" />
<ClInclude Include="JSON.h" />
<ClInclude Include="Level1Scene.h" />
<ClInclude Include="Matrix.h" />
<ClInclude Include="PhysicsBody.h" />
<ClInclude Include="PhysicsSystem.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@
<ClInclude Include="PhysicsTestScene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Level1Scene.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AnimationController.cpp">
Expand Down
109 changes: 52 additions & 57 deletions Klock_Trials_Of_time/Klock_Trials_Of_time/Level1Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Sprite>(entity);
ECS::AttachComponent<Transform>(entity);

ECS::AttachComponent<PhysicsBody>(entity);
//Sets up components
std::string fileName = "Klock_Png.png";
ECS::GetComponent<Sprite>(entity).LoadSprite(fileName, 30, 50);
ECS::GetComponent<Transform>(entity).SetPosition(vec3(0.f, 0.f, 99.f));
//Grabs reference to various components
auto& tempSpr = ECS::GetComponent<Sprite>(entity);
auto& tempPhysBody = ECS::GetComponent<PhysicsBody>(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();
Expand Down Expand Up @@ -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<Sprite>(entity);
ECS::AttachComponent<Transform>(entity);

ECS::AttachComponent<PhysicsBody>(entity);
//Sets up components
std::string fileName = "Klock_png.png";
ECS::GetComponent<Sprite>(entity).LoadSprite(fileName, 25, 25);
ECS::GetComponent<Transform>(entity).SetPosition(vec3(0.f, 0.f, 97.f));
//Grabs reference to various components
auto& tempSpr = ECS::GetComponent<Sprite>(entity);
auto& tempPhysBody = ECS::GetComponent<PhysicsBody>(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
Expand Down
2 changes: 1 addition & 1 deletion Klock_Trials_Of_time/Klock_Trials_Of_time/PhysicsBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a50ec5c

Please sign in to comment.