breakout clone

Started by
0 comments, last by shotgunnutter 16 years, 4 months ago
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; }
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.


I just wanted to see if he would actually do it. Also, this test will rule out any problems with system services.

This topic is closed to new replies.

Advertisement