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
36 static int board
[28][16],snakelength
;
37 static unsigned int score
,hiscore
=0;
38 static short dir
,frames
,apple
,level
=1,dead
=0;
39 static struct plugin_api
* rb
;
43 char pscore
[5],hscore
[17];
44 rb
->lcd_clear_display();
45 rb
->snprintf(pscore
,sizeof(pscore
),"%d",score
);
46 rb
->lcd_putsxy(3,12,"oops...");
47 rb
->lcd_putsxy(3,22,"Your score :");
48 rb
->lcd_putsxy(3,32, pscore
);
51 rb
->lcd_putsxy(3,42,"New High Score!");
54 rb
->snprintf(hscore
,sizeof(hscore
),"High Score: %d",hiscore
);
55 rb
->lcd_putsxy(3,42,hscore
);
62 void colission (short x
, short y
)
64 switch (board
[x
][y
]) {
76 if (x
==28 || x
<0 || y
==16 || y
<0)
80 void move_head (short x
, short y
)
100 rb
->lcd_fillrect(x
*4,y
*4,4,4);
106 for (x
=0; x
<28; x
++) {
107 for (y
=0; y
<16; y
++) {
108 switch (board
[x
][y
]) {
123 if (board
[x
][y
]==snakelength
) {
125 rb
->lcd_clearrect(x
*4,y
*4,4,4);
139 rb
->lcd_clear_display();
140 for (x
=0; x
<28; x
++) {
141 for (y
=0; y
<16; y
++) {
142 switch (board
[x
][y
]) {
144 rb
->lcd_fillrect((x
*4)+1,y
*4,2,4);
145 rb
->lcd_fillrect(x
*4,(y
*4)+1,4,2);
150 rb
->lcd_fillrect(x
*4,y
*4,4,4);
158 void game_pause (void) {
159 rb
->lcd_clear_display();
160 rb
->lcd_putsxy(3,12,"Game Paused");
161 rb
->lcd_putsxy(3,22,"[Play] to resume");
162 rb
->lcd_putsxy(3,32,"[Off] to quit");
165 switch (rb
->button_get(true)) {
191 } while (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);
201 switch (rb
->button_get(false)) {
224 void game_init(void) {
226 char plevel
[10],phscore
[20];
228 for (x
=0; x
<28; x
++) {
229 for (y
=0; y
<16; y
++) {
240 rb
->lcd_clear_display();
241 rb
->lcd_setfont(FONT_SYSFIXED
);
242 rb
->snprintf(plevel
,sizeof(plevel
),"Level - %d",level
);
243 rb
->snprintf(phscore
,sizeof(phscore
),"High Score: %d",hiscore
);
244 rb
->lcd_puts(0,0, plevel
);
245 rb
->lcd_puts(0,1, "(1-slow, 9-fast)");
246 rb
->lcd_puts(0,2, "OFF - quit");
247 rb
->lcd_puts(0,3, "PLAY - start/pause");
248 rb
->lcd_puts(0,4, phscore
);
252 switch (rb
->button_get(true)) {
271 rb
->snprintf(plevel
,sizeof(plevel
),"Level - %d",level
);
272 rb
->lcd_puts(0,0, plevel
);
278 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
280 TEST_PLUGIN_API(api
);
285 rb
->lcd_clear_display();