Hey guys,
I've tried searching the forums for a solution, and I've found some helpful threads that have given me some clues as how the Intersect() function works, but I just can't get it to work.
I'm simply trying to get a block to stop moving when it collides with another, stationary block.
Here's the code:
float left1, left2, right1, right2, top1, top2, bottom1, bottom2;
left1 = Sprite.GetPosition().x;
left2 = Spr.GetPosition().x;
right1 = left1 - Sprite.GetSize().x;
right2 = left2 - Spr.GetSize().x;
top1 = Sprite.GetPosition().y;
top2 = Spr.GetPosition().y;
bottom1 = top1 + Sprite.GetSize().y;
bottom2 = top2 + Sprite.GetSize().y;
sf::FloatRect Rect(left1, top1, right1, bottom1);
sf::FloatRect Rect2(left2, top2, right2, bottom2);
// Get elapsed time
float ElapsedTime = App.GetFrameTime();
// Move the sprite
if(Rect.Intersects(Rect2))
{
cout << 1;
}
else
{
// Key
}
The collision of the two sprites just won't work, Sprite just runs through Spr.