Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

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.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!