summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/wormlet.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/apps/plugins/wormlet.c b/apps/plugins/wormlet.c
index 4d86453178..3f67e61857 100644
--- a/apps/plugins/wormlet.c
+++ b/apps/plugins/wormlet.c
@@ -348,6 +348,8 @@ CONFIG_KEYPAD == MROBE500_PAD
348#define COLOR_BG LCD_RGBPACK(181, 199, 231) 348#define COLOR_BG LCD_RGBPACK(181, 199, 231)
349#endif 349#endif
350 350
351#define CHECK_SQUARE_COLLISION(x1,y1,s1,x2,y2,s2) (x1+s1>x2)&&(x2+s2>x1)&&(y1+s1>y2)&&(y2+s2>y1)
352
351/** 353/**
352 * All the properties that a worm has. 354 * All the properties that a worm has.
353 */ 355 */
@@ -830,21 +832,19 @@ static void make_food(int index)
830 the entire food lies within the FIELD */ 832 the entire food lies within the FIELD */
831 x = rb->rand() % (FIELD_RECT_WIDTH - food_size); 833 x = rb->rand() % (FIELD_RECT_WIDTH - food_size);
832 y = rb->rand() % (FIELD_RECT_HEIGHT - food_size); 834 y = rb->rand() % (FIELD_RECT_HEIGHT - food_size);
833 835 collisionDetected = false;
834 /* Ensure that the new food doesn't collide with any 836 /* Ensure that the new food doesn't collide with any
835 existing foods or arghs. 837 existing foods or arghs.
836 If one or more corners of the new food hit any existing 838 If the new food hit any existing
837 argh or food a collision is detected. 839 argh or food a collision is detected.
838 */ 840 */
839 collisionDetected = 841
840 food_collision(x , y ) >= 0 || 842 for (i=0; i<MAX_FOOD && !collisionDetected; i++) {
841 food_collision(x , y + food_size - 1) >= 0 || 843 collisionDetected = CHECK_SQUARE_COLLISION(x,y,food_size,foodx[i],foody[i],food_size);
842 food_collision(x + food_size - 1, y ) >= 0 || 844 }
843 food_collision(x + food_size - 1, y + food_size - 1) >= 0 || 845 for (i=0; i<argh_count && !collisionDetected; i++) {
844 argh_collision(x , y ) >= 0 || 846 collisionDetected = CHECK_SQUARE_COLLISION(x,y,food_size,arghx[i],arghy[i],argh_size);
845 argh_collision(x , y + food_size - 1) >= 0 || 847 }
846 argh_collision(x + food_size - 1, y ) >= 0 ||
847 argh_collision(x + food_size - 1, y + food_size - 1) >= 0;
848 848
849 /* use coordinates for further testing */ 849 /* use coordinates for further testing */
850 foodx[index] = x; 850 foodx[index] = x;
@@ -853,7 +853,9 @@ static void make_food(int index)
853 /* now test wether we accidently hit the worm with food ;) */ 853 /* now test wether we accidently hit the worm with food ;) */
854 i = 0; 854 i = 0;
855 for (i = 0; i < worm_count && !collisionDetected; i++) { 855 for (i = 0; i < worm_count && !collisionDetected; i++) {
856 collisionDetected |= worm_food_collision(&worms[i], index); 856
857 collisionDetected = worm_food_collision(&worms[i], index);
858
857 } 859 }
858 } 860 }
859 while (collisionDetected); 861 while (collisionDetected);
@@ -919,21 +921,19 @@ static void make_argh(int index)
919 the entire food lies within the FIELD */ 921 the entire food lies within the FIELD */
920 x = rb->rand() % (FIELD_RECT_WIDTH - argh_size); 922 x = rb->rand() % (FIELD_RECT_WIDTH - argh_size);
921 y = rb->rand() % (FIELD_RECT_HEIGHT - argh_size); 923 y = rb->rand() % (FIELD_RECT_HEIGHT - argh_size);
922 924 collisionDetected = false;
923 /* Ensure that the new argh doesn't intersect with any 925 /* Ensure that the new argh doesn't intersect with any
924 existing foods or arghs. 926 existing foods or arghs.
925 If one or more corners of the new argh hit any existing 927 If the new argh hit any existing
926 argh or food an intersection is detected. 928 argh or food an intersection is detected.
927 */ 929 */
928 collisionDetected = 930
929 food_collision(x , y ) >= 0 || 931 for (i=0; i<MAX_FOOD && !collisionDetected; i++) {
930 food_collision(x , y + argh_size - 1) >= 0 || 932 collisionDetected = CHECK_SQUARE_COLLISION(x,y,argh_size,foodx[i],foody[i],food_size);
931 food_collision(x + argh_size - 1, y ) >= 0 || 933 }
932 food_collision(x + argh_size - 1, y + argh_size - 1) >= 0 || 934 for (i=0; i<argh_count && !collisionDetected; i++) {
933 argh_collision(x , y ) >= 0 || 935 collisionDetected = CHECK_SQUARE_COLLISION(x,y,argh_size,arghx[i],arghy[i],argh_size);
934 argh_collision(x , y + argh_size - 1) >= 0 || 936 }
935 argh_collision(x + argh_size - 1, y ) >= 0 ||
936 argh_collision(x + argh_size - 1, y + argh_size - 1) >= 0;
937 937
938 /* use the candidate coordinates to make a real argh */ 938 /* use the candidate coordinates to make a real argh */
939 arghx[index] = x; 939 arghx[index] = x;