SFML community forums

Help => Graphics => Topic started by: marksie on June 18, 2016, 10:41:14 am

Title: Boundry Boxes on Shapes
Post by: marksie on June 18, 2016, 10:41:14 am
Hi all,

Yesterday I download SFML 2.3 and started writing my first pong game. However I am having some issues with Bounding Boxes when it comes to collision detection.

I have been using the tutorials that are provided so far. I can create two paddles and a ball. However the player movable Paddle goes off the screen when in reality I want it to stop. Looking at the bounding box example, I cant see how I would use this with screen coordinates. Any help would be appreciated.

I can see how to look for collisions between object (I think). But the paddle going off the screen is baffling me.

// get the bounding box of the entity
sf::FloatRect boundingBox = entity.getGlobalBounds();

// check collision with a point
sf::Vector2f point = ...;
if (boundingBox.contains(point))
{
    // collision!
}




 
Title: Re: Boundry Boxes on Shapes
Post by: Laurent on June 18, 2016, 01:08:30 pm
The algorithm is not that complicated, if you take 5 minutes to think about it outside your code.

if (paddle.top < 0)
    paddle.top = 0
else if (paddle.bottom > screen.height)
    paddle.bottom = screen.height

I let you turn this into valid code ;)