1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Philipp Pertermann
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "lib/configfile.h"
23 #include "lib/helper.h"
24 #include "lib/playback_control.h"
28 /* size of the field the worm lives in */
29 #define FIELD_RECT_X 1
30 #define FIELD_RECT_Y 1
31 #define FIELD_RECT_WIDTH (LCD_WIDTH - 45)
32 #define FIELD_RECT_HEIGHT (LCD_HEIGHT - 2)
34 /* when the game starts */
35 #define INITIAL_WORM_LENGTH 10
37 /* num of pixel the worm grows per eaten food */
38 #define WORM_PER_FOOD 7
40 /* num of worms creeping in the FIELD */
43 /* minimal distance between a worm and an argh
44 when a new argh is made */
45 #define MIN_ARGH_DIST 5
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_STARTPAUSE BUTTON_PLAY
55 #define BTN_QUIT BUTTON_OFF
56 #define BTN_STOPRESET BUTTON_ON
57 #define BTN_TOGGLE_KEYS BUTTON_F1
59 #if BUTTON_REMOTE != 0
60 #define BTN_RC_UP BUTTON_RC_VOL_UP
61 #define BTN_RC_DOWN BUTTON_RC_VOL_DOWN
66 #elif (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
67 #define BTN_DIR_UP BUTTON_UP
68 #define BTN_DIR_DOWN BUTTON_DOWN
69 #define BTN_DIR_LEFT BUTTON_LEFT
70 #define BTN_DIR_RIGHT BUTTON_RIGHT
71 #define BTN_PLAYER2_DIR1 BUTTON_F2
72 #define BTN_PLAYER2_DIR2 BUTTON_F3
73 #define BTN_STARTPAUSE BUTTON_SELECT
74 #define BTN_QUIT BUTTON_OFF
75 #define BTN_STOPRESET BUTTON_ON
76 #define BTN_TOGGLE_KEYS BUTTON_F1
78 #elif (CONFIG_KEYPAD == ONDIO_PAD)
79 #define BTN_DIR_UP BUTTON_UP
80 #define BTN_DIR_DOWN BUTTON_DOWN
81 #define BTN_DIR_LEFT BUTTON_LEFT
82 #define BTN_DIR_RIGHT BUTTON_RIGHT
83 #define BTN_STARTPAUSE (BUTTON_MENU|BUTTON_REL)
84 #define BTN_QUIT (BUTTON_OFF|BUTTON_REL)
85 #define BTN_STOPRESET (BUTTON_OFF|BUTTON_MENU)
87 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
88 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
90 #define BTN_DIR_UP BUTTON_MENU
91 #define BTN_DIR_DOWN BUTTON_PLAY
92 #define BTN_DIR_LEFT BUTTON_LEFT
93 #define BTN_DIR_RIGHT BUTTON_RIGHT
94 #define BTN_STARTPAUSE (BUTTON_SELECT|BUTTON_REL)
95 #define BTN_QUIT (BUTTON_SELECT|BUTTON_MENU)
96 #define BTN_STOPRESET (BUTTON_SELECT|BUTTON_PLAY)
98 #elif (CONFIG_KEYPAD == IRIVER_H300_PAD) || (CONFIG_KEYPAD == IRIVER_H100_PAD)
100 #define BTN_DIR_UP BUTTON_UP
101 #define BTN_DIR_DOWN BUTTON_DOWN
102 #define BTN_DIR_LEFT BUTTON_LEFT
103 #define BTN_DIR_RIGHT BUTTON_RIGHT
104 #define BTN_STARTPAUSE (BUTTON_SELECT|BUTTON_REL)
105 #define BTN_QUIT BUTTON_OFF
106 #define BTN_STOPRESET BUTTON_ON
108 #define BTN_RC_QUIT BUTTON_RC_STOP
110 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
112 #define BTN_DIR_UP BUTTON_UP
113 #define BTN_DIR_DOWN BUTTON_DOWN
114 #define BTN_DIR_LEFT BUTTON_LEFT
115 #define BTN_DIR_RIGHT BUTTON_RIGHT
116 #define BTN_STARTPAUSE BUTTON_PLAY
117 #define BTN_QUIT BUTTON_POWER
118 #define BTN_STOPRESET BUTTON_REC
120 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
122 #define BTN_DIR_UP BUTTON_UP
123 #define BTN_DIR_DOWN BUTTON_DOWN
124 #define BTN_DIR_LEFT BUTTON_LEFT
125 #define BTN_DIR_RIGHT BUTTON_RIGHT
126 #define BTN_STARTPAUSE BUTTON_SELECT
127 #define BTN_QUIT BUTTON_POWER
128 #define BTN_STOPRESET BUTTON_A
130 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
131 (CONFIG_KEYPAD == SANSA_C200_PAD)
133 #define BTN_DIR_UP BUTTON_UP
134 #define BTN_DIR_DOWN BUTTON_DOWN
135 #define BTN_DIR_LEFT BUTTON_LEFT
136 #define BTN_DIR_RIGHT BUTTON_RIGHT
137 #define BTN_STARTPAUSE BUTTON_SELECT
138 #define BTN_QUIT BUTTON_POWER
139 #define BTN_STOPRESET BUTTON_REC
141 #elif (CONFIG_KEYPAD == SANSA_CLIP_PAD)
143 #define BTN_DIR_UP BUTTON_UP
144 #define BTN_DIR_DOWN BUTTON_DOWN
145 #define BTN_DIR_LEFT BUTTON_LEFT
146 #define BTN_DIR_RIGHT BUTTON_RIGHT
147 #define BTN_STARTPAUSE BUTTON_SELECT
148 #define BTN_QUIT BUTTON_POWER
149 #define BTN_STOPRESET BUTTON_HOME
151 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
153 #define BTN_DIR_UP BUTTON_UP
154 #define BTN_DIR_DOWN BUTTON_DOWN
155 #define BTN_DIR_LEFT BUTTON_LEFT
156 #define BTN_DIR_RIGHT BUTTON_RIGHT
157 #define BTN_STARTPAUSE BUTTON_SELECT
158 #define BTN_QUIT (BUTTON_HOME|BUTTON_REPEAT)
159 #define BTN_STOPRESET (BUTTON_SELECT | BUTTON_UP)
161 #elif (CONFIG_KEYPAD == SANSA_M200_PAD)
163 #define BTN_DIR_UP BUTTON_UP
164 #define BTN_DIR_DOWN BUTTON_DOWN
165 #define BTN_DIR_LEFT BUTTON_LEFT
166 #define BTN_DIR_RIGHT BUTTON_RIGHT
167 #define BTN_STARTPAUSE (BUTTON_SELECT | BUTTON_REL)
168 #define BTN_QUIT BUTTON_POWER
169 #define BTN_STOPRESET (BUTTON_SELECT | BUTTON_UP)
171 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
173 #define BTN_DIR_UP BUTTON_SCROLL_UP
174 #define BTN_DIR_DOWN BUTTON_SCROLL_DOWN
175 #define BTN_DIR_LEFT BUTTON_LEFT
176 #define BTN_DIR_RIGHT BUTTON_RIGHT
177 #define BTN_STARTPAUSE BUTTON_PLAY
178 #define BTN_QUIT BUTTON_POWER
179 #define BTN_STOPRESET BUTTON_REW
181 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
183 #define BTN_DIR_UP BUTTON_UP
184 #define BTN_DIR_DOWN BUTTON_DOWN
185 #define BTN_DIR_LEFT BUTTON_LEFT
186 #define BTN_DIR_RIGHT BUTTON_RIGHT
187 #define BTN_STARTPAUSE BUTTON_SELECT
188 #define BTN_QUIT BUTTON_BACK
189 #define BTN_STOPRESET BUTTON_MENU
191 #elif (CONFIG_KEYPAD == MROBE100_PAD)
193 #define BTN_DIR_UP BUTTON_UP
194 #define BTN_DIR_DOWN BUTTON_DOWN
195 #define BTN_DIR_LEFT BUTTON_LEFT
196 #define BTN_DIR_RIGHT BUTTON_RIGHT
197 #define BTN_STARTPAUSE BUTTON_SELECT
198 #define BTN_QUIT BUTTON_POWER
199 #define BTN_STOPRESET BUTTON_DISPLAY
201 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
203 #define BTN_DIR_UP BUTTON_RC_VOL_UP
204 #define BTN_DIR_DOWN BUTTON_RC_VOL_DOWN
205 #define BTN_DIR_LEFT BUTTON_RC_REW
206 #define BTN_DIR_RIGHT BUTTON_RC_FF
207 #define BTN_STARTPAUSE BUTTON_RC_PLAY
208 #define BTN_QUIT BUTTON_RC_REC
209 #define BTN_STOPRESET BUTTON_RC_MODE
211 #elif (CONFIG_KEYPAD == COWOND2_PAD)
213 #define BTN_QUIT BUTTON_POWER
215 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
217 #define BTN_DIR_UP BUTTON_UP
218 #define BTN_DIR_DOWN BUTTON_DOWN
219 #define BTN_DIR_LEFT BUTTON_LEFT
220 #define BTN_DIR_RIGHT BUTTON_RIGHT
221 #define BTN_STARTPAUSE BUTTON_PLAY
222 #define BTN_QUIT BUTTON_BACK
223 #define BTN_STOPRESET BUTTON_MENU
225 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
227 #define BTN_DIR_UP BUTTON_UP
228 #define BTN_DIR_DOWN BUTTON_DOWN
229 #define BTN_DIR_LEFT BUTTON_LEFT
230 #define BTN_DIR_RIGHT BUTTON_RIGHT
231 #define BTN_STARTPAUSE BUTTON_MENU
232 #define BTN_QUIT BUTTON_POWER
233 #define BTN_STOPRESET BUTTON_VIEW
235 #elif (CONFIG_KEYPAD == ONDAVX747_PAD) || CONFIG_KEYPAD == MROBE500_PAD
237 #define BTN_QUIT BUTTON_POWER
239 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
241 #define BTN_DIR_UP BUTTON_UP
242 #define BTN_DIR_DOWN BUTTON_DOWN
243 #define BTN_DIR_LEFT BUTTON_LEFT
244 #define BTN_DIR_RIGHT BUTTON_RIGHT
245 #define BTN_STARTPAUSE BUTTON_PLAY
246 #define BTN_QUIT BUTTON_FFWD
247 #define BTN_STOPRESET BUTTON_REW
250 #error No keymap defined!
253 #ifdef HAVE_TOUCHSCREEN
255 #define BTN_DIR_UP BUTTON_TOPMIDDLE
258 #define BTN_DIR_DOWN BUTTON_BOTTOMMIDDLE
261 #define BTN_DIR_LEFT BUTTON_MIDLEFT
263 #ifndef BTN_DIR_RIGHT
264 #define BTN_DIR_RIGHT BUTTON_MIDRIGHT
266 #ifndef BTN_STARTPAUSE
267 #define BTN_STARTPAUSE BUTTON_CENTER
270 #define BTN_QUIT BUTTON_TOPLEFT
272 #ifndef BTN_STOPRESET
273 #define BTN_STOPRESET BUTTON_TOPRIGHT
277 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
281 #define MAX_WORM_SEGMENTS 128
282 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 64)
286 #define MAX_WORM_SEGMENTS 128
287 #elif (LCD_WIDTH == 132) && (LCD_HEIGHT == 80)
291 #define MAX_WORM_SEGMENTS 128
292 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 96)
296 #define MAX_WORM_SEGMENTS 128
297 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
301 #define MAX_WORM_SEGMENTS 128
302 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128)
306 #define MAX_WORM_SEGMENTS 128
307 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
311 #define MAX_WORM_SEGMENTS 256
312 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132)
316 #define MAX_WORM_SEGMENTS 256
317 #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176)
321 #define MAX_WORM_SEGMENTS 512
322 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 220)
326 #define MAX_WORM_SEGMENTS 512
327 #elif ((LCD_WIDTH == 320) && (LCD_HEIGHT == 240)) || \
328 ((LCD_WIDTH == 240) && ((LCD_HEIGHT == 320) || (LCD_HEIGHT == 400)))
332 #define MAX_WORM_SEGMENTS 512
333 #elif ((LCD_WIDTH == 640) && (LCD_HEIGHT == 480)) || \
334 ((LCD_WIDTH == 480) && (LCD_HEIGHT == 640))
338 #define MAX_WORM_SEGMENTS 512
341 #ifdef HAVE_LCD_COLOR
342 #define COLOR_WORM LCD_RGBPACK(80, 40, 0)
343 #define COLOR_ARGH LCD_RGBPACK(175, 0, 0)
344 #define COLOR_FOOD LCD_RGBPACK(0, 150, 0)
345 #define COLOR_FG LCD_RGBPACK(0, 0, 0)
346 #define COLOR_BG LCD_RGBPACK(181, 199, 231)
350 * All the properties that a worm has.
353 /* The worm is stored in a ring of xy coordinates */
354 int x
[MAX_WORM_SEGMENTS
];
355 int y
[MAX_WORM_SEGMENTS
];
357 int head
; /* index of the head within the buffer */
358 int tail
; /* index of the tail within the buffer */
359 int growing
; /* number of cyles the worm still keeps growing */
360 bool alive
; /* the worms living state */
362 /* direction vector in which the worm moves */
363 int dirx
; /* only values -1 0 1 allowed */
364 int diry
; /* only values -1 0 1 allowed */
366 /* this method is used to fetch the direction the user
367 has selected. It can be one of the values
368 human_player1, human_player2, remote_player, virtual_player.
369 All these values are fuctions, that can change the direction
371 void (*fetch_worm_direction
)(struct worm
*w
);
374 /* stores the highscore - besides it was scored by a virtual player */
375 static int highscore
;
377 #define MAX_FOOD 5 /* maximal number of food items */
379 /* The arrays store the food coordinates */
380 static int foodx
[MAX_FOOD
];
381 static int foody
[MAX_FOOD
];
383 #define MAX_ARGH 100 /* maximal number of argh items */
384 #define ARGHS_PER_FOOD 2 /* number of arghs produced per eaten food */
386 /* The arrays store the argh coordinates */
387 static int arghx
[MAX_ARGH
];
388 static int arghy
[MAX_ARGH
];
390 /* the number of arghs that are currently in use */
391 static int argh_count
;
393 /* the number of arghs per food, settable by user */
394 static int arghs_per_food
= ARGHS_PER_FOOD
;
395 /* the size of the argh, settable by user */
396 static int argh_size
= ARGH_SIZE
;
397 /* the size of the food, settable by user */
398 static int food_size
= FOOD_SIZE
;
399 /* the speed of the worm, settable by user */
400 static int speed
= SPEED
;
401 /* the amount a worm grows by eating a food, settable by user */
402 static int worm_food
= WORM_PER_FOOD
;
404 /* End additional variables */
407 /* just a buffer used for debug output */
408 static char debugout
[15];
411 /* the number of active worms (dead or alive) */
412 static int worm_count
= MAX_WORMS
;
414 /* in multiplayer mode: en- / disables the remote worm control
415 in singleplayer mode: toggles 4 / 2 button worm control */
416 static bool use_remote
= false;
418 /* return values of check_collision */
419 #define COLLISION_NONE 0
420 #define COLLISION_WORM 1
421 #define COLLISION_FOOD 2
422 #define COLLISION_ARGH 3
423 #define COLLISION_FIELD 4
425 /* constants for use as directions.
426 Note that the values are ordered clockwise.
427 Thus increasing / decreasing the values
428 is equivalent to right / left turns. */
434 /* direction of human player 1 */
435 static int player1_dir
= EAST
;
436 /* direction of human player 2 */
437 static int player2_dir
= EAST
;
438 /* direction of human player 3 */
439 static int player3_dir
= EAST
;
441 /* the number of (human) players that currently
443 static int players
= 1;
445 #define SETTINGS_VERSION 1
446 #define SETTINGS_MIN_VERSION 1
447 #define SETTINGS_FILENAME "wormlet.cfg"
449 static struct configdata config
[] =
451 {TYPE_INT
, 0, 1024, { .int_p
= &highscore
}, "highscore", NULL
},
452 {TYPE_INT
, 0, 15, { .int_p
= &arghs_per_food
}, "arghs per food", NULL
},
453 {TYPE_INT
, 0, 15, { .int_p
= &argh_size
}, "argh size", NULL
},
454 {TYPE_INT
, 0, 15, { .int_p
= &food_size
}, "food size", NULL
},
455 {TYPE_INT
, 0, 3, { .int_p
= &players
}, "players", NULL
},
456 {TYPE_INT
, 0, 3, { .int_p
= &worm_count
}, "worms", NULL
},
457 {TYPE_INT
, 0, 20, { .int_p
= &speed
}, "speed", NULL
},
458 {TYPE_INT
, 0, 15, { .int_p
= &worm_food
}, "Worm Growth Per Food", NULL
}
462 static void set_debug_out(char *str
){
463 strcpy(debugout
, str
);
468 * Returns the direction id in which the worm
469 * currently is creeping.
470 * @param struct worm *w The worm that is to be investigated.
471 * w Must not be null.
472 * @return int A value 0 <= value < 4
473 * Note the predefined constants NORTH, SOUTH, EAST, WEST
475 static int get_worm_dir(struct worm
*w
)
495 * Set the direction of the specified worm with a direction id.
496 * Increasing the value by 1 means to turn the worm direction
497 * to right by 90 degree.
498 * @param struct worm *w The worm that is to be altered. w Must not be null.
499 * @param int dir The new direction in which the worm is to creep.
500 * dir must be 0 <= dir < 4. Use predefined constants
501 * NORTH, SOUTH, EAST, WEST
503 static void set_worm_dir(struct worm
*w
, int dir
)
526 * Returns the current length of the worm array. This
527 * is also a value for the number of bends that are in the worm.
528 * @return int a positive value with 0 <= value < MAX_WORM_SEGMENTS
530 static int get_worm_array_length(struct worm
*w
)
532 /* initial simple calculation will be overwritten if wrong. */
533 int retVal
= w
->head
- w
->tail
;
535 /* if the worm 'crosses' the boundaries of the ringbuffer */
537 retVal
= w
->head
+ MAX_WORM_SEGMENTS
- w
->tail
;
544 * Returns the score the specified worm. The score is the length
546 * @param struct worm *w The worm that is to be investigated.
547 * w must not be null.
548 * @return int The length of the worm (>= 0).
550 static int get_score(struct worm
*w
)
553 int length
= get_worm_array_length(w
);
555 for (i
= 0; i
< length
; i
++) {
557 /* The iteration iterates the length of the worm.
558 Here's the conversion to the true indices within the worm arrays. */
559 int linestart
= (w
->tail
+ i
) % MAX_WORM_SEGMENTS
;
560 int lineend
= (linestart
+ 1) % MAX_WORM_SEGMENTS
;
561 int startx
= w
->x
[linestart
];
562 int starty
= w
->y
[linestart
];
563 int endx
= w
->x
[lineend
];
564 int endy
= w
->y
[lineend
];
566 int minimum
, maximum
;
568 if (startx
== endx
) {
569 minimum
= MIN(starty
, endy
);
570 maximum
= MAX(starty
, endy
);
572 minimum
= MIN(startx
, endx
);
573 maximum
= MAX(startx
, endx
);
575 retval
+= abs(maximum
- minimum
);
581 * Determines wether the line specified by startx, starty, endx, endy intersects
582 * the rectangle specified by x, y, width, height. Note that the line must be exactly
583 * horizontal or vertical (startx == endx or starty == endy).
584 * @param int startx The x coordinate of the start point of the line.
585 * @param int starty The y coordinate of the start point of the line.
586 * @param int endx The x coordinate of the end point of the line.
587 * @param int endy The y coordinate of the end point of the line.
588 * @param int x The x coordinate of the top left corner of the rectangle.
589 * @param int y The y coordinate of the top left corner of the rectangle.
590 * @param int width The width of the rectangle.
591 * @param int height The height of the rectangle.
592 * @return bool Returns true if the specified line intersects with the recangle.
594 static bool line_in_rect(int startx
, int starty
, int endx
, int endy
,
595 int x
, int y
, int width
, int height
)
598 int simple
, simplemin
, simplemax
;
599 int compa
, compb
, compmin
, compmax
;
601 if (startx
== endx
) {
604 simplemax
= x
+ width
;
609 compmax
= y
+ height
;
613 simplemax
= y
+ height
;
622 compa
= MIN(compa
, compb
);
623 compb
= MAX(temp
, compb
);
625 if (simplemin
<= simple
&& simple
<= simplemax
) {
626 if ((compmin
<= compa
&& compa
<= compmax
) ||
627 (compmin
<= compb
&& compb
<= compmax
) ||
628 (compa
<= compmin
&& compb
>= compmax
)) {
636 * Tests wether the specified worm intersects with the rect.
637 * @param struct worm *w The worm to be investigated
638 * @param int x The x coordinate of the top left corner of the rect
639 * @param int y The y coordinate of the top left corner of the rect
640 * @param int widht The width of the rect
641 * @param int height The height of the rect
642 * @return bool Returns true if the worm intersects with the rect
644 static bool worm_in_rect(struct worm
*w
, int x
, int y
, int width
, int height
)
649 /* get_worm_array_length is expensive -> buffer the value */
650 int wormLength
= get_worm_array_length(w
);
653 /* test each entry that is part of the worm */
654 for (i
= 0; i
< wormLength
&& retval
== false; i
++) {
656 /* The iteration iterates the length of the worm.
657 Here's the conversion to the true indices within the worm arrays. */
658 int linestart
= (w
->tail
+ i
) % MAX_WORM_SEGMENTS
;
659 int lineend
= (linestart
+ 1) % MAX_WORM_SEGMENTS
;
660 int startx
= w
->x
[linestart
];
661 int starty
= w
->y
[linestart
];
662 int endx
= w
->x
[lineend
];
663 int endy
= w
->y
[lineend
];
665 retval
= line_in_rect(startx
, starty
, endx
, endy
, x
, y
, width
, height
);
672 * Checks wether a specific food in the food arrays is at the
673 * specified coordinates.
674 * @param int foodIndex The index of the food in the food arrays
675 * @param int x the x coordinate.
676 * @param int y the y coordinate.
677 * @return Returns true if the coordinate hits the food specified by
680 static bool specific_food_collision(int foodIndex
, int x
, int y
)
683 if (x
>= foodx
[foodIndex
] &&
684 x
< foodx
[foodIndex
] + food_size
&&
685 y
>= foody
[foodIndex
] &&
686 y
< foody
[foodIndex
] + food_size
) {
694 * Returns the index of the food that is at the
695 * given coordinates. If no food is at the coordinates
697 * @return int -1 <= value < MAX_FOOD
699 static int food_collision(int x
, int y
)
703 for (i
= 0; i
< MAX_FOOD
; i
++) {
704 if (specific_food_collision(i
, x
, y
)) {
713 * Checks wether a specific argh in the argh arrays is at the
714 * specified coordinates.
715 * @param int arghIndex The index of the argh in the argh arrays
716 * @param int x the x coordinate.
717 * @param int y the y coordinate.
718 * @return Returns true if the coordinate hits the argh specified by
721 static bool specific_argh_collision(int arghIndex
, int x
, int y
)
723 if ( x
>= arghx
[arghIndex
] &&
724 y
>= arghy
[arghIndex
] &&
725 x
< arghx
[arghIndex
] + argh_size
&&
726 y
< arghy
[arghIndex
] + argh_size
)
735 * Returns the index of the argh that is at the
736 * given coordinates. If no argh is at the coordinates
738 * @param int x The x coordinate.
739 * @param int y The y coordinate.
740 * @return int -1 <= value < argh_count <= MAX_ARGH
742 static int argh_collision(int x
, int y
)
747 /* search for the argh that has the specified coords */
748 for (i
= 0; i
< argh_count
; i
++) {
749 if (specific_argh_collision(i
, x
, y
)) {
758 * Checks wether the worm collides with the food at the specfied food-arrays.
759 * @param int foodIndex The index of the food in the arrays. Ensure the value is
760 * 0 <= foodIndex <= MAX_FOOD
761 * @return Returns true if the worm collides with the specified food.
763 static bool worm_food_collision(struct worm
*w
, int foodIndex
)
767 retVal
= worm_in_rect(w
, foodx
[foodIndex
], foody
[foodIndex
],
768 food_size
- 1, food_size
- 1);
774 * Returns true if the worm hits the argh within the next moves (unless
775 * the worm changes it's direction).
776 * @param struct worm *w - The worm to investigate
777 * @param int argh_idx - The index of the argh
778 * @param int moves - The number of moves that are considered.
779 * @return Returns false if the specified argh is not hit within the next
782 static bool worm_argh_collision_in_moves(struct worm
*w
, int argh_idx
, int moves
)
789 x2
= w
->x
[w
->head
] + moves
* w
->dirx
;
790 y2
= w
->y
[w
->head
] + moves
* w
->diry
;
792 retVal
= line_in_rect(x1
, y1
, x2
, y2
, arghx
[argh_idx
], arghy
[argh_idx
],
793 argh_size
, argh_size
);
798 * Checks wether the worm collides with the argh at the specfied argh-arrays.
799 * @param int arghIndex The index of the argh in the arrays.
800 * Ensure the value is 0 <= arghIndex < argh_count <= MAX_ARGH
801 * @return Returns true if the worm collides with the specified argh.
803 static bool worm_argh_collision(struct worm
*w
, int arghIndex
)
807 retVal
= worm_in_rect(w
, arghx
[arghIndex
], arghy
[arghIndex
],
808 argh_size
- 1, argh_size
- 1);
814 * Find new coordinates for the food stored in foodx[index], foody[index]
815 * that don't collide with any other food or argh
817 * Ensure that 0 <= index < MAX_FOOD.
819 static void make_food(int index
)
823 bool collisionDetected
= false;
827 /* make coordinates for a new food so that
828 the entire food lies within the FIELD */
829 x
= rb
->rand() % (FIELD_RECT_WIDTH
- food_size
);
830 y
= rb
->rand() % (FIELD_RECT_HEIGHT
- food_size
);
832 /* Ensure that the new food doesn't collide with any
833 existing foods or arghs.
834 If one or more corners of the new food hit any existing
835 argh or food a collision is detected.
838 food_collision(x
, y
) >= 0 ||
839 food_collision(x
, y
+ food_size
- 1) >= 0 ||
840 food_collision(x
+ food_size
- 1, y
) >= 0 ||
841 food_collision(x
+ food_size
- 1, y
+ food_size
- 1) >= 0 ||
842 argh_collision(x
, y
) >= 0 ||
843 argh_collision(x
, y
+ food_size
- 1) >= 0 ||
844 argh_collision(x
+ food_size
- 1, y
) >= 0 ||
845 argh_collision(x
+ food_size
- 1, y
+ food_size
- 1) >= 0;
847 /* use coordinates for further testing */
851 /* now test wether we accidently hit the worm with food ;) */
853 for (i
= 0; i
< worm_count
&& !collisionDetected
; i
++) {
854 collisionDetected
|= worm_food_collision(&worms
[i
], index
);
857 while (collisionDetected
);
862 * Clears a food from the lcd buffer.
863 * @param int index The index of the food arrays under which
864 * the coordinates of the desired food can be found. Ensure
865 * that the value is 0 <= index <= MAX_FOOD.
867 static void clear_food(int index
)
869 /* remove the old food from the screen */
870 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
871 rb
->lcd_fillrect(foodx
[index
] + FIELD_RECT_X
,
872 foody
[index
] + FIELD_RECT_Y
,
873 food_size
, food_size
);
874 rb
->lcd_set_drawmode(DRMODE_SOLID
);
878 * Draws a food in the lcd buffer.
879 * @param int index The index of the food arrays under which
880 * the coordinates of the desired food can be found. Ensure
881 * that the value is 0 <= index <= MAX_FOOD.
883 static void draw_food(int index
)
885 /* draw the food object */
886 #ifdef HAVE_LCD_COLOR
887 rb
->lcd_set_foreground(COLOR_FOOD
);
889 rb
->lcd_fillrect(foodx
[index
] + FIELD_RECT_X
,
890 foody
[index
] + FIELD_RECT_Y
,
891 food_size
, food_size
);
892 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
893 rb
->lcd_fillrect(foodx
[index
] + FIELD_RECT_X
+ 1,
894 foody
[index
] + FIELD_RECT_Y
+ 1,
895 food_size
- 2, food_size
- 2);
896 rb
->lcd_set_drawmode(DRMODE_SOLID
);
897 #ifdef HAVE_LCD_COLOR
898 rb
->lcd_set_foreground(COLOR_FG
);
903 * Find new coordinates for the argh stored in arghx[index], arghy[index]
904 * that don't collide with any other food or argh.
906 * Ensure that 0 <= index < argh_count < MAX_ARGH.
908 static void make_argh(int index
)
912 bool collisionDetected
= false;
916 /* make coordinates for a new argh so that
917 the entire food lies within the FIELD */
918 x
= rb
->rand() % (FIELD_RECT_WIDTH
- argh_size
);
919 y
= rb
->rand() % (FIELD_RECT_HEIGHT
- argh_size
);
921 /* Ensure that the new argh doesn't intersect with any
922 existing foods or arghs.
923 If one or more corners of the new argh hit any existing
924 argh or food an intersection is detected.
927 food_collision(x
, y
) >= 0 ||
928 food_collision(x
, y
+ argh_size
- 1) >= 0 ||
929 food_collision(x
+ argh_size
- 1, y
) >= 0 ||
930 food_collision(x
+ argh_size
- 1, y
+ argh_size
- 1) >= 0 ||
931 argh_collision(x
, y
) >= 0 ||
932 argh_collision(x
, y
+ argh_size
- 1) >= 0 ||
933 argh_collision(x
+ argh_size
- 1, y
) >= 0 ||
934 argh_collision(x
+ argh_size
- 1, y
+ argh_size
- 1) >= 0;
936 /* use the candidate coordinates to make a real argh */
940 /* now test wether we accidently hit the worm with argh ;) */
941 for (i
= 0; i
< worm_count
&& !collisionDetected
; i
++) {
942 collisionDetected
|= worm_argh_collision(&worms
[i
], index
);
943 collisionDetected
|= worm_argh_collision_in_moves(&worms
[i
], index
,
947 while (collisionDetected
);
952 * Draws an argh in the lcd buffer.
953 * @param int index The index of the argh arrays under which
954 * the coordinates of the desired argh can be found. Ensure
955 * that the value is 0 <= index < argh_count <= MAX_ARGH.
957 static void draw_argh(int index
)
959 /* draw the new argh */
960 #ifdef HAVE_LCD_COLOR
961 rb
->lcd_set_foreground(COLOR_ARGH
);
963 rb
->lcd_fillrect(arghx
[index
] + FIELD_RECT_X
,
964 arghy
[index
] + FIELD_RECT_Y
,
965 argh_size
, argh_size
);
966 #ifdef HAVE_LCD_COLOR
967 rb
->lcd_set_foreground(COLOR_FG
);
971 static void virtual_player(struct worm
*w
);
973 * Initialzes the specified worm with INITIAL_WORM_LENGTH
974 * and the tail at the specified position. The worm will
975 * be initialized alive and creeping EAST.
976 * @param struct worm *w The worm that is to be initialized
977 * @param int x The x coordinate at which the tail of the worm starts.
978 * x must be 0 <= x < FIELD_RECT_WIDTH.
979 * @param int y The y coordinate at which the tail of the worm starts
980 * y must be 0 <= y < FIELD_RECT_WIDTH.
982 static void init_worm(struct worm
*w
, int x
, int y
)
984 /* initialize the worm size */
988 w
->x
[w
->head
] = x
+ 1;
994 /* set the initial direction the worm creeps to */
998 w
->growing
= INITIAL_WORM_LENGTH
- 1;
1000 w
->fetch_worm_direction
= virtual_player
;
1004 * Writes the direction that was stored for
1005 * human player 1 into the specified worm. This function
1006 * may be used to be stored in worm.fetch_worm_direction.
1008 * the direction is read from player1_dir.
1009 * @param struct worm *w - The worm of which the direction
1012 static void human_player1(struct worm
*w
) {
1013 set_worm_dir(w
, player1_dir
);
1017 * Writes the direction that was stored for
1018 * human player 2 into the specified worm. This function
1019 * may be used to be stored in worm.fetch_worm_direction.
1021 * the direction is read from player2_dir.
1022 * @param struct worm *w - The worm of which the direction
1025 static void human_player2(struct worm
*w
) {
1026 set_worm_dir(w
, player2_dir
);
1030 * Writes the direction that was stored for
1031 * human player using a remote control
1032 * into the specified worm. This function
1033 * may be used to be stored in worm.fetch_worm_direction.
1035 * the direction is read from player3_dir.
1036 * @param struct worm *w - The worm of which the direction
1039 static void remote_player(struct worm
*w
) {
1040 set_worm_dir(w
, player3_dir
);
1044 * Initializes the worm-, food- and argh-arrays, draws a frame,
1045 * makes some food and argh and display all that stuff.
1047 static void init_wormlet(void)
1051 for (i
= 0; i
< worm_count
; i
++) {
1052 /* Initialize all the worm coordinates to center. */
1053 int x
= (int)(FIELD_RECT_WIDTH
/ 2);
1054 int y
= (int)((FIELD_RECT_HEIGHT
- 20)/ 2) + i
* 10;
1056 init_worm(&worms
[i
], x
, y
);
1064 worms
[0].fetch_worm_direction
= human_player1
;
1069 worms
[1].fetch_worm_direction
= remote_player
;
1071 worms
[1].fetch_worm_direction
= human_player2
;
1076 worms
[2].fetch_worm_direction
= human_player2
;
1079 /* Needed when the game is restarted using BTN_STOPRESET */
1080 rb
->lcd_clear_display();
1082 /* make and display some food and argh */
1083 argh_count
= MAX_FOOD
;
1084 for (i
= 0; i
< MAX_FOOD
; i
++) {
1091 /* draw the game field */
1092 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1093 rb
->lcd_fillrect(0, 0, FIELD_RECT_WIDTH
+ 2, FIELD_RECT_HEIGHT
+ 2);
1094 rb
->lcd_fillrect(1, 1, FIELD_RECT_WIDTH
, FIELD_RECT_HEIGHT
);
1095 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1097 /* make everything visible */
1103 * Move the worm one step further if it is alive.
1104 * The direction in which the worm moves is taken from dirx and diry.
1105 * move_worm decreases growing if > 0. While the worm is growing the tail
1106 * is left untouched.
1107 * @param struct worm *w The worm to move. w must not be NULL.
1109 static void move_worm(struct worm
*w
)
1112 /* determine the head point and its precessor */
1113 int headx
= w
->x
[w
->head
];
1114 int heady
= w
->y
[w
->head
];
1115 int prehead
= (w
->head
+ MAX_WORM_SEGMENTS
- 1) % MAX_WORM_SEGMENTS
;
1116 int preheadx
= w
->x
[prehead
];
1117 int preheady
= w
->y
[prehead
];
1119 /* determine the old direction */
1122 if (headx
== preheadx
) {
1124 olddiry
= (heady
> preheady
) ? 1 : -1;
1127 olddirx
= (headx
> preheadx
) ? 1 : -1;
1131 a change of direction means a new segment
1133 if (olddirx
!= w
->dirx
||
1134 olddiry
!= w
->diry
) {
1135 w
->head
= (w
->head
+ 1) % MAX_WORM_SEGMENTS
;
1138 /* new head position */
1139 w
->x
[w
->head
] = headx
+ w
->dirx
;
1140 w
->y
[w
->head
] = heady
+ w
->diry
;
1143 /* while the worm is growing no tail procession is necessary */
1144 if (w
->growing
> 0) {
1145 /* update the worms grow state */
1149 /* if the worm isn't growing the tail has to be dragged */
1151 /* index of the end of the tail segment */
1152 int tail_segment_end
= (w
->tail
+ 1) % MAX_WORM_SEGMENTS
;
1154 /* drag the end of the tail */
1155 /* only one coordinate has to be altered. Here it is
1156 determined which one */
1157 int dir
= 0; /* specifies wether the coord has to be in- or decreased */
1158 if (w
->x
[w
->tail
] == w
->x
[tail_segment_end
]) {
1159 dir
= (w
->y
[w
->tail
] - w
->y
[tail_segment_end
] < 0) ? 1 : -1;
1160 w
->y
[w
->tail
] += dir
;
1162 dir
= (w
->x
[w
->tail
] - w
->x
[tail_segment_end
] < 0) ? 1 : -1;
1163 w
->x
[w
->tail
] += dir
;
1166 /* when the tail has been dragged so far that it meets
1167 the next segment start the tail segment is obsolete and
1169 if (w
->x
[w
->tail
] == w
->x
[tail_segment_end
] &&
1170 w
->y
[w
->tail
] == w
->y
[tail_segment_end
]){
1172 /* drop the last tail point */
1173 w
->tail
= tail_segment_end
;
1180 * Draws the head and clears the tail of the worm in
1181 * the display buffer. lcd_update() is NOT called thus
1182 * the caller has to take care that the buffer is displayed.
1184 static void draw_worm(struct worm
*w
)
1186 /* draw the new head */
1187 int x
= w
->x
[w
->head
];
1188 int y
= w
->y
[w
->head
];
1189 #ifdef HAVE_LCD_COLOR
1190 rb
->lcd_set_foreground(COLOR_WORM
);
1192 if (x
>= 0 && x
< FIELD_RECT_WIDTH
&& y
>= 0 && y
< FIELD_RECT_HEIGHT
) {
1193 rb
->lcd_drawpixel(x
+ FIELD_RECT_X
, y
+ FIELD_RECT_Y
);
1196 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1198 /* clear the space behind the worm */
1201 if (x
>= 0 && x
< FIELD_RECT_WIDTH
&& y
>= 0 && y
< FIELD_RECT_HEIGHT
) {
1202 rb
->lcd_drawpixel(x
+ FIELD_RECT_X
, y
+ FIELD_RECT_Y
);
1204 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1205 #ifdef HAVE_LCD_COLOR
1206 rb
->lcd_set_foreground(COLOR_FG
);
1211 * Checks wether the coordinate is part of the worm. Returns
1212 * true if any part of the worm was hit - including the head.
1213 * @param x int The x coordinate
1214 * @param y int The y coordinate
1215 * @return int The index of the worm arrays that contain x, y.
1216 * Returns -1 if the coordinates are not part of the worm.
1218 static int specific_worm_collision(struct worm
*w
, int x
, int y
)
1222 /* get_worm_array_length is expensive -> buffer the value */
1223 int wormLength
= get_worm_array_length(w
);
1226 /* test each entry that is part of the worm */
1227 for (i
= 0; i
< wormLength
&& retVal
== -1; i
++) {
1229 /* The iteration iterates the length of the worm.
1230 Here's the conversion to the true indices within the worm arrays. */
1231 int linestart
= (w
->tail
+ i
) % MAX_WORM_SEGMENTS
;
1232 int lineend
= (linestart
+ 1) % MAX_WORM_SEGMENTS
;
1233 bool samex
= (w
->x
[linestart
] == x
) && (w
->x
[lineend
] == x
);
1234 bool samey
= (w
->y
[linestart
] == y
) && (w
->y
[lineend
] == y
);
1235 if (samex
|| samey
){
1236 int test
, min
, max
, tmp
;
1239 min
= w
->x
[linestart
];
1240 max
= w
->x
[lineend
];
1243 min
= w
->y
[linestart
];
1244 max
= w
->y
[lineend
];
1249 min
= MIN(min
, max
);
1250 max
= MAX(tmp
, max
);
1252 if (min
<= test
&& test
<= max
) {
1261 * Increases the length of the specified worm by marking
1262 * that it may grow by len pixels. Note that the worm has
1263 * to move to make the growing happen.
1264 * @param worm *w The worm that is to be altered.
1265 * @param int len A positive value specifying the amount of
1266 * pixels the worm may grow.
1268 static void add_growing(struct worm
*w
, int len
) {
1273 * Determins the worm that is at the coordinates x, y. The parameter
1274 * w is a switch parameter that changes the functionality of worm_collision.
1275 * If w is specified and x,y hits the head of w NULL is returned.
1276 * This is a useful way to determine wether the head of w hits
1277 * any worm but including itself but excluding its own head.
1278 * (It hits always its own head ;))
1279 * If w is set to NULL worm_collision returns any worm including all heads
1280 * that is at position of x,y.
1281 * @param struct worm *w The worm of which the head should be excluded in
1282 * the test. w may be set to NULL.
1283 * @param int x The x coordinate that is checked
1284 * @param int y The y coordinate that is checkec
1285 * @return struct worm* The worm that has been hit by x,y. If no worm
1286 * was at the position NULL is returned.
1288 static struct worm
* worm_collision(struct worm
*w
, int x
, int y
)
1290 struct worm
*retVal
= NULL
;
1292 for (i
= 0; (i
< worm_count
) && (retVal
== NULL
); i
++) {
1293 int collision_at
= specific_worm_collision(&worms
[i
], x
, y
);
1294 if (collision_at
!= -1) {
1295 if (!(w
== &worms
[i
] && collision_at
== w
->head
)){
1304 * Returns true if the head of the worm just has
1305 * crossed the field boundaries.
1306 * @return bool true if the worm just has wrapped.
1308 static bool field_collision(struct worm
*w
)
1310 bool retVal
= false;
1311 if ((w
->x
[w
->head
] >= FIELD_RECT_WIDTH
) ||
1312 (w
->y
[w
->head
] >= FIELD_RECT_HEIGHT
) ||
1313 (w
->x
[w
->head
] < 0) ||
1314 (w
->y
[w
->head
] < 0))
1323 * Returns true if the specified coordinates are within the
1324 * field specified by the FIELD_RECT_XXX constants.
1325 * @param int x The x coordinate of the point that is investigated
1326 * @param int y The y coordinate of the point that is investigated
1327 * @return bool Returns false if x,y specifies a point outside the
1330 static bool is_in_field_rect(int x
, int y
)
1332 bool retVal
= false;
1333 retVal
= (x
>= 0 && x
< FIELD_RECT_WIDTH
&&
1334 y
>= 0 && y
< FIELD_RECT_HEIGHT
);
1339 * Checks and returns wether the head of the w
1340 * is colliding with something currently.
1341 * @return int One of the values:
1348 static int check_collision(struct worm
*w
)
1350 int retVal
= COLLISION_NONE
;
1352 if (worm_collision(w
, w
->x
[w
->head
], w
->y
[w
->head
]) != NULL
)
1353 retVal
= COLLISION_WORM
;
1355 if (food_collision(w
->x
[w
->head
], w
->y
[w
->head
]) >= 0)
1356 retVal
= COLLISION_FOOD
;
1358 if (argh_collision(w
->x
[w
->head
], w
->y
[w
->head
]) >= 0)
1359 retVal
= COLLISION_ARGH
;
1361 if (field_collision(w
))
1362 retVal
= COLLISION_FIELD
;
1368 * Returns the index of the food that is closest to the point
1369 * specified by x, y. This index may be used in the foodx and
1371 * @param int x The x coordinate of the point
1372 * @param int y The y coordinate of the point
1373 * @return int A value usable as index in foodx and foody.
1375 static int get_nearest_food(int x
, int y
)
1377 int nearestfood
= 0;
1378 int olddistance
= FIELD_RECT_WIDTH
+ FIELD_RECT_HEIGHT
;
1382 for (foodindex
= 0; foodindex
< MAX_FOOD
; foodindex
++) {
1384 deltax
= foodx
[foodindex
] - x
;
1385 deltay
= foody
[foodindex
] - y
;
1386 deltax
= deltax
> 0 ? deltax
: deltax
* (-1);
1387 deltay
= deltay
> 0 ? deltay
: deltay
* (-1);
1388 distance
= deltax
+ deltay
;
1390 if (distance
< olddistance
) {
1391 olddistance
= distance
;
1392 nearestfood
= foodindex
;
1399 * Returns wether the specified position is next to the worm
1400 * and in the direction the worm looks. Use this method to
1401 * test wether this position would be hit with the next move of
1402 * the worm unless the worm changes its direction.
1403 * @param struct worm *w - The worm to be investigated
1404 * @param int x - The x coordinate of the position to test.
1405 * @param int y - The y coordinate of the position to test.
1406 * @return Returns true if the worm will hit the position unless
1407 * it change its direction before the next move.
1409 static bool is_in_front_of_worm(struct worm
*w
, int x
, int y
)
1411 bool infront
= false;
1412 int deltax
= x
- w
->x
[w
->head
];
1413 int deltay
= y
- w
->y
[w
->head
];
1416 infront
= (w
->diry
* deltay
) > 0;
1418 infront
= (w
->dirx
* deltax
) > 0;
1424 * Returns true if the worm will collide with the next move unless
1425 * it changes its direction.
1426 * @param struct worm *w - The worm to be investigated.
1427 * @return Returns true if the worm will collide with the next move
1428 * unless it changes its direction.
1430 static bool will_worm_collide(struct worm
*w
)
1432 int x
= w
->x
[w
->head
] + w
->dirx
;
1433 int y
= w
->y
[w
->head
] + w
->diry
;
1434 bool retVal
= !is_in_field_rect(x
, y
);
1436 retVal
= (argh_collision(x
, y
) != -1);
1440 retVal
= (worm_collision(w
, x
, y
) != NULL
);
1447 * may be used to be stored in worm.fetch_worm_direction for
1448 * worms that are not controlled by humans but by artificial stupidity.
1449 * A direction is searched that doesn't lead to collision but to the nearest
1450 * food - but not very intelligent. The direction is written to the specified
1452 * @param struct worm *w - The worm of which the direction
1455 static void virtual_player(struct worm
*w
)
1458 int plana
, planb
, planc
;
1459 /* find the next lunch */
1460 int nearestfood
= get_nearest_food(w
->x
[w
->head
], w
->y
[w
->head
]);
1462 /* determine in which direction it is */
1464 /* in front of me? */
1465 bool infront
= is_in_front_of_worm(w
, foodx
[nearestfood
], foody
[nearestfood
]);
1467 /* left right of me? */
1468 int olddir
= get_worm_dir(w
);
1469 set_worm_dir(w
, (olddir
+ 1) % 4);
1470 isright
= is_in_front_of_worm(w
, foodx
[nearestfood
], foody
[nearestfood
]);
1471 set_worm_dir(w
, olddir
);
1473 /* detect situation, set strategy */
1477 planb
= (olddir
+ 1) % 4;
1478 planc
= (olddir
+ 3) % 4;
1481 planb
= (olddir
+ 3) % 4;
1482 planc
= (olddir
+ 1) % 4;
1486 plana
= (olddir
+ 1) % 4;
1488 planc
= (olddir
+ 3) % 4;
1490 plana
= (olddir
+ 3) % 4;
1492 planc
= (olddir
+ 1) % 4;
1496 /* test for collision */
1497 set_worm_dir(w
, plana
);
1498 if (will_worm_collide(w
)){
1501 set_worm_dir(w
, planb
);
1503 /* test for collision */
1504 if (will_worm_collide(w
)) {
1507 set_worm_dir(w
, planc
);
1513 * prints out the score board with all the status information
1516 static void score_board(void)
1522 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1523 rb
->lcd_fillrect(FIELD_RECT_WIDTH
+ 2, 0,
1524 LCD_WIDTH
- FIELD_RECT_WIDTH
- 2, LCD_HEIGHT
);
1525 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1526 for (i
= 0; i
< worm_count
; i
++) {
1527 int score
= get_score(&worms
[i
]);
1530 if (worms
[i
].fetch_worm_direction
!= virtual_player
){
1531 if (highscore
< score
) {
1537 rb
->snprintf(buf
, sizeof (buf
),"Len:%d", score
);
1540 switch (check_collision(&worms
[i
])) {
1541 case COLLISION_NONE
:
1542 if (worms
[i
].growing
> 0)
1552 case COLLISION_WORM
:
1556 case COLLISION_FOOD
:
1560 case COLLISION_ARGH
:
1564 case COLLISION_FIELD
:
1568 rb
->lcd_putsxy(FIELD_RECT_WIDTH
+ 3, y
, buf
);
1569 rb
->lcd_putsxy(FIELD_RECT_WIDTH
+ 3, y
+8, buf2
);
1571 if (!worms
[i
].alive
){
1572 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1573 rb
->lcd_fillrect(FIELD_RECT_WIDTH
+ 2, y
,
1574 LCD_WIDTH
- FIELD_RECT_WIDTH
- 2, 17);
1575 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1579 rb
->snprintf(buf
, sizeof(buf
), "Hs: %d", highscore
);
1580 #ifndef DEBUG_WORMLET
1581 rb
->lcd_putsxy(FIELD_RECT_WIDTH
+ 3, LCD_HEIGHT
- 8, buf
);
1583 rb
->lcd_putsxy(FIELD_RECT_WIDTH
+ 3, LCD_HEIGHT
- 8, debugout
);
1588 * Checks for collisions of the worm and its environment and
1589 * takes appropriate actions like growing the worm or killing it.
1590 * @return bool Returns true if the worm is dead. Returns
1591 * false if the worm is healthy, up and creeping.
1593 static bool process_collisions(struct worm
*w
)
1597 w
->alive
&= !field_collision(w
);
1601 /* check if food was eaten */
1602 index
= food_collision(w
->x
[w
->head
], w
->y
[w
->head
]);
1610 for (i
= 0; i
< arghs_per_food
; i
++) {
1612 if (argh_count
> MAX_ARGH
)
1613 argh_count
= MAX_ARGH
;
1614 make_argh(argh_count
- 1);
1615 draw_argh(argh_count
- 1);
1618 add_growing(w
, worm_food
);
1623 /* check if argh was eaten */
1625 index
= argh_collision(w
->x
[w
->head
], w
->y
[w
->head
]);
1630 if (worm_collision(w
, w
->x
[w
->head
], w
->y
[w
->head
]) != NULL
) {
1640 * The main loop of the game.
1641 * @return bool Returns true if the game ended
1642 * with a dead worm. Returns false if the user
1643 * aborted the game manually.
1645 static int run(void)
1648 int wormDead
= false;
1649 bool paused
= false;
1651 /* ticks are counted to compensate speed variations */
1652 long cycle_start
= 0, cycle_end
= 0;
1653 #ifdef DEBUG_WORMLET
1654 int ticks_to_max_cycle_reset
= 20;
1659 /* initialize the board and so on */
1662 cycle_start
= *rb
->current_tick
;
1663 /* change the direction of the worm */
1667 long cycle_duration
=0;
1669 #ifdef HAS_BUTTON_HOLD
1670 if (rb
->button_hold())
1675 case BTN_STARTPAUSE
:
1680 return 1; /* restart game */
1688 return 2; /* back to menu */
1695 if (players
== 1 && !use_remote
) {
1696 player1_dir
= NORTH
;
1701 if (players
== 1 && !use_remote
) {
1702 player1_dir
= SOUTH
;
1707 if (players
!= 1 || use_remote
) {
1708 player1_dir
= (player1_dir
+ 3) % 4;
1715 if (players
!= 1 || use_remote
) {
1716 player1_dir
= (player1_dir
+ 1) % 4;
1723 case BTN_PLAYER2_DIR1
:
1724 player2_dir
= (player2_dir
+ 3) % 4;
1727 case BTN_PLAYER2_DIR2
:
1728 player2_dir
= (player2_dir
+ 1) % 4;
1734 player3_dir
= (player3_dir
+ 1) % 4;
1738 player3_dir
= (player3_dir
+ 3) % 4;
1744 for (i
= 0; i
< worm_count
; i
++) {
1745 worms
[i
].fetch_worm_direction(&worms
[i
]);
1749 for (i
= 0; i
< worm_count
; i
++){
1750 struct worm
*w
= &worms
[i
];
1752 wormDead
&= process_collisions(w
);
1757 if (button
== BTN_STOPRESET
) {
1761 /* here the wormlet game cycle ends
1762 thus the current tick is stored
1764 cycle_end
= *rb
->current_tick
;
1766 /* The duration of the game cycle */
1767 cycle_duration
= cycle_end
- cycle_start
;
1768 cycle_duration
= MAX(0, cycle_duration
);
1769 cycle_duration
= MIN(speed
-1, cycle_duration
);
1772 #ifdef DEBUG_WORMLET
1773 ticks_to_max_cycle_reset
--;
1774 if (ticks_to_max_cycle_reset
<= 0) {
1778 if (max_cycle
< cycle_duration
) {
1779 max_cycle
= cycle_duration
;
1780 ticks_to_max_cycle_reset
= 20;
1782 rb
->snprintf(buf
, sizeof buf
, "ticks %d", max_cycle
);
1786 /* adjust the number of ticks to wait for a button.
1787 This ensures that a complete game cycle including
1788 user input runs in constant time */
1789 button
= rb
->button_get_w_tmo(speed
- cycle_duration
);
1790 cycle_start
= *rb
->current_tick
;
1793 rb
->splash(HZ
*2, "Game Over!");
1795 return 2; /* back to menu */
1798 #ifdef DEBUG_WORMLET
1801 * Just a test routine that checks that worm_food_collision works
1802 * in some typical situations.
1804 static void test_worm_food_collision(void)
1806 int collision_count
= 0;
1808 rb
->lcd_clear_display();
1809 init_worm(&worms
[0], 10, 10);
1810 add_growing(&worms
[0], 10);
1811 set_worm_dir(&worms
[0], EAST
);
1812 for (i
= 0; i
< 10; i
++) {
1813 move_worm(&worms
[0]);
1814 draw_worm(&worms
[0]);
1817 set_worm_dir(&worms
[0], SOUTH
);
1818 for (i
= 0; i
< 10; i
++) {
1819 move_worm(&worms
[0]);
1820 draw_worm(&worms
[0]);
1825 for (foody
[0] = 20; foody
[0] > 0; foody
[0] --) {
1828 draw_worm(&worms
[0]);
1830 collision
= worm_food_collision(&worms
[0], 0);
1834 rb
->snprintf(buf
, sizeof buf
, "collisions: %d", collision_count
);
1835 rb
->lcd_putsxy(0, LCD_HEIGHT
-8, buf
);
1838 if (collision_count
!= food_size
) {
1839 rb
->button_get(true);
1844 for (foodx
[0] = 30; foodx
[0] > 0; foodx
[0] --) {
1847 draw_worm(&worms
[0]);
1849 collision
= worm_food_collision(&worms
[0], 0);
1853 rb
->snprintf(buf
, sizeof buf
, "collisions: %d", collision_count
);
1854 rb
->lcd_putsxy(0, LCD_HEIGHT
-8, buf
);
1857 if (collision_count
!= food_size
* 2) {
1858 rb
->button_get(true);
1863 static bool expensive_worm_in_rect(struct worm
*w
, int rx
, int ry
, int rw
, int rh
)
1866 bool retVal
= false;
1867 for (x
= rx
; x
< rx
+ rw
; x
++){
1868 for (y
= ry
; y
< ry
+ rh
; y
++) {
1869 if (specific_worm_collision(w
, x
, y
) != -1) {
1877 static void test_worm_argh_collision(void)
1881 int collision_count
= 0;
1882 rb
->lcd_clear_display();
1883 init_worm(&worms
[0], 10, 10);
1884 add_growing(&worms
[0], 40);
1885 for (dir
= 0; dir
< 4; dir
++) {
1886 set_worm_dir(&worms
[0], (EAST
+ dir
) % 4);
1887 for (i
= 0; i
< 10; i
++) {
1888 move_worm(&worms
[0]);
1889 draw_worm(&worms
[0]);
1894 for (arghy
[0] = 0; arghy
[0] < FIELD_RECT_HEIGHT
- argh_size
; arghy
[0]++){
1898 collision
= worm_argh_collision(&worms
[0], 0);
1902 rb
->snprintf(buf
, sizeof buf
, "collisions: %d", collision_count
);
1903 rb
->lcd_putsxy(0, LCD_HEIGHT
-8, buf
);
1906 if (collision_count
!= argh_size
* 2) {
1907 rb
->button_get(true);
1911 for (arghx
[0] = 0; arghx
[0] < FIELD_RECT_HEIGHT
- argh_size
; arghx
[0]++){
1915 collision
= worm_argh_collision(&worms
[0], 0);
1919 rb
->snprintf(buf
, sizeof buf
, "collisions: %d", collision_count
);
1920 rb
->lcd_putsxy(0, LCD_HEIGHT
-8, buf
);
1923 if (collision_count
!= argh_size
* 4) {
1924 rb
->button_get(true);
1928 static int testline_in_rect(void)
1930 int testfailed
= -1;
1943 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
1944 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
1945 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
1946 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
1948 rb
->lcd_putsxy(0, 0, "failed 1");
1949 rb
->button_get(true);
1955 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
1956 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
1957 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
1958 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
1959 rb
->lcd_putsxy(0, 0, "failed 2");
1961 rb
->button_get(true);
1967 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
1968 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
1969 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
1970 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
1971 rb
->lcd_putsxy(0, 0, "failed 3");
1973 rb
->button_get(true);
1979 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
1980 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
1981 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
1982 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
1983 rb
->lcd_putsxy(0, 0, "failed 4");
1985 rb
->button_get(true);
1991 if (line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) ||
1992 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
1993 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
1994 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
1995 rb
->lcd_putsxy(0, 0, "failed 5");
1997 rb
->button_get(true);
2004 if (line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) ||
2005 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2006 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2007 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2008 rb
->lcd_putsxy(0, 0, "failed 6");
2010 rb
->button_get(true);
2019 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2020 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2021 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2022 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2023 rb
->lcd_putsxy(0, 0, "failed 7");
2025 rb
->button_get(true);
2031 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2032 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2033 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2034 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2035 rb
->lcd_putsxy(0, 0, "failed 8");
2037 rb
->button_get(true);
2043 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2044 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2045 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2046 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2047 rb
->lcd_putsxy(0, 0, "failed 9");
2049 rb
->button_get(true);
2055 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2056 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2057 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2058 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2059 rb
->lcd_putsxy(0, 0, "failed 10");
2061 rb
->button_get(true);
2067 if (line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) ||
2068 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2069 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2070 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2071 rb
->lcd_putsxy(0, 0, "failed 11");
2073 rb
->button_get(true);
2080 if (line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) ||
2081 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2082 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2083 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2084 rb
->lcd_putsxy(0, 0, "failed 12");
2086 rb
->button_get(true);
2100 if (!(line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2101 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
))) {
2102 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2103 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2104 rb
->lcd_putsxy(0, 0, "failed 13");
2106 rb
->button_get(true);
2120 if (!(line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2121 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
))) {
2122 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2123 rb
->lcd_invertrect(rx
, ry
, rw
, rh
);
2124 rb
->lcd_putsxy(0, 0, "failed 14");
2126 rb
->button_get(true);
2130 rb
->lcd_clear_display();
2136 * Just a test routine to test wether specific_worm_collision might work properly
2138 static int test_specific_worm_collision(void)
2145 rb
->lcd_clear_display();
2146 init_worm(&worms
[0], 10, 20);
2147 add_growing(&worms
[0], 20 - INITIAL_WORM_LENGTH
);
2149 for (dir
= EAST
; dir
< EAST
+ 4; dir
++) {
2151 set_worm_dir(&worms
[0], dir
% 4);
2152 for (i
= 0; i
< 5; i
++) {
2153 if (!(dir
% 4 == NORTH
&& i
== 9)) {
2154 move_worm(&worms
[0]);
2155 draw_worm(&worms
[0]);
2160 for (y
= 15; y
< 30; y
++){
2161 for (x
= 5; x
< 20; x
++) {
2162 if (specific_worm_collision(&worms
[0], x
, y
) != -1) {
2165 rb
->lcd_invertpixel(x
+ FIELD_RECT_X
, y
+ FIELD_RECT_Y
);
2166 rb
->snprintf(buf
, sizeof buf
, "collisions %d", collisions
);
2167 rb
->lcd_putsxy(0, LCD_HEIGHT
- 8, buf
);
2171 if (collisions
!= 21) {
2172 rb
->button_get(true);
2177 static void test_make_argh(void)
2183 int last_failures
= 0;
2185 rb
->lcd_clear_display();
2188 for (worm_idx
= 0; worm_idx
< worm_count
; worm_idx
++) {
2189 init_worm(&worms
[worm_idx
], 10 + worm_idx
* 20, 20);
2190 add_growing(&worms
[worm_idx
], 40 - INITIAL_WORM_LENGTH
);
2193 for (dir
= EAST
; dir
< EAST
+ 4; dir
++) {
2194 for (worm_idx
= 0; worm_idx
< worm_count
; worm_idx
++) {
2195 set_worm_dir(&worms
[worm_idx
], dir
% 4);
2196 for (i
= 0; i
< 10; i
++) {
2197 if (!(dir
% 4 == NORTH
&& i
== 9)) {
2198 move_worm(&worms
[worm_idx
]);
2199 draw_worm(&worms
[worm_idx
]);
2207 for (seed
= 0; hit
< 20; seed
+= 2) {
2211 x
= rb
->rand() % (FIELD_RECT_WIDTH
- argh_size
);
2212 y
= rb
->rand() % (FIELD_RECT_HEIGHT
- argh_size
);
2214 for (worm_idx
= 0; worm_idx
< worm_count
; worm_idx
++){
2215 if (expensive_worm_in_rect(&worms
[worm_idx
], x
, y
, argh_size
, argh_size
)) {
2219 tries
= make_argh(0);
2220 if ((x
== arghx
[0] && y
== arghy
[0]) || tries
< 2) {
2224 rb
->snprintf(buf
, sizeof buf
, "(%d;%d) fail%d try%d",
2225 x
, y
, failures
, tries
);
2226 rb
->lcd_putsxy(0, LCD_HEIGHT
- 8, buf
);
2228 rb
->lcd_invertrect(x
+ FIELD_RECT_X
, y
+ FIELD_RECT_Y
,
2229 argh_size
, argh_size
);
2233 rb
->lcd_invertrect(x
+ FIELD_RECT_X
, y
+ FIELD_RECT_Y
,
2234 argh_size
, argh_size
);
2235 rb
->lcd_clearrect(arghx
[0] + FIELD_RECT_X
, arghy
[0] + FIELD_RECT_Y
,
2236 argh_size
, argh_size
);
2238 if (failures
> last_failures
) {
2239 rb
->button_get(true);
2241 last_failures
= failures
;
2248 static void test_worm_argh_collision_in_moves(void) {
2251 rb
->lcd_clear_display();
2252 init_worm(&worms
[0], 10, 20);
2258 set_worm_dir(&worms
[0], EAST
);
2259 for (i
= 0; i
< 20; i
++) {
2261 move_worm(&worms
[0]);
2262 draw_worm(&worms
[0]);
2263 if (worm_argh_collision_in_moves(&worms
[0], 0, 5)){
2266 rb
->snprintf(buf
, sizeof buf
, "in 5 moves hits: %d", hit_count
);
2267 rb
->lcd_putsxy(0, LCD_HEIGHT
- 8, buf
);
2270 if (hit_count
!= argh_size
+ 5) {
2271 rb
->button_get(true);
2274 #endif /* DEBUG_WORMLET */
2277 * Reverts default settings
2279 static void default_settings(void)
2281 arghs_per_food
= ARGHS_PER_FOOD
;
2282 argh_size
= ARGH_SIZE
;
2283 food_size
= FOOD_SIZE
;
2285 worm_food
= WORM_PER_FOOD
;
2287 worm_count
= MAX_WORMS
;
2293 * Launches the wormlet game
2295 static bool launch_wormlet(void)
2297 int game_result
= 1;
2299 rb
->lcd_clear_display();
2301 /* Turn off backlight timeout */
2302 backlight_force_on(); /* backlight control in lib/helper.c */
2304 /* start the game */
2305 while (game_result
== 1)
2306 game_result
= run();
2308 switch (game_result
)
2311 /* Turn on backlight timeout (revert to settings) */
2312 backlight_use_settings(); /* backlight control in lib/helper.c */
2322 enum plugin_status
plugin_start(UNUSED_ATTR
const void* parameter
)
2329 if (configfile_load(SETTINGS_FILENAME
, config
,
2330 sizeof(config
)/sizeof(*config
),
2331 SETTINGS_MIN_VERSION
) < 0)
2333 /* If the loading failed, save a new config file (as the disk is
2334 already spinning) */
2335 configfile_save(SETTINGS_FILENAME
, config
,
2336 sizeof(config
)/sizeof(*config
),
2340 #ifdef HAVE_LCD_COLOR
2341 rb
->lcd_set_foreground(COLOR_FG
);
2342 rb
->lcd_set_background(COLOR_BG
);
2346 rb
->lcd_set_backdrop(NULL
);
2349 #ifdef DEBUG_WORMLET
2351 test_worm_argh_collision_in_moves();
2353 test_worm_food_collision();
2354 test_worm_argh_collision();
2355 test_specific_worm_collision();
2360 static const struct opt_items noyes
[2] = {
2365 static const struct opt_items remoteonly_option
[1] = {
2366 { "Remote Control", -1 }
2369 static const struct opt_items key24_option
[2] = {
2370 { "4 Key Control", -1 },
2371 { "2 Key Control", -1 }
2375 static const struct opt_items remote_option
[2] = {
2376 { "Remote Control", -1 },
2377 { "No Rem. Control", -1 }
2380 static const struct opt_items key2_option
[1] = {
2381 { "2 Key Control", -1 }
2385 static const struct opt_items nokey_option
[1] = {
2386 { "Out of Control", -1 }
2389 MENUITEM_STRINGLIST(menu
, "Wormlet Menu", NULL
, "Play Wormlet!",
2390 "Number of Worms", "Number of Players", "Control Style",
2391 "Worm Growth Per Food","Worm Speed","Arghs Per Food",
2392 "Argh Size","Food Size","Revert to Default Settings",
2393 "Playback Control", "Quit");
2395 rb
->button_clear_queue();
2397 while (!menu_quit
) {
2398 switch(rb
->do_menu(&menu
, &result
, NULL
, false))
2401 rb
->lcd_setfont(FONT_SYSFIXED
);
2405 rb
->set_int("Number of Worms", "", UNIT_INT
, &worm_count
, NULL
,
2407 if (worm_count
< players
) {
2408 worm_count
= players
;
2413 rb
->set_int("Number of Players", "", UNIT_INT
, &players
, NULL
,
2416 rb
->set_int("Number of Players", "", UNIT_INT
, &players
, NULL
,
2419 if (players
> worm_count
) {
2420 worm_count
= players
;
2429 rb
->set_option("Control Style",&use_remote
,INT
,
2430 nokey_option
, 1, NULL
);
2433 rb
->set_option("Control Style",&use_remote
,INT
,
2434 key24_option
, 2, NULL
);
2438 rb
->set_option("Control Style",&use_remote
,INT
,
2439 remote_option
, 2, NULL
);
2441 rb
->set_option("Control Style",&use_remote
,INT
,
2442 key2_option
, 1, NULL
);
2446 rb
->set_option("Control Style",&use_remote
,INT
,
2447 remoteonly_option
, 1, NULL
);
2452 rb
->set_int("Worm Growth Per Food", "", UNIT_INT
, &worm_food
,
2453 NULL
, 1, 0, 15, NULL
);
2456 new_setting
= 20 - speed
;
2457 rb
->set_int("Worm Speed", "", UNIT_INT
, &new_setting
,
2458 NULL
, 1, 0, 20, NULL
);
2459 speed
= 20 - new_setting
;
2462 rb
->set_int("Arghs Per Food", "", UNIT_INT
, &arghs_per_food
,
2463 NULL
, 1, 0, 8, NULL
);
2466 rb
->set_int("Argh Size", "", UNIT_INT
, &argh_size
,
2467 NULL
, 1, 2, 10, NULL
);
2470 rb
->set_int("Food Size", "", UNIT_INT
, &food_size
,
2471 NULL
, 1, 2, 10, NULL
);
2475 rb
->set_option("Reset Settings?", &new_setting
, INT
, noyes
, 2, NULL
);
2476 if (new_setting
== 1)
2480 playback_control(NULL
);
2488 configfile_save(SETTINGS_FILENAME
, config
,
2489 sizeof(config
)/sizeof(*config
),