I am trying to create a basic breakout game for one of my classes…i am having some troubles however with the last parts of the game. I cannot figure out how to make the ball bounce off of the brick and then the paddle and have the brick disappear. Any help would be greatly appreciated!!!
that kinda depence on the design of the rest of the program.
depending on which collision detection methode you use you should in the process of determing the collision get the 2 objects that collide (the ball and the brick) and where they collide, calculate in which direction the ball is suppose to go and then simply call the apporiate methodes on the 2 objects. (for example ball.setDirection(), and brick.destroy()
The bounce is very very basic physics… google “angle of reflection”
AS for removing the brick, as already said it depends on how you are doing screen updates to begin with. If iy were my game Id likely be doing active rendering and just re-draw all the bricks each frame. If you use an image for each color brick and just draw by BLT it will all egt cached on the graphcis card and shoudl be very very fast.
u.v = |U|*|V| * cos(theta)
But yeh, vector math is key.
@Jeff:
Although angle of reflection will work, it might not be applicable.
In the old pong game the reflection was based on what part of the paddle the ball landed on.
If it landed near the centre the ball bounced of normally. The farther out the greater the angle.
So it was shaped more like a lens then a paddle.
Otherwise the ball would allways fly at the same angles, or would it not?
Or am I getting something wrong?
@OverKill
you are right. Also some versions use the current movement of the paddle to bias the reflection vector.
Seriously guys. I use normal vector math on it and it works fine.
You can take into account the forces.
Acceleration of paddle and ball and gravity and so forth.
Don’t add gravity unless you want a very different game. In fact, for Arkanoid/Breakout, you don’t want to change the ball speed at all. “Simple” physics of reflecting the ball is sufficient for Arkanoid. Pong needed a more complicated physics arrangement (which wasn’t very realistic, BTW) because it needed a way to actually control the ball. Once a developer has basic physics down in his game, it’s quite easy to add the ability to deflect the ball by moving the paddle while it hits.