Onle one table row per WPS tag
[maemo-rb.git] / apps / plugins / star.c
blobd11e3187db89ceb7b97c0c8192c5a596c10d00d3
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"
22 #ifdef HAVE_LCD_BITMAP
23 #include "lib/display_text.h"
24 #include "lib/playback_control.h"
26 PLUGIN_HEADER
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_SA9200_PAD
332 #define STAR_QUIT BUTTON_POWER
333 #define STAR_LEFT BUTTON_PREV
334 #define STAR_RIGHT BUTTON_NEXT
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_RIGHT
341 #define STAR_TOGGLE_CONTROL_NAME "PLAY"
342 #define STAR_QUIT_NAME "POWER"
343 #define STAR_LEVEL_UP_NAME "VOL UP"
344 #define STAR_LEVEL_DOWN_NAME "VOL DOWN"
345 #define STAR_LEVEL_REPEAT_NAME "RIGHT"
347 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
349 #define STAR_QUIT BUTTON_POWER
350 #define STAR_QUIT_NAME "POWER"
352 #elif (CONFIG_KEYPAD == ONDAVX777_PAD)
353 #define STAR_QUIT BUTTON_POWER
354 #define STAR_QUIT_NAME "POWER"
356 #elif CONFIG_KEYPAD == MROBE500_PAD
357 #define STAR_QUIT BUTTON_POWER
358 #define STAR_QUIT_NAME "POWER"
360 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
362 #define STAR_QUIT BUTTON_REC
363 #define STAR_LEFT BUTTON_LEFT
364 #define STAR_RIGHT BUTTON_RIGHT
365 #define STAR_UP BUTTON_UP
366 #define STAR_DOWN BUTTON_DOWN
367 #define STAR_LEVEL_UP_PRE (BUTTON_FFWD|BUTTON_UP)
368 #define STAR_LEVEL_UP (BUTTON_REW|BUTTON_UP)
369 #define STAR_LEVEL_DOWN_PRE (BUTTON_FFWD|BUTTON_DOWN)
370 #define STAR_LEVEL_DOWN (BUTTON_REW|BUTTON_DOWN)
371 #define STAR_TOGGLE_CONTROL (BUTTON_PLAY|BUTTON_UP)
372 #define STAR_LEVEL_REPEAT (BUTTON_PLAY|BUTTON_DOWN)
373 #define STAR_TOGGLE_CONTROL_NAME "PLAY"
374 #define STAR_QUIT_NAME "REC"
375 #define STAR_LEVEL_UP_NAME "UP"
376 #define STAR_LEVEL_DOWN_NAME "DOWN"
377 #define STAR_LEVEL_REPEAT_NAME "PLAY"
379 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
381 #define STAR_QUIT BUTTON_REC
382 #define STAR_LEFT BUTTON_PREV
383 #define STAR_RIGHT BUTTON_NEXT
384 #define STAR_UP BUTTON_UP
385 #define STAR_DOWN BUTTON_DOWN
386 #define STAR_TOGGLE_CONTROL BUTTON_PLAY
387 #define STAR_LEVEL_UP BUTTON_OK
388 #define STAR_LEVEL_DOWN BUTTON_CANCEL
389 #define STAR_LEVEL_REPEAT BUTTON_MENU
390 #define STAR_TOGGLE_CONTROL_NAME "PLAY"
391 #define STAR_QUIT_NAME "REC"
392 #define STAR_LEVEL_UP_NAME "OK"
393 #define STAR_LEVEL_DOWN_NAME "CANCEL"
394 #define STAR_LEVEL_REPEAT_NAME "MENU"
396 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
398 #define STAR_QUIT (BUTTON_REC | BUTTON_PLAY)
399 #define STAR_LEFT BUTTON_VOL_DOWN
400 #define STAR_RIGHT BUTTON_VOL_UP
401 #define STAR_UP BUTTON_PREV
402 #define STAR_DOWN BUTTON_NEXT
403 #define STAR_TOGGLE_CONTROL_PRE BUTTON_SELECT
404 #define STAR_TOGGLE_CONTROL (BUTTON_SELECT | BUTTON_REL)
405 #define STAR_LEVEL_UP BUTTON_PLAY
406 #define STAR_LEVEL_DOWN BUTTON_REC
407 #define STAR_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_REPEAT)
408 #define STAR_TOGGLE_CONTROL_NAME "SELECT"
409 #define STAR_QUIT_NAME "REC + PLAY"
410 #define STAR_LEVEL_UP_NAME "PLAY"
411 #define STAR_LEVEL_DOWN_NAME "REC"
412 #define STAR_LEVEL_REPEAT_NAME "SELECT LONG"
414 #else
415 #error No keymap defined!
416 #endif
418 #ifdef HAVE_TOUCHSCREEN
419 //#ifndef STAR_QUIT
420 //#define STAR_QUIT BUTTON_TOPLEFT
421 //#define STAR_QUIT_NAME "TOPLEFT"
422 //#endif
423 #ifndef STAR_LEFT
424 #define STAR_LEFT BUTTON_MIDLEFT
425 #endif
426 #ifndef STAR_RIGHT
427 #define STAR_RIGHT BUTTON_MIDRIGHT
428 #endif
429 #ifndef STAR_UP
430 #define STAR_UP BUTTON_TOPMIDDLE
431 #endif
432 #ifndef STAR_DOWN
433 #define STAR_DOWN BUTTON_BOTTOMMIDDLE
434 #endif
435 #ifndef STAR_TOGGLE_CONTROL
436 #define STAR_TOGGLE_CONTROL BUTTON_CENTER
437 #define STAR_TOGGLE_CONTROL_NAME "CENTER"
438 #endif
439 #ifndef STAR_LEVEL_UP
440 #define STAR_LEVEL_UP BUTTON_TOPLEFT
441 #define STAR_LEVEL_UP_NAME "TOPLEFT"
442 #endif
443 #ifndef STAR_LEVEL_DOWN
444 #define STAR_LEVEL_DOWN BUTTON_BOTTOMLEFT
445 #define STAR_LEVEL_DOWN_NAME "BOTTOMLEFT"
446 #endif
447 #ifndef STAR_LEVEL_REPEAT
448 #define STAR_LEVEL_REPEAT BUTTON_BOTTOMRIGHT
449 #define STAR_LEVEL_REPEAT_NAME "BOTTOMRIGHT"
450 #endif
451 #endif
453 /* function returns because of USB? */
454 static bool usb_detected = false;
456 /* position of the ball */
457 static int ball_x, ball_y;
459 /* position of the block */
460 static int block_x, block_y;
462 /* number of stars to get to finish the level */
463 static int star_count;
465 /* the object we control : ball or block */
466 static int control;
468 /* the current board */
469 static char board[STAR_HEIGHT][STAR_WIDTH];
471 #include "pluginbitmaps/star_tiles.h"
473 #define TILE_WIDTH BMPWIDTH_star_tiles
474 #define TILE_HEIGHT (BMPHEIGHT_star_tiles/5)
475 #define STAR_OFFSET_X ((LCD_WIDTH - STAR_WIDTH * TILE_WIDTH) / 2)
476 #define STAR_OFFSET_Y ((LCD_HEIGHT - STAR_HEIGHT * TILE_HEIGHT - MAX(TILE_HEIGHT, 8)) / 2)
478 #define WALL 0
479 #define SPACE 1
480 #define BLOCK 2
481 #define STAR 3
482 #define BALL 4
484 /* char font size */
485 static int char_width = -1;
486 static int char_height = -1;
488 /* this arrays contains a group of levels loaded into memory */
489 static unsigned char* levels =
490 "****************\n"
491 "*X**........o*x*\n"
492 "*..........o.***\n"
493 "*.......**o....*\n"
494 "*...**.o......**\n"
495 "**.o..o.....o..*\n"
496 "*.o......o**.o.*\n"
497 "*.....**o.....o*\n"
498 "****************\n"
499 "\n"
500 ".*..*.*.*...*.**\n"
501 "*...o.........X*\n"
502 "...*o..*o...o...\n"
503 "*.*.o.....o..*.*\n"
504 "......*...o...*.\n"
505 "*....*x*..o....*\n"
506 "...*..*.*...*oo*\n"
507 "*.............*.\n"
508 ".*..*........*..\n"
509 "\n"
510 "****************\n"
511 "*...........o*x*\n"
512 "*...**......**X*\n"
513 "*...*o.........*\n"
514 "*.o.....o**...o*\n"
515 "*.*o..o..o*..o**\n"
516 "*.**o.*o..o.o***\n"
517 "*o....**o......*\n"
518 "****************\n"
519 "\n"
520 "****************\n"
521 "*............*x*\n"
522 "*.....*........*\n"
523 "**o*o.o*o*o*o*o*\n"
524 "*.*.*o.o*.*.*.**\n"
525 "**o*o*o.o*o*o*o*\n"
526 "*.....*........*\n"
527 "*...*.......*X.*\n"
528 "****************\n"
529 "\n"
530 ".**************.\n"
531 "*X..*...*..*...*\n"
532 "*..*o.*.o..o.*.*\n"
533 "**......*..*...*\n"
534 "*o.*o*........**\n"
535 "**.....*.o.*...*\n"
536 "*o*..*.*.*...*x*\n"
537 "*...*....o*..*o*\n"
538 ".**************.\n"
539 "\n"
540 "....************\n"
541 "...*...o...*o.o*\n"
542 "..*....o....*.**\n"
543 ".*.....o.......*\n"
544 "*X.....o.......*\n"
545 "**.....o..*...**\n"
546 "*......o....*..*\n"
547 "*x.*...o..**o..*\n"
548 "****************\n"
549 "\n"
550 "****************\n"
551 "*..............*\n"
552 ".**.***..*o.**o*\n"
553 ".*o..*o.*.*.*.*.\n"
554 "..*..*..***.**..\n"
555 ".**..*..*o*.*o**\n"
556 "*..............*\n"
557 "*..X*o....x..*o*\n"
558 "****************\n"
559 "\n"
560 "***************.\n"
561 "*..o**.........*\n"
562 "*..*o..**.o....*\n"
563 "*..o**.*.*o....*\n"
564 "**.....**..*o*.*\n"
565 "**.*.......o*o.*\n"
566 "*oxo*...o..*X*.*\n"
567 "**.............*\n"
568 ".***************\n"
569 "\n"
570 "..*.***********.\n"
571 ".*o*o......*..X*\n"
572 "*o.o*....o....*.\n"
573 ".*.*..o**..o*..*\n"
574 "*..*o.*oxo....o*\n"
575 "*.....o**.....*.\n"
576 "*o*o.........*..\n"
577 "*...........*...\n"
578 ".***********....\n"
579 "\n"
580 "....***********.\n"
581 "*****.o........*\n"
582 "*...x.***o.o*.o*\n"
583 "*.o...*o.*o...*.\n"
584 "*.....*..o..*.o*\n"
585 "*o*o..*.o*..*X*.\n"
586 ".*o...***..***..\n"
587 "*.........*.*.*.\n"
588 ".*********..*..*\n"
589 "\n"
590 "****************\n"
591 "*......*......X*\n"
592 "*..*oo.....oo.**\n"
593 "**...o...**...o*\n"
594 "*o....*o*oo..***\n"
595 "**.**....**....*\n"
596 "*o..o*.o....x.o*\n"
597 "**o***....*...**\n"
598 "***************.\n"
599 "\n"
600 "**.....**..****.\n"
601 "*X*****o.***.o**\n"
602 "*....oo.....o..*\n"
603 "*.**..**o..*o*.*\n"
604 "*.*.o.*.*o.**..*\n"
605 "*.**..**...*x*.*\n"
606 "*.....o........*\n"
607 "*........o.....*\n"
608 "****************\n"
609 "\n"
610 ".**************.\n"
611 "*.X*........o.**\n"
612 "*.*...*o...o**.*\n"
613 "*.......o....*.*\n"
614 "*.o..........*o*\n"
615 "*.*......o.....*\n"
616 "**......o.o..*o*\n"
617 "*x..*....o.*.*.*\n"
618 ".**************.\n"
619 "\n"
620 "****************\n"
621 "*o*o........o*o*\n"
622 "*.o*X......**..*\n"
623 "*.x........o...*\n"
624 "*........o*....*\n"
625 "*......o.......*\n"
626 "*.o*........*..*\n"
627 "*o*o........o*o*\n"
628 "****************\n"
629 "\n"
630 ".******.********\n"
631 "*.....o*.....o.*\n"
632 "*.*.o.*..*...o.*\n"
633 "*..X*...*oo.*o.*\n"
634 ".*.*...*.o..x*.*\n"
635 "*o.......*..*o.*\n"
636 ".*......o.....*.\n"
637 "*o............o*\n"
638 "****************\n"
639 "\n"
640 "****************\n"
641 "**.x*o.o......o*\n"
642 "*o.Xo*o.......**\n"
643 "**.***........**\n"
644 "**.....o*o*....*\n"
645 "*oo.......o*o..*\n"
646 "**.o....****o..*\n"
647 "**o*..*........*\n"
648 "****************\n"
649 "\n"
650 "****************\n"
651 "*.o*........*X.*\n"
652 "*.*..o*oo*o..*.*\n"
653 "*....*o**o*.o..*\n"
654 "*.o*.......o*..*\n"
655 "*..o*o....o*...*\n"
656 "*.*..*.**o*..*.*\n"
657 "*....o.*o...x..*\n"
658 "****************\n"
659 "\n"
660 "****************\n"
661 "*.o....o..x*...*\n"
662 "*..*o*o...*o...*\n"
663 "*...*o*....*o..*\n"
664 "*...o..*...o*o.*\n"
665 "*.*o*...*.o*...*\n"
666 "*.o*o.*.o.*....*\n"
667 "*o*X..*.....*..*\n"
668 "****************\n"
669 "\n"
670 "****************\n"
671 "*o...**.....**o*\n"
672 "*.*..*......*o.*\n"
673 "*.o*...o**..o..*\n"
674 "*.*....*o......*\n"
675 "*....*...o*....*\n"
676 "*.**.o*.**o..*x*\n"
677 "*.o*.*o.....**X*\n"
678 "****************\n"
679 "\n"
680 "****************\n"
681 "*...o*o........*\n"
682 "**o..o*.**o...**\n"
683 "*.*.*.o...*..*.*\n"
684 "*.x.*..**..*.Xo*\n"
685 "*.*..*...o.*.*.*\n"
686 "**...o**.*o..o**\n"
687 "*........o*o...*\n"
688 "****************";
691 * Do a pretty transition from one level to another.
693 static void star_transition_update(void)
695 const int center_x = LCD_WIDTH / 2;
696 const int center_y = LCD_HEIGHT / 2;
697 int x = 0;
698 int y = 0;
699 #if LCD_WIDTH >= LCD_HEIGHT
700 #if defined(IPOD_VIDEO)
701 const int step = 4;
702 #else
703 const int step = 1;
704 #endif
705 const int lcd_demi_width = LCD_WIDTH / 2;
706 int var_y = 0;
708 for (; x < lcd_demi_width ; x+=step)
710 var_y += LCD_HEIGHT;
711 if (var_y > LCD_WIDTH)
713 var_y -= LCD_WIDTH;
714 y+=step;
716 if( x )
718 rb->lcd_update_rect(center_x - x, center_y - y, x*2, step);
719 rb->lcd_update_rect(center_x - x, center_y + y - step, x*2, step);
721 if( y )
723 rb->lcd_update_rect(center_x - x, center_y - y, step, y*2);
724 rb->lcd_update_rect(center_x + x - step, center_y - y, step, y*2);
726 STAR_SLEEP
728 #else
729 int lcd_demi_height = LCD_HEIGHT / 2;
730 int var_x = 0;
732 for (; y < lcd_demi_height ; y++)
734 var_x += LCD_WIDTH;
735 if (var_x > LCD_HEIGHT)
737 var_x -= LCD_HEIGHT;
738 x++;
740 if( x )
742 rb->lcd_update_rect(center_x - x, center_y - y, x * 2, 1);
743 rb->lcd_update_rect(center_x - x, center_y + y - 1, x * 2, 1);
745 if( y )
747 rb->lcd_update_rect(center_x - x, center_y - y, 1, y * 2);
748 rb->lcd_update_rect(center_x + x - 1, center_y - y, 1, y * 2);
750 STAR_SLEEP
752 #endif
753 rb->lcd_update();
757 * Display information board of the current level.
759 static void star_display_board_info(int current_level)
761 int label_pos_y, tile_pos_y;
762 char str_info[32];
764 if (TILE_HEIGHT > char_height)
766 tile_pos_y = LCD_HEIGHT - TILE_HEIGHT;
767 label_pos_y = tile_pos_y + (TILE_HEIGHT - char_height) / 2;
769 else
771 label_pos_y = LCD_HEIGHT - char_height;
772 tile_pos_y = label_pos_y + (char_height - TILE_HEIGHT) / 2;
775 rb->snprintf(str_info, sizeof(str_info), "L:%02d", current_level + 1);
776 rb->lcd_putsxy(STAR_OFFSET_X, label_pos_y, str_info);
777 rb->snprintf(str_info, sizeof(str_info), "S:%02d", star_count);
778 rb->lcd_putsxy(LCD_WIDTH/2 - 2 * char_width, label_pos_y, str_info);
779 rb->lcd_putsxy(STAR_OFFSET_X + (STAR_WIDTH-1) * TILE_WIDTH - 2 * char_width,
780 label_pos_y, "C:");
782 rb->lcd_bitmap_part(star_tiles, 0, control == STAR_CONTROL_BALL ?
783 BALL*TILE_HEIGHT : BLOCK*TILE_HEIGHT,
784 STRIDE( SCREEN_MAIN,
785 BMPWIDTH_star_tiles, BMPHEIGHT_star_tiles),
786 STAR_OFFSET_X + (STAR_WIDTH-1) * TILE_WIDTH,
787 tile_pos_y, TILE_WIDTH, TILE_HEIGHT);
789 rb->lcd_update_rect(0, MIN(label_pos_y, tile_pos_y), LCD_WIDTH,
790 MAX(TILE_HEIGHT, char_height));
795 * Load a level into board array.
797 static int star_load_level(int current_level)
799 int x, y;
800 char *ptr_tab;
802 if (current_level < 0)
803 current_level = 0;
804 else if (current_level > STAR_LEVEL_COUNT-1)
805 current_level = STAR_LEVEL_COUNT-1;
808 ptr_tab = levels + current_level * STAR_LEVEL_SIZE;
809 control = STAR_CONTROL_BALL;
810 star_count = 0;
812 rb->lcd_clear_display();
814 for (y = 0 ; y < STAR_HEIGHT ; y++)
816 for (x = 0 ; x < STAR_WIDTH ; x++)
818 board[y][x] = *ptr_tab;
819 switch (*ptr_tab)
821 # define DRAW_TILE( a ) \
822 rb->lcd_bitmap_part( star_tiles, 0, \
823 a*TILE_HEIGHT, \
824 STRIDE( SCREEN_MAIN, \
825 BMPWIDTH_star_tiles, \
826 BMPHEIGHT_star_tiles), \
827 STAR_OFFSET_X + x * TILE_WIDTH, \
828 STAR_OFFSET_Y + y * TILE_HEIGHT, \
829 TILE_WIDTH, TILE_HEIGHT);
831 case STAR_VOID:
832 DRAW_TILE( SPACE );
833 break;
835 case STAR_WALL:
836 DRAW_TILE( WALL );
837 break;
839 case STAR_STAR:
840 DRAW_TILE( STAR );
841 star_count++;
842 break;
844 case STAR_BALL:
845 ball_x = x;
846 ball_y = y;
847 DRAW_TILE( BALL );
848 break;
851 case STAR_BLOCK:
852 block_x = x;
853 block_y = y;
854 DRAW_TILE( BLOCK );
855 break;
857 ptr_tab++;
859 ptr_tab++;
861 star_display_board_info(current_level);
862 star_transition_update();
863 return 1;
866 static void star_animate_tile(int tile_no, int start_x, int start_y,
867 int delta_x, int delta_y)
869 int i;
871 if (delta_x != 0) /* horizontal */
873 for (i = 1 ; i <= TILE_WIDTH ; i++)
875 STAR_SLEEP
876 rb->lcd_bitmap_part(star_tiles, 0, SPACE * TILE_HEIGHT,
877 STRIDE( SCREEN_MAIN,
878 BMPWIDTH_star_tiles, BMPHEIGHT_star_tiles),
879 start_x, start_y, TILE_WIDTH, TILE_HEIGHT);
880 rb->lcd_bitmap_part(star_tiles, 0, tile_no * TILE_HEIGHT,
881 STRIDE( SCREEN_MAIN,
882 BMPWIDTH_star_tiles, BMPHEIGHT_star_tiles),
883 start_x + delta_x * i, start_y, TILE_WIDTH, TILE_HEIGHT);
884 rb->lcd_update_rect(start_x + delta_x * i - (delta_x>0?1:0),
885 start_y, TILE_WIDTH + 1, TILE_HEIGHT);
888 else /* vertical */
890 for (i = 1 ; i <= TILE_HEIGHT ; i++)
892 STAR_SLEEP
893 rb->lcd_bitmap_part(star_tiles, 0, SPACE * TILE_HEIGHT,
894 STRIDE( SCREEN_MAIN,
895 BMPWIDTH_star_tiles, BMPHEIGHT_star_tiles),
896 start_x, start_y, TILE_WIDTH, TILE_HEIGHT);
897 rb->lcd_bitmap_part(star_tiles, 0, tile_no * TILE_HEIGHT,
898 STRIDE( SCREEN_MAIN,
899 BMPWIDTH_star_tiles, BMPHEIGHT_star_tiles),
900 start_x, start_y + delta_y * i, TILE_WIDTH, TILE_HEIGHT);
901 rb->lcd_update_rect(start_x, start_y + delta_y * i - (delta_y>0?1:0),
902 TILE_WIDTH, TILE_HEIGHT + 1);
908 * Run the game.
910 static int star_run_game(int current_level)
912 int move_x = 0;
913 int move_y = 0;
914 int key;
915 int lastkey = BUTTON_NONE;
917 int label_offset_y;
919 label_offset_y = LCD_HEIGHT - char_height;
921 if (!star_load_level(current_level))
922 return 0;
924 while (true)
926 move_x = 0;
927 move_y = 0;
929 while ((move_x == 0) && (move_y == 0))
931 key = rb->button_get(true);
932 switch (key)
934 #ifdef STAR_RC_QUIT
935 case STAR_RC_QUIT:
936 #endif
937 case STAR_QUIT:
938 return -1;
940 case STAR_LEFT:
941 move_x = -1;
942 break;
944 case STAR_RIGHT:
945 move_x = 1;
946 break;
948 case STAR_UP:
949 move_y = -1;
950 break;
952 case STAR_DOWN:
953 move_y = 1;
954 break;
956 case STAR_LEVEL_DOWN:
957 #ifdef STAR_LEVEL_DOWN_PRE
958 if (lastkey != STAR_LEVEL_DOWN_PRE)
959 break;
960 #endif
961 if (current_level > 0)
963 current_level--;
964 star_load_level(current_level);
966 break;
968 case STAR_LEVEL_REPEAT:
969 star_load_level(current_level);
970 break;
972 case STAR_LEVEL_UP:
973 #ifdef STAR_LEVEL_UP_PRE
974 if (lastkey != STAR_LEVEL_UP_PRE)
975 break;
976 #endif
977 if (current_level < STAR_LEVEL_COUNT - 1)
979 current_level++;
980 star_load_level(current_level);
982 break;
984 case STAR_TOGGLE_CONTROL:
985 #ifdef STAR_TOGGLE_CONTROL_PRE
986 if (lastkey != STAR_TOGGLE_CONTROL_PRE)
987 break;
988 #endif
989 #ifdef STAR_TOGGLE_CONTROL2
990 case STAR_TOGGLE_CONTROL2:
991 #endif
992 if (control == STAR_CONTROL_BALL)
993 control = STAR_CONTROL_BLOCK;
994 else
995 control = STAR_CONTROL_BALL;
996 star_display_board_info(current_level);
997 break;
999 default:
1000 if (rb->default_event_handler(key) == SYS_USB_CONNECTED)
1002 usb_detected = true;
1003 return 0;
1005 break;
1007 if (key != BUTTON_NONE)
1008 lastkey = key;
1011 if (control == STAR_CONTROL_BALL)
1013 board[ball_y][ball_x] = STAR_VOID;
1014 while ((board[ball_y + move_y][ball_x + move_x] == STAR_VOID
1015 || board[ball_y + move_y][ball_x + move_x] == STAR_STAR))
1018 star_animate_tile(BALL, STAR_OFFSET_X + ball_x * TILE_WIDTH,
1019 STAR_OFFSET_Y + ball_y * TILE_HEIGHT,
1020 move_x, move_y);
1021 ball_x += move_x;
1022 ball_y += move_y;
1024 if (board[ball_y][ball_x] == STAR_STAR)
1026 board[ball_y][ball_x] = STAR_VOID;
1027 star_count--;
1029 star_display_board_info(current_level);
1032 board[ball_y][ball_x] = STAR_BALL;
1034 else
1036 board[block_y][block_x] = STAR_VOID;
1037 while (board[block_y + move_y][block_x + move_x] == STAR_VOID)
1039 star_animate_tile(BLOCK, STAR_OFFSET_X + block_x * TILE_WIDTH,
1040 STAR_OFFSET_Y + block_y * TILE_HEIGHT,
1041 move_x, move_y);
1042 block_x += move_x;
1043 block_y += move_y;
1045 board[block_y][block_x] = STAR_BLOCK;
1048 if (star_count == 0)
1050 current_level++;
1051 if (current_level == STAR_LEVEL_COUNT)
1053 rb->lcd_clear_display();
1054 rb->splash(HZ*2, "Congratulations!");
1055 rb->lcd_update();
1057 /* There is no such level as STAR_LEVEL_COUNT so it can't be the
1058 * current_level */
1059 current_level--;
1060 return 1;
1062 star_load_level(current_level);
1068 * Display help text.
1070 static bool star_help(void)
1072 static char* help_text[] = {
1073 "Star", "", "Aim", "",
1074 "Take", "all", "the", "stars", "to", "go", "to", "the", "next", "level.",
1075 "You", "can", "toggle", "control", "with", "the", "block", "to", "use",
1076 "it", "as", "a", "mobile", "wall.", "The", "block", "cannot", "take",
1077 "stars.", "", "",
1078 "Controls", "",
1079 STAR_TOGGLE_CONTROL_NAME":", "Toggle", "control", "",
1080 STAR_QUIT_NAME":", "Exit", "",
1081 STAR_LEVEL_DOWN_NAME":", "Prev.", "level", "",
1082 STAR_LEVEL_REPEAT_NAME":", "Reset", "level", "",
1083 STAR_LEVEL_UP_NAME":", "Next", "level"
1085 static struct style_text formation[]={
1086 { 0, TEXT_CENTER|TEXT_UNDERLINE },
1087 { 2, C_RED },
1088 { 35, C_RED },
1089 LAST_STYLE_ITEM
1091 #if LCD_DEPTH > 1 && !defined(HAVE_LCD_COLOR)
1092 rb->lcd_set_background(LCD_WHITE);
1093 rb->lcd_set_foreground(LCD_BLACK);
1094 #endif
1095 if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
1096 return true;
1097 #if LCD_DEPTH > 1 && !defined(HAVE_LCD_COLOR)
1098 rb->lcd_set_background(LCD_BLACK);
1099 rb->lcd_set_foreground(LCD_WHITE);
1100 #endif
1101 return false;
1105 * Display the choice menu.
1107 static int star_menu(void)
1109 int selection, level=1;
1110 bool menu_quit = false;
1112 MENUITEM_STRINGLIST(menu, "Star Menu", NULL,
1113 "Start Game","Choose Level",
1114 "Help", "Playback Control", "Quit");
1116 while(!menu_quit)
1118 switch(rb->do_menu(&menu, &selection, NULL, false))
1120 case 0:
1121 /* use system font and get the size of char */
1122 rb->lcd_setfont(FONT_SYSFIXED);
1123 rb->lcd_getstringsize("a", &char_width, &char_height);
1124 star_run_game(level-1);
1125 rb->lcd_setfont(FONT_UI);
1126 break;
1127 case 1:
1128 rb->set_int("Level", "", UNIT_INT, &level,
1129 NULL, 1, 1, STAR_LEVEL_COUNT, NULL );
1130 break;
1131 case 2:
1132 if(star_help())
1133 usb_detected = true;
1134 break;
1135 case 3:
1136 playback_control(NULL);
1137 break;
1138 case 4:
1139 menu_quit = true;
1140 break;
1142 if(usb_detected)
1143 return PLUGIN_USB_CONNECTED;
1146 return PLUGIN_OK;
1150 * Main entry point
1152 enum plugin_status plugin_start(const void* parameter)
1154 (void)parameter;
1156 #if LCD_DEPTH > 1
1157 rb->lcd_set_backdrop(NULL);
1158 rb->lcd_set_background( LCD_BLACK );
1159 rb->lcd_set_foreground( LCD_WHITE );
1160 #endif
1162 /* display choice menu */
1163 return star_menu();
1166 #endif