mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
Wormlet: Fix food and argh possibly overlapping each other.
Flyspray: FS#10589 Author: Asael Reiter git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22724 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
d270452402
commit
ee28c8d711
1 changed files with 23 additions and 23 deletions
|
@ -348,6 +348,8 @@ CONFIG_KEYPAD == MROBE500_PAD
|
||||||
#define COLOR_BG LCD_RGBPACK(181, 199, 231)
|
#define COLOR_BG LCD_RGBPACK(181, 199, 231)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define CHECK_SQUARE_COLLISION(x1,y1,s1,x2,y2,s2) (x1+s1>x2)&&(x2+s2>x1)&&(y1+s1>y2)&&(y2+s2>y1)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the properties that a worm has.
|
* All the properties that a worm has.
|
||||||
*/
|
*/
|
||||||
|
@ -830,21 +832,19 @@ static void make_food(int index)
|
||||||
the entire food lies within the FIELD */
|
the entire food lies within the FIELD */
|
||||||
x = rb->rand() % (FIELD_RECT_WIDTH - food_size);
|
x = rb->rand() % (FIELD_RECT_WIDTH - food_size);
|
||||||
y = rb->rand() % (FIELD_RECT_HEIGHT - food_size);
|
y = rb->rand() % (FIELD_RECT_HEIGHT - food_size);
|
||||||
|
collisionDetected = false;
|
||||||
/* Ensure that the new food doesn't collide with any
|
/* Ensure that the new food doesn't collide with any
|
||||||
existing foods or arghs.
|
existing foods or arghs.
|
||||||
If one or more corners of the new food hit any existing
|
If the new food hit any existing
|
||||||
argh or food a collision is detected.
|
argh or food a collision is detected.
|
||||||
*/
|
*/
|
||||||
collisionDetected =
|
|
||||||
food_collision(x , y ) >= 0 ||
|
for (i=0; i<MAX_FOOD && !collisionDetected; i++) {
|
||||||
food_collision(x , y + food_size - 1) >= 0 ||
|
collisionDetected = CHECK_SQUARE_COLLISION(x,y,food_size,foodx[i],foody[i],food_size);
|
||||||
food_collision(x + food_size - 1, y ) >= 0 ||
|
}
|
||||||
food_collision(x + food_size - 1, y + food_size - 1) >= 0 ||
|
for (i=0; i<argh_count && !collisionDetected; i++) {
|
||||||
argh_collision(x , y ) >= 0 ||
|
collisionDetected = CHECK_SQUARE_COLLISION(x,y,food_size,arghx[i],arghy[i],argh_size);
|
||||||
argh_collision(x , y + food_size - 1) >= 0 ||
|
}
|
||||||
argh_collision(x + food_size - 1, y ) >= 0 ||
|
|
||||||
argh_collision(x + food_size - 1, y + food_size - 1) >= 0;
|
|
||||||
|
|
||||||
/* use coordinates for further testing */
|
/* use coordinates for further testing */
|
||||||
foodx[index] = x;
|
foodx[index] = x;
|
||||||
|
@ -853,7 +853,9 @@ static void make_food(int index)
|
||||||
/* now test wether we accidently hit the worm with food ;) */
|
/* now test wether we accidently hit the worm with food ;) */
|
||||||
i = 0;
|
i = 0;
|
||||||
for (i = 0; i < worm_count && !collisionDetected; i++) {
|
for (i = 0; i < worm_count && !collisionDetected; i++) {
|
||||||
collisionDetected |= worm_food_collision(&worms[i], index);
|
|
||||||
|
collisionDetected = worm_food_collision(&worms[i], index);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (collisionDetected);
|
while (collisionDetected);
|
||||||
|
@ -919,21 +921,19 @@ static void make_argh(int index)
|
||||||
the entire food lies within the FIELD */
|
the entire food lies within the FIELD */
|
||||||
x = rb->rand() % (FIELD_RECT_WIDTH - argh_size);
|
x = rb->rand() % (FIELD_RECT_WIDTH - argh_size);
|
||||||
y = rb->rand() % (FIELD_RECT_HEIGHT - argh_size);
|
y = rb->rand() % (FIELD_RECT_HEIGHT - argh_size);
|
||||||
|
collisionDetected = false;
|
||||||
/* Ensure that the new argh doesn't intersect with any
|
/* Ensure that the new argh doesn't intersect with any
|
||||||
existing foods or arghs.
|
existing foods or arghs.
|
||||||
If one or more corners of the new argh hit any existing
|
If the new argh hit any existing
|
||||||
argh or food an intersection is detected.
|
argh or food an intersection is detected.
|
||||||
*/
|
*/
|
||||||
collisionDetected =
|
|
||||||
food_collision(x , y ) >= 0 ||
|
for (i=0; i<MAX_FOOD && !collisionDetected; i++) {
|
||||||
food_collision(x , y + argh_size - 1) >= 0 ||
|
collisionDetected = CHECK_SQUARE_COLLISION(x,y,argh_size,foodx[i],foody[i],food_size);
|
||||||
food_collision(x + argh_size - 1, y ) >= 0 ||
|
}
|
||||||
food_collision(x + argh_size - 1, y + argh_size - 1) >= 0 ||
|
for (i=0; i<argh_count && !collisionDetected; i++) {
|
||||||
argh_collision(x , y ) >= 0 ||
|
collisionDetected = CHECK_SQUARE_COLLISION(x,y,argh_size,arghx[i],arghy[i],argh_size);
|
||||||
argh_collision(x , y + argh_size - 1) >= 0 ||
|
}
|
||||||
argh_collision(x + argh_size - 1, y ) >= 0 ||
|
|
||||||
argh_collision(x + argh_size - 1, y + argh_size - 1) >= 0;
|
|
||||||
|
|
||||||
/* use the candidate coordinates to make a real argh */
|
/* use the candidate coordinates to make a real argh */
|
||||||
arghx[index] = x;
|
arghx[index] = x;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue