Sign in to follow this  
davidcoell

breakout clone problem (again)

Recommended Posts

Hi, I'm really sorry to bring up the breakout collision problem again. I've had a look at the topics previously posted about the collision between the ball and the blocks and most of it just doesnt make any sense to me. i am new to programming so was wondering if someone could point me in the right direction. My math isnt that good so bare that in mind. I'm designing a 2D breakout clone and just want to know if theres any easy way to detect ball and brick collision. i have successfully managed collision with the bat and ball using sin and cos and putting the data into a array which i'm suprised i achieved but having no luck at all with the ball and brick collision, any help would be most appreciated, remember i'm a beginner....i'm using directx8...thanks

Share this post


Link to post
Share on other sites
well say if you have something like brickArray[25][20] (i picked 25x20 becasue 25 bricks can fit horizontaly and 20 bricks vertically if the bricks are 32x30 in a 800x600 resolution) now if you wanted to detect collisions with the bricks something like this should work ...



bool brickArray[25][20];
// after you have filled it with where you want your bricks

for (int y = 0; y < 20; y ++)
{
for (int x = 0; x < 25; x ++)
{
if (brickArray[x][y])
{
xNew = x * 25;
yNew = y * 20;
// then you can use a standard bounding box
// check to see if they collided
// now say if they collided ...
brickArray[25][20] = false;
}
}
}




so now if you draw them in the exact same way ... when you come to a brick that is false it wont be displayed.

hope this helped.

Share this post


Link to post
Share on other sites
Thanks but this wouldnt take into account the corners of the blocks and the ballspeed etc would it......

I was wondering if anyone knows some decent books on physics in games as i need to improve my knowledge in this area.

In the mean time anyone got anymore suggestions...

Thanks

Share this post


Link to post
Share on other sites
depends how square your blocks are and how fast your ball is going. is it going faster than a pixel per frame?

Share this post


Link to post
Share on other sites

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