Skip to content

Instantly share code, notes, and snippets.

@Saafan
Last active November 9, 2020 10:55
Show Gist options
  • Save Saafan/94225a318fad4fa1e11371f77ec633fb to your computer and use it in GitHub Desktop.
Save Saafan/94225a318fad4fa1e11371f77ec633fb to your computer and use it in GitHub Desktop.
Vec2 CharacterPoints[4];
void UpdateCollisionPoints()
{
//The 5s below is just a small buffer,
//Change them accordingly
CharacterPoints[0] = Vec2(posX - 5, posY - 5);
CharacterPoints[1] = Vec2(posX + character_Width + 5, posY - 5);
CharacterPoints[2] = Vec2(posX - 5, PosY + character_Height + 5);
CharacterPoints[3] = Vec2(posX + character_Width - 5, posY + chrachter_Height + 5);
}
bool CheckCollision()
{
for (size_t i = 0; i < num_of_lanes; i++)
{
for (size_t i = 0; i < 4 /* Change the Number accordingly */; i++)
{
if (lane.x < CharacterPoints[i].x && lane.x + lane_Segment_Width > CharacterPoints[i].x)
{
if (lane.y < CharacterPoints[i].y && lane.y + lane_Segment_Heigt > CharacterPoints[i].y)
{
return true; //return that It'll Collide
}
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment