summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZakk Roberts <midk@rockbox.org>2006-03-13 03:13:05 +0000
committerZakk Roberts <midk@rockbox.org>2006-03-13 03:13:05 +0000
commitc091a77381ab9fba79919da84a507bccab902b2f (patch)
tree30a7a52db2153c6e4047680acc05ae59e6860251
parent7a10c08af4f3d2e8365b24dfb668cddad1c08fcb (diff)
downloadrockbox-c091a77381ab9fba79919da84a507bccab902b2f.tar.gz
rockbox-c091a77381ab9fba79919da84a507bccab902b2f.zip
Adapted Wormlet to all other models with bitmap LCDs - fullscreen on all of them - with colors where possible. Untested on all models except Recorder and iPod 5G; might be a bit buggy.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9020 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/SOURCES5
-rw-r--r--apps/plugins/wormlet.c410
2 files changed, 266 insertions, 149 deletions
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index 7cd2882ab6..a4a1a34912 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -32,6 +32,8 @@ plasma.c
32 32
33bejeweled.c 33bejeweled.c
34bounce.c 34bounce.c
35wormlet.c
36
35#if (LCD_WIDTH != 138) && (LCD_WIDTH != 128) 37#if (LCD_WIDTH != 138) && (LCD_WIDTH != 128)
36/* These need adjusting for the Mini's and iRiver if'p screen */ 38/* These need adjusting for the Mini's and iRiver if'p screen */
37brickmania.c 39brickmania.c
@@ -59,9 +61,6 @@ sudoku.c
59video.c 61video.c
60#endif 62#endif
61vu_meter.c 63vu_meter.c
62#if CONFIG_KEYPAD == RECORDER_PAD /* Recorder models only for now */
63wormlet.c
64#endif
65 64
66#ifdef CONFIG_RTC 65#ifdef CONFIG_RTC
67clock.c 66clock.c
diff --git a/apps/plugins/wormlet.c b/apps/plugins/wormlet.c
index 6016cda873..8c2497648a 100644
--- a/apps/plugins/wormlet.c
+++ b/apps/plugins/wormlet.c
@@ -18,8 +18,6 @@
18 ****************************************************************************/ 18 ****************************************************************************/
19#include "plugin.h" 19#include "plugin.h"
20 20
21#if defined(HAVE_LCD_BITMAP) && (CONFIG_KEYPAD == RECORDER_PAD)
22
23PLUGIN_HEADER 21PLUGIN_HEADER
24 22
25/* size of the field the worm lives in */ 23/* size of the field the worm lives in */
@@ -28,31 +26,118 @@ PLUGIN_HEADER
28#define FIELD_RECT_WIDTH (LCD_WIDTH - 45) 26#define FIELD_RECT_WIDTH (LCD_WIDTH - 45)
29#define FIELD_RECT_HEIGHT (LCD_HEIGHT - 2) 27#define FIELD_RECT_HEIGHT (LCD_HEIGHT - 2)
30 28
31/* size of the ring of the worm 29/* size of the ring of the worm
32 choos a value that is a power of 2 to help 30 choos a value that is a power of 2 to help
33 the compiler optimize modul operations*/ 31 the compiler optimize modul operations*/
34#define MAX_WORM_SEGMENTS 64 32#define MAX_WORM_SEGMENTS 64
35 33
36/* when the game starts */ 34/* when the game starts */
37#define INITIAL_WORM_LENGTH 10 35#define INITIAL_WORM_LENGTH 10
38 36
39/* num of pixel the worm grows per eaten food */ 37/* num of pixel the worm grows per eaten food */
40#define WORM_PER_FOOD 7 38#define WORM_PER_FOOD 7
41 39
42/* num of worms creeping in the FIELD */ 40/* num of worms creeping in the FIELD */
43#define MAX_WORMS 3 41#define MAX_WORMS 3
44 42
45/* minimal distance between a worm and an argh 43/* minimal distance between a worm and an argh
46 when a new argh is made */ 44 when a new argh is made */
47#define MIN_ARGH_DIST 5 45#define MIN_ARGH_DIST 5
48 46
47#if (CONFIG_KEYPAD == RECORDER_PAD)
48#define BTN_DIR_UP BUTTON_UP
49#define BTN_DIR_DOWN BUTTON_DOWN
50#define BTN_DIR_LEFT BUTTON_LEFT
51#define BTN_DIR_RIGHT BUTTON_RIGHT
52#define BTN_PLAYER2_DIR1 BUTTON_F2
53#define BTN_PLAYER2_DIR2 BUTTON_F3
54#define BTN_RC_UP BUTTON_RC_VOL_UP
55#define BTN_RC_DOWN BUTTON_RC_VOL_DOWN
56#define BTN_STARTPAUSE BUTTON_PLAY
57#define BTN_QUIT BUTTON_OFF
58#define BTN_STOPRESET BUTTON_ON
59#define BTN_TOGGLE_KEYS BUTTON_F1
60
61#define REMOTE
62#define MULTIPLAYER
63
64#define PLAYERS_TEXT "UP/DN"
65#define WORMS_TEXT "L/R"
66#define KEY_CONTROL_TEXT "F1"
67
68#elif (CONFIG_KEYPAD == ONDIO_PAD)
69#define BTN_DIR_UP BUTTON_UP
70#define BTN_DIR_DOWN BUTTON_DOWN
71#define BTN_DIR_LEFT BUTTON_LEFT
72#define BTN_DIR_RIGHT BUTTON_RIGHT
73#define BTN_STARTPAUSE (BUTTON_MODE|BUTTON_REL)
74#define BTN_QUIT (BUTTON_ONOFF|BUTTON_REL)
75#define BTN_STOPRESET (BUTTON_ONOFF|BUTTON_MODE)
76
77#define PLAYERS_TEXT "UP/DN"
78#define WORMS_TEXT "L/R"
79
80#elif (CONFIG_KEYPAD == IPOD_4G_PAD)
81
82#define BTN_DIR_UP BUTTON_MENU
83#define BTN_DIR_DOWN BUTTON_PLAY
84#define BTN_DIR_LEFT BUTTON_LEFT
85#define BTN_DIR_RIGHT BUTTON_RIGHT
86#define BTN_STARTPAUSE (BUTTON_SELECT|BUTTON_REL)
87#define BTN_QUIT (BUTTON_SELECT|BUTTON_MENU)
88#define BTN_STOPRESET (BUTTON_SELECT|BUTTON_PLAY)
89
90#define PLAYERS_TEXT "Menu/Play"
91#define WORMS_TEXT "Left/Right"
92
93#elif (CONFIG_KEYPAD == IRIVER_H300_PAD) ||
94 (CONFIG_KEYPAD == IRIVER_H100_PAD)
95
96#define BTN_DIR_UP BUTTON_UP
97#define BTN_DIR_DOWN BUTTON_DOWN
98#define BTN_DIR_LEFT BUTTON_LEFT
99#define BTN_DIR_RIGHT BUTTON_RIGHT
100#define BTN_STARTPAUSE (BUTTON_SELECT|BUTTON_REL)
101#define BTN_QUIT BUTTON_OFF
102#define BTN_STOPRESET BUTTON_ON
103
104#define PLAYERS_TEXT "Up/Down"
105#define WORMS_TEXT "Left/Right"
106
107#endif
108
109#if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
110#define FOOD_SIZE 3
111#define ARGH_SIZE 4
112#define SPEED 14
113#elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
114#define FOOD_SIZE 4
115#define ARGH_SIZE 5
116#define SPEED 8
117#elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132)
118#define COLOR_LCD
119#define FOOD_SIZE 4
120#define ARGH_SIZE 5
121#define SPEED 6
122#elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176)
123#define COLOR_LCD
124#define FOOD_SIZE 5
125#define ARGH_SIZE 6
126#define SPEED 4
127#elif (LCD_WIDTH == 320) && (LCD_HEIGHT == 240)
128#define COLOR_LCD
129#define FOOD_SIZE 7
130#define ARGH_SIZE 8
131#define SPEED 4
132#endif
133
49/** 134/**
50 * All the properties that a worm has. 135 * All the properties that a worm has.
51 */ 136 */
52static struct worm { 137static struct worm {
53 /* The worm is stored in a ring of xy coordinates */ 138 /* The worm is stored in a ring of xy coordinates */
54 char x[MAX_WORM_SEGMENTS]; 139 int x[MAX_WORM_SEGMENTS];
55 char y[MAX_WORM_SEGMENTS]; 140 int y[MAX_WORM_SEGMENTS];
56 141
57 int head; /* index of the head within the buffer */ 142 int head; /* index of the head within the buffer */
58 int tail; /* index of the tail within the buffer */ 143 int tail; /* index of the tail within the buffer */
@@ -65,8 +150,8 @@ static struct worm {
65 150
66 /* this method is used to fetch the direction the user 151 /* this method is used to fetch the direction the user
67 has selected. It can be one of the values 152 has selected. It can be one of the values
68 human_player1, human_player2, remote_player, virtual_player. 153 human_player1, human_player2, remote_player, virtual_player.
69 All these values are fuctions, that can change the direction 154 All these values are fuctions, that can change the direction
70 of the worm */ 155 of the worm */
71 void (*fetch_worm_direction)(struct worm *w); 156 void (*fetch_worm_direction)(struct worm *w);
72} worms[MAX_WORMS]; 157} worms[MAX_WORMS];
@@ -74,22 +159,20 @@ static struct worm {
74/* stores the highscore - besides it was scored by a virtual player */ 159/* stores the highscore - besides it was scored by a virtual player */
75static int highscore; 160static int highscore;
76 161
77#define MAX_FOOD 5 /* maximal number of food items */ 162#define MAX_FOOD 5 /* maximal number of food items */
78#define FOOD_SIZE 3 /* the width and height of a food */
79 163
80/* The arrays store the food coordinates */ 164/* The arrays store the food coordinates */
81static char foodx[MAX_FOOD]; 165static char foodx[MAX_FOOD];
82static char foody[MAX_FOOD]; 166static char foody[MAX_FOOD];
83 167
84#define MAX_ARGH 100 /* maximal number of argh items */ 168#define MAX_ARGH 100 /* maximal number of argh items */
85#define ARGH_SIZE 4 /* the width and height of a argh */
86#define ARGHS_PER_FOOD 2 /* number of arghs produced per eaten food */ 169#define ARGHS_PER_FOOD 2 /* number of arghs produced per eaten food */
87 170
88/* The arrays store the argh coordinates */ 171/* The arrays store the argh coordinates */
89static char arghx[MAX_ARGH]; 172static char arghx[MAX_ARGH];
90static char arghy[MAX_ARGH]; 173static char arghy[MAX_ARGH];
91 174
92/* the number of arghs that are currently in use */ 175/* the number of arghs that are currently in use */
93static int argh_count; 176static int argh_count;
94 177
95#ifdef DEBUG_WORMLET 178#ifdef DEBUG_WORMLET
@@ -97,9 +180,6 @@ static int argh_count;
97static char debugout[15]; 180static char debugout[15];
98#endif 181#endif
99 182
100/* the number of ticks each game cycle should take */
101#define SPEED 14
102
103/* the number of active worms (dead or alive) */ 183/* the number of active worms (dead or alive) */
104static int worm_count = MAX_WORMS; 184static int worm_count = MAX_WORMS;
105 185
@@ -124,9 +204,9 @@ static bool use_remote = false;
124#define SOUTH 3 204#define SOUTH 3
125 205
126/* direction of human player 1 */ 206/* direction of human player 1 */
127static int player1_dir = EAST; 207static int player1_dir = EAST;
128/* direction of human player 2 */ 208/* direction of human player 2 */
129static int player2_dir = EAST; 209static int player2_dir = EAST;
130/* direction of human player 3 */ 210/* direction of human player 3 */
131static int player3_dir = EAST; 211static int player3_dir = EAST;
132 212
@@ -146,7 +226,7 @@ static void set_debug_out(char *str){
146/** 226/**
147 * Returns the direction id in which the worm 227 * Returns the direction id in which the worm
148 * currently is creeping. 228 * currently is creeping.
149 * @param struct worm *w The worm that is to be investigated. 229 * @param struct worm *w The worm that is to be investigated.
150 * w Must not be null. 230 * w Must not be null.
151 * @return int A value 0 <= value < 4 231 * @return int A value 0 <= value < 4
152 * Note the predefined constants NORTH, SOUTH, EAST, WEST 232 * Note the predefined constants NORTH, SOUTH, EAST, WEST
@@ -175,7 +255,7 @@ static int get_worm_dir(struct worm *w) {
175 * to right by 90 degree. 255 * to right by 90 degree.
176 * @param struct worm *w The worm that is to be altered. w Must not be null. 256 * @param struct worm *w The worm that is to be altered. w Must not be null.
177 * @param int dir The new direction in which the worm is to creep. 257 * @param int dir The new direction in which the worm is to creep.
178 * dir must be 0 <= dir < 4. Use predefined constants 258 * dir must be 0 <= dir < 4. Use predefined constants
179 * NORTH, SOUTH, EAST, WEST 259 * NORTH, SOUTH, EAST, WEST
180 */ 260 */
181static void set_worm_dir(struct worm *w, int dir) { 261static void set_worm_dir(struct worm *w, int dir) {
@@ -255,7 +335,7 @@ static int get_score(struct worm *w) {
255/** 335/**
256 * Determines wether the line specified by startx, starty, endx, endy intersects 336 * Determines wether the line specified by startx, starty, endx, endy intersects
257 * the rectangle specified by x, y, width, height. Note that the line must be exactly 337 * the rectangle specified by x, y, width, height. Note that the line must be exactly
258 * horizontal or vertical (startx == endx or starty == endy). 338 * horizontal or vertical (startx == endx or starty == endy).
259 * @param int startx The x coordinate of the start point of the line. 339 * @param int startx The x coordinate of the start point of the line.
260 * @param int starty The y coordinate of the start point of the line. 340 * @param int starty The y coordinate of the start point of the line.
261 * @param int endx The x coordinate of the end point of the line. 341 * @param int endx The x coordinate of the end point of the line.
@@ -305,7 +385,7 @@ static bool line_in_rect(int startx, int starty, int endx, int endy, int x, int
305 return retval; 385 return retval;
306} 386}
307 387
308/** 388/**
309 * Tests wether the specified worm intersects with the rect. 389 * Tests wether the specified worm intersects with the rect.
310 * @param struct worm *w The worm to be investigated 390 * @param struct worm *w The worm to be investigated
311 * @param int x The x coordinate of the top left corner of the rect 391 * @param int x The x coordinate of the top left corner of the rect
@@ -433,7 +513,7 @@ static bool worm_food_collision(struct worm *w, int foodIndex)
433{ 513{
434 bool retVal = false; 514 bool retVal = false;
435 515
436 retVal = worm_in_rect(w, foodx[foodIndex], foody[foodIndex], 516 retVal = worm_in_rect(w, foodx[foodIndex], foody[foodIndex],
437 FOOD_SIZE - 1, FOOD_SIZE - 1); 517 FOOD_SIZE - 1, FOOD_SIZE - 1);
438 518
439 return retVal; 519 return retVal;
@@ -443,7 +523,7 @@ static bool worm_food_collision(struct worm *w, int foodIndex)
443 * Returns true if the worm hits the argh within the next moves (unless 523 * Returns true if the worm hits the argh within the next moves (unless
444 * the worm changes it's direction). 524 * the worm changes it's direction).
445 * @param struct worm *w - The worm to investigate 525 * @param struct worm *w - The worm to investigate
446 * @param int argh_idx - The index of the argh 526 * @param int argh_idx - The index of the argh
447 * @param int moves - The number of moves that are considered. 527 * @param int moves - The number of moves that are considered.
448 * @return Returns false if the specified argh is not hit within the next 528 * @return Returns false if the specified argh is not hit within the next
449 * moves. 529 * moves.
@@ -457,7 +537,7 @@ static bool worm_argh_collision_in_moves(struct worm *w, int argh_idx, int moves
457 x2 = w->x[w->head] + moves * w->dirx; 537 x2 = w->x[w->head] + moves * w->dirx;
458 y2 = w->y[w->head] + moves * w->diry; 538 y2 = w->y[w->head] + moves * w->diry;
459 539
460 retVal = line_in_rect(x1, y1, x2, y2, arghx[argh_idx], arghy[argh_idx], 540 retVal = line_in_rect(x1, y1, x2, y2, arghx[argh_idx], arghy[argh_idx],
461 ARGH_SIZE, ARGH_SIZE); 541 ARGH_SIZE, ARGH_SIZE);
462 return retVal; 542 return retVal;
463} 543}
@@ -472,7 +552,7 @@ static bool worm_argh_collision(struct worm *w, int arghIndex)
472{ 552{
473 bool retVal = false; 553 bool retVal = false;
474 554
475 retVal = worm_in_rect(w, arghx[arghIndex], arghy[arghIndex], 555 retVal = worm_in_rect(w, arghx[arghIndex], arghy[arghIndex],
476 ARGH_SIZE - 1, ARGH_SIZE - 1); 556 ARGH_SIZE - 1, ARGH_SIZE - 1);
477 557
478 return retVal; 558 return retVal;
@@ -481,7 +561,7 @@ static bool worm_argh_collision(struct worm *w, int arghIndex)
481/** 561/**
482 * Find new coordinates for the food stored in foodx[index], foody[index] 562 * Find new coordinates for the food stored in foodx[index], foody[index]
483 * that don't collide with any other food or argh 563 * that don't collide with any other food or argh
484 * @param int index 564 * @param int index
485 * Ensure that 0 <= index < MAX_FOOD. 565 * Ensure that 0 <= index < MAX_FOOD.
486 */ 566 */
487static int make_food(int index) { 567static int make_food(int index) {
@@ -504,12 +584,12 @@ static int make_food(int index) {
504 If one or more corners of the new food hit any existing 584 If one or more corners of the new food hit any existing
505 argh or food a collision is detected. 585 argh or food a collision is detected.
506 */ 586 */
507 collisionDetected = 587 collisionDetected =
508 food_collision(x , y ) >= 0 || 588 food_collision(x , y ) >= 0 ||
509 food_collision(x , y + FOOD_SIZE - 1) >= 0 || 589 food_collision(x , y + FOOD_SIZE - 1) >= 0 ||
510 food_collision(x + FOOD_SIZE - 1, y ) >= 0 || 590 food_collision(x + FOOD_SIZE - 1, y ) >= 0 ||
511 food_collision(x + FOOD_SIZE - 1, y + FOOD_SIZE - 1) >= 0 || 591 food_collision(x + FOOD_SIZE - 1, y + FOOD_SIZE - 1) >= 0 ||
512 argh_collision(x , y ) >= 0 || 592 argh_collision(x , y ) >= 0 ||
513 argh_collision(x , y + FOOD_SIZE - 1) >= 0 || 593 argh_collision(x , y + FOOD_SIZE - 1) >= 0 ||
514 argh_collision(x + FOOD_SIZE - 1, y ) >= 0 || 594 argh_collision(x + FOOD_SIZE - 1, y ) >= 0 ||
515 argh_collision(x + FOOD_SIZE - 1, y + FOOD_SIZE - 1) >= 0; 595 argh_collision(x + FOOD_SIZE - 1, y + FOOD_SIZE - 1) >= 0;
@@ -531,7 +611,7 @@ static int make_food(int index) {
531/** 611/**
532 * Clears a food from the lcd buffer. 612 * Clears a food from the lcd buffer.
533 * @param int index The index of the food arrays under which 613 * @param int index The index of the food arrays under which
534 * the coordinates of the desired food can be found. Ensure 614 * the coordinates of the desired food can be found. Ensure
535 * that the value is 0 <= index <= MAX_FOOD. 615 * that the value is 0 <= index <= MAX_FOOD.
536 */ 616 */
537static void clear_food(int index) 617static void clear_food(int index)
@@ -547,13 +627,16 @@ static void clear_food(int index)
547/** 627/**
548 * Draws a food in the lcd buffer. 628 * Draws a food in the lcd buffer.
549 * @param int index The index of the food arrays under which 629 * @param int index The index of the food arrays under which
550 * the coordinates of the desired food can be found. Ensure 630 * the coordinates of the desired food can be found. Ensure
551 * that the value is 0 <= index <= MAX_FOOD. 631 * that the value is 0 <= index <= MAX_FOOD.
552 */ 632 */
553static void draw_food(int index) 633static void draw_food(int index)
554{ 634{
555 /* draw the food object */ 635 /* draw the food object */
556 rb->lcd_fillrect(foodx[index] + FIELD_RECT_X, 636#ifdef COLOR_LCD
637 rb->lcd_set_foreground(LCD_RGBPACK(0, 150, 0));
638#endif
639 rb->lcd_fillrect(foodx[index] + FIELD_RECT_X,
557 foody[index] + FIELD_RECT_Y, 640 foody[index] + FIELD_RECT_Y,
558 FOOD_SIZE, FOOD_SIZE); 641 FOOD_SIZE, FOOD_SIZE);
559 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); 642 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
@@ -561,18 +644,21 @@ static void draw_food(int index)
561 foody[index] + FIELD_RECT_Y + 1, 644 foody[index] + FIELD_RECT_Y + 1,
562 FOOD_SIZE - 2, FOOD_SIZE - 2); 645 FOOD_SIZE - 2, FOOD_SIZE - 2);
563 rb->lcd_set_drawmode(DRMODE_SOLID); 646 rb->lcd_set_drawmode(DRMODE_SOLID);
647#ifdef COLOR_LCD
648 rb->lcd_set_foreground(LCD_RGBPACK(0, 0, 0));
649#endif
564} 650}
565 651
566/** 652/**
567 * Find new coordinates for the argh stored in arghx[index], arghy[index] 653 * Find new coordinates for the argh stored in arghx[index], arghy[index]
568 * that don't collide with any other food or argh. 654 * that don't collide with any other food or argh.
569 * @param int index 655 * @param int index
570 * Ensure that 0 <= index < argh_count < MAX_ARGH. 656 * Ensure that 0 <= index < argh_count < MAX_ARGH.
571 */ 657 */
572static int make_argh(int index) 658static int make_argh(int index)
573{ 659{
574 int x = -1; 660 int x = -1;
575 int y = -1; 661 int y = -1;
576 bool collisionDetected = false; 662 bool collisionDetected = false;
577 int tries = 0; 663 int tries = 0;
578 int i; 664 int i;
@@ -589,12 +675,12 @@ static int make_argh(int index)
589 If one or more corners of the new argh hit any existing 675 If one or more corners of the new argh hit any existing
590 argh or food an intersection is detected. 676 argh or food an intersection is detected.
591 */ 677 */
592 collisionDetected = 678 collisionDetected =
593 food_collision(x , y ) >= 0 || 679 food_collision(x , y ) >= 0 ||
594 food_collision(x , y + ARGH_SIZE - 1) >= 0 || 680 food_collision(x , y + ARGH_SIZE - 1) >= 0 ||
595 food_collision(x + ARGH_SIZE - 1, y ) >= 0 || 681 food_collision(x + ARGH_SIZE - 1, y ) >= 0 ||
596 food_collision(x + ARGH_SIZE - 1, y + ARGH_SIZE - 1) >= 0 || 682 food_collision(x + ARGH_SIZE - 1, y + ARGH_SIZE - 1) >= 0 ||
597 argh_collision(x , y ) >= 0 || 683 argh_collision(x , y ) >= 0 ||
598 argh_collision(x , y + ARGH_SIZE - 1) >= 0 || 684 argh_collision(x , y + ARGH_SIZE - 1) >= 0 ||
599 argh_collision(x + ARGH_SIZE - 1, y ) >= 0 || 685 argh_collision(x + ARGH_SIZE - 1, y ) >= 0 ||
600 argh_collision(x + ARGH_SIZE - 1, y + ARGH_SIZE - 1) >= 0; 686 argh_collision(x + ARGH_SIZE - 1, y + ARGH_SIZE - 1) >= 0;
@@ -606,7 +692,7 @@ static int make_argh(int index)
606 /* now test wether we accidently hit the worm with argh ;) */ 692 /* now test wether we accidently hit the worm with argh ;) */
607 for (i = 0; i < worm_count && !collisionDetected; i++) { 693 for (i = 0; i < worm_count && !collisionDetected; i++) {
608 collisionDetected |= worm_argh_collision(&worms[i], index); 694 collisionDetected |= worm_argh_collision(&worms[i], index);
609 collisionDetected |= worm_argh_collision_in_moves(&worms[i], index, 695 collisionDetected |= worm_argh_collision_in_moves(&worms[i], index,
610 MIN_ARGH_DIST); 696 MIN_ARGH_DIST);
611 } 697 }
612 } 698 }
@@ -617,15 +703,21 @@ static int make_argh(int index)
617/** 703/**
618 * Draws an argh in the lcd buffer. 704 * Draws an argh in the lcd buffer.
619 * @param int index The index of the argh arrays under which 705 * @param int index The index of the argh arrays under which
620 * the coordinates of the desired argh can be found. Ensure 706 * the coordinates of the desired argh can be found. Ensure
621 * that the value is 0 <= index < argh_count <= MAX_ARGH. 707 * that the value is 0 <= index < argh_count <= MAX_ARGH.
622 */ 708 */
623static void draw_argh(int index) 709static void draw_argh(int index)
624{ 710{
625 /* draw the new argh */ 711 /* draw the new argh */
626 rb->lcd_fillrect(arghx[index] + FIELD_RECT_X, 712#ifdef COLOR_LCD
627 arghy[index] + FIELD_RECT_Y, 713 rb->lcd_set_foreground(LCD_RGBPACK(175, 0, 0));
714#endif
715 rb->lcd_fillrect(arghx[index] + FIELD_RECT_X,
716 arghy[index] + FIELD_RECT_Y,
628 ARGH_SIZE, ARGH_SIZE); 717 ARGH_SIZE, ARGH_SIZE);
718#ifdef COLOR_LCD
719 rb->lcd_set_foreground(LCD_RGBPACK(0, 0, 0));
720#endif
629} 721}
630 722
631static void virtual_player(struct worm *w); 723static void virtual_player(struct worm *w);
@@ -659,40 +751,40 @@ static void init_worm(struct worm *w, int x, int y){
659 w->fetch_worm_direction = virtual_player; 751 w->fetch_worm_direction = virtual_player;
660} 752}
661 753
662/** 754/**
663 * Writes the direction that was stored for 755 * Writes the direction that was stored for
664 * human player 1 into the specified worm. This function 756 * human player 1 into the specified worm. This function
665 * may be used to be stored in worm.fetch_worm_direction. 757 * may be used to be stored in worm.fetch_worm_direction.
666 * The value of 758 * The value of
667 * the direction is read from player1_dir. 759 * the direction is read from player1_dir.
668 * @param struct worm *w - The worm of which the direction 760 * @param struct worm *w - The worm of which the direction
669 * is altered. 761 * is altered.
670 */ 762 */
671static void human_player1(struct worm *w) { 763static void human_player1(struct worm *w) {
672 set_worm_dir(w, player1_dir); 764 set_worm_dir(w, player1_dir);
673} 765}
674 766
675/** 767/**
676 * Writes the direction that was stored for 768 * Writes the direction that was stored for
677 * human player 2 into the specified worm. This function 769 * human player 2 into the specified worm. This function
678 * may be used to be stored in worm.fetch_worm_direction. 770 * may be used to be stored in worm.fetch_worm_direction.
679 * The value of 771 * The value of
680 * the direction is read from player2_dir. 772 * the direction is read from player2_dir.
681 * @param struct worm *w - The worm of which the direction 773 * @param struct worm *w - The worm of which the direction
682 * is altered. 774 * is altered.
683 */ 775 */
684static void human_player2(struct worm *w) { 776static void human_player2(struct worm *w) {
685 set_worm_dir(w, player2_dir); 777 set_worm_dir(w, player2_dir);
686} 778}
687 779
688/** 780/**
689 * Writes the direction that was stored for 781 * Writes the direction that was stored for
690 * human player using a remote control 782 * human player using a remote control
691 * into the specified worm. This function 783 * into the specified worm. This function
692 * may be used to be stored in worm.fetch_worm_direction. 784 * may be used to be stored in worm.fetch_worm_direction.
693 * The value of 785 * The value of
694 * the direction is read from player3_dir. 786 * the direction is read from player3_dir.
695 * @param struct worm *w - The worm of which the direction 787 * @param struct worm *w - The worm of which the direction
696 * is altered. 788 * is altered.
697 */ 789 */
698static void remote_player(struct worm *w) { 790static void remote_player(struct worm *w) {
@@ -735,7 +827,7 @@ static void init_wormlet(void)
735 worms[2].fetch_worm_direction = human_player2; 827 worms[2].fetch_worm_direction = human_player2;
736 } 828 }
737 829
738 /* Needed when the game is restarted using BUTTON_ON */ 830 /* Needed when the game is restarted using BTN_STOPRESET */
739 rb->lcd_clear_display(); 831 rb->lcd_clear_display();
740 832
741 /* make and display some food and argh */ 833 /* make and display some food and argh */
@@ -758,9 +850,9 @@ static void init_wormlet(void)
758} 850}
759 851
760 852
761/** 853/**
762 * Move the worm one step further if it is alive. 854 * Move the worm one step further if it is alive.
763 * The direction in which the worm moves is taken from dirx and diry. 855 * The direction in which the worm moves is taken from dirx and diry.
764 * move_worm decreases growing if > 0. While the worm is growing the tail 856 * move_worm decreases growing if > 0. While the worm is growing the tail
765 * is left untouched. 857 * is left untouched.
766 * @param struct worm *w The worm to move. w must not be NULL. 858 * @param struct worm *w The worm to move. w must not be NULL.
@@ -787,7 +879,7 @@ static void move_worm(struct worm *w)
787 } 879 }
788 880
789 /* olddir == dir? 881 /* olddir == dir?
790 a change of direction means a new segment 882 a change of direction means a new segment
791 has been opened */ 883 has been opened */
792 if (olddirx != w->dirx || 884 if (olddirx != w->dirx ||
793 olddiry != w->diry) { 885 olddiry != w->diry) {
@@ -804,15 +896,15 @@ static void move_worm(struct worm *w)
804 /* update the worms grow state */ 896 /* update the worms grow state */
805 w->growing--; 897 w->growing--;
806 } 898 }
807 899
808 /* if the worm isn't growing the tail has to be dragged */ 900 /* if the worm isn't growing the tail has to be dragged */
809 else { 901 else {
810 /* index of the end of the tail segment */ 902 /* index of the end of the tail segment */
811 int tail_segment_end = (w->tail + 1) % MAX_WORM_SEGMENTS; 903 int tail_segment_end = (w->tail + 1) % MAX_WORM_SEGMENTS;
812 904
813 /* drag the end of the tail */ 905 /* drag the end of the tail */
814 /* only one coordinate has to be altered. Here it is 906 /* only one coordinate has to be altered. Here it is
815 determined which one */ 907 determined which one */
816 int dir = 0; /* specifies wether the coord has to be in- or decreased */ 908 int dir = 0; /* specifies wether the coord has to be in- or decreased */
817 if (w->x[w->tail] == w->x[tail_segment_end]) { 909 if (w->x[w->tail] == w->x[tail_segment_end]) {
818 dir = (w->y[w->tail] - w->y[tail_segment_end] < 0) ? 1 : -1; 910 dir = (w->y[w->tail] - w->y[tail_segment_end] < 0) ? 1 : -1;
@@ -827,7 +919,7 @@ static void move_worm(struct worm *w)
827 must be freed */ 919 must be freed */
828 if (w->x[w->tail] == w->x[tail_segment_end] && 920 if (w->x[w->tail] == w->x[tail_segment_end] &&
829 w->y[w->tail] == w->y[tail_segment_end]){ 921 w->y[w->tail] == w->y[tail_segment_end]){
830 922
831 /* drop the last tail point */ 923 /* drop the last tail point */
832 w->tail = tail_segment_end; 924 w->tail = tail_segment_end;
833 } 925 }
@@ -836,12 +928,15 @@ static void move_worm(struct worm *w)
836} 928}
837 929
838/** 930/**
839 * Draws the head and clears the tail of the worm in 931 * Draws the head and clears the tail of the worm in
840 * the display buffer. lcd_update() is NOT called thus 932 * the display buffer. lcd_update() is NOT called thus
841 * the caller has to take care that the buffer is displayed. 933 * the caller has to take care that the buffer is displayed.
842 */ 934 */
843static void draw_worm(struct worm *w) 935static void draw_worm(struct worm *w)
844{ 936{
937#ifdef COLOR_LCD
938 rb->lcd_set_foreground(LCD_RGBPACK(80, 40, 0));
939#endif
845 /* draw the new head */ 940 /* draw the new head */
846 int x = w->x[w->head]; 941 int x = w->x[w->head];
847 int y = w->y[w->head]; 942 int y = w->y[w->head];
@@ -858,16 +953,19 @@ static void draw_worm(struct worm *w)
858 rb->lcd_drawpixel(x + FIELD_RECT_X, y + FIELD_RECT_Y); 953 rb->lcd_drawpixel(x + FIELD_RECT_X, y + FIELD_RECT_Y);
859 } 954 }
860 rb->lcd_set_drawmode(DRMODE_SOLID); 955 rb->lcd_set_drawmode(DRMODE_SOLID);
956#ifdef COLOR_LCD
957 rb->lcd_set_foreground(LCD_RGBPACK(0, 0, 0));
958#endif
861} 959}
862 960
863/** 961/**
864 * Checks wether the coordinate is part of the worm. Returns 962 * Checks wether the coordinate is part of the worm. Returns
865 * true if any part of the worm was hit - including the head. 963 * true if any part of the worm was hit - including the head.
866 * @param x int The x coordinate 964 * @param x int The x coordinate
867 * @param y int The y coordinate 965 * @param y int The y coordinate
868 * @return int The index of the worm arrays that contain x, y. 966 * @return int The index of the worm arrays that contain x, y.
869 * Returns -1 if the coordinates are not part of the worm. 967 * Returns -1 if the coordinates are not part of the worm.
870 */ 968 */
871static int specific_worm_collision(struct worm *w, int x, int y) 969static int specific_worm_collision(struct worm *w, int x, int y)
872{ 970{
873 int retVal = -1; 971 int retVal = -1;
@@ -891,7 +989,7 @@ static int specific_worm_collision(struct worm *w, int x, int y)
891 if (samey) { 989 if (samey) {
892 min = w->x[linestart]; 990 min = w->x[linestart];
893 max = w->x[lineend]; 991 max = w->x[lineend];
894 test = x; 992 test = x;
895 } else { 993 } else {
896 min = w->y[linestart]; 994 min = w->y[linestart];
897 max = w->y[lineend]; 995 max = w->y[lineend];
@@ -911,7 +1009,7 @@ static int specific_worm_collision(struct worm *w, int x, int y)
911} 1009}
912 1010
913/** 1011/**
914 * Increases the length of the specified worm by marking 1012 * Increases the length of the specified worm by marking
915 * that it may grow by len pixels. Note that the worm has 1013 * that it may grow by len pixels. Note that the worm has
916 * to move to make the growing happen. 1014 * to move to make the growing happen.
917 * @param worm *w The worm that is to be altered. 1015 * @param worm *w The worm that is to be altered.
@@ -926,8 +1024,8 @@ static void add_growing(struct worm *w, int len) {
926 * Determins the worm that is at the coordinates x, y. The parameter 1024 * Determins the worm that is at the coordinates x, y. The parameter
927 * w is a switch parameter that changes the functionality of worm_collision. 1025 * w is a switch parameter that changes the functionality of worm_collision.
928 * If w is specified and x,y hits the head of w NULL is returned. 1026 * If w is specified and x,y hits the head of w NULL is returned.
929 * This is a useful way to determine wether the head of w hits 1027 * This is a useful way to determine wether the head of w hits
930 * any worm but including itself but excluding its own head. 1028 * any worm but including itself but excluding its own head.
931 * (It hits always its own head ;)) 1029 * (It hits always its own head ;))
932 * If w is set to NULL worm_collision returns any worm including all heads 1030 * If w is set to NULL worm_collision returns any worm including all heads
933 * that is at position of x,y. 1031 * that is at position of x,y.
@@ -954,9 +1052,9 @@ static struct worm* worm_collision(struct worm *w, int x, int y){
954 1052
955/** 1053/**
956 * Returns true if the head of the worm just has 1054 * Returns true if the head of the worm just has
957 * crossed the field boundaries. 1055 * crossed the field boundaries.
958 * @return bool true if the worm just has wrapped. 1056 * @return bool true if the worm just has wrapped.
959 */ 1057 */
960static bool field_collision(struct worm *w) 1058static bool field_collision(struct worm *w)
961{ 1059{
962 bool retVal = false; 1060 bool retVal = false;
@@ -972,11 +1070,11 @@ static bool field_collision(struct worm *w)
972 1070
973 1071
974/** 1072/**
975 * Returns true if the specified coordinates are within the 1073 * Returns true if the specified coordinates are within the
976 * field specified by the FIELD_RECT_XXX constants. 1074 * field specified by the FIELD_RECT_XXX constants.
977 * @param int x The x coordinate of the point that is investigated 1075 * @param int x The x coordinate of the point that is investigated
978 * @param int y The y coordinate of the point that is investigated 1076 * @param int y The y coordinate of the point that is investigated
979 * @return bool Returns false if x,y specifies a point outside the 1077 * @return bool Returns false if x,y specifies a point outside the
980 * field of worms. 1078 * field of worms.
981 */ 1079 */
982static bool is_in_field_rect(int x, int y) { 1080static bool is_in_field_rect(int x, int y) {
@@ -1017,7 +1115,7 @@ static int check_collision(struct worm *w)
1017 1115
1018/** 1116/**
1019 * Returns the index of the food that is closest to the point 1117 * Returns the index of the food that is closest to the point
1020 * specified by x, y. This index may be used in the foodx and 1118 * specified by x, y. This index may be used in the foodx and
1021 * foody arrays. 1119 * foody arrays.
1022 * @param int x The x coordinate of the point 1120 * @param int x The x coordinate of the point
1023 * @param int y The y coordinate of the point 1121 * @param int y The y coordinate of the point
@@ -1045,10 +1143,10 @@ static int get_nearest_food(int x, int y){
1045 return nearestfood; 1143 return nearestfood;
1046} 1144}
1047 1145
1048/** 1146/**
1049 * Returns wether the specified position is next to the worm 1147 * Returns wether the specified position is next to the worm
1050 * and in the direction the worm looks. Use this method to 1148 * and in the direction the worm looks. Use this method to
1051 * test wether this position would be hit with the next move of 1149 * test wether this position would be hit with the next move of
1052 * the worm unless the worm changes its direction. 1150 * the worm unless the worm changes its direction.
1053 * @param struct worm *w - The worm to be investigated 1151 * @param struct worm *w - The worm to be investigated
1054 * @param int x - The x coordinate of the position to test. 1152 * @param int x - The x coordinate of the position to test.
@@ -1083,21 +1181,21 @@ static bool will_worm_collide(struct worm *w) {
1083 if (!retVal) { 1181 if (!retVal) {
1084 retVal = (argh_collision(x, y) != -1); 1182 retVal = (argh_collision(x, y) != -1);
1085 } 1183 }
1086 1184
1087 if (!retVal) { 1185 if (!retVal) {
1088 retVal = (worm_collision(w, x, y) != NULL); 1186 retVal = (worm_collision(w, x, y) != NULL);
1089 } 1187 }
1090 return retVal; 1188 return retVal;
1091} 1189}
1092 1190
1093/** 1191/**
1094 * This function 1192 * This function
1095 * may be used to be stored in worm.fetch_worm_direction for 1193 * may be used to be stored in worm.fetch_worm_direction for
1096 * worms that are not controlled by humans but by artificial stupidity. 1194 * worms that are not controlled by humans but by artificial stupidity.
1097 * A direction is searched that doesn't lead to collision but to the nearest 1195 * A direction is searched that doesn't lead to collision but to the nearest
1098 * food - but not very intelligent. The direction is written to the specified 1196 * food - but not very intelligent. The direction is written to the specified
1099 * worm. 1197 * worm.
1100 * @param struct worm *w - The worm of which the direction 1198 * @param struct worm *w - The worm of which the direction
1101 * is altered. 1199 * is altered.
1102 */ 1200 */
1103static void virtual_player(struct worm *w) { 1201static void virtual_player(struct worm *w) {
@@ -1171,7 +1269,7 @@ static void score_board(void)
1171 rb->lcd_set_drawmode(DRMODE_SOLID); 1269 rb->lcd_set_drawmode(DRMODE_SOLID);
1172 for (i = 0; i < worm_count; i++) { 1270 for (i = 0; i < worm_count; i++) {
1173 int score = get_score(&worms[i]); 1271 int score = get_score(&worms[i]);
1174 1272
1175 /* high score */ 1273 /* high score */
1176 if (worms[i].fetch_worm_direction != virtual_player){ 1274 if (worms[i].fetch_worm_direction != virtual_player){
1177 if (highscore < score) { 1275 if (highscore < score) {
@@ -1184,7 +1282,7 @@ static void score_board(void)
1184 1282
1185 /* worm state */ 1283 /* worm state */
1186 switch (check_collision(&worms[i])) { 1284 switch (check_collision(&worms[i])) {
1187 case COLLISION_NONE: 1285 case COLLISION_NONE:
1188 if (worms[i].growing > 0) 1286 if (worms[i].growing > 0)
1189 buf2 = "Growing"; 1287 buf2 = "Growing";
1190 else { 1288 else {
@@ -1195,19 +1293,19 @@ static void score_board(void)
1195 } 1293 }
1196 break; 1294 break;
1197 1295
1198 case COLLISION_WORM: 1296 case COLLISION_WORM:
1199 buf2 = "Wormed"; 1297 buf2 = "Wormed";
1200 break; 1298 break;
1201 1299
1202 case COLLISION_FOOD: 1300 case COLLISION_FOOD:
1203 buf2 = "Growing"; 1301 buf2 = "Growing";
1204 break; 1302 break;
1205 1303
1206 case COLLISION_ARGH: 1304 case COLLISION_ARGH:
1207 buf2 = "Argh"; 1305 buf2 = "Argh";
1208 break; 1306 break;
1209 1307
1210 case COLLISION_FIELD: 1308 case COLLISION_FIELD:
1211 buf2 = "Crashed"; 1309 buf2 = "Crashed";
1212 break; 1310 break;
1213 } 1311 }
@@ -1248,11 +1346,11 @@ static bool process_collisions(struct worm *w)
1248 index = food_collision(w->x[w->head], w->y[w->head]); 1346 index = food_collision(w->x[w->head], w->y[w->head]);
1249 if (index != -1){ 1347 if (index != -1){
1250 int i; 1348 int i;
1251 1349
1252 clear_food(index); 1350 clear_food(index);
1253 make_food(index); 1351 make_food(index);
1254 draw_food(index); 1352 draw_food(index);
1255 1353
1256 for (i = 0; i < ARGHS_PER_FOOD; i++) { 1354 for (i = 0; i < ARGHS_PER_FOOD; i++) {
1257 argh_count++; 1355 argh_count++;
1258 if (argh_count > MAX_ARGH) 1356 if (argh_count > MAX_ARGH)
@@ -1287,7 +1385,7 @@ static bool process_collisions(struct worm *w)
1287 * @return bool Returns true if the game ended 1385 * @return bool Returns true if the game ended
1288 * with a dead worm. Returns false if the user 1386 * with a dead worm. Returns false if the user
1289 * aborted the game manually. 1387 * aborted the game manually.
1290 */ 1388 */
1291static bool run(void) 1389static bool run(void)
1292{ 1390{
1293 int button = 0; 1391 int button = 0;
@@ -1306,24 +1404,24 @@ static bool run(void)
1306 1404
1307 cycle_start = *rb->current_tick; 1405 cycle_start = *rb->current_tick;
1308 /* change the direction of the worm */ 1406 /* change the direction of the worm */
1309 while (button != BUTTON_OFF && ! wormDead) 1407 while (button != BTN_QUIT && ! wormDead)
1310 { 1408 {
1311 int i; 1409 int i;
1312 long cycle_duration ; 1410 long cycle_duration ;
1313 switch (button) { 1411 switch (button) {
1314 case BUTTON_UP: 1412 case BTN_DIR_UP:
1315 if (players == 1 && !use_remote) { 1413 if (players == 1 && !use_remote) {
1316 player1_dir = NORTH; 1414 player1_dir = NORTH;
1317 } 1415 }
1318 break; 1416 break;
1319 1417
1320 case BUTTON_DOWN: 1418 case BTN_DIR_DOWN:
1321 if (players == 1 && !use_remote) { 1419 if (players == 1 && !use_remote) {
1322 player1_dir = SOUTH; 1420 player1_dir = SOUTH;
1323 } 1421 }
1324 break; 1422 break;
1325 1423
1326 case BUTTON_LEFT: 1424 case BTN_DIR_LEFT:
1327 if (players != 1 || use_remote) { 1425 if (players != 1 || use_remote) {
1328 player1_dir = (player1_dir + 3) % 4; 1426 player1_dir = (player1_dir + 3) % 4;
1329 } else { 1427 } else {
@@ -1331,7 +1429,7 @@ static bool run(void)
1331 } 1429 }
1332 break; 1430 break;
1333 1431
1334 case BUTTON_RIGHT: 1432 case BTN_DIR_RIGHT:
1335 if (players != 1 || use_remote) { 1433 if (players != 1 || use_remote) {
1336 player1_dir = (player1_dir + 1) % 4; 1434 player1_dir = (player1_dir + 1) % 4;
1337 } else { 1435 } else {
@@ -1339,28 +1437,32 @@ static bool run(void)
1339 } 1437 }
1340 break; 1438 break;
1341 1439
1342 case BUTTON_F2: 1440#ifdef MULTIPLAYER
1441 case BTN_PLAYER2_DIR1:
1343 player2_dir = (player2_dir + 3) % 4; 1442 player2_dir = (player2_dir + 3) % 4;
1344 break; 1443 break;
1345 1444
1346 case BUTTON_F3: 1445 case BTN_PLAYER2_DIR2:
1347 player2_dir = (player2_dir + 1) % 4; 1446 player2_dir = (player2_dir + 1) % 4;
1348 break; 1447 break;
1448#endif
1349 1449
1350 case BUTTON_RC_VOL_UP: 1450#ifdef REMOTE
1451 case BTN_RC_UP:
1351 player3_dir = (player3_dir + 1) % 4; 1452 player3_dir = (player3_dir + 1) % 4;
1352 break; 1453 break;
1353 1454
1354 case BUTTON_RC_VOL_DOWN: 1455 case BTN_RC_DOWN:
1355 player3_dir = (player3_dir + 3) % 4; 1456 player3_dir = (player3_dir + 3) % 4;
1356 break; 1457 break;
1458#endif
1357 1459
1358 case BUTTON_PLAY: 1460 case BTN_STARTPAUSE:
1359 do { 1461 do {
1360 button = rb->button_get(true); 1462 button = rb->button_get(true);
1361 } while (button != BUTTON_PLAY && 1463 } while (button != BTN_STARTPAUSE &&
1362 button != BUTTON_OFF && 1464 button != BTN_QUIT &&
1363 button != BUTTON_ON); 1465 button != BTN_STOPRESET);
1364 break; 1466 break;
1365 } 1467 }
1366 1468
@@ -1377,7 +1479,7 @@ static bool run(void)
1377 } 1479 }
1378 score_board(); 1480 score_board();
1379 rb->lcd_update(); 1481 rb->lcd_update();
1380 if (button == BUTTON_ON) { 1482 if (button == BTN_STOPRESET) {
1381 wormDead = true; 1483 wormDead = true;
1382 } 1484 }
1383 1485
@@ -1478,7 +1580,6 @@ static void test_worm_food_collision(void) {
1478 1580
1479} 1581}
1480 1582
1481
1482static bool expensive_worm_in_rect(struct worm *w, int rx, int ry, int rw, int rh){ 1583static bool expensive_worm_in_rect(struct worm *w, int rx, int ry, int rw, int rh){
1483 int x, y; 1584 int x, y;
1484 bool retVal = false; 1585 bool retVal = false;
@@ -1876,10 +1977,10 @@ static void test_worm_argh_collision_in_moves(void) {
1876 rb->snprintf(buf, sizeof buf, "in 5 moves hits: %d", hit_count); 1977 rb->snprintf(buf, sizeof buf, "in 5 moves hits: %d", hit_count);
1877 rb->lcd_putsxy(0, LCD_HEIGHT - 8, buf); 1978 rb->lcd_putsxy(0, LCD_HEIGHT - 8, buf);
1878 rb->lcd_update(); 1979 rb->lcd_update();
1879 } 1980 }
1880 if (hit_count != ARGH_SIZE + 5) { 1981 if (hit_count != ARGH_SIZE + 5) {
1881 rb->button_get(true); 1982 rb->button_get(true);
1882 } 1983 }
1883} 1984}
1884#endif /* DEBUG_WORMLET */ 1985#endif /* DEBUG_WORMLET */
1885 1986
@@ -1892,12 +1993,16 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1892{ 1993{
1893 bool worm_dead = false; 1994 bool worm_dead = false;
1894 int button; 1995 int button;
1895 1996
1896 (void)(parameter); 1997 (void)(parameter);
1897 1998
1898 rb = api; 1999 rb = api;
1899 rb->lcd_setfont(FONT_SYSFIXED); 2000 rb->lcd_setfont(FONT_SYSFIXED);
1900 2001
2002#ifdef COLOR_LCD
2003 rb->lcd_set_background(LCD_RGBPACK(200, 210, 230));
2004#endif
2005
1901#ifdef DEBUG_WORMLET 2006#ifdef DEBUG_WORMLET
1902 testline_in_rect(); 2007 testline_in_rect();
1903 test_worm_argh_collision_in_moves(); 2008 test_worm_argh_collision_in_moves();
@@ -1905,47 +2010,65 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1905 test_worm_food_collision(); 2010 test_worm_food_collision();
1906 test_worm_argh_collision(); 2011 test_worm_argh_collision();
1907 test_specific_worm_collision(); 2012 test_specific_worm_collision();
1908#endif 2013#endif
1909 2014
1910 /* Setup screen */ 2015 /* Setup screen */
1911 do { 2016 do {
1912 char buf[20]; 2017 char buf[40];
1913 char* ptr; 2018 char* ptr;
1914 rb->lcd_clear_display(); 2019 rb->lcd_clear_display();
1915 2020
1916 /* first line players */ 2021 /* first line players */
1917 rb->snprintf(buf, sizeof buf, "%d Players UP/DN", players); 2022#ifdef MULTIPLAYER
2023 rb->snprintf(buf, sizeof buf, "%d Players (%s)", players, PLAYERS_TEXT);
2024#else
2025 rb->snprintf(buf, sizeof buf, "1 Player");
2026#endif
1918 rb->lcd_puts(0, 0, buf); 2027 rb->lcd_puts(0, 0, buf);
1919 2028
1920 /* second line worms */ 2029 /* second line worms */
1921 rb->snprintf(buf, sizeof buf, "%d Worms L/R", worm_count); 2030 rb->snprintf(buf, sizeof buf, "%d Worms (%s)", worm_count, WORMS_TEXT);
1922 rb->lcd_puts(0, 1, buf); 2031 rb->lcd_puts(0, 1, buf);
1923 2032
2033#if defined MULTIPLAYER && defined REMOTE
1924 /* third line control */ 2034 /* third line control */
1925 if (players > 1) { 2035 if (players > 1) {
1926 if (use_remote) { 2036 if (use_remote) {
1927 ptr = "Remote Control F1"; 2037 rb->snprintf(buf, sizeof(buf), "Remote Control (%s)", KEY_CONTROL_TEXT);
2038 ptr = buf;
1928 } else { 2039 } else {
1929 ptr = "No Rem. Control F1"; 2040 rb->snprintf(buf, sizeof(buf), "No Rem. Control (%s)", KEY_CONTROL_TEXT);
2041 ptr = buf;
1930 } 2042 }
1931 } else { 2043 } else {
1932 if (players > 0) { 2044 if (players > 0) {
1933 if (use_remote) { 2045 if (use_remote) {
1934 ptr = "2 Key Control F1"; 2046 rb->snprintf(buf, sizeof(buf), "2 Key Control (%s)", KEY_CONTROL_TEXT);
2047 ptr = buf;
1935 } else { 2048 } else {
1936 ptr = "4 Key Control F1"; 2049 rb->snprintf(buf, sizeof(buf), "4 Key Control (%s)", KEY_CONTROL_TEXT);
2050 ptr = buf;
1937 } 2051 }
1938 } else { 2052 } else {
1939 ptr = "Out Of Control"; 2053 ptr = "Out Of Control";
1940 } 2054 }
1941 } 2055 }
1942 rb->lcd_puts(0, 2, ptr); 2056 rb->lcd_puts(0, 2, ptr);
2057#endif
1943 rb->lcd_update(); 2058 rb->lcd_update();
1944 2059
1945 /* user selection */ 2060 /* user selection */
1946 button = rb->button_get(true); 2061 button = rb->button_get(true);
1947 switch (button) { 2062 switch (button) {
1948 case BUTTON_UP: 2063#ifdef MULTIPLAYER
2064 case BTN_TOGGLE_KEYS:
2065 use_remote = !use_remote;
2066 if (players > 2) {
2067 use_remote = true;
2068 }
2069 break;
2070
2071 case BTN_DIR_UP:
1949 if (players < 3) { 2072 if (players < 3) {
1950 players ++; 2073 players ++;
1951 if (players > worm_count) { 2074 if (players > worm_count) {
@@ -1956,12 +2079,14 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1956 } 2079 }
1957 } 2080 }
1958 break; 2081 break;
1959 case BUTTON_DOWN: 2082
2083 case BTN_DIR_DOWN:
1960 if (players > 0) { 2084 if (players > 0) {
1961 players --; 2085 players --;
1962 } 2086 }
1963 break; 2087 break;
1964 case BUTTON_LEFT: 2088#endif
2089 case BTN_DIR_LEFT:
1965 if (worm_count > 1) { 2090 if (worm_count > 1) {
1966 worm_count--; 2091 worm_count--;
1967 if (worm_count < players) { 2092 if (worm_count < players) {
@@ -1969,56 +2094,49 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1969 } 2094 }
1970 } 2095 }
1971 break; 2096 break;
1972 case BUTTON_RIGHT: 2097
2098 case BTN_DIR_RIGHT:
1973 if (worm_count < MAX_WORMS) { 2099 if (worm_count < MAX_WORMS) {
1974 worm_count ++; 2100 worm_count ++;
1975 } 2101 }
1976 break; 2102 break;
1977 case BUTTON_F1:
1978 use_remote = !use_remote;
1979 if (players > 2) {
1980 use_remote = true;
1981 }
1982 break;
1983 2103
1984 default: 2104 default:
1985 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) 2105 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
1986 return PLUGIN_USB_CONNECTED; 2106 return PLUGIN_USB_CONNECTED;
1987 break; 2107 break;
1988 } 2108 }
1989 } while (button != BUTTON_PLAY && 2109 } while (button != BTN_STARTPAUSE &&
1990 button != BUTTON_OFF && button != BUTTON_ON); 2110 button != BTN_QUIT && button != BTN_STOPRESET);
1991 2111
1992 rb->lcd_clear_display(); 2112 rb->lcd_clear_display();
1993 /* end of setup */ 2113 /* end of setup */
1994 2114
1995 do { 2115 do {
1996 2116
1997 /* button state will be overridden if 2117 /* button state will be overridden if
1998 the game quits with the death of the worm. 2118 the game quits with the death of the worm.
1999 Initializing button to BUTTON_OFF ensures 2119 Initializing button to BTN_QUIT ensures
2000 that the user can hit BUTTON_OFF during the 2120 that the user can hit BTN_QUIT during the
2001 game to return to the menu. 2121 game to return to the menu.
2002 */ 2122 */
2003 button = BUTTON_OFF; 2123 button = BTN_QUIT;
2004 2124
2005 /* start the game */ 2125 /* start the game */
2006 worm_dead = run(); 2126 worm_dead = run();
2007 2127
2008 /* if worm isn't dead the game was quit 2128 /* if worm isn't dead the game was quit
2009 via BUTTON_OFF -> no need to wait for buttons. */ 2129 via BTN_QUIT -> no need to wait for buttons. */
2010 if (worm_dead) { 2130 if (worm_dead) {
2011 do { 2131 do {
2012 button = rb->button_get(true); 2132 button = rb->button_get(true);
2013 } 2133 }
2014 /* BUTTON_ON -> start new game */ 2134 /* BTN_STOPRESET -> start new game */
2015 /* BUTTON_OFF -> back to game menu */ 2135 /* BTN_QUIT -> back to game menu */
2016 while (button != BUTTON_OFF && button != BUTTON_ON); 2136 while (button != BTN_QUIT && button != BTN_STOPRESET);
2017 } 2137 }
2018 } 2138 }
2019 while (button != BUTTON_OFF); 2139 while (button != BTN_QUIT);
2020 2140
2021 return PLUGIN_OK; 2141 return PLUGIN_OK;
2022} 2142}
2023
2024#endif