Thread: breakout style game collision detection

1. breakout style game collision detection

i have gotten the paddle to ball and the wall collisions working, but i can't get the ball to block collisions working good. I think the prob is because i am usualy moving the ball 5 units at a time. I am trying using a loop so if i move 5 units at a time i test for each 5 but only draw at the end, but this still does not work.
here is some of the code

Code:
for (i =0; i< 6; i++)
{
block_collision_detection();
textprintf(screen, font, 2,
ball.x += ball.x_speed/6;
ball.y += ball.y_speed/6;
}

void block_collision_detection()
{
int x,y;
for (x=0; x<SCRX/BLOCK_W; x++)
{
for (y=0; y<SCRY/BLOCK_H-2; y++)
{
if (map.block[x][y].active && BBCD(ball.bounding_box, map.block[x][y].bounding_box))
{
//find out which side of the block the bounce is on and bounce
if (!block_hit)
{
if (ball.bounding_box.bottom >= map.block[x][y].bounding_box.top && ball.bounding_box.bottom <= map.block[x][y].bounding_box.bottom && ball.bounding_box.left >= map.block[x][y].bounding_box.left && ball.bounding_box.right <= map.block[x][y].bounding_box.right) ball.bounce(TOP, xblip);
else if (ball.bounding_box.top <= map.block[x][y].bounding_box.bottom && ball.bounding_box.top >= map.block[x][y].bounding_box.top && ball.bounding_box.left >= map.block[x][y].bounding_box.left && ball.bounding_box.right <= map.block[x][y].bounding_box.right) ball.bounce(BOTTOM, xblip);
else ball.bounce(LEFT, xblip);

map.block[x][y].del();
block_hit = true;
}
}
}
}
return;
}

2. I've made a breakout-like game. It's on my homepage (named Ball), source code included.
It's not the best collision detection, especially not in higher velocities, but it works.
Basically, you split the block into 4 triangles and check which one the ball is in (when overlapping).
Code:
+------+
|\    /|
| \  / |
|  \/  |
|  /\  |
| /  \ |
|/    \|
+------+

3. you could try checking before the ball hits the block,

ie,

if(ball'snextposition >= block's min width/height etc., && <= blocks' max widh height etc.,)
bounce back the ball;

4. Originally posted by mickey
bounce back the ball;
In which direction then? If it's coming from the bottom right, 45 degrees straight at the corner of the block. Bounce down, or bounce right???

5. huh? it's upto you where you want the ball's next direction be??

6. Your algorithm only checks whether the ball overlaps the block or not, nothing of which direction it should bounce. The resulting direction may seem logical to an intelligent human, but not to a computer. Should you reverse DX? DY? Or both?

7. Maybe just check if the cooridiates of the ball and the range of the paddles' front side is the same