Sign in to follow this  

breakout clone

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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;
float paddle_left, paddle_right, paddle_top, paddle_bottom;


Then you need a series of comparisons, for example:


if (ball_right > paddle_left)
//ball is colliding with left side of paddle, reverse X direction

if (ball_top < paddle_bottom)
//ball is colliding with bottom of paddle, reverse y direction


and so on.


Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this