Fix warning about missing newline at the EOF
[maemo-rb.git] / apps / plugins / star.c
blobcf04e02edc2d9ef5135c0c4a48917f7e3d2f351e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Frederic Dang Ngoc
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 ****************************************************************************/
21 #include "plugin.h"
23 #include "lib/display_text.h"
24 #include "lib/playback_control.h"
28 /* size of a level in file */
29 #define STAR_LEVEL_SIZE ((STAR_WIDTH + 1) * STAR_HEIGHT + 1)
31 /* size of the game board */
32 #define STAR_WIDTH 16
33 #define STAR_HEIGHT 9
35 /* number of level */
36 #define STAR_LEVEL_COUNT 20
38 /* values of object in the board */
39 #define STAR_VOID '.'
40 #define STAR_WALL '*'
41 #define STAR_STAR 'o'
42 #define STAR_BALL 'X'
43 #define STAR_BLOCK 'x'
45 /* sleep time between two frames */
46 #if (LCD_HEIGHT * LCD_WIDTH >= 70000) && defined(IPOD_ARCH)
47 /* iPod 5G LCD is *slow* */
48 #define STAR_SLEEP rb->yield();
49 #elif (LCD_HEIGHT * LCD_WIDTH >= 30000)
50 #define STAR_SLEEP rb->sleep(0);
51 #else
52 #define STAR_SLEEP rb->sleep(1);
53 #endif
55 /* value of ball and block control */
56 #define STAR_CONTROL_BALL 0
57 #define STAR_CONTROL_BLOCK 1
59 /* variable button definitions */
60 #if CONFIG_KEYPAD == RECORDER_PAD
61 #define STAR_QUIT BUTTON_OFF
62 #define STAR_LEFT BUTTON_LEFT
63 #define STAR_RIGHT BUTTON_RIGHT
64 #define STAR_UP BUTTON_UP
65 #define STAR_DOWN BUTTON_DOWN
66 #define STAR_TOGGLE_CONTROL BUTTON_ON
67 #define STAR_TOGGLE_CONTROL2 BUTTON_PLAY
68 #define STAR_LEVEL_UP BUTTON_F3
69 #define STAR_LEVEL_DOWN BUTTON_F1
70 #define STAR_LEVEL_REPEAT BUTTON_F2
71 #define STAR_TOGGLE_CONTROL_NAME "ON"
72 #define STAR_QUIT_NAME "OFF"
73 #define STAR_LEVEL_UP_NAME "F3"
74 #define STAR_LEVEL_DOWN_NAME "F1"
75 #define STAR_LEVEL_REPEAT_NAME "F2"
77 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
78 #define STAR_QUIT BUTTON_OFF
79 #define STAR_LEFT BUTTON_LEFT
80 #define STAR_RIGHT BUTTON_RIGHT
81 #define STAR_UP BUTTON_UP
82 #define STAR_DOWN BUTTON_DOWN
83 #define STAR_TOGGLE_CONTROL BUTTON_ON
84 #define STAR_TOGGLE_CONTROL2 BUTTON_SELECT
85 #define STAR_LEVEL_UP BUTTON_F3
86 #define STAR_LEVEL_DOWN BUTTON_F1
87 #define STAR_LEVEL_REPEAT BUTTON_F2
88 #define STAR_TOGGLE_CONTROL_NAME "ON/SELECT"
89 #define STAR_QUIT_NAME "OFF"
90 #define STAR_LEVEL_UP_NAME "F3"
91 #define STAR_LEVEL_DOWN_NAME "F1"
92 #define STAR_LEVEL_REPEAT_NAME "F2"
94 #elif CONFIG_KEYPAD == ONDIO_PAD
95 #define STAR_QUIT BUTTON_OFF
96 #define STAR_LEFT BUTTON_LEFT
97 #define STAR_RIGHT BUTTON_RIGHT
98 #define STAR_UP BUTTON_UP
99 #define STAR_DOWN BUTTON_DOWN
100 #define STAR_TOGGLE_CONTROL_PRE BUTTON_MENU
101 #define STAR_TOGGLE_CONTROL (BUTTON_MENU | BUTTON_REL)
102 #define STAR_LEVEL_UP (BUTTON_MENU | BUTTON_RIGHT)
103 #define STAR_LEVEL_DOWN (BUTTON_MENU | BUTTON_LEFT)
104 #define STAR_LEVEL_REPEAT (BUTTON_MENU | BUTTON_UP)
105 #define STAR_TOGGLE_CONTROL_NAME "MODE"
106 #define STAR_QUIT_NAME "OFF"
107 #define STAR_LEVEL_UP_NAME "M >"
108 #define STAR_LEVEL_DOWN_NAME "M <"
109 #define STAR_LEVEL_REPEAT_NAME "M ^"
111 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
112 (CONFIG_KEYPAD == IRIVER_H300_PAD)
113 #define STAR_QUIT BUTTON_OFF
114 #define STAR_LEFT BUTTON_LEFT
115 #define STAR_RIGHT BUTTON_RIGHT
116 #define STAR_UP BUTTON_UP
117 #define STAR_DOWN BUTTON_DOWN
118 #define STAR_TOGGLE_CONTROL BUTTON_MODE
119 #define STAR_TOGGLE_CONTROL2 BUTTON_SELECT
120 #define STAR_LEVEL_UP (BUTTON_ON | BUTTON_RIGHT)
121 #define STAR_LEVEL_DOWN (BUTTON_ON | BUTTON_LEFT)
122 #define STAR_LEVEL_REPEAT (BUTTON_ON | BUTTON_SELECT)
123 #define STAR_TOGGLE_CONTROL_NAME "MODE/SELECT"
124 #define STAR_QUIT_NAME "OFF"
125 #define STAR_LEVEL_UP_NAME "ON + RIGHT"
126 #define STAR_LEVEL_DOWN_NAME "ON + LEFT"
127 #define STAR_LEVEL_REPEAT_NAME "ON + NAVI"
129 #define STAR_RC_QUIT BUTTON_RC_STOP
130 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
131 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
132 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
134 #define STAR_QUIT (BUTTON_SELECT | BUTTON_MENU)
135 #define STAR_LEFT BUTTON_LEFT
136 #define STAR_RIGHT BUTTON_RIGHT
137 #define STAR_UP BUTTON_MENU
138 #define STAR_DOWN BUTTON_PLAY
139 #define STAR_TOGGLE_CONTROL_PRE BUTTON_SELECT
140 #define STAR_TOGGLE_CONTROL (BUTTON_SELECT | BUTTON_REL)
141 #define STAR_LEVEL_UP (BUTTON_SELECT | BUTTON_RIGHT)
142 #define STAR_LEVEL_DOWN (BUTTON_SELECT | BUTTON_LEFT)
143 #define STAR_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_PLAY)
144 #define STAR_TOGGLE_CONTROL_NAME "SELECT"
145 #define STAR_QUIT_NAME "S + MENU"
146 #define STAR_LEVEL_UP_NAME "S >"
147 #define STAR_LEVEL_DOWN_NAME "S <"
148 #define STAR_LEVEL_REPEAT_NAME "S + PLAY"
150 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
152 #define STAR_QUIT BUTTON_POWER
153 #define STAR_LEFT BUTTON_LEFT
154 #define STAR_RIGHT BUTTON_RIGHT
155 #define STAR_UP BUTTON_UP
156 #define STAR_DOWN BUTTON_DOWN
157 #define STAR_TOGGLE_CONTROL BUTTON_SELECT
158 #define STAR_LEVEL_UP_PRE BUTTON_REC
159 #define STAR_LEVEL_UP (BUTTON_REC|BUTTON_REL)
160 #define STAR_LEVEL_DOWN_PRE BUTTON_REC
161 #define STAR_LEVEL_DOWN (BUTTON_REC|BUTTON_REPEAT)
162 #define STAR_LEVEL_REPEAT BUTTON_PLAY
163 #define STAR_TOGGLE_CONTROL_NAME "SELECT"
164 #define STAR_QUIT_NAME "POWER"
165 #define STAR_LEVEL_UP_NAME "REC"
166 #define STAR_LEVEL_DOWN_NAME "REC.."
167 #define STAR_LEVEL_REPEAT_NAME "PLAY"
169 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
171 #define STAR_QUIT BUTTON_POWER
172 #define STAR_LEFT BUTTON_LEFT
173 #define STAR_RIGHT BUTTON_RIGHT
174 #define STAR_UP BUTTON_UP
175 #define STAR_DOWN BUTTON_DOWN
176 #define STAR_TOGGLE_CONTROL BUTTON_SELECT
177 #define STAR_LEVEL_UP BUTTON_VOL_UP
178 #define STAR_LEVEL_DOWN BUTTON_VOL_DOWN
179 #define STAR_LEVEL_REPEAT BUTTON_A
180 #define STAR_TOGGLE_CONTROL_NAME "SELECT"
181 #define STAR_QUIT_NAME "POWER"
182 #define STAR_LEVEL_UP_NAME "VOL UP"
183 #define STAR_LEVEL_DOWN_NAME "VOL DOWN"
184 #define STAR_LEVEL_REPEAT_NAME "A"
186 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
187 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
188 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
189 (CONFIG_KEYPAD == SANSA_M200_PAD)
191 #define STAR_QUIT BUTTON_POWER
192 #define STAR_LEFT BUTTON_LEFT
193 #define STAR_RIGHT BUTTON_RIGHT
194 #define STAR_UP BUTTON_UP
195 #define STAR_DOWN BUTTON_DOWN
196 #define STAR_TOGGLE_CONTROL BUTTON_SELECT
197 #define STAR_LEVEL_UP (BUTTON_SELECT | BUTTON_RIGHT)
198 #define STAR_LEVEL_DOWN (BUTTON_SELECT | BUTTON_LEFT)
199 #define STAR_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_DOWN)
200 #define STAR_TOGGLE_CONTROL_NAME "SELECT"
201 #define STAR_QUIT_NAME "POWER"
202 #define STAR_LEVEL_UP_NAME "SELECT + RIGHT"
203 #define STAR_LEVEL_DOWN_NAME "SELECT + LEFT"
204 #define STAR_LEVEL_REPEAT_NAME "SELECT + DOWN"
206 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
208 #define STAR_QUIT (BUTTON_HOME|BUTTON_REPEAT)
209 #define STAR_LEFT BUTTON_LEFT
210 #define STAR_RIGHT BUTTON_RIGHT
211 #define STAR_UP BUTTON_UP
212 #define STAR_DOWN BUTTON_DOWN
213 #define STAR_TOGGLE_CONTROL BUTTON_SELECT
214 #define STAR_LEVEL_UP (BUTTON_SELECT | BUTTON_RIGHT)
215 #define STAR_LEVEL_DOWN (BUTTON_SELECT | BUTTON_LEFT)
216 #define STAR_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_DOWN)
217 #define STAR_TOGGLE_CONTROL_NAME "SELECT"
218 #define STAR_QUIT_NAME "HOME"
219 #define STAR_LEVEL_UP_NAME "SELECT + RIGHT"
220 #define STAR_LEVEL_DOWN_NAME "SELECT + LEFT"
221 #define STAR_LEVEL_REPEAT_NAME "SELECT + DOWN"
223 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
225 #define STAR_QUIT BUTTON_POWER
226 #define STAR_LEFT BUTTON_LEFT
227 #define STAR_RIGHT BUTTON_RIGHT
228 #define STAR_UP BUTTON_SCROLL_UP
229 #define STAR_DOWN BUTTON_SCROLL_DOWN
230 #define STAR_TOGGLE_CONTROL BUTTON_REW
231 #define STAR_LEVEL_UP (BUTTON_PLAY | BUTTON_SCROLL_UP)
232 #define STAR_LEVEL_DOWN (BUTTON_PLAY | BUTTON_SCROLL_DOWN)
233 #define STAR_LEVEL_REPEAT (BUTTON_PLAY | BUTTON_RIGHT)
234 #define STAR_TOGGLE_CONTROL_NAME "REW"
235 #define STAR_QUIT_NAME "POWER"
236 #define STAR_LEVEL_UP_NAME "PLAY+UP"
237 #define STAR_LEVEL_DOWN_NAME "PLAY+DOWN"
238 #define STAR_LEVEL_REPEAT_NAME "PLAY+RIGHT"
240 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
242 #define STAR_QUIT BUTTON_BACK
243 #define STAR_LEFT BUTTON_LEFT
244 #define STAR_RIGHT BUTTON_RIGHT
245 #define STAR_UP BUTTON_UP
246 #define STAR_DOWN BUTTON_DOWN
247 #define STAR_TOGGLE_CONTROL BUTTON_SELECT
248 #define STAR_LEVEL_UP BUTTON_VOL_UP
249 #define STAR_LEVEL_DOWN BUTTON_VOL_DOWN
250 #define STAR_LEVEL_REPEAT BUTTON_MENU
251 #define STAR_TOGGLE_CONTROL_NAME "SELECT"
252 #define STAR_QUIT_NAME "BACK"
253 #define STAR_LEVEL_UP_NAME "VOL UP"
254 #define STAR_LEVEL_DOWN_NAME "VOL DOWN"
255 #define STAR_LEVEL_REPEAT_NAME "MENU"
257 #elif (CONFIG_KEYPAD == MROBE100_PAD)
259 #define STAR_QUIT BUTTON_POWER
260 #define STAR_LEFT BUTTON_LEFT
261 #define STAR_RIGHT BUTTON_RIGHT
262 #define STAR_UP BUTTON_UP
263 #define STAR_DOWN BUTTON_DOWN
264 #define STAR_TOGGLE_CONTROL BUTTON_SELECT
265 #define STAR_LEVEL_UP BUTTON_PLAY
266 #define STAR_LEVEL_DOWN BUTTON_MENU
267 #define STAR_LEVEL_REPEAT BUTTON_DISPLAY
268 #define STAR_TOGGLE_CONTROL_NAME "SELECT"
269 #define STAR_QUIT_NAME "POWER"
270 #define STAR_LEVEL_UP_NAME "PLAY"
271 #define STAR_LEVEL_DOWN_NAME "MENU"
272 #define STAR_LEVEL_REPEAT_NAME "DISPLAY"
274 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
276 #define STAR_QUIT BUTTON_RC_REC
277 #define STAR_LEFT BUTTON_RC_REW
278 #define STAR_RIGHT BUTTON_RC_FF
279 #define STAR_UP BUTTON_RC_VOL_UP
280 #define STAR_DOWN BUTTON_RC_VOL_DOWN
281 #define STAR_TOGGLE_CONTROL BUTTON_RC_MODE
282 #define STAR_LEVEL_UP (BUTTON_RC_PLAY|BUTTON_RC_VOL_UP)
283 #define STAR_LEVEL_DOWN (BUTTON_RC_PLAY|BUTTON_RC_VOL_DOWN)
284 #define STAR_LEVEL_REPEAT (BUTTON_RC_PLAY|BUTTON_RC_MENU)
285 #define STAR_TOGGLE_CONTROL_NAME "MODE"
286 #define STAR_QUIT_NAME "REC"
287 #define STAR_LEVEL_UP_NAME "PLAY+VOL+"
288 #define STAR_LEVEL_DOWN_NAME "PLAY+VOL-"
289 #define STAR_LEVEL_REPEAT_NAME "PLAY+MENU"
291 #elif (CONFIG_KEYPAD == COWON_D2_PAD)
293 #define STAR_QUIT BUTTON_POWER
294 #define STAR_QUIT_NAME "POWER"
296 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
298 #define STAR_QUIT BUTTON_BACK
299 #define STAR_LEFT BUTTON_LEFT
300 #define STAR_RIGHT BUTTON_RIGHT
301 #define STAR_UP BUTTON_UP
302 #define STAR_DOWN BUTTON_DOWN
303 #define STAR_TOGGLE_CONTROL BUTTON_PLAY
304 #define STAR_LEVEL_UP (BUTTON_CUSTOM | BUTTON_UP)
305 #define STAR_LEVEL_DOWN (BUTTON_CUSTOM | BUTTON_DOWN)
306 #define STAR_LEVEL_REPEAT (BUTTON_CUSTOM | BUTTON_RIGHT)
307 #define STAR_TOGGLE_CONTROL_NAME "PLAY"
308 #define STAR_QUIT_NAME "BACK"
309 #define STAR_LEVEL_UP_NAME "CUSTOM+UP"
310 #define STAR_LEVEL_DOWN_NAME "CUSTOM+DOWN"
311 #define STAR_LEVEL_REPEAT_NAME "CUSTOM+RIGHT"
313 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
315 #define STAR_QUIT BUTTON_POWER
316 #define STAR_LEFT BUTTON_LEFT
317 #define STAR_RIGHT BUTTON_RIGHT
318 #define STAR_UP BUTTON_UP
319 #define STAR_DOWN BUTTON_DOWN
320 #define STAR_TOGGLE_CONTROL BUTTON_SELECT
321 #define STAR_LEVEL_UP BUTTON_VOL_UP
322 #define STAR_LEVEL_DOWN BUTTON_VOL_DOWN
323 #define STAR_LEVEL_REPEAT BUTTON_VIEW
324 #define STAR_TOGGLE_CONTROL_NAME "SELECT"
325 #define STAR_QUIT_NAME "POWER"
326 #define STAR_LEVEL_UP_NAME "VOL UP"
327 #define STAR_LEVEL_DOWN_NAME "VOL DOWN"
328 #define STAR_LEVEL_REPEAT_NAME "VIEW"
330 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
332 #define STAR_QUIT BUTTON_POWER
333 #define STAR_LEFT BUTTON_LEFT
334 #define STAR_RIGHT BUTTON_RIGHT
335 #define STAR_UP BUTTON_UP
336 #define STAR_DOWN BUTTON_DOWN
337 #define STAR_TOGGLE_CONTROL BUTTON_PLAY
338 #define STAR_LEVEL_UP BUTTON_VOL_UP
339 #define STAR_LEVEL_DOWN BUTTON_VOL_DOWN
340 #define STAR_LEVEL_REPEAT BUTTON_NEXT
341 #define STAR_TOGGLE_CONTROL_NAME "PLAY"
342 #define STAR_QUIT_NAME "POWER"
343 #define STAR_LEVEL_UP_NAME "VOL +"
344 #define STAR_LEVEL_DOWN_NAME "VOL -"
345 #define STAR_LEVEL_REPEAT_NAME "NEXT"
347 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
349 #define STAR_QUIT BUTTON_POWER
350 #define STAR_LEFT BUTTON_PREV
351 #define STAR_RIGHT BUTTON_NEXT
352 #define STAR_UP BUTTON_UP
353 #define STAR_DOWN BUTTON_DOWN
354 #define STAR_TOGGLE_CONTROL BUTTON_PLAY
355 #define STAR_LEVEL_UP BUTTON_VOL_UP
356 #define STAR_LEVEL_DOWN BUTTON_VOL_DOWN
357 #define STAR_LEVEL_REPEAT BUTTON_RIGHT
358 #define STAR_TOGGLE_CONTROL_NAME "PLAY"
359 #define STAR_QUIT_NAME "POWER"
360 #define STAR_LEVEL_UP_NAME "VOL UP"
361 #define STAR_LEVEL_DOWN_NAME "VOL DOWN"
362 #define STAR_LEVEL_REPEAT_NAME "RIGHT"
364 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
366 #define STAR_QUIT BUTTON_POWER
367 #define STAR_QUIT_NAME "POWER"
369 #elif (CONFIG_KEYPAD == ONDAVX777_PAD)
370 #define STAR_QUIT BUTTON_POWER
371 #define STAR_QUIT_NAME "POWER"
373 #elif CONFIG_KEYPAD == MROBE500_PAD
374 #define STAR_QUIT BUTTON_POWER
375 #define STAR_QUIT_NAME "POWER"
377 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
379 #define STAR_QUIT BUTTON_REC
380 #define STAR_LEFT BUTTON_LEFT
381 #define STAR_RIGHT BUTTON_RIGHT
382 #define STAR_UP BUTTON_UP
383 #define STAR_DOWN BUTTON_DOWN
384 #define STAR_LEVEL_UP_PRE (BUTTON_FFWD|BUTTON_UP)
385 #define STAR_LEVEL_UP (BUTTON_REW|BUTTON_UP)
386 #define STAR_LEVEL_DOWN_PRE (BUTTON_FFWD|BUTTON_DOWN)
387 #define STAR_LEVEL_DOWN (BUTTON_REW|BUTTON_DOWN)
388 #define STAR_TOGGLE_CONTROL (BUTTON_PLAY|BUTTON_UP)
389 #define STAR_LEVEL_REPEAT (BUTTON_PLAY|BUTTON_DOWN)
390 #define STAR_TOGGLE_CONTROL_NAME "PLAY"
391 #define STAR_QUIT_NAME "REC"
392 #define STAR_LEVEL_UP_NAME "UP"
393 #define STAR_LEVEL_DOWN_NAME "DOWN"
394 #define STAR_LEVEL_REPEAT_NAME "PLAY"
396 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
398 #define STAR_QUIT BUTTON_REC
399 #define STAR_LEFT BUTTON_PREV
400 #define STAR_RIGHT BUTTON_NEXT
401 #define STAR_UP BUTTON_UP
402 #define STAR_DOWN BUTTON_DOWN
403 #define STAR_TOGGLE_CONTROL BUTTON_PLAY
404 #define STAR_LEVEL_UP BUTTON_OK
405 #define STAR_LEVEL_DOWN BUTTON_CANCEL
406 #define STAR_LEVEL_REPEAT BUTTON_MENU
407 #define STAR_TOGGLE_CONTROL_NAME "PLAY"
408 #define STAR_QUIT_NAME "REC"
409 #define STAR_LEVEL_UP_NAME "OK"
410 #define STAR_LEVEL_DOWN_NAME "CANCEL"
411 #define STAR_LEVEL_REPEAT_NAME "MENU"
413 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
415 #define STAR_QUIT (BUTTON_REC | BUTTON_PLAY)
416 #define STAR_LEFT BUTTON_VOL_DOWN
417 #define STAR_RIGHT BUTTON_VOL_UP
418 #define STAR_UP BUTTON_REW
419 #define STAR_DOWN BUTTON_FF
420 #define STAR_TOGGLE_CONTROL_PRE BUTTON_FUNC
421 #define STAR_TOGGLE_CONTROL (BUTTON_FUNC | BUTTON_REL)
422 #define STAR_LEVEL_UP BUTTON_PLAY
423 #define STAR_LEVEL_DOWN BUTTON_REC
424 #define STAR_LEVEL_REPEAT (BUTTON_FUNC | BUTTON_REPEAT)
425 #define STAR_TOGGLE_CONTROL_NAME "FUNC"
426 #define STAR_QUIT_NAME "REC + PLAY"
427 #define STAR_LEVEL_UP_NAME "PLAY"
428 #define STAR_LEVEL_DOWN_NAME "REC"
429 #define STAR_LEVEL_REPEAT_NAME "FUNC LONG"
431 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
433 #define STAR_QUIT (BUTTON_REC | BUTTON_REPEAT)
434 #define STAR_LEFT BUTTON_REW
435 #define STAR_RIGHT BUTTON_FF
436 #define STAR_UP BUTTON_UP
437 #define STAR_DOWN BUTTON_DOWN
438 #define STAR_TOGGLE_CONTROL_PRE BUTTON_MENU
439 #define STAR_TOGGLE_CONTROL (BUTTON_MENU | BUTTON_REL)
440 #define STAR_LEVEL_UP BUTTON_PLAY
441 #define STAR_LEVEL_DOWN BUTTON_REC
442 #define STAR_LEVEL_REPEAT (BUTTON_MENU | BUTTON_REPEAT)
443 #define STAR_TOGGLE_CONTROL_NAME "MENU"
444 #define STAR_QUIT_NAME "REC LONG"
445 #define STAR_LEVEL_UP_NAME "PLAY"
446 #define STAR_LEVEL_DOWN_NAME "REC"
447 #define STAR_LEVEL_REPEAT_NAME "MENU LONG"
449 #elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD
451 #define STAR_QUIT BUTTON_POWER
452 #define STAR_LEFT BUTTON_LEFT
453 #define STAR_RIGHT BUTTON_RIGHT
454 #define STAR_UP BUTTON_UP
455 #define STAR_DOWN BUTTON_DOWN
456 #define STAR_TOGGLE_CONTROL BUTTON_SELECT
457 #define STAR_LEVEL_UP BUTTON_VOL_UP
458 #define STAR_LEVEL_DOWN BUTTON_VOL_DOWN
459 #define STAR_LEVEL_REPEAT (BUTTON_BACK | BUTTON_REPEAT)
460 #define STAR_TOGGLE_CONTROL_NAME "SELECT"
461 #define STAR_QUIT_NAME "POWER"
462 #define STAR_LEVEL_UP_NAME "Vol+"
463 #define STAR_LEVEL_DOWN_NAME "Vol-"
464 #define STAR_LEVEL_REPEAT_NAME "BACK LONG"
466 #elif CONFIG_KEYPAD == SANSA_CONNECT_PAD
468 #define STAR_QUIT BUTTON_POWER
469 #define STAR_LEFT BUTTON_LEFT
470 #define STAR_RIGHT BUTTON_RIGHT
471 #define STAR_UP BUTTON_UP
472 #define STAR_DOWN BUTTON_DOWN
473 #define STAR_TOGGLE_CONTROL BUTTON_SELECT
474 #define STAR_LEVEL_UP BUTTON_VOL_UP
475 #define STAR_LEVEL_DOWN BUTTON_VOL_DOWN
476 #define STAR_LEVEL_REPEAT (BUTTON_PREV | BUTTON_REPEAT)
477 #define STAR_TOGGLE_CONTROL_NAME "SELECT"
478 #define STAR_QUIT_NAME "POWER"
479 #define STAR_LEVEL_UP_NAME "Vol+"
480 #define STAR_LEVEL_DOWN_NAME "Vol-"
481 #define STAR_LEVEL_REPEAT_NAME "PREV LONG"
483 #elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
485 #define STAR_QUIT BUTTON_BACK
486 #define STAR_LEFT BUTTON_LEFT
487 #define STAR_RIGHT BUTTON_RIGHT
488 #define STAR_UP BUTTON_UP
489 #define STAR_DOWN BUTTON_DOWN
490 #define STAR_TOGGLE_CONTROL BUTTON_SELECT
491 #define STAR_LEVEL_UP BUTTON_MENU
492 #define STAR_LEVEL_DOWN BUTTON_POWER
493 #define STAR_LEVEL_REPEAT BUTTON_USER
494 #define STAR_TOGGLE_CONTROL_NAME "Select"
495 #define STAR_QUIT_NAME "Back"
496 #define STAR_LEVEL_UP_NAME "Menu"
497 #define STAR_LEVEL_DOWN_NAME "Power"
498 #define STAR_LEVEL_REPEAT_NAME "User"
500 #else
501 #error No keymap defined!
502 #endif
504 #ifdef HAVE_TOUCHSCREEN
505 //#ifndef STAR_QUIT
506 //#define STAR_QUIT BUTTON_TOPLEFT
507 //#define STAR_QUIT_NAME "TOPLEFT"
508 //#endif
509 #ifndef STAR_LEFT
510 #define STAR_LEFT BUTTON_MIDLEFT
511 #endif
512 #ifndef STAR_RIGHT
513 #define STAR_RIGHT BUTTON_MIDRIGHT
514 #endif
515 #ifndef STAR_UP
516 #define STAR_UP BUTTON_TOPMIDDLE
517 #endif
518 #ifndef STAR_DOWN
519 #define STAR_DOWN BUTTON_BOTTOMMIDDLE
520 #endif
521 #ifndef STAR_TOGGLE_CONTROL
522 #define STAR_TOGGLE_CONTROL BUTTON_CENTER
523 #define STAR_TOGGLE_CONTROL_NAME "CENTER"
524 #endif
525 #ifndef STAR_LEVEL_UP
526 #define STAR_LEVEL_UP BUTTON_TOPLEFT
527 #define STAR_LEVEL_UP_NAME "TOPLEFT"
528 #endif
529 #ifndef STAR_LEVEL_DOWN
530 #define STAR_LEVEL_DOWN BUTTON_BOTTOMLEFT
531 #define STAR_LEVEL_DOWN_NAME "BOTTOMLEFT"
532 #endif
533 #ifndef STAR_LEVEL_REPEAT
534 #define STAR_LEVEL_REPEAT BUTTON_BOTTOMRIGHT
535 #define STAR_LEVEL_REPEAT_NAME "BOTTOMRIGHT"
536 #endif
537 #endif
539 /* function returns because of USB? */
540 static bool usb_detected = false;
542 /* position of the ball */
543 static int ball_x, ball_y;
545 /* position of the block */
546 static int block_x, block_y;
548 /* number of stars to get to finish the level */
549 static int star_count;
551 /* the object we control : ball or block */
552 static int control;
554 /* the current board */
555 static char board[STAR_HEIGHT][STAR_WIDTH];
557 #include "pluginbitmaps/star_tiles.h"
559 #define TILE_WIDTH BMPWIDTH_star_tiles
560 #define TILE_HEIGHT (BMPHEIGHT_star_tiles/5)
561 #define STAR_OFFSET_X ((LCD_WIDTH - STAR_WIDTH * TILE_WIDTH) / 2)
562 #define STAR_OFFSET_Y ((LCD_HEIGHT - STAR_HEIGHT * TILE_HEIGHT - MAX(TILE_HEIGHT, 8)) / 2)
564 #define WALL 0
565 #define SPACE 1
566 #define BLOCK 2
567 #define STAR 3
568 #define BALL 4
570 /* char font size */
571 static int char_width = -1;
572 static int char_height = -1;
574 /* this arrays contains a group of levels loaded into memory */
575 static unsigned char* levels =
576 "****************\n"
577 "*X**........o*x*\n"
578 "*..........o.***\n"
579 "*.......**o....*\n"
580 "*...**.o......**\n"
581 "**.o..o.....o..*\n"
582 "*.o......o**.o.*\n"
583 "*.....**o.....o*\n"
584 "****************\n"
585 "\n"
586 ".*..*.*.*...*.**\n"
587 "*...o.........X*\n"
588 "...*o..*o...o...\n"
589 "*.*.o.....o..*.*\n"
590 "......*...o...*.\n"
591 "*....*x*..o....*\n"
592 "...*..*.*...*oo*\n"
593 "*.............*.\n"
594 ".*..*........*..\n"
595 "\n"
596 "****************\n"
597 "*...........o*x*\n"
598 "*...**......**X*\n"
599 "*...*o.........*\n"
600 "*.o.....o**...o*\n"
601 "*.*o..o..o*..o**\n"
602 "*.**o.*o..o.o***\n"
603 "*o....**o......*\n"
604 "****************\n"
605 "\n"
606 "****************\n"
607 "*............*x*\n"
608 "*.....*........*\n"
609 "**o*o.o*o*o*o*o*\n"
610 "*.*.*o.o*.*.*.**\n"
611 "**o*o*o.o*o*o*o*\n"
612 "*.....*........*\n"
613 "*...*.......*X.*\n"
614 "****************\n"
615 "\n"
616 ".**************.\n"
617 "*X..*...*..*...*\n"
618 "*..*o.*.o..o.*.*\n"
619 "**......*..*...*\n"
620 "*o.*o*........**\n"
621 "**.....*.o.*...*\n"
622 "*o*..*.*.*...*x*\n"
623 "*...*....o*..*o*\n"
624 ".**************.\n"
625 "\n"
626 "....************\n"
627 "...*...o...*o.o*\n"
628 "..*....o....*.**\n"
629 ".*.....o.......*\n"
630 "*X.....o.......*\n"
631 "**.....o..*...**\n"
632 "*......o....*..*\n"
633 "*x.*...o..**o..*\n"
634 "****************\n"
635 "\n"
636 "****************\n"
637 "*..............*\n"
638 ".**.***..*o.**o*\n"
639 ".*o..*o.*.*.*.*.\n"
640 "..*..*..***.**..\n"
641 ".**..*..*o*.*o**\n"
642 "*..............*\n"
643 "*..X*o....x..*o*\n"
644 "****************\n"
645 "\n"
646 "***************.\n"
647 "*..o**.........*\n"
648 "*..*o..**.o....*\n"
649 "*..o**.*.*o....*\n"
650 "**.....**..*o*.*\n"
651 "**.*.......o*o.*\n"
652 "*oxo*...o..*X*.*\n"
653 "**.............*\n"
654 ".***************\n"
655 "\n"
656 "..*.***********.\n"
657 ".*o*o......*..X*\n"
658 "*o.o*....o....*.\n"
659 ".*.*..o**..o*..*\n"
660 "*..*o.*oxo....o*\n"
661 "*.....o**.....*.\n"
662 "*o*o.........*..\n"
663 "*...........*...\n"
664 ".***********....\n"
665 "\n"
666 "....***********.\n"
667 "*****.o........*\n"
668 "*...x.***o.o*.o*\n"
669 "*.o...*o.*o...*.\n"
670 "*.....*..o..*.o*\n"
671 "*o*o..*.o*..*X*.\n"
672 ".*o...***..***..\n"
673 "*.........*.*.*.\n"
674 ".*********..*..*\n"
675 "\n"
676 "****************\n"
677 "*......*......X*\n"
678 "*..*oo.....oo.**\n"
679 "**...o...**...o*\n"
680 "*o....*o*oo..***\n"
681 "**.**....**....*\n"
682 "*o..o*.o....x.o*\n"
683 "**o***....*...**\n"
684 "***************.\n"
685 "\n"
686 "**.....**..****.\n"
687 "*X*****o.***.o**\n"
688 "*....oo.....o..*\n"
689 "*.**..**o..*o*.*\n"
690 "*.*.o.*.*o.**..*\n"
691 "*.**..**...*x*.*\n"
692 "*.....o........*\n"
693 "*........o.....*\n"
694 "****************\n"
695 "\n"
696 ".**************.\n"
697 "*.X*........o.**\n"
698 "*.*...*o...o**.*\n"
699 "*.......o....*.*\n"
700 "*.o..........*o*\n"
701 "*.*......o.....*\n"
702 "**......o.o..*o*\n"
703 "*x..*....o.*.*.*\n"
704 ".**************.\n"
705 "\n"
706 "****************\n"
707 "*o*o........o*o*\n"
708 "*.o*X......**..*\n"
709 "*.x........o...*\n"
710 "*........o*....*\n"
711 "*......o.......*\n"
712 "*.o*........*..*\n"
713 "*o*o........o*o*\n"
714 "****************\n"
715 "\n"
716 ".******.********\n"
717 "*.....o*.....o.*\n"
718 "*.*.o.*..*...o.*\n"
719 "*..X*...*oo.*o.*\n"
720 ".*.*...*.o..x*.*\n"
721 "*o.......*..*o.*\n"
722 ".*......o.....*.\n"
723 "*o............o*\n"
724 "****************\n"
725 "\n"
726 "****************\n"
727 "**.x*o.o......o*\n"
728 "*o.Xo*o.......**\n"
729 "**.***........**\n"
730 "**.....o*o*....*\n"
731 "*oo.......o*o..*\n"
732 "**.o....****o..*\n"
733 "**o*..*........*\n"
734 "****************\n"
735 "\n"
736 "****************\n"
737 "*.o*........*X.*\n"
738 "*.*..o*oo*o..*.*\n"
739 "*....*o**o*.o..*\n"
740 "*.o*.......o*..*\n"
741 "*..o*o....o*...*\n"
742 "*.*..*.**o*..*.*\n"
743 "*....o.*o...x..*\n"
744 "****************\n"
745 "\n"
746 "****************\n"
747 "*.o....o..x*...*\n"
748 "*..*o*o...*o...*\n"
749 "*...*o*....*o..*\n"
750 "*...o..*...o*o.*\n"
751 "*.*o*...*.o*...*\n"
752 "*.o*o.*.o.*....*\n"
753 "*o*X..*.....*..*\n"
754 "****************\n"
755 "\n"
756 "****************\n"
757 "*o...**.....**o*\n"
758 "*.*..*......*o.*\n"
759 "*.o*...o**..o..*\n"
760 "*.*....*o......*\n"
761 "*....*...o*....*\n"
762 "*.**.o*.**o..*x*\n"
763 "*.o*.*o.....**X*\n"
764 "****************\n"
765 "\n"
766 "****************\n"
767 "*...o*o........*\n"
768 "**o..o*.**o...**\n"
769 "*.*.*.o...*..*.*\n"
770 "*.x.*..**..*.Xo*\n"
771 "*.*..*...o.*.*.*\n"
772 "**...o**.*o..o**\n"
773 "*........o*o...*\n"
774 "****************";
777 * Do a pretty transition from one level to another.
779 static void star_transition_update(void)
781 const int center_x = LCD_WIDTH / 2;
782 const int center_y = LCD_HEIGHT / 2;
783 int x = 0;
784 int y = 0;
785 #if LCD_WIDTH >= LCD_HEIGHT
786 #if defined(IPOD_VIDEO)
787 const int step = 4;
788 #else
789 const int step = 1;
790 #endif
791 const int lcd_demi_width = LCD_WIDTH / 2;
792 int var_y = 0;
794 for (; x < lcd_demi_width ; x+=step)
796 var_y += LCD_HEIGHT;
797 if (var_y > LCD_WIDTH)
799 var_y -= LCD_WIDTH;
800 y+=step;
802 if( x )
804 rb->lcd_update_rect(center_x - x, center_y - y, x*2, step);
805 rb->lcd_update_rect(center_x - x, center_y + y - step, x*2, step);
807 if( y )
809 rb->lcd_update_rect(center_x - x, center_y - y, step, y*2);
810 rb->lcd_update_rect(center_x + x - step, center_y - y, step, y*2);
812 STAR_SLEEP
814 #else
815 int lcd_demi_height = LCD_HEIGHT / 2;
816 int var_x = 0;
818 for (; y < lcd_demi_height ; y++)
820 var_x += LCD_WIDTH;
821 if (var_x > LCD_HEIGHT)
823 var_x -= LCD_HEIGHT;
824 x++;
826 if( x )
828 rb->lcd_update_rect(center_x - x, center_y - y, x * 2, 1);
829 rb->lcd_update_rect(center_x - x, center_y + y - 1, x * 2, 1);
831 if( y )
833 rb->lcd_update_rect(center_x - x, center_y - y, 1, y * 2);
834 rb->lcd_update_rect(center_x + x - 1, center_y - y, 1, y * 2);
836 STAR_SLEEP
838 #endif
839 rb->lcd_update();
843 * Display information board of the current level.
845 static void star_display_board_info(int current_level)
847 int label_pos_y, tile_pos_y;
849 if (TILE_HEIGHT > char_height)
851 tile_pos_y = LCD_HEIGHT - TILE_HEIGHT;
852 label_pos_y = tile_pos_y + (TILE_HEIGHT - char_height) / 2;
854 else
856 label_pos_y = LCD_HEIGHT - char_height;
857 tile_pos_y = label_pos_y + (char_height - TILE_HEIGHT) / 2;
860 rb->lcd_putsxyf(STAR_OFFSET_X, label_pos_y, "L:%02d", current_level + 1);
861 rb->lcd_putsxyf(LCD_WIDTH/2 - 2 * char_width, label_pos_y, "S:%02d",
862 star_count);
863 rb->lcd_putsxy(STAR_OFFSET_X + (STAR_WIDTH-1) * TILE_WIDTH - 2 * char_width,
864 label_pos_y, "C:");
866 rb->lcd_bitmap_part(star_tiles, 0, control == STAR_CONTROL_BALL ?
867 BALL*TILE_HEIGHT : BLOCK*TILE_HEIGHT,
868 STRIDE( SCREEN_MAIN,
869 BMPWIDTH_star_tiles, BMPHEIGHT_star_tiles),
870 STAR_OFFSET_X + (STAR_WIDTH-1) * TILE_WIDTH,
871 tile_pos_y, TILE_WIDTH, TILE_HEIGHT);
873 rb->lcd_update_rect(0, MIN(label_pos_y, tile_pos_y), LCD_WIDTH,
874 MAX(TILE_HEIGHT, char_height));
879 * Load a level into board array.
881 static int star_load_level(int current_level)
883 int x, y;
884 char *ptr_tab;
886 if (current_level < 0)
887 current_level = 0;
888 else if (current_level > STAR_LEVEL_COUNT-1)
889 current_level = STAR_LEVEL_COUNT-1;
892 ptr_tab = levels + current_level * STAR_LEVEL_SIZE;
893 control = STAR_CONTROL_BALL;
894 star_count = 0;
896 rb->lcd_clear_display();
898 for (y = 0 ; y < STAR_HEIGHT ; y++)
900 for (x = 0 ; x < STAR_WIDTH ; x++)
902 board[y][x] = *ptr_tab;
903 switch (*ptr_tab)
905 # define DRAW_TILE( a ) \
906 rb->lcd_bitmap_part( star_tiles, 0, \
907 a*TILE_HEIGHT, \
908 STRIDE( SCREEN_MAIN, \
909 BMPWIDTH_star_tiles, \
910 BMPHEIGHT_star_tiles), \
911 STAR_OFFSET_X + x * TILE_WIDTH, \
912 STAR_OFFSET_Y + y * TILE_HEIGHT, \
913 TILE_WIDTH, TILE_HEIGHT);
915 case STAR_VOID:
916 DRAW_TILE( SPACE );
917 break;
919 case STAR_WALL:
920 DRAW_TILE( WALL );
921 break;
923 case STAR_STAR:
924 DRAW_TILE( STAR );
925 star_count++;
926 break;
928 case STAR_BALL:
929 ball_x = x;
930 ball_y = y;
931 DRAW_TILE( BALL );
932 break;
935 case STAR_BLOCK:
936 block_x = x;
937 block_y = y;
938 DRAW_TILE( BLOCK );
939 break;
941 ptr_tab++;
943 ptr_tab++;
945 star_display_board_info(current_level);
946 star_transition_update();
947 return 1;
950 static void star_animate_tile(int tile_no, int start_x, int start_y,
951 int delta_x, int delta_y)
953 int i;
955 if (delta_x != 0) /* horizontal */
957 for (i = 1 ; i <= TILE_WIDTH ; i++)
959 STAR_SLEEP
960 rb->lcd_bitmap_part(star_tiles, 0, SPACE * TILE_HEIGHT,
961 STRIDE( SCREEN_MAIN,
962 BMPWIDTH_star_tiles, BMPHEIGHT_star_tiles),
963 start_x, start_y, TILE_WIDTH, TILE_HEIGHT);
964 rb->lcd_bitmap_part(star_tiles, 0, tile_no * TILE_HEIGHT,
965 STRIDE( SCREEN_MAIN,
966 BMPWIDTH_star_tiles, BMPHEIGHT_star_tiles),
967 start_x + delta_x * i, start_y, TILE_WIDTH, TILE_HEIGHT);
968 rb->lcd_update_rect(start_x + delta_x * i - (delta_x>0?1:0),
969 start_y, TILE_WIDTH + 1, TILE_HEIGHT);
972 else /* vertical */
974 for (i = 1 ; i <= TILE_HEIGHT ; i++)
976 STAR_SLEEP
977 rb->lcd_bitmap_part(star_tiles, 0, SPACE * TILE_HEIGHT,
978 STRIDE( SCREEN_MAIN,
979 BMPWIDTH_star_tiles, BMPHEIGHT_star_tiles),
980 start_x, start_y, TILE_WIDTH, TILE_HEIGHT);
981 rb->lcd_bitmap_part(star_tiles, 0, tile_no * TILE_HEIGHT,
982 STRIDE( SCREEN_MAIN,
983 BMPWIDTH_star_tiles, BMPHEIGHT_star_tiles),
984 start_x, start_y + delta_y * i, TILE_WIDTH, TILE_HEIGHT);
985 rb->lcd_update_rect(start_x, start_y + delta_y * i - (delta_y>0?1:0),
986 TILE_WIDTH, TILE_HEIGHT + 1);
992 * Run the game.
994 static int star_run_game(int current_level)
996 int move_x = 0;
997 int move_y = 0;
998 int key;
999 #if defined(STAR_LEVEL_DOWN_PRE) || \
1000 defined(STAR_LEVEL_UP_PRE) || \
1001 defined(STAR_TOGGLE_CONTROL_PRE)
1002 int lastkey = BUTTON_NONE;
1003 #endif
1005 if (!star_load_level(current_level))
1006 return 0;
1008 while (true)
1010 move_x = 0;
1011 move_y = 0;
1013 while ((move_x == 0) && (move_y == 0))
1015 key = rb->button_get(true);
1016 switch (key)
1018 #ifdef STAR_RC_QUIT
1019 case STAR_RC_QUIT:
1020 #endif
1021 case STAR_QUIT:
1022 return -1;
1024 case STAR_LEFT:
1025 move_x = -1;
1026 break;
1028 case STAR_RIGHT:
1029 move_x = 1;
1030 break;
1032 case STAR_UP:
1033 move_y = -1;
1034 break;
1036 case STAR_DOWN:
1037 move_y = 1;
1038 break;
1040 case STAR_LEVEL_DOWN:
1041 #ifdef STAR_LEVEL_DOWN_PRE
1042 if (lastkey != STAR_LEVEL_DOWN_PRE)
1043 break;
1044 #endif
1045 if (current_level > 0)
1047 current_level--;
1048 star_load_level(current_level);
1050 break;
1052 case STAR_LEVEL_REPEAT:
1053 star_load_level(current_level);
1054 break;
1056 case STAR_LEVEL_UP:
1057 #ifdef STAR_LEVEL_UP_PRE
1058 if (lastkey != STAR_LEVEL_UP_PRE)
1059 break;
1060 #endif
1061 if (current_level < STAR_LEVEL_COUNT - 1)
1063 current_level++;
1064 star_load_level(current_level);
1066 break;
1068 case STAR_TOGGLE_CONTROL:
1069 #ifdef STAR_TOGGLE_CONTROL_PRE
1070 if (lastkey != STAR_TOGGLE_CONTROL_PRE)
1071 break;
1072 #endif
1073 #ifdef STAR_TOGGLE_CONTROL2
1074 case STAR_TOGGLE_CONTROL2:
1075 #endif
1076 if (control == STAR_CONTROL_BALL)
1077 control = STAR_CONTROL_BLOCK;
1078 else
1079 control = STAR_CONTROL_BALL;
1080 star_display_board_info(current_level);
1081 break;
1083 default:
1084 if (rb->default_event_handler(key) == SYS_USB_CONNECTED)
1086 usb_detected = true;
1087 return 0;
1089 break;
1091 #if defined(STAR_LEVEL_DOWN_PRE) || \
1092 defined(STAR_LEVEL_UP_PRE) || \
1093 defined(STAR_TOGGLE_CONTROL_PRE)
1094 if (key != BUTTON_NONE)
1095 lastkey = key;
1096 #endif
1099 if (control == STAR_CONTROL_BALL)
1101 board[ball_y][ball_x] = STAR_VOID;
1102 while ((board[ball_y + move_y][ball_x + move_x] == STAR_VOID
1103 || board[ball_y + move_y][ball_x + move_x] == STAR_STAR))
1106 star_animate_tile(BALL, STAR_OFFSET_X + ball_x * TILE_WIDTH,
1107 STAR_OFFSET_Y + ball_y * TILE_HEIGHT,
1108 move_x, move_y);
1109 ball_x += move_x;
1110 ball_y += move_y;
1112 if (board[ball_y][ball_x] == STAR_STAR)
1114 board[ball_y][ball_x] = STAR_VOID;
1115 star_count--;
1117 star_display_board_info(current_level);
1120 board[ball_y][ball_x] = STAR_BALL;
1122 else
1124 board[block_y][block_x] = STAR_VOID;
1125 while (board[block_y + move_y][block_x + move_x] == STAR_VOID)
1127 star_animate_tile(BLOCK, STAR_OFFSET_X + block_x * TILE_WIDTH,
1128 STAR_OFFSET_Y + block_y * TILE_HEIGHT,
1129 move_x, move_y);
1130 block_x += move_x;
1131 block_y += move_y;
1133 board[block_y][block_x] = STAR_BLOCK;
1136 if (star_count == 0)
1138 current_level++;
1139 if (current_level == STAR_LEVEL_COUNT)
1141 rb->lcd_clear_display();
1142 rb->splash(HZ*2, "Congratulations!");
1143 rb->lcd_update();
1145 /* There is no such level as STAR_LEVEL_COUNT so it can't be the
1146 * current_level */
1147 current_level--;
1148 return 1;
1150 star_load_level(current_level);
1156 * Display help text.
1158 static bool star_help(void)
1160 static char* help_text[] = {
1161 "Star", "", "Aim", "",
1162 "Take", "all", "the", "stars", "to", "go", "to", "the", "next", "level.",
1163 "You", "can", "toggle", "control", "with", "the", "block", "to", "use",
1164 "it", "as", "a", "mobile", "wall.", "The", "block", "cannot", "take",
1165 "stars.", "", "",
1166 "Controls", "",
1167 STAR_TOGGLE_CONTROL_NAME":", "Toggle", "control", "",
1168 STAR_QUIT_NAME":", "Exit", "",
1169 STAR_LEVEL_DOWN_NAME":", "Prev.", "level", "",
1170 STAR_LEVEL_REPEAT_NAME":", "Reset", "level", "",
1171 STAR_LEVEL_UP_NAME":", "Next", "level"
1173 static struct style_text formation[]={
1174 { 0, TEXT_CENTER|TEXT_UNDERLINE },
1175 { 2, C_RED },
1176 { 35, C_RED },
1177 LAST_STYLE_ITEM
1179 #if LCD_DEPTH > 1 && !defined(HAVE_LCD_COLOR)
1180 rb->lcd_set_background(LCD_WHITE);
1181 rb->lcd_set_foreground(LCD_BLACK);
1182 #endif
1183 if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
1184 return true;
1185 #if LCD_DEPTH > 1 && !defined(HAVE_LCD_COLOR)
1186 rb->lcd_set_background(LCD_BLACK);
1187 rb->lcd_set_foreground(LCD_WHITE);
1188 #endif
1189 return false;
1193 * Display the choice menu.
1195 static int star_menu(void)
1197 int selection, level=1;
1198 bool menu_quit = false;
1200 MENUITEM_STRINGLIST(menu, "Star Menu", NULL,
1201 "Start Game","Choose Level",
1202 "Help", "Playback Control", "Quit");
1204 while(!menu_quit)
1206 switch(rb->do_menu(&menu, &selection, NULL, false))
1208 case 0:
1209 /* use system font and get the size of char */
1210 rb->lcd_setfont(FONT_SYSFIXED);
1211 rb->lcd_getstringsize("a", &char_width, &char_height);
1212 star_run_game(level-1);
1213 rb->lcd_setfont(FONT_UI);
1214 break;
1215 case 1:
1216 rb->set_int("Level", "", UNIT_INT, &level,
1217 NULL, 1, 1, STAR_LEVEL_COUNT, NULL );
1218 break;
1219 case 2:
1220 if(star_help())
1221 usb_detected = true;
1222 break;
1223 case 3:
1224 playback_control(NULL);
1225 break;
1226 case 4:
1227 menu_quit = true;
1228 break;
1230 if(usb_detected)
1231 return PLUGIN_USB_CONNECTED;
1234 return PLUGIN_OK;
1238 * Main entry point
1240 enum plugin_status plugin_start(const void* parameter)
1242 (void)parameter;
1244 #if LCD_DEPTH > 1
1245 rb->lcd_set_backdrop(NULL);
1246 rb->lcd_set_background( LCD_BLACK );
1247 rb->lcd_set_foreground( LCD_WHITE );
1248 #endif
1250 /* display choice menu */
1251 return star_menu();