|
Breakout Clone help
I am making a simple clone of Breakout as my first game. I have finished every aspect of the game and it is totally playable.
I have run into a problem with the collision detection.
Maps are stored in the m_iMapData[20][24] array.
Here is the code:
Phew... well I think you can see what my problem is. The ball sometimes will pass right through bricks, and has a problem colliding with diagnals.
Btw.. the bricks size is 32x16 and the ball is 8x8.
Can someone point me in the right direction? I would really appreciate it. Sorry for the big code post.
-BwuceWee
March 01, 2001 12:55 PM
Not sure if this is the problem or not, but I notice you aren''t basically doing this:
If ball direction is up then
If ball is touching brick then
Set direction down
If ball direction is down then
If ball is touching brick then
Set direction up
You should put an "else if" on the 4th line, otherwise if your ball IS moving up and collided, you''ll set the direction down and when it moves onto the next if statement the ball WILL be moving down and since it''s still touching a brick you''ll set it''s direction back up, which is the original direction to start with.
If ball direction is up then
If ball is touching brick then
Set direction down
If ball direction is down then
If ball is touching brick then
Set direction up
You should put an "else if" on the 4th line, otherwise if your ball IS moving up and collided, you''ll set the direction down and when it moves onto the next if statement the ball WILL be moving down and since it''s still touching a brick you''ll set it''s direction back up, which is the original direction to start with.
Also - notice your X direction testing - you've copied and pasted the code (obviously) but forgot to alter BALL_NEGATIVE_X (or whatever) to BALL_POSITIVE_X in the last if statement. This means you're doing the same test twice. Also see above post.
Andrew.
Edited by - adpeace on March 1, 2001 7:22:05 PM
Andrew.
Edited by - adpeace on March 1, 2001 7:22:05 PM
No. I think he''s having problems when the ball speed is increased...
Pixel by pixel, it''s easy. You just collision test every movement of the ball as it''s made... but when the ball speed dictates skipping a set number of pixels between redraws (say 8 pixels) when that speed dictates a number of pixels greater than the height or width of the ball, you find the ball is actually encased in the block during collision detection...
I believe that''s what he''s talking about because I''m having the same problem myself. I''m still working out the details but I haven''t got a solution yet. Right now, the best I can think of is to collision test for every pixel adjustment of the ball before actually calculating the placement, which admittedly seems like a waste of processor power, but what can be done to correct it...?
I believe that''s what BwuceWee is asking... Any ideas?
Regards,
Jumpster
BTW: BwuceWee... If that''s not what you''re wanting, let me know. I still personally would like to hear any ideas that may be presented though...
Pixel by pixel, it''s easy. You just collision test every movement of the ball as it''s made... but when the ball speed dictates skipping a set number of pixels between redraws (say 8 pixels) when that speed dictates a number of pixels greater than the height or width of the ball, you find the ball is actually encased in the block during collision detection...
I believe that''s what he''s talking about because I''m having the same problem myself. I''m still working out the details but I haven''t got a solution yet. Right now, the best I can think of is to collision test for every pixel adjustment of the ball before actually calculating the placement, which admittedly seems like a waste of processor power, but what can be done to correct it...?
I believe that''s what BwuceWee is asking... Any ideas?
Regards,
Jumpster
BTW: BwuceWee... If that''s not what you''re wanting, let me know. I still personally would like to hear any ideas that may be presented though...
Regards,JumpsterSemper Fi
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement