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) || \
236 (CONFIG_KEYPAD == ONDAVX777_PAD) || \
237 CONFIG_KEYPAD == MROBE500_PAD
239 #define BTN_QUIT BUTTON_POWER
241 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
243 #define BTN_DIR_UP BUTTON_UP
244 #define BTN_DIR_DOWN BUTTON_DOWN
245 #define BTN_DIR_LEFT BUTTON_LEFT
246 #define BTN_DIR_RIGHT BUTTON_RIGHT
247 #define BTN_STARTPAUSE BUTTON_PLAY
248 #define BTN_QUIT BUTTON_FFWD
249 #define BTN_STOPRESET BUTTON_REW
252 #error No keymap defined!
255 #ifdef HAVE_TOUCHSCREEN
257 #define BTN_DIR_UP BUTTON_TOPMIDDLE
260 #define BTN_DIR_DOWN BUTTON_BOTTOMMIDDLE
263 #define BTN_DIR_LEFT BUTTON_MIDLEFT
265 #ifndef BTN_DIR_RIGHT
266 #define BTN_DIR_RIGHT BUTTON_MIDRIGHT
268 #ifndef BTN_STARTPAUSE
269 #define BTN_STARTPAUSE BUTTON_CENTER
272 #define BTN_QUIT BUTTON_TOPLEFT
274 #ifndef BTN_STOPRESET
275 #define BTN_STOPRESET BUTTON_TOPRIGHT
279 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
283 #define MAX_WORM_SEGMENTS 128
284 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 64)
288 #define MAX_WORM_SEGMENTS 128
289 #elif (LCD_WIDTH == 132) && (LCD_HEIGHT == 80)
293 #define MAX_WORM_SEGMENTS 128
294 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 96)
298 #define MAX_WORM_SEGMENTS 128
299 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
303 #define MAX_WORM_SEGMENTS 128
304 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128)
308 #define MAX_WORM_SEGMENTS 128
309 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
313 #define MAX_WORM_SEGMENTS 256
314 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132)
318 #define MAX_WORM_SEGMENTS 256
319 #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176)
323 #define MAX_WORM_SEGMENTS 512
324 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 220)
328 #define MAX_WORM_SEGMENTS 512
329 #elif ((LCD_WIDTH == 320) && (LCD_HEIGHT == 240)) || \
330 ((LCD_WIDTH == 240) && ((LCD_HEIGHT == 320) || (LCD_HEIGHT == 400)))
334 #define MAX_WORM_SEGMENTS 512
335 #elif ((LCD_WIDTH == 640) && (LCD_HEIGHT == 480)) || \
336 ((LCD_WIDTH == 480) && (LCD_HEIGHT == 640))
340 #define MAX_WORM_SEGMENTS 512
343 #ifdef HAVE_LCD_COLOR
344 #define COLOR_WORM LCD_RGBPACK(80, 40, 0)
345 #define COLOR_ARGH LCD_RGBPACK(175, 0, 0)
346 #define COLOR_FOOD LCD_RGBPACK(0, 150, 0)
347 #define COLOR_FG LCD_RGBPACK(0, 0, 0)
348 #define COLOR_BG LCD_RGBPACK(181, 199, 231)
351 #define CHECK_SQUARE_COLLISION(x1,y1,s1,x2,y2,s2) (x1+s1>x2)&&(x2+s2>x1)&&(y1+s1>y2)&&(y2+s2>y1)
354 * All the properties that a worm has.
357 /* The worm is stored in a ring of xy coordinates */
358 int x
[MAX_WORM_SEGMENTS
];
359 int y
[MAX_WORM_SEGMENTS
];
361 int head
; /* index of the head within the buffer */
362 int tail
; /* index of the tail within the buffer */
363 int growing
; /* number of cyles the worm still keeps growing */
364 bool alive
; /* the worms living state */
366 /* direction vector in which the worm moves */
367 int dirx
; /* only values -1 0 1 allowed */
368 int diry
; /* only values -1 0 1 allowed */
370 /* this method is used to fetch the direction the user
371 has selected. It can be one of the values
372 human_player1, human_player2, remote_player, virtual_player.
373 All these values are fuctions, that can change the direction
375 void (*fetch_worm_direction
)(struct worm
*w
);
378 /* stores the highscore - besides it was scored by a virtual player */
379 static int highscore
;
381 #define MAX_FOOD 5 /* maximal number of food items */
383 /* The arrays store the food coordinates */
384 static int foodx
[MAX_FOOD
];
385 static int foody
[MAX_FOOD
];
387 #define MAX_ARGH 100 /* maximal number of argh items */
388 #define ARGHS_PER_FOOD 2 /* number of arghs produced per eaten food */
390 /* The arrays store the argh coordinates */
391 static int arghx
[MAX_ARGH
];
392 static int arghy
[MAX_ARGH
];
394 /* the number of arghs that are currently in use */
395 static int argh_count
;
397 /* the number of arghs per food, settable by user */
398 static int arghs_per_food
= ARGHS_PER_FOOD
;
399 /* the size of the argh, settable by user */
400 static int argh_size
= ARGH_SIZE
;
401 /* the size of the food, settable by user */
402 static int food_size
= FOOD_SIZE
;
403 /* the speed of the worm, settable by user */
404 static int speed
= SPEED
;
405 /* the amount a worm grows by eating a food, settable by user */
406 static int worm_food
= WORM_PER_FOOD
;
408 /* End additional variables */
411 /* just a buffer used for debug output */
412 static char debugout
[15];
415 /* the number of active worms (dead or alive) */
416 static int worm_count
= MAX_WORMS
;
418 /* in multiplayer mode: en- / disables the remote worm control
419 in singleplayer mode: toggles 4 / 2 button worm control */
420 static bool use_remote
= false;
422 /* return values of check_collision */
423 #define COLLISION_NONE 0
424 #define COLLISION_WORM 1
425 #define COLLISION_FOOD 2
426 #define COLLISION_ARGH 3
427 #define COLLISION_FIELD 4
429 /* constants for use as directions.
430 Note that the values are ordered clockwise.
431 Thus increasing / decreasing the values
432 is equivalent to right / left turns. */
438 /* direction of human player 1 */
439 static int player1_dir
= EAST
;
440 /* direction of human player 2 */
441 static int player2_dir
= EAST
;
442 /* direction of human player 3 */
443 static int player3_dir
= EAST
;
445 /* the number of (human) players that currently
447 static int players
= 1;
449 #define SETTINGS_VERSION 1
450 #define SETTINGS_MIN_VERSION 1
451 #define SETTINGS_FILENAME "wormlet.cfg"
453 static struct configdata config
[] =
455 {TYPE_INT
, 0, 1024, { .int_p
= &highscore
}, "highscore", NULL
},
456 {TYPE_INT
, 0, 15, { .int_p
= &arghs_per_food
}, "arghs per food", NULL
},
457 {TYPE_INT
, 0, 15, { .int_p
= &argh_size
}, "argh size", NULL
},
458 {TYPE_INT
, 0, 15, { .int_p
= &food_size
}, "food size", NULL
},
459 {TYPE_INT
, 0, 3, { .int_p
= &players
}, "players", NULL
},
460 {TYPE_INT
, 0, 3, { .int_p
= &worm_count
}, "worms", NULL
},
461 {TYPE_INT
, 0, 20, { .int_p
= &speed
}, "speed", NULL
},
462 {TYPE_INT
, 0, 15, { .int_p
= &worm_food
}, "Worm Growth Per Food", NULL
}
466 static void set_debug_out(char *str
){
467 strcpy(debugout
, str
);
472 * Returns the direction id in which the worm
473 * currently is creeping.
474 * @param struct worm *w The worm that is to be investigated.
475 * w Must not be null.
476 * @return int A value 0 <= value < 4
477 * Note the predefined constants NORTH, SOUTH, EAST, WEST
479 static int get_worm_dir(struct worm
*w
)
499 * Set the direction of the specified worm with a direction id.
500 * Increasing the value by 1 means to turn the worm direction
501 * to right by 90 degree.
502 * @param struct worm *w The worm that is to be altered. w Must not be null.
503 * @param int dir The new direction in which the worm is to creep.
504 * dir must be 0 <= dir < 4. Use predefined constants
505 * NORTH, SOUTH, EAST, WEST
507 static void set_worm_dir(struct worm
*w
, int dir
)
530 * Returns the current length of the worm array. This
531 * is also a value for the number of bends that are in the worm.
532 * @return int a positive value with 0 <= value < MAX_WORM_SEGMENTS
534 static int get_worm_array_length(struct worm
*w
)
536 /* initial simple calculation will be overwritten if wrong. */
537 int retVal
= w
->head
- w
->tail
;
539 /* if the worm 'crosses' the boundaries of the ringbuffer */
541 retVal
= w
->head
+ MAX_WORM_SEGMENTS
- w
->tail
;
548 * Returns the score the specified worm. The score is the length
550 * @param struct worm *w The worm that is to be investigated.
551 * w must not be null.
552 * @return int The length of the worm (>= 0).
554 static int get_score(struct worm
*w
)
557 int length
= get_worm_array_length(w
);
559 for (i
= 0; i
< length
; i
++) {
561 /* The iteration iterates the length of the worm.
562 Here's the conversion to the true indices within the worm arrays. */
563 int linestart
= (w
->tail
+ i
) % MAX_WORM_SEGMENTS
;
564 int lineend
= (linestart
+ 1) % MAX_WORM_SEGMENTS
;
565 int startx
= w
->x
[linestart
];
566 int starty
= w
->y
[linestart
];
567 int endx
= w
->x
[lineend
];
568 int endy
= w
->y
[lineend
];
570 int minimum
, maximum
;
572 if (startx
== endx
) {
573 minimum
= MIN(starty
, endy
);
574 maximum
= MAX(starty
, endy
);
576 minimum
= MIN(startx
, endx
);
577 maximum
= MAX(startx
, endx
);
579 retval
+= abs(maximum
- minimum
);
585 * Determines wether the line specified by startx, starty, endx, endy intersects
586 * the rectangle specified by x, y, width, height. Note that the line must be exactly
587 * horizontal or vertical (startx == endx or starty == endy).
588 * @param int startx The x coordinate of the start point of the line.
589 * @param int starty The y coordinate of the start point of the line.
590 * @param int endx The x coordinate of the end point of the line.
591 * @param int endy The y coordinate of the end point of the line.
592 * @param int x The x coordinate of the top left corner of the rectangle.
593 * @param int y The y coordinate of the top left corner of the rectangle.
594 * @param int width The width of the rectangle.
595 * @param int height The height of the rectangle.
596 * @return bool Returns true if the specified line intersects with the recangle.
598 static bool line_in_rect(int startx
, int starty
, int endx
, int endy
,
599 int x
, int y
, int width
, int height
)
602 int simple
, simplemin
, simplemax
;
603 int compa
, compb
, compmin
, compmax
;
605 if (startx
== endx
) {
608 simplemax
= x
+ width
;
613 compmax
= y
+ height
;
617 simplemax
= y
+ height
;
626 compa
= MIN(compa
, compb
);
627 compb
= MAX(temp
, compb
);
629 if (simplemin
<= simple
&& simple
<= simplemax
) {
630 if ((compmin
<= compa
&& compa
<= compmax
) ||
631 (compmin
<= compb
&& compb
<= compmax
) ||
632 (compa
<= compmin
&& compb
>= compmax
)) {
640 * Tests wether the specified worm intersects with the rect.
641 * @param struct worm *w The worm to be investigated
642 * @param int x The x coordinate of the top left corner of the rect
643 * @param int y The y coordinate of the top left corner of the rect
644 * @param int widht The width of the rect
645 * @param int height The height of the rect
646 * @return bool Returns true if the worm intersects with the rect
648 static bool worm_in_rect(struct worm
*w
, int x
, int y
, int width
, int height
)
653 /* get_worm_array_length is expensive -> buffer the value */
654 int wormLength
= get_worm_array_length(w
);
657 /* test each entry that is part of the worm */
658 for (i
= 0; i
< wormLength
&& retval
== false; i
++) {
660 /* The iteration iterates the length of the worm.
661 Here's the conversion to the true indices within the worm arrays. */
662 int linestart
= (w
->tail
+ i
) % MAX_WORM_SEGMENTS
;
663 int lineend
= (linestart
+ 1) % MAX_WORM_SEGMENTS
;
664 int startx
= w
->x
[linestart
];
665 int starty
= w
->y
[linestart
];
666 int endx
= w
->x
[lineend
];
667 int endy
= w
->y
[lineend
];
669 retval
= line_in_rect(startx
, starty
, endx
, endy
, x
, y
, width
, height
);
676 * Checks wether a specific food in the food arrays is at the
677 * specified coordinates.
678 * @param int foodIndex The index of the food in the food arrays
679 * @param int x the x coordinate.
680 * @param int y the y coordinate.
681 * @return Returns true if the coordinate hits the food specified by
684 static bool specific_food_collision(int foodIndex
, int x
, int y
)
687 if (x
>= foodx
[foodIndex
] &&
688 x
< foodx
[foodIndex
] + food_size
&&
689 y
>= foody
[foodIndex
] &&
690 y
< foody
[foodIndex
] + food_size
) {
698 * Returns the index of the food that is at the
699 * given coordinates. If no food is at the coordinates
701 * @return int -1 <= value < MAX_FOOD
703 static int food_collision(int x
, int y
)
707 for (i
= 0; i
< MAX_FOOD
; i
++) {
708 if (specific_food_collision(i
, x
, y
)) {
717 * Checks wether a specific argh in the argh arrays is at the
718 * specified coordinates.
719 * @param int arghIndex The index of the argh in the argh arrays
720 * @param int x the x coordinate.
721 * @param int y the y coordinate.
722 * @return Returns true if the coordinate hits the argh specified by
725 static bool specific_argh_collision(int arghIndex
, int x
, int y
)
727 if ( x
>= arghx
[arghIndex
] &&
728 y
>= arghy
[arghIndex
] &&
729 x
< arghx
[arghIndex
] + argh_size
&&
730 y
< arghy
[arghIndex
] + argh_size
)
739 * Returns the index of the argh that is at the
740 * given coordinates. If no argh is at the coordinates
742 * @param int x The x coordinate.
743 * @param int y The y coordinate.
744 * @return int -1 <= value < argh_count <= MAX_ARGH
746 static int argh_collision(int x
, int y
)
751 /* search for the argh that has the specified coords */
752 for (i
= 0; i
< argh_count
; i
++) {
753 if (specific_argh_collision(i
, x
, y
)) {
762 * Checks wether the worm collides with the food at the specfied food-arrays.
763 * @param int foodIndex The index of the food in the arrays. Ensure the value is
764 * 0 <= foodIndex <= MAX_FOOD
765 * @return Returns true if the worm collides with the specified food.
767 static bool worm_food_collision(struct worm
*w
, int foodIndex
)
771 retVal
= worm_in_rect(w
, foodx
[foodIndex
], foody
[foodIndex
],
772 food_size
- 1, food_size
- 1);
778 * Returns true if the worm hits the argh within the next moves (unless
779 * the worm changes it's direction).
780 * @param struct worm *w - The worm to investigate
781 * @param int argh_idx - The index of the argh
782 * @param int moves - The number of moves that are considered.
783 * @return Returns false if the specified argh is not hit within the next
786 static bool worm_argh_collision_in_moves(struct worm
*w
, int argh_idx
, int moves
)
793 x2
= w
->x
[w
->head
] + moves
* w
->dirx
;
794 y2
= w
->y
[w
->head
] + moves
* w
->diry
;
796 retVal
= line_in_rect(x1
, y1
, x2
, y2
, arghx
[argh_idx
], arghy
[argh_idx
],
797 argh_size
, argh_size
);
802 * Checks wether the worm collides with the argh at the specfied argh-arrays.
803 * @param int arghIndex The index of the argh in the arrays.
804 * Ensure the value is 0 <= arghIndex < argh_count <= MAX_ARGH
805 * @return Returns true if the worm collides with the specified argh.
807 static bool worm_argh_collision(struct worm
*w
, int arghIndex
)
811 retVal
= worm_in_rect(w
, arghx
[arghIndex
], arghy
[arghIndex
],
812 argh_size
- 1, argh_size
- 1);
818 * Find new coordinates for the food stored in foodx[index], foody[index]
819 * that don't collide with any other food or argh
821 * Ensure that 0 <= index < MAX_FOOD.
823 static void make_food(int index
)
827 bool collisionDetected
= false;
831 /* make coordinates for a new food so that
832 the entire food lies within the FIELD */
833 x
= rb
->rand() % (FIELD_RECT_WIDTH
- food_size
);
834 y
= rb
->rand() % (FIELD_RECT_HEIGHT
- food_size
);
835 collisionDetected
= false;
836 /* Ensure that the new food doesn't collide with any
837 existing foods or arghs.
838 If the new food hit any existing
839 argh or food a collision is detected.
842 for (i
=0; i
<MAX_FOOD
&& !collisionDetected
; i
++) {
843 collisionDetected
= CHECK_SQUARE_COLLISION(x
,y
,food_size
,foodx
[i
],foody
[i
],food_size
);
845 for (i
=0; i
<argh_count
&& !collisionDetected
; i
++) {
846 collisionDetected
= CHECK_SQUARE_COLLISION(x
,y
,food_size
,arghx
[i
],arghy
[i
],argh_size
);
849 /* use coordinates for further testing */
853 /* now test wether we accidently hit the worm with food ;) */
855 for (i
= 0; i
< worm_count
&& !collisionDetected
; i
++) {
857 collisionDetected
= worm_food_collision(&worms
[i
], index
);
861 while (collisionDetected
);
866 * Clears a food from the lcd buffer.
867 * @param int index The index of the food arrays under which
868 * the coordinates of the desired food can be found. Ensure
869 * that the value is 0 <= index <= MAX_FOOD.
871 static void clear_food(int index
)
873 /* remove the old food from the screen */
874 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
875 rb
->lcd_fillrect(foodx
[index
] + FIELD_RECT_X
,
876 foody
[index
] + FIELD_RECT_Y
,
877 food_size
, food_size
);
878 rb
->lcd_set_drawmode(DRMODE_SOLID
);
882 * Draws a food in the lcd buffer.
883 * @param int index The index of the food arrays under which
884 * the coordinates of the desired food can be found. Ensure
885 * that the value is 0 <= index <= MAX_FOOD.
887 static void draw_food(int index
)
889 /* draw the food object */
890 #ifdef HAVE_LCD_COLOR
891 rb
->lcd_set_foreground(COLOR_FOOD
);
893 rb
->lcd_fillrect(foodx
[index
] + FIELD_RECT_X
,
894 foody
[index
] + FIELD_RECT_Y
,
895 food_size
, food_size
);
896 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
897 rb
->lcd_fillrect(foodx
[index
] + FIELD_RECT_X
+ 1,
898 foody
[index
] + FIELD_RECT_Y
+ 1,
899 food_size
- 2, food_size
- 2);
900 rb
->lcd_set_drawmode(DRMODE_SOLID
);
901 #ifdef HAVE_LCD_COLOR
902 rb
->lcd_set_foreground(COLOR_FG
);
907 * Find new coordinates for the argh stored in arghx[index], arghy[index]
908 * that don't collide with any other food or argh.
910 * Ensure that 0 <= index < argh_count < MAX_ARGH.
912 static void make_argh(int index
)
916 bool collisionDetected
= false;
920 /* make coordinates for a new argh so that
921 the entire food lies within the FIELD */
922 x
= rb
->rand() % (FIELD_RECT_WIDTH
- argh_size
);
923 y
= rb
->rand() % (FIELD_RECT_HEIGHT
- argh_size
);
924 collisionDetected
= false;
925 /* Ensure that the new argh doesn't intersect with any
926 existing foods or arghs.
927 If the new argh hit any existing
928 argh or food an intersection is detected.
931 for (i
=0; i
<MAX_FOOD
&& !collisionDetected
; i
++) {
932 collisionDetected
= CHECK_SQUARE_COLLISION(x
,y
,argh_size
,foodx
[i
],foody
[i
],food_size
);
934 for (i
=0; i
<argh_count
&& !collisionDetected
; i
++) {
935 collisionDetected
= CHECK_SQUARE_COLLISION(x
,y
,argh_size
,arghx
[i
],arghy
[i
],argh_size
);
938 /* use the candidate coordinates to make a real argh */
942 /* now test wether we accidently hit the worm with argh ;) */
943 for (i
= 0; i
< worm_count
&& !collisionDetected
; i
++) {
944 collisionDetected
|= worm_argh_collision(&worms
[i
], index
);
945 collisionDetected
|= worm_argh_collision_in_moves(&worms
[i
], index
,
949 while (collisionDetected
);
954 * Draws an argh in the lcd buffer.
955 * @param int index The index of the argh arrays under which
956 * the coordinates of the desired argh can be found. Ensure
957 * that the value is 0 <= index < argh_count <= MAX_ARGH.
959 static void draw_argh(int index
)
961 /* draw the new argh */
962 #ifdef HAVE_LCD_COLOR
963 rb
->lcd_set_foreground(COLOR_ARGH
);
965 rb
->lcd_fillrect(arghx
[index
] + FIELD_RECT_X
,
966 arghy
[index
] + FIELD_RECT_Y
,
967 argh_size
, argh_size
);
968 #ifdef HAVE_LCD_COLOR
969 rb
->lcd_set_foreground(COLOR_FG
);
973 static void virtual_player(struct worm
*w
);
975 * Initialzes the specified worm with INITIAL_WORM_LENGTH
976 * and the tail at the specified position. The worm will
977 * be initialized alive and creeping EAST.
978 * @param struct worm *w The worm that is to be initialized
979 * @param int x The x coordinate at which the tail of the worm starts.
980 * x must be 0 <= x < FIELD_RECT_WIDTH.
981 * @param int y The y coordinate at which the tail of the worm starts
982 * y must be 0 <= y < FIELD_RECT_WIDTH.
984 static void init_worm(struct worm
*w
, int x
, int y
)
986 /* initialize the worm size */
990 w
->x
[w
->head
] = x
+ 1;
996 /* set the initial direction the worm creeps to */
1000 w
->growing
= INITIAL_WORM_LENGTH
- 1;
1002 w
->fetch_worm_direction
= virtual_player
;
1006 * Writes the direction that was stored for
1007 * human player 1 into the specified worm. This function
1008 * may be used to be stored in worm.fetch_worm_direction.
1010 * the direction is read from player1_dir.
1011 * @param struct worm *w - The worm of which the direction
1014 static void human_player1(struct worm
*w
) {
1015 set_worm_dir(w
, player1_dir
);
1019 * Writes the direction that was stored for
1020 * human player 2 into the specified worm. This function
1021 * may be used to be stored in worm.fetch_worm_direction.
1023 * the direction is read from player2_dir.
1024 * @param struct worm *w - The worm of which the direction
1027 static void human_player2(struct worm
*w
) {
1028 set_worm_dir(w
, player2_dir
);
1032 * Writes the direction that was stored for
1033 * human player using a remote control
1034 * into the specified worm. This function
1035 * may be used to be stored in worm.fetch_worm_direction.
1037 * the direction is read from player3_dir.
1038 * @param struct worm *w - The worm of which the direction
1041 static void remote_player(struct worm
*w
) {
1042 set_worm_dir(w
, player3_dir
);
1046 * Initializes the worm-, food- and argh-arrays, draws a frame,
1047 * makes some food and argh and display all that stuff.
1049 static void init_wormlet(void)
1053 for (i
= 0; i
< worm_count
; i
++) {
1054 /* Initialize all the worm coordinates to center. */
1055 int x
= (int)(FIELD_RECT_WIDTH
/ 2);
1056 int y
= (int)((FIELD_RECT_HEIGHT
- 20)/ 2) + i
* 10;
1058 init_worm(&worms
[i
], x
, y
);
1066 worms
[0].fetch_worm_direction
= human_player1
;
1071 worms
[1].fetch_worm_direction
= remote_player
;
1073 worms
[1].fetch_worm_direction
= human_player2
;
1078 worms
[2].fetch_worm_direction
= human_player2
;
1081 /* Needed when the game is restarted using BTN_STOPRESET */
1082 rb
->lcd_clear_display();
1084 /* make and display some food and argh */
1085 argh_count
= MAX_FOOD
;
1086 for (i
= 0; i
< MAX_FOOD
; i
++) {
1093 /* draw the game field */
1094 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1095 rb
->lcd_fillrect(0, 0, FIELD_RECT_WIDTH
+ 2, FIELD_RECT_HEIGHT
+ 2);
1096 rb
->lcd_fillrect(1, 1, FIELD_RECT_WIDTH
, FIELD_RECT_HEIGHT
);
1097 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1099 /* make everything visible */
1105 * Move the worm one step further if it is alive.
1106 * The direction in which the worm moves is taken from dirx and diry.
1107 * move_worm decreases growing if > 0. While the worm is growing the tail
1108 * is left untouched.
1109 * @param struct worm *w The worm to move. w must not be NULL.
1111 static void move_worm(struct worm
*w
)
1114 /* determine the head point and its precessor */
1115 int headx
= w
->x
[w
->head
];
1116 int heady
= w
->y
[w
->head
];
1117 int prehead
= (w
->head
+ MAX_WORM_SEGMENTS
- 1) % MAX_WORM_SEGMENTS
;
1118 int preheadx
= w
->x
[prehead
];
1119 int preheady
= w
->y
[prehead
];
1121 /* determine the old direction */
1124 if (headx
== preheadx
) {
1126 olddiry
= (heady
> preheady
) ? 1 : -1;
1129 olddirx
= (headx
> preheadx
) ? 1 : -1;
1133 a change of direction means a new segment
1135 if (olddirx
!= w
->dirx
||
1136 olddiry
!= w
->diry
) {
1137 w
->head
= (w
->head
+ 1) % MAX_WORM_SEGMENTS
;
1140 /* new head position */
1141 w
->x
[w
->head
] = headx
+ w
->dirx
;
1142 w
->y
[w
->head
] = heady
+ w
->diry
;
1145 /* while the worm is growing no tail procession is necessary */
1146 if (w
->growing
> 0) {
1147 /* update the worms grow state */
1151 /* if the worm isn't growing the tail has to be dragged */
1153 /* index of the end of the tail segment */
1154 int tail_segment_end
= (w
->tail
+ 1) % MAX_WORM_SEGMENTS
;
1156 /* drag the end of the tail */
1157 /* only one coordinate has to be altered. Here it is
1158 determined which one */
1159 int dir
= 0; /* specifies wether the coord has to be in- or decreased */
1160 if (w
->x
[w
->tail
] == w
->x
[tail_segment_end
]) {
1161 dir
= (w
->y
[w
->tail
] - w
->y
[tail_segment_end
] < 0) ? 1 : -1;
1162 w
->y
[w
->tail
] += dir
;
1164 dir
= (w
->x
[w
->tail
] - w
->x
[tail_segment_end
] < 0) ? 1 : -1;
1165 w
->x
[w
->tail
] += dir
;
1168 /* when the tail has been dragged so far that it meets
1169 the next segment start the tail segment is obsolete and
1171 if (w
->x
[w
->tail
] == w
->x
[tail_segment_end
] &&
1172 w
->y
[w
->tail
] == w
->y
[tail_segment_end
]){
1174 /* drop the last tail point */
1175 w
->tail
= tail_segment_end
;
1182 * Draws the head and clears the tail of the worm in
1183 * the display buffer. lcd_update() is NOT called thus
1184 * the caller has to take care that the buffer is displayed.
1186 static void draw_worm(struct worm
*w
)
1188 /* draw the new head */
1189 int x
= w
->x
[w
->head
];
1190 int y
= w
->y
[w
->head
];
1191 #ifdef HAVE_LCD_COLOR
1192 rb
->lcd_set_foreground(COLOR_WORM
);
1194 if (x
>= 0 && x
< FIELD_RECT_WIDTH
&& y
>= 0 && y
< FIELD_RECT_HEIGHT
) {
1195 rb
->lcd_drawpixel(x
+ FIELD_RECT_X
, y
+ FIELD_RECT_Y
);
1198 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1200 /* clear the space behind the worm */
1203 if (x
>= 0 && x
< FIELD_RECT_WIDTH
&& y
>= 0 && y
< FIELD_RECT_HEIGHT
) {
1204 rb
->lcd_drawpixel(x
+ FIELD_RECT_X
, y
+ FIELD_RECT_Y
);
1206 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1207 #ifdef HAVE_LCD_COLOR
1208 rb
->lcd_set_foreground(COLOR_FG
);
1213 * Checks wether the coordinate is part of the worm. Returns
1214 * true if any part of the worm was hit - including the head.
1215 * @param x int The x coordinate
1216 * @param y int The y coordinate
1217 * @return int The index of the worm arrays that contain x, y.
1218 * Returns -1 if the coordinates are not part of the worm.
1220 static int specific_worm_collision(struct worm
*w
, int x
, int y
)
1224 /* get_worm_array_length is expensive -> buffer the value */
1225 int wormLength
= get_worm_array_length(w
);
1228 /* test each entry that is part of the worm */
1229 for (i
= 0; i
< wormLength
&& retVal
== -1; i
++) {
1231 /* The iteration iterates the length of the worm.
1232 Here's the conversion to the true indices within the worm arrays. */
1233 int linestart
= (w
->tail
+ i
) % MAX_WORM_SEGMENTS
;
1234 int lineend
= (linestart
+ 1) % MAX_WORM_SEGMENTS
;
1235 bool samex
= (w
->x
[linestart
] == x
) && (w
->x
[lineend
] == x
);
1236 bool samey
= (w
->y
[linestart
] == y
) && (w
->y
[lineend
] == y
);
1237 if (samex
|| samey
){
1238 int test
, min
, max
, tmp
;
1241 min
= w
->x
[linestart
];
1242 max
= w
->x
[lineend
];
1245 min
= w
->y
[linestart
];
1246 max
= w
->y
[lineend
];
1251 min
= MIN(min
, max
);
1252 max
= MAX(tmp
, max
);
1254 if (min
<= test
&& test
<= max
) {
1263 * Increases the length of the specified worm by marking
1264 * that it may grow by len pixels. Note that the worm has
1265 * to move to make the growing happen.
1266 * @param worm *w The worm that is to be altered.
1267 * @param int len A positive value specifying the amount of
1268 * pixels the worm may grow.
1270 static void add_growing(struct worm
*w
, int len
) {
1275 * Determins the worm that is at the coordinates x, y. The parameter
1276 * w is a switch parameter that changes the functionality of worm_collision.
1277 * If w is specified and x,y hits the head of w NULL is returned.
1278 * This is a useful way to determine wether the head of w hits
1279 * any worm but including itself but excluding its own head.
1280 * (It hits always its own head ;))
1281 * If w is set to NULL worm_collision returns any worm including all heads
1282 * that is at position of x,y.
1283 * @param struct worm *w The worm of which the head should be excluded in
1284 * the test. w may be set to NULL.
1285 * @param int x The x coordinate that is checked
1286 * @param int y The y coordinate that is checkec
1287 * @return struct worm* The worm that has been hit by x,y. If no worm
1288 * was at the position NULL is returned.
1290 static struct worm
* worm_collision(struct worm
*w
, int x
, int y
)
1292 struct worm
*retVal
= NULL
;
1294 for (i
= 0; (i
< worm_count
) && (retVal
== NULL
); i
++) {
1295 int collision_at
= specific_worm_collision(&worms
[i
], x
, y
);
1296 if (collision_at
!= -1) {
1297 if (!(w
== &worms
[i
] && collision_at
== w
->head
)){
1306 * Returns true if the head of the worm just has
1307 * crossed the field boundaries.
1308 * @return bool true if the worm just has wrapped.
1310 static bool field_collision(struct worm
*w
)
1312 bool retVal
= false;
1313 if ((w
->x
[w
->head
] >= FIELD_RECT_WIDTH
) ||
1314 (w
->y
[w
->head
] >= FIELD_RECT_HEIGHT
) ||
1315 (w
->x
[w
->head
] < 0) ||
1316 (w
->y
[w
->head
] < 0))
1325 * Returns true if the specified coordinates are within the
1326 * field specified by the FIELD_RECT_XXX constants.
1327 * @param int x The x coordinate of the point that is investigated
1328 * @param int y The y coordinate of the point that is investigated
1329 * @return bool Returns false if x,y specifies a point outside the
1332 static bool is_in_field_rect(int x
, int y
)
1334 bool retVal
= false;
1335 retVal
= (x
>= 0 && x
< FIELD_RECT_WIDTH
&&
1336 y
>= 0 && y
< FIELD_RECT_HEIGHT
);
1341 * Checks and returns wether the head of the w
1342 * is colliding with something currently.
1343 * @return int One of the values:
1350 static int check_collision(struct worm
*w
)
1352 int retVal
= COLLISION_NONE
;
1354 if (worm_collision(w
, w
->x
[w
->head
], w
->y
[w
->head
]) != NULL
)
1355 retVal
= COLLISION_WORM
;
1357 if (food_collision(w
->x
[w
->head
], w
->y
[w
->head
]) >= 0)
1358 retVal
= COLLISION_FOOD
;
1360 if (argh_collision(w
->x
[w
->head
], w
->y
[w
->head
]) >= 0)
1361 retVal
= COLLISION_ARGH
;
1363 if (field_collision(w
))
1364 retVal
= COLLISION_FIELD
;
1370 * Returns the index of the food that is closest to the point
1371 * specified by x, y. This index may be used in the foodx and
1373 * @param int x The x coordinate of the point
1374 * @param int y The y coordinate of the point
1375 * @return int A value usable as index in foodx and foody.
1377 static int get_nearest_food(int x
, int y
)
1379 int nearestfood
= 0;
1380 int olddistance
= FIELD_RECT_WIDTH
+ FIELD_RECT_HEIGHT
;
1384 for (foodindex
= 0; foodindex
< MAX_FOOD
; foodindex
++) {
1386 deltax
= foodx
[foodindex
] - x
;
1387 deltay
= foody
[foodindex
] - y
;
1388 deltax
= deltax
> 0 ? deltax
: deltax
* (-1);
1389 deltay
= deltay
> 0 ? deltay
: deltay
* (-1);
1390 distance
= deltax
+ deltay
;
1392 if (distance
< olddistance
) {
1393 olddistance
= distance
;
1394 nearestfood
= foodindex
;
1401 * Returns wether the specified position is next to the worm
1402 * and in the direction the worm looks. Use this method to
1403 * test wether this position would be hit with the next move of
1404 * the worm unless the worm changes its direction.
1405 * @param struct worm *w - The worm to be investigated
1406 * @param int x - The x coordinate of the position to test.
1407 * @param int y - The y coordinate of the position to test.
1408 * @return Returns true if the worm will hit the position unless
1409 * it change its direction before the next move.
1411 static bool is_in_front_of_worm(struct worm
*w
, int x
, int y
)
1413 bool infront
= false;
1414 int deltax
= x
- w
->x
[w
->head
];
1415 int deltay
= y
- w
->y
[w
->head
];
1418 infront
= (w
->diry
* deltay
) > 0;
1420 infront
= (w
->dirx
* deltax
) > 0;
1426 * Returns true if the worm will collide with the next move unless
1427 * it changes its direction.
1428 * @param struct worm *w - The worm to be investigated.
1429 * @return Returns true if the worm will collide with the next move
1430 * unless it changes its direction.
1432 static bool will_worm_collide(struct worm
*w
)
1434 int x
= w
->x
[w
->head
] + w
->dirx
;
1435 int y
= w
->y
[w
->head
] + w
->diry
;
1436 bool retVal
= !is_in_field_rect(x
, y
);
1438 retVal
= (argh_collision(x
, y
) != -1);
1442 retVal
= (worm_collision(w
, x
, y
) != NULL
);
1449 * may be used to be stored in worm.fetch_worm_direction for
1450 * worms that are not controlled by humans but by artificial stupidity.
1451 * A direction is searched that doesn't lead to collision but to the nearest
1452 * food - but not very intelligent. The direction is written to the specified
1454 * @param struct worm *w - The worm of which the direction
1457 static void virtual_player(struct worm
*w
)
1460 int plana
, planb
, planc
;
1461 /* find the next lunch */
1462 int nearestfood
= get_nearest_food(w
->x
[w
->head
], w
->y
[w
->head
]);
1464 /* determine in which direction it is */
1466 /* in front of me? */
1467 bool infront
= is_in_front_of_worm(w
, foodx
[nearestfood
], foody
[nearestfood
]);
1469 /* left right of me? */
1470 int olddir
= get_worm_dir(w
);
1471 set_worm_dir(w
, (olddir
+ 1) % 4);
1472 isright
= is_in_front_of_worm(w
, foodx
[nearestfood
], foody
[nearestfood
]);
1473 set_worm_dir(w
, olddir
);
1475 /* detect situation, set strategy */
1479 planb
= (olddir
+ 1) % 4;
1480 planc
= (olddir
+ 3) % 4;
1483 planb
= (olddir
+ 3) % 4;
1484 planc
= (olddir
+ 1) % 4;
1488 plana
= (olddir
+ 1) % 4;
1490 planc
= (olddir
+ 3) % 4;
1492 plana
= (olddir
+ 3) % 4;
1494 planc
= (olddir
+ 1) % 4;
1498 /* test for collision */
1499 set_worm_dir(w
, plana
);
1500 if (will_worm_collide(w
)){
1503 set_worm_dir(w
, planb
);
1505 /* test for collision */
1506 if (will_worm_collide(w
)) {
1509 set_worm_dir(w
, planc
);
1515 * prints out the score board with all the status information
1518 static void score_board(void)
1524 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1525 rb
->lcd_fillrect(FIELD_RECT_WIDTH
+ 2, 0,
1526 LCD_WIDTH
- FIELD_RECT_WIDTH
- 2, LCD_HEIGHT
);
1527 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1528 for (i
= 0; i
< worm_count
; i
++) {
1529 int score
= get_score(&worms
[i
]);
1532 if (worms
[i
].fetch_worm_direction
!= virtual_player
){
1533 if (highscore
< score
) {
1539 rb
->snprintf(buf
, sizeof (buf
),"Len:%d", score
);
1542 switch (check_collision(&worms
[i
])) {
1543 case COLLISION_NONE
:
1544 if (worms
[i
].growing
> 0)
1554 case COLLISION_WORM
:
1558 case COLLISION_FOOD
:
1562 case COLLISION_ARGH
:
1566 case COLLISION_FIELD
:
1570 rb
->lcd_putsxy(FIELD_RECT_WIDTH
+ 3, y
, buf
);
1571 rb
->lcd_putsxy(FIELD_RECT_WIDTH
+ 3, y
+8, buf2
);
1573 if (!worms
[i
].alive
){
1574 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1575 rb
->lcd_fillrect(FIELD_RECT_WIDTH
+ 2, y
,
1576 LCD_WIDTH
- FIELD_RECT_WIDTH
- 2, 17);
1577 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1581 rb
->snprintf(buf
, sizeof(buf
), "Hs: %d", highscore
);
1582 #ifndef DEBUG_WORMLET
1583 rb
->lcd_putsxy(FIELD_RECT_WIDTH
+ 3, LCD_HEIGHT
- 8, buf
);
1585 rb
->lcd_putsxy(FIELD_RECT_WIDTH
+ 3, LCD_HEIGHT
- 8, debugout
);
1590 * Checks for collisions of the worm and its environment and
1591 * takes appropriate actions like growing the worm or killing it.
1592 * @return bool Returns true if the worm is dead. Returns
1593 * false if the worm is healthy, up and creeping.
1595 static bool process_collisions(struct worm
*w
)
1599 w
->alive
&= !field_collision(w
);
1603 /* check if food was eaten */
1604 index
= food_collision(w
->x
[w
->head
], w
->y
[w
->head
]);
1612 for (i
= 0; i
< arghs_per_food
; i
++) {
1614 if (argh_count
> MAX_ARGH
)
1615 argh_count
= MAX_ARGH
;
1616 make_argh(argh_count
- 1);
1617 draw_argh(argh_count
- 1);
1620 add_growing(w
, worm_food
);
1625 /* check if argh was eaten */
1627 index
= argh_collision(w
->x
[w
->head
], w
->y
[w
->head
]);
1632 if (worm_collision(w
, w
->x
[w
->head
], w
->y
[w
->head
]) != NULL
) {
1642 * The main loop of the game.
1643 * @return bool Returns true if the game ended
1644 * with a dead worm. Returns false if the user
1645 * aborted the game manually.
1647 static int run(void)
1650 int wormDead
= false;
1651 bool paused
= false;
1653 /* ticks are counted to compensate speed variations */
1654 long cycle_start
= 0, cycle_end
= 0;
1655 #ifdef DEBUG_WORMLET
1656 int ticks_to_max_cycle_reset
= 20;
1661 /* initialize the board and so on */
1664 cycle_start
= *rb
->current_tick
;
1665 /* change the direction of the worm */
1669 long cycle_duration
=0;
1671 #ifdef HAS_BUTTON_HOLD
1672 if (rb
->button_hold())
1677 case BTN_STARTPAUSE
:
1682 return 1; /* restart game */
1690 return 2; /* back to menu */
1697 if (players
== 1 && !use_remote
) {
1698 player1_dir
= NORTH
;
1703 if (players
== 1 && !use_remote
) {
1704 player1_dir
= SOUTH
;
1709 if (players
!= 1 || use_remote
) {
1710 player1_dir
= (player1_dir
+ 3) % 4;
1717 if (players
!= 1 || use_remote
) {
1718 player1_dir
= (player1_dir
+ 1) % 4;
1725 case BTN_PLAYER2_DIR1
:
1726 player2_dir
= (player2_dir
+ 3) % 4;
1729 case BTN_PLAYER2_DIR2
:
1730 player2_dir
= (player2_dir
+ 1) % 4;
1736 player3_dir
= (player3_dir
+ 1) % 4;
1740 player3_dir
= (player3_dir
+ 3) % 4;
1746 for (i
= 0; i
< worm_count
; i
++) {
1747 worms
[i
].fetch_worm_direction(&worms
[i
]);
1751 for (i
= 0; i
< worm_count
; i
++){
1752 struct worm
*w
= &worms
[i
];
1754 wormDead
&= process_collisions(w
);
1759 if (button
== BTN_STOPRESET
) {
1763 /* here the wormlet game cycle ends
1764 thus the current tick is stored
1766 cycle_end
= *rb
->current_tick
;
1768 /* The duration of the game cycle */
1769 cycle_duration
= cycle_end
- cycle_start
;
1770 cycle_duration
= MAX(0, cycle_duration
);
1771 cycle_duration
= MIN(speed
-1, cycle_duration
);
1774 #ifdef DEBUG_WORMLET
1775 ticks_to_max_cycle_reset
--;
1776 if (ticks_to_max_cycle_reset
<= 0) {
1780 if (max_cycle
< cycle_duration
) {
1781 max_cycle
= cycle_duration
;
1782 ticks_to_max_cycle_reset
= 20;
1784 rb
->snprintf(buf
, sizeof buf
, "ticks %d", max_cycle
);
1788 /* adjust the number of ticks to wait for a button.
1789 This ensures that a complete game cycle including
1790 user input runs in constant time */
1791 button
= rb
->button_get_w_tmo(speed
- cycle_duration
);
1792 cycle_start
= *rb
->current_tick
;
1795 rb
->splash(HZ
*2, "Game Over!");
1797 return 2; /* back to menu */
1800 #ifdef DEBUG_WORMLET
1803 * Just a test routine that checks that worm_food_collision works
1804 * in some typical situations.
1806 static void test_worm_food_collision(void)
1808 int collision_count
= 0;
1810 rb
->lcd_clear_display();
1811 init_worm(&worms
[0], 10, 10);
1812 add_growing(&worms
[0], 10);
1813 set_worm_dir(&worms
[0], EAST
);
1814 for (i
= 0; i
< 10; i
++) {
1815 move_worm(&worms
[0]);
1816 draw_worm(&worms
[0]);
1819 set_worm_dir(&worms
[0], SOUTH
);
1820 for (i
= 0; i
< 10; i
++) {
1821 move_worm(&worms
[0]);
1822 draw_worm(&worms
[0]);
1827 for (foody
[0] = 20; foody
[0] > 0; foody
[0] --) {
1830 draw_worm(&worms
[0]);
1832 collision
= worm_food_collision(&worms
[0], 0);
1836 rb
->snprintf(buf
, sizeof buf
, "collisions: %d", collision_count
);
1837 rb
->lcd_putsxy(0, LCD_HEIGHT
-8, buf
);
1840 if (collision_count
!= food_size
) {
1841 rb
->button_get(true);
1846 for (foodx
[0] = 30; foodx
[0] > 0; foodx
[0] --) {
1849 draw_worm(&worms
[0]);
1851 collision
= worm_food_collision(&worms
[0], 0);
1855 rb
->snprintf(buf
, sizeof buf
, "collisions: %d", collision_count
);
1856 rb
->lcd_putsxy(0, LCD_HEIGHT
-8, buf
);
1859 if (collision_count
!= food_size
* 2) {
1860 rb
->button_get(true);
1865 static bool expensive_worm_in_rect(struct worm
*w
, int rx
, int ry
, int rw
, int rh
)
1868 bool retVal
= false;
1869 for (x
= rx
; x
< rx
+ rw
; x
++){
1870 for (y
= ry
; y
< ry
+ rh
; y
++) {
1871 if (specific_worm_collision(w
, x
, y
) != -1) {
1879 static void test_worm_argh_collision(void)
1883 int collision_count
= 0;
1884 rb
->lcd_clear_display();
1885 init_worm(&worms
[0], 10, 10);
1886 add_growing(&worms
[0], 40);
1887 for (dir
= 0; dir
< 4; dir
++) {
1888 set_worm_dir(&worms
[0], (EAST
+ dir
) % 4);
1889 for (i
= 0; i
< 10; i
++) {
1890 move_worm(&worms
[0]);
1891 draw_worm(&worms
[0]);
1896 for (arghy
[0] = 0; arghy
[0] < FIELD_RECT_HEIGHT
- argh_size
; arghy
[0]++){
1900 collision
= worm_argh_collision(&worms
[0], 0);
1904 rb
->snprintf(buf
, sizeof buf
, "collisions: %d", collision_count
);
1905 rb
->lcd_putsxy(0, LCD_HEIGHT
-8, buf
);
1908 if (collision_count
!= argh_size
* 2) {
1909 rb
->button_get(true);
1913 for (arghx
[0] = 0; arghx
[0] < FIELD_RECT_HEIGHT
- argh_size
; arghx
[0]++){
1917 collision
= worm_argh_collision(&worms
[0], 0);
1921 rb
->snprintf(buf
, sizeof buf
, "collisions: %d", collision_count
);
1922 rb
->lcd_putsxy(0, LCD_HEIGHT
-8, buf
);
1925 if (collision_count
!= argh_size
* 4) {
1926 rb
->button_get(true);
1930 static int testline_in_rect(void)
1932 int testfailed
= -1;
1945 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
1946 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
1947 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
1948 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
1950 rb
->lcd_putsxy(0, 0, "failed 1");
1951 rb
->button_get(true);
1957 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
1958 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
1959 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
1960 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
1961 rb
->lcd_putsxy(0, 0, "failed 2");
1963 rb
->button_get(true);
1969 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
1970 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
1971 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
1972 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
1973 rb
->lcd_putsxy(0, 0, "failed 3");
1975 rb
->button_get(true);
1981 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
1982 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
1983 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
1984 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
1985 rb
->lcd_putsxy(0, 0, "failed 4");
1987 rb
->button_get(true);
1993 if (line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) ||
1994 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
1995 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
1996 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
1997 rb
->lcd_putsxy(0, 0, "failed 5");
1999 rb
->button_get(true);
2006 if (line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) ||
2007 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2008 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2009 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2010 rb
->lcd_putsxy(0, 0, "failed 6");
2012 rb
->button_get(true);
2021 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2022 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2023 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2024 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2025 rb
->lcd_putsxy(0, 0, "failed 7");
2027 rb
->button_get(true);
2033 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2034 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2035 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2036 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2037 rb
->lcd_putsxy(0, 0, "failed 8");
2039 rb
->button_get(true);
2045 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2046 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2047 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2048 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2049 rb
->lcd_putsxy(0, 0, "failed 9");
2051 rb
->button_get(true);
2057 if (!line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2058 !line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2059 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2060 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2061 rb
->lcd_putsxy(0, 0, "failed 10");
2063 rb
->button_get(true);
2069 if (line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) ||
2070 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2071 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2072 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2073 rb
->lcd_putsxy(0, 0, "failed 11");
2075 rb
->button_get(true);
2082 if (line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) ||
2083 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
)) {
2084 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2085 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2086 rb
->lcd_putsxy(0, 0, "failed 12");
2088 rb
->button_get(true);
2102 if (!(line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2103 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
))) {
2104 rb
->lcd_drawrect(rx
, ry
, rw
, rh
);
2105 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2106 rb
->lcd_putsxy(0, 0, "failed 13");
2108 rb
->button_get(true);
2122 if (!(line_in_rect(x1
, y1
, x2
, y2
, rx
, ry
, rw
, rh
) &&
2123 line_in_rect(x2
, y2
, x1
, y1
, rx
, ry
, rw
, rh
))) {
2124 rb
->lcd_drawline(x1
, y1
, x2
, y2
);
2125 rb
->lcd_invertrect(rx
, ry
, rw
, rh
);
2126 rb
->lcd_putsxy(0, 0, "failed 14");
2128 rb
->button_get(true);
2132 rb
->lcd_clear_display();
2138 * Just a test routine to test wether specific_worm_collision might work properly
2140 static int test_specific_worm_collision(void)
2147 rb
->lcd_clear_display();
2148 init_worm(&worms
[0], 10, 20);
2149 add_growing(&worms
[0], 20 - INITIAL_WORM_LENGTH
);
2151 for (dir
= EAST
; dir
< EAST
+ 4; dir
++) {
2153 set_worm_dir(&worms
[0], dir
% 4);
2154 for (i
= 0; i
< 5; i
++) {
2155 if (!(dir
% 4 == NORTH
&& i
== 9)) {
2156 move_worm(&worms
[0]);
2157 draw_worm(&worms
[0]);
2162 for (y
= 15; y
< 30; y
++){
2163 for (x
= 5; x
< 20; x
++) {
2164 if (specific_worm_collision(&worms
[0], x
, y
) != -1) {
2167 rb
->lcd_invertpixel(x
+ FIELD_RECT_X
, y
+ FIELD_RECT_Y
);
2168 rb
->snprintf(buf
, sizeof buf
, "collisions %d", collisions
);
2169 rb
->lcd_putsxy(0, LCD_HEIGHT
- 8, buf
);
2173 if (collisions
!= 21) {
2174 rb
->button_get(true);
2179 static void test_make_argh(void)
2185 int last_failures
= 0;
2187 rb
->lcd_clear_display();
2190 for (worm_idx
= 0; worm_idx
< worm_count
; worm_idx
++) {
2191 init_worm(&worms
[worm_idx
], 10 + worm_idx
* 20, 20);
2192 add_growing(&worms
[worm_idx
], 40 - INITIAL_WORM_LENGTH
);
2195 for (dir
= EAST
; dir
< EAST
+ 4; dir
++) {
2196 for (worm_idx
= 0; worm_idx
< worm_count
; worm_idx
++) {
2197 set_worm_dir(&worms
[worm_idx
], dir
% 4);
2198 for (i
= 0; i
< 10; i
++) {
2199 if (!(dir
% 4 == NORTH
&& i
== 9)) {
2200 move_worm(&worms
[worm_idx
]);
2201 draw_worm(&worms
[worm_idx
]);
2209 for (seed
= 0; hit
< 20; seed
+= 2) {
2213 x
= rb
->rand() % (FIELD_RECT_WIDTH
- argh_size
);
2214 y
= rb
->rand() % (FIELD_RECT_HEIGHT
- argh_size
);
2216 for (worm_idx
= 0; worm_idx
< worm_count
; worm_idx
++){
2217 if (expensive_worm_in_rect(&worms
[worm_idx
], x
, y
, argh_size
, argh_size
)) {
2221 tries
= make_argh(0);
2222 if ((x
== arghx
[0] && y
== arghy
[0]) || tries
< 2) {
2226 rb
->snprintf(buf
, sizeof buf
, "(%d;%d) fail%d try%d",
2227 x
, y
, failures
, tries
);
2228 rb
->lcd_putsxy(0, LCD_HEIGHT
- 8, buf
);
2230 rb
->lcd_invertrect(x
+ FIELD_RECT_X
, y
+ FIELD_RECT_Y
,
2231 argh_size
, argh_size
);
2235 rb
->lcd_invertrect(x
+ FIELD_RECT_X
, y
+ FIELD_RECT_Y
,
2236 argh_size
, argh_size
);
2237 rb
->lcd_clearrect(arghx
[0] + FIELD_RECT_X
, arghy
[0] + FIELD_RECT_Y
,
2238 argh_size
, argh_size
);
2240 if (failures
> last_failures
) {
2241 rb
->button_get(true);
2243 last_failures
= failures
;
2250 static void test_worm_argh_collision_in_moves(void) {
2253 rb
->lcd_clear_display();
2254 init_worm(&worms
[0], 10, 20);
2260 set_worm_dir(&worms
[0], EAST
);
2261 for (i
= 0; i
< 20; i
++) {
2263 move_worm(&worms
[0]);
2264 draw_worm(&worms
[0]);
2265 if (worm_argh_collision_in_moves(&worms
[0], 0, 5)){
2268 rb
->snprintf(buf
, sizeof buf
, "in 5 moves hits: %d", hit_count
);
2269 rb
->lcd_putsxy(0, LCD_HEIGHT
- 8, buf
);
2272 if (hit_count
!= argh_size
+ 5) {
2273 rb
->button_get(true);
2276 #endif /* DEBUG_WORMLET */
2279 * Reverts default settings
2281 static void default_settings(void)
2283 arghs_per_food
= ARGHS_PER_FOOD
;
2284 argh_size
= ARGH_SIZE
;
2285 food_size
= FOOD_SIZE
;
2287 worm_food
= WORM_PER_FOOD
;
2289 worm_count
= MAX_WORMS
;
2295 * Launches the wormlet game
2297 static bool launch_wormlet(void)
2299 int game_result
= 1;
2301 rb
->lcd_clear_display();
2303 /* Turn off backlight timeout */
2304 backlight_force_on(); /* backlight control in lib/helper.c */
2306 /* start the game */
2307 while (game_result
== 1)
2308 game_result
= run();
2310 switch (game_result
)
2313 /* Turn on backlight timeout (revert to settings) */
2314 backlight_use_settings(); /* backlight control in lib/helper.c */
2324 enum plugin_status
plugin_start(const void* parameter
)
2333 if (configfile_load(SETTINGS_FILENAME
, config
,
2334 sizeof(config
)/sizeof(*config
),
2335 SETTINGS_MIN_VERSION
) < 0)
2337 /* If the loading failed, save a new config file (as the disk is
2338 already spinning) */
2339 configfile_save(SETTINGS_FILENAME
, config
,
2340 sizeof(config
)/sizeof(*config
),
2344 #ifdef HAVE_LCD_COLOR
2345 rb
->lcd_set_foreground(COLOR_FG
);
2346 rb
->lcd_set_background(COLOR_BG
);
2350 rb
->lcd_set_backdrop(NULL
);
2353 #ifdef DEBUG_WORMLET
2355 test_worm_argh_collision_in_moves();
2357 test_worm_food_collision();
2358 test_worm_argh_collision();
2359 test_specific_worm_collision();
2364 static const struct opt_items noyes
[2] = {
2369 static const struct opt_items remoteonly_option
[1] = {
2370 { "Remote Control", -1 }
2373 static const struct opt_items key24_option
[2] = {
2374 { "4 Key Control", -1 },
2375 { "2 Key Control", -1 }
2379 static const struct opt_items remote_option
[2] = {
2380 { "Remote Control", -1 },
2381 { "No Rem. Control", -1 }
2384 static const struct opt_items key2_option
[1] = {
2385 { "2 Key Control", -1 }
2389 static const struct opt_items nokey_option
[1] = {
2390 { "Out of Control", -1 }
2393 MENUITEM_STRINGLIST(menu
, "Wormlet Menu", NULL
, "Play Wormlet!",
2394 "Number of Worms", "Number of Players", "Control Style",
2395 "Worm Growth Per Food","Worm Speed","Arghs Per Food",
2396 "Argh Size","Food Size","Revert to Default Settings",
2397 "Playback Control", "Quit");
2399 rb
->button_clear_queue();
2401 while (!menu_quit
) {
2402 switch(rb
->do_menu(&menu
, &result
, NULL
, false))
2405 rb
->lcd_setfont(FONT_SYSFIXED
);
2409 rb
->set_int("Number of Worms", "", UNIT_INT
, &worm_count
, NULL
,
2411 if (worm_count
< players
) {
2412 worm_count
= players
;
2417 rb
->set_int("Number of Players", "", UNIT_INT
, &players
, NULL
,
2420 rb
->set_int("Number of Players", "", UNIT_INT
, &players
, NULL
,
2423 if (players
> worm_count
) {
2424 worm_count
= players
;
2433 rb
->set_option("Control Style",&use_remote
,INT
,
2434 nokey_option
, 1, NULL
);
2437 rb
->set_option("Control Style",&use_remote
,INT
,
2438 key24_option
, 2, NULL
);
2442 rb
->set_option("Control Style",&use_remote
,INT
,
2443 remote_option
, 2, NULL
);
2445 rb
->set_option("Control Style",&use_remote
,INT
,
2446 key2_option
, 1, NULL
);
2450 rb
->set_option("Control Style",&use_remote
,INT
,
2451 remoteonly_option
, 1, NULL
);
2456 rb
->set_int("Worm Growth Per Food", "", UNIT_INT
, &worm_food
,
2457 NULL
, 1, 0, 15, NULL
);
2460 new_setting
= 20 - speed
;
2461 rb
->set_int("Worm Speed", "", UNIT_INT
, &new_setting
,
2462 NULL
, 1, 0, 20, NULL
);
2463 speed
= 20 - new_setting
;
2466 rb
->set_int("Arghs Per Food", "", UNIT_INT
, &arghs_per_food
,
2467 NULL
, 1, 0, 8, NULL
);
2470 rb
->set_int("Argh Size", "", UNIT_INT
, &argh_size
,
2471 NULL
, 1, 2, 10, NULL
);
2474 rb
->set_int("Food Size", "", UNIT_INT
, &food_size
,
2475 NULL
, 1, 2, 10, NULL
);
2479 rb
->set_option("Reset Settings?", &new_setting
, INT
, noyes
, 2, NULL
);
2480 if (new_setting
== 1)
2484 playback_control(NULL
);
2492 configfile_save(SETTINGS_FILENAME
, config
,
2493 sizeof(config
)/sizeof(*config
),