Brickmania: Revert to using intersection checks for testing if powerup hit

paddle

r24925 introduced a potential bug: the collision detection with the paddle is
not using the line intersection checks and consequently could cause the powerup
to be missed if the drop speed is fast enough (which varies depending on the
target because of the speed scaling).

Thanks for Karl Kurbjun for noticing and alerting!


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24934 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Tomer Shalev 2010-02-27 08:24:45 +00:00
parent 45a14f31d0
commit 66916c6d67

View file

@ -1533,6 +1533,13 @@ static int brickmania_game_loop(void)
if (brick_on_board==0) if (brick_on_board==0)
brick_on_board--; brick_on_board--;
/* Setup the pad line-later used in intersection test */
pad_line.p1.x = pad_pos_x;
pad_line.p1.y = PAD_POS_Y;
pad_line.p2.x = pad_pos_x + pad_width;
pad_line.p2.y = PAD_POS_Y;
if (game_state!=ST_PAUSE) if (game_state!=ST_PAUSE)
{ {
/* move the fires */ /* move the fires */
@ -1568,7 +1575,8 @@ static int brickmania_game_loop(void)
} }
} }
} }
/* move the powerups */
/* move and handle the powerups */
for (k=0;k<used_powers;k++) for (k=0;k<used_powers;k++)
{ {
int remove_power = 0; int remove_power = 0;
@ -1580,10 +1588,21 @@ static int brickmania_game_loop(void)
/* power hit bottom */ /* power hit bottom */
remove_power = 1; remove_power = 1;
} }
else if (power[k].top>PAD_POS_Y-POWERUP_HEIGHT && else
power[k].x_pos>=pad_pos_x &&
power[k].x_pos<pad_pos_x+pad_width)
{ {
/* Use misc_line to check if the center of the powerup
* hit the paddle.
*/
misc_line.p1.x = power[k].x_pos;
misc_line.p1.y = power[k].top;
misc_line.p2 = misc_line.p1;
misc_line.p2.y += SPEED_POWER;
/* Check if the powerup will hit the paddle */
if (check_lines(&misc_line, &pad_line, &pt_hit))
{
/* power hit paddle */ /* power hit paddle */
remove_power = 1; remove_power = 1;
switch(power[k].type) switch(power[k].type)
@ -1691,6 +1710,7 @@ static int brickmania_game_loop(void)
} }
} }
} }
}
/* draw the fires */ /* draw the fires */
for(k=0;k<used_fires;k++) for(k=0;k<used_fires;k++)
@ -1711,14 +1731,7 @@ static int brickmania_game_loop(void)
INT3(POWERUP_HEIGHT)); INT3(POWERUP_HEIGHT));
} }
/* Setup the pad line-later used in intersection test */ /* handle all of the bricks */
pad_line.p1.x = pad_pos_x;
pad_line.p1.y = PAD_POS_Y;
pad_line.p2.x = pad_pos_x + pad_width;
pad_line.p2.y = PAD_POS_Y;
/* handle all of the bricks/powerups */
for (i=0; i<NUM_BRICKS_ROWS; i++) for (i=0; i<NUM_BRICKS_ROWS; i++)
{ {
for (j=0; j<NUM_BRICKS_COLS ;j++) for (j=0; j<NUM_BRICKS_COLS ;j++)