1
General / I need help with this game i am trying to make.
« on: May 09, 2011, 07:49:01 pm »
Well I tried implementing your method actually :wink: but I think I've screwed up somewhere as my angle always goes towards the bottom left corner, which results in the opponent gaining a point Heres the code anyway:
Collision:
The bounce:
Thanks Dimple your the man
- Simon
Collision:
Code: [Select]
bool Collision (const sf::Sprite& a, const sf::Sprite& b)
{
int aX = a.GetPosition().x;
int bX = b.GetPosition().x;
int aY = a.GetPosition().y;
int bY = b.GetPosition().y;
int aW = a.GetSize().x;
int bW = b.GetSize().x;
int aH = a.GetSize().y;
int bH = b.GetSize().y;
if ((aX < (bX + bW)) && (aX + aW) > bX && (aY < (bY + bH)) && ((aY + aH) > bY))
{
return true;
}
return false;
}
The bounce:
Code: [Select]
// Check collision between Bat and ball
if (Collision(PlayerBat, Ball))
{
Ball.Move(cos((ballAngle/180)*PI) * ballSpeed, sin((ballAngle/180)*PI) * ballSpeed); // Move the ball
}
Thanks Dimple your the man
- Simon