1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Itai Shaked
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
25 ok, a little explanation -
26 board holds the snake and apple position - 1+ - snake body (the number
27 represents the age [1 is the snake's head]).
28 -1 is an apple, and 0 is a clear spot.
29 dir is the current direction of the snake - 0=up, 1=right, 2=down, 3=left;
34 #ifdef HAVE_LCD_BITMAP
38 /* variable button definitions */
39 #if CONFIG_KEYPAD == RECORDER_PAD
40 #define SNAKE_QUIT BUTTON_OFF
41 #define SNAKE_UP BUTTON_UP
42 #define SNAKE_DOWN BUTTON_DOWN
43 #define SNAKE_PLAYPAUSE BUTTON_PLAY
45 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
46 #define SNAKE_QUIT BUTTON_OFF
47 #define SNAKE_UP BUTTON_UP
48 #define SNAKE_DOWN BUTTON_DOWN
49 #define SNAKE_PLAYPAUSE BUTTON_SELECT
51 #elif CONFIG_KEYPAD == ONDIO_PAD
52 #define SNAKE_QUIT BUTTON_OFF
53 #define SNAKE_UP BUTTON_UP
54 #define SNAKE_DOWN BUTTON_DOWN
55 #define SNAKE_PLAYPAUSE BUTTON_MENU
57 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
58 (CONFIG_KEYPAD == IRIVER_H300_PAD)
59 #define SNAKE_QUIT BUTTON_OFF
60 #define SNAKE_UP BUTTON_UP
61 #define SNAKE_DOWN BUTTON_DOWN
62 #define SNAKE_PLAYPAUSE BUTTON_ON
64 #define SNAKE_RC_QUIT BUTTON_RC_STOP
66 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
67 (CONFIG_KEYPAD == IPOD_3G_PAD)
68 #define SNAKE_QUIT (BUTTON_SELECT|BUTTON_MENU)
69 #define SNAKE_UP BUTTON_MENU
70 #define SNAKE_DOWN BUTTON_PLAY
71 #define SNAKE_PLAYPAUSE BUTTON_SELECT
73 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
74 #define SNAKE_QUIT BUTTON_POWER
75 #define SNAKE_UP BUTTON_UP
76 #define SNAKE_DOWN BUTTON_DOWN
77 #define SNAKE_PLAYPAUSE BUTTON_PLAY
79 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
80 #define SNAKE_QUIT BUTTON_POWER
81 #define SNAKE_UP BUTTON_UP
82 #define SNAKE_DOWN BUTTON_DOWN
83 #define SNAKE_PLAYPAUSE BUTTON_SELECT
85 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
86 #define SNAKE_QUIT BUTTON_POWER
87 #define SNAKE_UP BUTTON_UP
88 #define SNAKE_DOWN BUTTON_DOWN
89 #define SNAKE_PLAYPAUSE BUTTON_SELECT
91 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
92 #define SNAKE_QUIT BUTTON_POWER
93 #define SNAKE_UP BUTTON_SCROLL_UP
94 #define SNAKE_DOWN BUTTON_SCROLL_DOWN
95 #define SNAKE_PLAYPAUSE BUTTON_PLAY
98 #error "lacks keymapping"
101 #define BOARD_WIDTH (LCD_WIDTH/4)
102 #define BOARD_HEIGHT (LCD_HEIGHT/4)
104 static int board
[BOARD_WIDTH
][BOARD_HEIGHT
],snakelength
;
105 static unsigned int score
,hiscore
=0,level
=1;
106 static short dir
,frames
,apple
,dead
=0;
107 static struct plugin_api
* rb
;
112 rb
->lcd_clear_display();
113 rb
->snprintf(pscore
,sizeof(pscore
),"Your score: %d",score
);
114 rb
->lcd_puts(0,0,"Oops...");
115 rb
->lcd_puts(0,1, pscore
);
118 rb
->lcd_puts(0,2,"New High Score!");
121 rb
->snprintf(pscore
,sizeof(pscore
),"High Score: %d",hiscore
);
122 rb
->lcd_puts(0,2,pscore
);
129 void colission (short x
, short y
)
131 switch (board
[x
][y
]) {
143 if (x
==BOARD_WIDTH
|| x
<0 || y
==BOARD_HEIGHT
|| y
<0)
147 void move_head (short x
, short y
)
167 rb
->lcd_fillrect(x
*4,y
*4,4,4);
173 for (x
=0; x
<BOARD_WIDTH
; x
++) {
174 for (y
=0; y
<BOARD_HEIGHT
; y
++) {
175 switch (board
[x
][y
]) {
190 if (board
[x
][y
]==snakelength
) {
192 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
193 rb
->lcd_fillrect(x
*4,y
*4,4,4);
194 rb
->lcd_set_drawmode(DRMODE_SOLID
);
208 rb
->lcd_clear_display();
209 for (x
=0; x
<BOARD_WIDTH
; x
++) {
210 for (y
=0; y
<BOARD_HEIGHT
; y
++) {
211 switch (board
[x
][y
]) {
213 rb
->lcd_fillrect((x
*4)+1,y
*4,2,4);
214 rb
->lcd_fillrect(x
*4,(y
*4)+1,4,2);
219 rb
->lcd_fillrect(x
*4,y
*4,4,4);
227 void game_pause (void) {
229 rb
->lcd_clear_display();
230 rb
->lcd_putsxy(3,12,"Game Paused");
231 #if CONFIG_KEYPAD == RECORDER_PAD
232 rb
->lcd_putsxy(3,22,"[Play] to resume");
233 #elif CONFIG_KEYPAD == ONDIO_PAD
234 rb
->lcd_putsxy(3,22,"[Mode] to resume");
236 rb
->lcd_putsxy(3,32,"[Off] to quit");
239 button
=rb
->button_get(true);
247 case SNAKE_PLAYPAUSE
:
252 if (rb
->default_event_handler(button
)==SYS_USB_CONNECTED
) {
274 x
=rb
->rand() % BOARD_WIDTH
;
275 y
=rb
->rand() % BOARD_HEIGHT
;
276 } while (board
[x
][y
]);
279 rb
->lcd_fillrect((x
*4)+1,y
*4,2,4);
280 rb
->lcd_fillrect(x
*4,(y
*4)+1,4,2);
286 button
=rb
->button_get(false);
288 #ifdef HAS_BUTTON_HOLD
289 if (rb
->button_hold())
290 button
= SNAKE_PLAYPAUSE
;
312 case SNAKE_PLAYPAUSE
:
316 if (rb
->default_event_handler(button
)==SYS_USB_CONNECTED
) {
325 void game_init(void) {
328 bool menu_quit
= false;
330 for (x
=0; x
<BOARD_WIDTH
; x
++) {
331 for (y
=0; y
<BOARD_HEIGHT
; y
++) {
341 MENUITEM_STRINGLIST(menu
,"Snake Menu",NULL
,"Start New Game","Starting Level",
345 switch(rb
->do_menu(&menu
, &selection
))
348 menu_quit
= true; /* start playing */
352 rb
->set_int("Starting Level", "", UNIT_INT
, &level
, NULL
,
357 dead
=1; /* quit program */
365 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
371 rb
->lcd_clear_display();
373 return (dead
==1)?PLUGIN_OK
:PLUGIN_USB_CONNECTED
;