Public Group

# breakout clone

This topic is 3866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am still working on a breakout clone and I am trying to get the ball to bounce of the paddle here is some of the code, I am very close to figuring it out I just need a little bit of help, let me know if you need more information // Reverse direction when you reach left or right edge if (x < -windowWidth || x > windowWidth - rsize) { if (x < -20.0f + i || x > 20.0f + rsize + i) { xstep = -xstep; } } // Reverse direction when you reach top or bottom edge if ((y < -windowHeight + rsize || y > windowHeight) || ( y - rsize < -90.0f)) { ystep = -ystep; }

##### Share on other sites
You can simplify the algorythm by working out the boundaries of each shape:

float ball_left , ball_right, ball_top, ball_bottom;

Then you need a series of comparisons, for example:

//ball is colliding with left side of paddle, reverse X direction

//ball is colliding with bottom of paddle, reverse y direction

and so on.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 37
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631414
• Total Posts
2999950
×