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 == ONDIO_PAD
46 #define SNAKE_QUIT BUTTON_OFF
47 #define SNAKE_UP BUTTON_UP
48 #define SNAKE_DOWN BUTTON_DOWN
49 #define SNAKE_PLAYPAUSE BUTTON_MENU
51 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
52 (CONFIG_KEYPAD == IRIVER_H300_PAD)
53 #define SNAKE_QUIT BUTTON_OFF
54 #define SNAKE_UP BUTTON_UP
55 #define SNAKE_DOWN BUTTON_DOWN
56 #define SNAKE_PLAYPAUSE BUTTON_ON
58 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
59 (CONFIG_KEYPAD == IPOD_3G_PAD)
60 #define SNAKE_QUIT (BUTTON_SELECT|BUTTON_MENU)
61 #define SNAKE_UP BUTTON_MENU
62 #define SNAKE_DOWN BUTTON_PLAY
63 #define SNAKE_PLAYPAUSE BUTTON_SELECT
65 #elif (CONFIG_KEYPAD == IAUDIO_X5_PAD)
66 #define SNAKE_QUIT BUTTON_POWER
67 #define SNAKE_UP BUTTON_UP
68 #define SNAKE_DOWN BUTTON_DOWN
69 #define SNAKE_PLAYPAUSE BUTTON_PLAY
71 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
72 #define SNAKE_QUIT BUTTON_A
73 #define SNAKE_UP BUTTON_UP
74 #define SNAKE_DOWN BUTTON_DOWN
75 #define SNAKE_PLAYPAUSE BUTTON_SELECT
78 #error "lacks keymapping"
81 #define BOARD_WIDTH (LCD_WIDTH/4)
82 #define BOARD_HEIGHT (LCD_HEIGHT/4)
84 static int board
[BOARD_WIDTH
][BOARD_HEIGHT
],snakelength
;
85 static unsigned int score
,hiscore
=0;
86 static short dir
,frames
,apple
,level
=1,dead
=0;
87 static struct plugin_api
* rb
;
91 char pscore
[5],hscore
[17];
92 rb
->lcd_clear_display();
93 rb
->snprintf(pscore
,sizeof(pscore
),"%d",score
);
94 rb
->lcd_putsxy(3,12,"oops...");
95 rb
->lcd_putsxy(3,22,"Your score :");
96 rb
->lcd_putsxy(3,32, pscore
);
99 rb
->lcd_putsxy(3,42,"New High Score!");
102 rb
->snprintf(hscore
,sizeof(hscore
),"High Score: %d",hiscore
);
103 rb
->lcd_putsxy(3,42,hscore
);
110 void colission (short x
, short y
)
112 switch (board
[x
][y
]) {
124 if (x
==BOARD_WIDTH
|| x
<0 || y
==BOARD_HEIGHT
|| y
<0)
128 void move_head (short x
, short y
)
148 rb
->lcd_fillrect(x
*4,y
*4,4,4);
154 for (x
=0; x
<BOARD_WIDTH
; x
++) {
155 for (y
=0; y
<BOARD_HEIGHT
; y
++) {
156 switch (board
[x
][y
]) {
171 if (board
[x
][y
]==snakelength
) {
173 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
174 rb
->lcd_fillrect(x
*4,y
*4,4,4);
175 rb
->lcd_set_drawmode(DRMODE_SOLID
);
189 rb
->lcd_clear_display();
190 for (x
=0; x
<BOARD_WIDTH
; x
++) {
191 for (y
=0; y
<BOARD_HEIGHT
; y
++) {
192 switch (board
[x
][y
]) {
194 rb
->lcd_fillrect((x
*4)+1,y
*4,2,4);
195 rb
->lcd_fillrect(x
*4,(y
*4)+1,4,2);
200 rb
->lcd_fillrect(x
*4,y
*4,4,4);
208 void game_pause (void) {
210 rb
->lcd_clear_display();
211 rb
->lcd_putsxy(3,12,"Game Paused");
212 #if CONFIG_KEYPAD == RECORDER_PAD
213 rb
->lcd_putsxy(3,22,"[Play] to resume");
214 #elif CONFIG_KEYPAD == ONDIO_PAD
215 rb
->lcd_putsxy(3,22,"[Mode] to resume");
217 rb
->lcd_putsxy(3,32,"[Off] to quit");
220 button
=rb
->button_get(true);
225 case SNAKE_PLAYPAUSE
:
230 if (rb
->default_event_handler(button
)==SYS_USB_CONNECTED
) {
252 x
=rb
->rand() % BOARD_WIDTH
;
253 y
=rb
->rand() % BOARD_HEIGHT
;
254 } while (board
[x
][y
]);
257 rb
->lcd_fillrect((x
*4)+1,y
*4,2,4);
258 rb
->lcd_fillrect(x
*4,(y
*4)+1,4,2);
264 button
=rb
->button_get(false);
281 case SNAKE_PLAYPAUSE
:
285 if (rb
->default_event_handler(button
)==SYS_USB_CONNECTED
) {
294 void game_init(void) {
297 char plevel
[10],phscore
[20];
299 for (x
=0; x
<BOARD_WIDTH
; x
++) {
300 for (y
=0; y
<BOARD_HEIGHT
; y
++) {
311 rb
->lcd_clear_display();
312 rb
->lcd_setfont(FONT_SYSFIXED
);
313 rb
->snprintf(plevel
,sizeof(plevel
),"Level - %d",level
);
314 rb
->snprintf(phscore
,sizeof(phscore
),"High Score: %d",hiscore
);
315 rb
->lcd_puts(0,0, plevel
);
316 rb
->lcd_puts(0,1, "(1-slow, 9-fast)");
317 rb
->lcd_puts(0,2, "OFF - quit");
318 #if CONFIG_KEYPAD == RECORDER_PAD
319 rb
->lcd_puts(0,3, "PLAY - start/pause");
320 #elif CONFIG_KEYPAD == ONDIO_PAD
321 rb
->lcd_puts(0,3, "MODE - start/pause");
323 rb
->lcd_puts(0,4, phscore
);
327 button
=rb
->button_get(true);
343 case SNAKE_PLAYPAUSE
:
347 if (rb
->default_event_handler(button
)==SYS_USB_CONNECTED
) {
353 rb
->snprintf(plevel
,sizeof(plevel
),"Level - %d",level
);
354 rb
->lcd_puts(0,0, plevel
);
360 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
366 rb
->lcd_clear_display();
368 return (dead
==1)?PLUGIN_OK
:PLUGIN_USB_CONNECTED
;