1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Itai Shaked
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 ****************************************************************************/
27 ok, a little explanation -
28 board holds the snake and apple position - 1+ - snake body (the number
29 represents the age [1 is the snake's head]).
30 -1 is an apple, and 0 is a clear spot.
31 dir is the current direction of the snake - 0=up, 1=right, 2=down, 3=left;
36 #ifdef HAVE_LCD_BITMAP
40 /* variable button definitions */
41 #if CONFIG_KEYPAD == RECORDER_PAD
42 #define SNAKE_QUIT BUTTON_OFF
43 #define SNAKE_LEFT BUTTON_LEFT
44 #define SNAKE_RIGHT BUTTON_RIGHT
45 #define SNAKE_UP BUTTON_UP
46 #define SNAKE_DOWN BUTTON_DOWN
47 #define SNAKE_PLAYPAUSE BUTTON_PLAY
49 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
50 #define SNAKE_QUIT BUTTON_OFF
51 #define SNAKE_LEFT BUTTON_LEFT
52 #define SNAKE_RIGHT BUTTON_RIGHT
53 #define SNAKE_UP BUTTON_UP
54 #define SNAKE_DOWN BUTTON_DOWN
55 #define SNAKE_PLAYPAUSE BUTTON_SELECT
57 #elif CONFIG_KEYPAD == ONDIO_PAD
58 #define SNAKE_QUIT BUTTON_OFF
59 #define SNAKE_LEFT BUTTON_LEFT
60 #define SNAKE_RIGHT BUTTON_RIGHT
61 #define SNAKE_UP BUTTON_UP
62 #define SNAKE_DOWN BUTTON_DOWN
63 #define SNAKE_PLAYPAUSE BUTTON_MENU
65 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
66 (CONFIG_KEYPAD == IRIVER_H300_PAD)
67 #define SNAKE_QUIT BUTTON_OFF
68 #define SNAKE_LEFT BUTTON_LEFT
69 #define SNAKE_RIGHT BUTTON_RIGHT
70 #define SNAKE_UP BUTTON_UP
71 #define SNAKE_DOWN BUTTON_DOWN
72 #define SNAKE_PLAYPAUSE BUTTON_ON
74 #define SNAKE_RC_QUIT BUTTON_RC_STOP
76 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
77 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
78 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
79 #define SNAKE_QUIT (BUTTON_SELECT|BUTTON_MENU)
80 #define SNAKE_LEFT BUTTON_LEFT
81 #define SNAKE_RIGHT BUTTON_RIGHT
82 #define SNAKE_UP BUTTON_MENU
83 #define SNAKE_DOWN BUTTON_PLAY
84 #define SNAKE_PLAYPAUSE BUTTON_SELECT
86 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
87 #define SNAKE_QUIT BUTTON_POWER
88 #define SNAKE_LEFT BUTTON_LEFT
89 #define SNAKE_RIGHT BUTTON_RIGHT
90 #define SNAKE_UP BUTTON_UP
91 #define SNAKE_DOWN BUTTON_DOWN
92 #define SNAKE_PLAYPAUSE BUTTON_PLAY
94 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
95 #define SNAKE_QUIT BUTTON_POWER
96 #define SNAKE_LEFT BUTTON_LEFT
97 #define SNAKE_RIGHT BUTTON_RIGHT
98 #define SNAKE_UP BUTTON_UP
99 #define SNAKE_DOWN BUTTON_DOWN
100 #define SNAKE_PLAYPAUSE BUTTON_SELECT
102 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
103 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
104 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
105 (CONFIG_KEYPAD == SANSA_M200_PAD)
106 #define SNAKE_QUIT BUTTON_POWER
107 #define SNAKE_LEFT BUTTON_LEFT
108 #define SNAKE_RIGHT BUTTON_RIGHT
109 #define SNAKE_UP BUTTON_UP
110 #define SNAKE_DOWN BUTTON_DOWN
111 #define SNAKE_PLAYPAUSE BUTTON_SELECT
113 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
114 #define SNAKE_QUIT (BUTTON_HOME|BUTTON_REPEAT)
115 #define SNAKE_LEFT BUTTON_LEFT
116 #define SNAKE_RIGHT BUTTON_RIGHT
117 #define SNAKE_UP BUTTON_UP
118 #define SNAKE_DOWN BUTTON_DOWN
119 #define SNAKE_PLAYPAUSE BUTTON_SELECT
121 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
122 #define SNAKE_QUIT BUTTON_POWER
123 #define SNAKE_LEFT BUTTON_LEFT
124 #define SNAKE_RIGHT BUTTON_RIGHT
125 #define SNAKE_UP BUTTON_SCROLL_UP
126 #define SNAKE_DOWN BUTTON_SCROLL_DOWN
127 #define SNAKE_PLAYPAUSE BUTTON_PLAY
129 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
130 #define SNAKE_QUIT BUTTON_BACK
131 #define SNAKE_LEFT BUTTON_LEFT
132 #define SNAKE_RIGHT BUTTON_RIGHT
133 #define SNAKE_UP BUTTON_UP
134 #define SNAKE_DOWN BUTTON_DOWN
135 #define SNAKE_PLAYPAUSE BUTTON_SELECT
137 #elif (CONFIG_KEYPAD == MROBE100_PAD)
138 #define SNAKE_QUIT BUTTON_POWER
139 #define SNAKE_LEFT BUTTON_LEFT
140 #define SNAKE_RIGHT BUTTON_RIGHT
141 #define SNAKE_UP BUTTON_UP
142 #define SNAKE_DOWN BUTTON_DOWN
143 #define SNAKE_PLAYPAUSE BUTTON_SELECT
145 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
146 #define SNAKE_QUIT BUTTON_RC_REC
147 #define SNAKE_LEFT BUTTON_RC_REW
148 #define SNAKE_RIGHT BUTTON_RC_FF
149 #define SNAKE_UP BUTTON_RC_VOL_UP
150 #define SNAKE_DOWN BUTTON_RC_VOL_DOWN
151 #define SNAKE_PLAYPAUSE BUTTON_RC_PLAY
153 #define SNAKE_RC_QUIT BUTTON_REC
155 #elif (CONFIG_KEYPAD == COWOND2_PAD)
156 #define SNAKE_QUIT BUTTON_POWER
158 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
159 #define SNAKE_QUIT BUTTON_BACK
160 #define SNAKE_LEFT BUTTON_LEFT
161 #define SNAKE_RIGHT BUTTON_RIGHT
162 #define SNAKE_UP BUTTON_UP
163 #define SNAKE_DOWN BUTTON_DOWN
164 #define SNAKE_PLAYPAUSE BUTTON_PLAY
166 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
167 #define SNAKE_QUIT BUTTON_POWER
168 #define SNAKE_LEFT BUTTON_LEFT
169 #define SNAKE_RIGHT BUTTON_RIGHT
170 #define SNAKE_UP BUTTON_UP
171 #define SNAKE_DOWN BUTTON_DOWN
172 #define SNAKE_PLAYPAUSE BUTTON_MENU
174 #elif CONFIG_KEYPAD == MROBE500_PAD
175 #define SNAKE_QUIT BUTTON_POWER
176 #define SNAKE_RC_QUIT BUTTON_RC_DOWN
178 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
179 #define SNAKE_QUIT BUTTON_POWER
182 #error No keymap defined!
185 #ifdef HAVE_TOUCHSCREEN
187 #define SNAKE_QUIT BUTTON_TOPLEFT
190 #define SNAKE_LEFT BUTTON_MIDLEFT
193 #define SNAKE_RIGHT BUTTON_MIDRIGHT
196 #define SNAKE_UP BUTTON_TOPMIDDLE
199 #define SNAKE_DOWN BUTTON_BOTTOMMIDDLE
201 #ifndef SNAKE_PLAYPAUSE
202 #define SNAKE_PLAYPAUSE BUTTON_CENTER
206 #define BOARD_WIDTH (LCD_WIDTH/4)
207 #define BOARD_HEIGHT (LCD_HEIGHT/4)
209 static int board
[BOARD_WIDTH
][BOARD_HEIGHT
],snakelength
;
210 static unsigned int score
,hiscore
=0,level
=1;
211 static int dir
,dead
=0;
217 rb
->lcd_clear_display();
218 rb
->snprintf(pscore
,sizeof(pscore
),"Your score: %d",score
);
219 rb
->lcd_puts(0,0,"Oops...");
220 rb
->lcd_puts(0,1, pscore
);
223 rb
->lcd_puts(0,2,"New High Score!");
226 rb
->snprintf(pscore
,sizeof(pscore
),"High Score: %d",hiscore
);
227 rb
->lcd_puts(0,2,pscore
);
234 void colission (short x
, short y
)
236 switch (board
[x
][y
]) {
248 if (x
==BOARD_WIDTH
|| x
<0 || y
==BOARD_HEIGHT
|| y
<0)
252 void move_head (short x
, short y
)
272 rb
->lcd_fillrect(x
*4,y
*4,4,4);
278 for (x
=0; x
<BOARD_WIDTH
; x
++) {
279 for (y
=0; y
<BOARD_HEIGHT
; y
++) {
280 switch (board
[x
][y
]) {
295 if (board
[x
][y
]==snakelength
) {
297 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
298 rb
->lcd_fillrect(x
*4,y
*4,4,4);
299 rb
->lcd_set_drawmode(DRMODE_SOLID
);
313 rb
->lcd_clear_display();
314 for (x
=0; x
<BOARD_WIDTH
; x
++) {
315 for (y
=0; y
<BOARD_HEIGHT
; y
++) {
316 switch (board
[x
][y
]) {
318 rb
->lcd_fillrect((x
*4)+1,y
*4,2,4);
319 rb
->lcd_fillrect(x
*4,(y
*4)+1,4,2);
324 rb
->lcd_fillrect(x
*4,y
*4,4,4);
332 void game_pause (void) {
334 rb
->lcd_clear_display();
335 rb
->lcd_putsxy(3,12,"Game Paused");
336 #if CONFIG_KEYPAD == RECORDER_PAD
337 rb
->lcd_putsxy(3,22,"[Play] to resume");
338 #elif CONFIG_KEYPAD == ONDIO_PAD
339 rb
->lcd_putsxy(3,22,"[Mode] to resume");
341 rb
->lcd_putsxy(3,32,"[Off] to quit");
344 button
=rb
->button_get(true);
352 case SNAKE_PLAYPAUSE
:
357 if (rb
->default_event_handler(button
)==SYS_USB_CONNECTED
) {
376 x
=rb
->rand() % BOARD_WIDTH
;
377 y
=rb
->rand() % BOARD_HEIGHT
;
378 } while (board
[x
][y
]);
381 rb
->lcd_fillrect((x
*4)+1,y
*4,2,4);
382 rb
->lcd_fillrect(x
*4,(y
*4)+1,4,2);
387 button
=rb
->button_get(false);
389 #ifdef HAS_BUTTON_HOLD
390 if (rb
->button_hold())
391 button
= SNAKE_PLAYPAUSE
;
413 case SNAKE_PLAYPAUSE
:
417 if (rb
->default_event_handler(button
)==SYS_USB_CONNECTED
) {
426 void game_init(void) {
429 bool menu_quit
= false;
431 for (x
=0; x
<BOARD_WIDTH
; x
++) {
432 for (y
=0; y
<BOARD_HEIGHT
; y
++) {
442 MENUITEM_STRINGLIST(menu
,"Snake Menu",NULL
,"Start New Game","Starting Level",
446 switch(rb
->do_menu(&menu
, &selection
, NULL
, false))
449 menu_quit
= true; /* start playing */
453 rb
->set_int("Starting Level", "", UNIT_INT
, &level
, NULL
,
458 dead
=1; /* quit program */
466 enum plugin_status
plugin_start(const void* parameter
)
471 rb
->lcd_clear_display();
473 return (dead
==1)?PLUGIN_OK
:PLUGIN_USB_CONNECTED
;