blob: b419d965c57e0b5c95cbd5d06ace602b9d61dc35 [file] [log] [blame]
Björn Stenberg020ab8f2003-06-29 21:10:27 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Frederic Dang Ngoc
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Björn Stenberg020ab8f2003-06-29 21:10:27 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "plugin.h"
22#ifdef HAVE_LCD_BITMAP
23
Jens Arnolda36b1d42006-01-15 18:20:18 +000024PLUGIN_HEADER
25
Björn Stenberg020ab8f2003-06-29 21:10:27 +000026/* size of a level in file */
27#define STAR_LEVEL_SIZE ((STAR_WIDTH + 1) * STAR_HEIGHT + 1)
28
29/* size of the game board */
30#define STAR_WIDTH 16
31#define STAR_HEIGHT 9
32
Björn Stenberg020ab8f2003-06-29 21:10:27 +000033/* number of level */
34#define STAR_LEVEL_COUNT 20
35
Björn Stenberg020ab8f2003-06-29 21:10:27 +000036/* values of object in the board */
Zakk Robertsec216ac2006-06-03 19:24:10 +000037#define STAR_VOID '.'
38#define STAR_WALL '*'
39#define STAR_STAR 'o'
40#define STAR_BALL 'X'
41#define STAR_BLOCK 'x'
Björn Stenberg020ab8f2003-06-29 21:10:27 +000042
43/* sleep time between two frames */
Tom Rossc7f5ccc2007-03-28 07:33:18 +000044#if (LCD_HEIGHT * LCD_WIDTH >= 70000) && defined(IPOD_ARCH)
45/* iPod 5G LCD is *slow* */
Jens Arnold4f1ca132006-10-21 00:24:54 +000046#define STAR_SLEEP rb->yield();
47#elif (LCD_HEIGHT * LCD_WIDTH >= 30000)
Shachar Liberman585510a2006-08-10 20:56:09 +000048#define STAR_SLEEP rb->sleep(0);
Antoine Cellerierfb3c0662006-06-11 13:25:44 +000049#else
Shachar Liberman585510a2006-08-10 20:56:09 +000050#define STAR_SLEEP rb->sleep(1);
Antoine Cellerierfb3c0662006-06-11 13:25:44 +000051#endif
Björn Stenberg020ab8f2003-06-29 21:10:27 +000052
53/* value of ball and block control */
54#define STAR_CONTROL_BALL 0
55#define STAR_CONTROL_BLOCK 1
56
Jens Arnold2afdf952004-10-22 00:22:07 +000057/* variable button definitions */
58#if CONFIG_KEYPAD == RECORDER_PAD
Jens Arnold4f1ca132006-10-21 00:24:54 +000059#define STAR_QUIT BUTTON_OFF
Jens Arnold29361ab2008-03-22 10:24:28 +000060#define STAR_LEFT BUTTON_LEFT
61#define STAR_RIGHT BUTTON_RIGHT
Jens Arnold4f1ca132006-10-21 00:24:54 +000062#define STAR_UP BUTTON_UP
63#define STAR_DOWN BUTTON_DOWN
Jens Arnold2afdf952004-10-22 00:22:07 +000064#define STAR_TOGGLE_CONTROL BUTTON_ON
65#define STAR_TOGGLE_CONTROL2 BUTTON_PLAY
Jens Arnold4f1ca132006-10-21 00:24:54 +000066#define STAR_LEVEL_UP BUTTON_F3
67#define STAR_LEVEL_DOWN BUTTON_F1
68#define STAR_LEVEL_REPEAT BUTTON_F2
69#define STAR_MENU_RUN BUTTON_PLAY
70#define STAR_MENU_RUN2 BUTTON_RIGHT
71#define STAR_MENU_RUN3 BUTTON_ON
Jens Arnold2afdf952004-10-22 00:22:07 +000072
Dave Chapmand64e6262007-01-14 13:48:09 +000073#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
74#define STAR_QUIT BUTTON_OFF
Jens Arnold29361ab2008-03-22 10:24:28 +000075#define STAR_LEFT BUTTON_LEFT
76#define STAR_RIGHT BUTTON_RIGHT
Dave Chapmand64e6262007-01-14 13:48:09 +000077#define STAR_UP BUTTON_UP
78#define STAR_DOWN BUTTON_DOWN
79#define STAR_TOGGLE_CONTROL BUTTON_ON
80#define STAR_TOGGLE_CONTROL2 BUTTON_SELECT
81#define STAR_LEVEL_UP BUTTON_F3
82#define STAR_LEVEL_DOWN BUTTON_F1
83#define STAR_LEVEL_REPEAT BUTTON_F2
84#define STAR_MENU_RUN BUTTON_SELECT
85#define STAR_MENU_RUN2 BUTTON_RIGHT
86#define STAR_MENU_RUN3 BUTTON_ON
87
Jens Arnold2afdf952004-10-22 00:22:07 +000088#elif CONFIG_KEYPAD == ONDIO_PAD
Jens Arnold4f1ca132006-10-21 00:24:54 +000089#define STAR_QUIT BUTTON_OFF
Jens Arnold29361ab2008-03-22 10:24:28 +000090#define STAR_LEFT BUTTON_LEFT
91#define STAR_RIGHT BUTTON_RIGHT
Jens Arnold4f1ca132006-10-21 00:24:54 +000092#define STAR_UP BUTTON_UP
93#define STAR_DOWN BUTTON_DOWN
Jens Arnold2afdf952004-10-22 00:22:07 +000094#define STAR_TOGGLE_CONTROL_PRE BUTTON_MENU
95#define STAR_TOGGLE_CONTROL (BUTTON_MENU | BUTTON_REL)
Jens Arnold4f1ca132006-10-21 00:24:54 +000096#define STAR_LEVEL_UP (BUTTON_MENU | BUTTON_RIGHT)
97#define STAR_LEVEL_DOWN (BUTTON_MENU | BUTTON_LEFT)
98#define STAR_LEVEL_REPEAT (BUTTON_MENU | BUTTON_UP)
99#define STAR_MENU_RUN BUTTON_RIGHT
Jens Arnold2afdf952004-10-22 00:22:07 +0000100
Daniel Stenberg01377e22005-06-29 12:47:24 +0000101#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
102 (CONFIG_KEYPAD == IRIVER_H300_PAD)
Jens Arnold4f1ca132006-10-21 00:24:54 +0000103#define STAR_QUIT BUTTON_OFF
Jens Arnold29361ab2008-03-22 10:24:28 +0000104#define STAR_LEFT BUTTON_LEFT
105#define STAR_RIGHT BUTTON_RIGHT
Jens Arnold4f1ca132006-10-21 00:24:54 +0000106#define STAR_UP BUTTON_UP
107#define STAR_DOWN BUTTON_DOWN
Shachar Liberman078e44e2006-08-10 17:21:01 +0000108#define STAR_TOGGLE_CONTROL BUTTON_MODE
109#define STAR_TOGGLE_CONTROL2 BUTTON_SELECT
Jens Arnold4f1ca132006-10-21 00:24:54 +0000110#define STAR_LEVEL_UP (BUTTON_ON | BUTTON_RIGHT)
111#define STAR_LEVEL_DOWN (BUTTON_ON | BUTTON_LEFT)
112#define STAR_LEVEL_REPEAT (BUTTON_ON | BUTTON_SELECT)
113#define STAR_MENU_RUN BUTTON_RIGHT
114#define STAR_MENU_RUN2 BUTTON_SELECT
Dave Chapman54d44c82005-12-14 01:31:37 +0000115
Kevin Ferrare0e027bd2006-06-30 16:43:47 +0000116#define STAR_RC_QUIT BUTTON_RC_STOP
Dave Chapmanfb4e3842006-02-24 20:54:09 +0000117#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
Jens Arnoldb7013222007-07-27 09:57:27 +0000118 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
119 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
Dave Chapman54d44c82005-12-14 01:31:37 +0000120
Jens Arnold4f1ca132006-10-21 00:24:54 +0000121#define STAR_QUIT (BUTTON_SELECT | BUTTON_MENU)
Jens Arnold29361ab2008-03-22 10:24:28 +0000122#define STAR_LEFT BUTTON_LEFT
123#define STAR_RIGHT BUTTON_RIGHT
Jens Arnold4f1ca132006-10-21 00:24:54 +0000124#define STAR_UP BUTTON_MENU
125#define STAR_DOWN BUTTON_PLAY
Zakk Robertsec216ac2006-06-03 19:24:10 +0000126#define STAR_TOGGLE_CONTROL_PRE BUTTON_SELECT
127#define STAR_TOGGLE_CONTROL (BUTTON_SELECT | BUTTON_REL)
Jens Arnold4f1ca132006-10-21 00:24:54 +0000128#define STAR_LEVEL_UP (BUTTON_SELECT | BUTTON_RIGHT)
129#define STAR_LEVEL_DOWN (BUTTON_SELECT | BUTTON_LEFT)
130#define STAR_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_PLAY)
131#define STAR_MENU_RUN BUTTON_RIGHT
132#define STAR_MENU_RUN2 BUTTON_SELECT
Dave Chapman54d44c82005-12-14 01:31:37 +0000133
Jens Arnold85a226d2007-03-16 23:02:39 +0000134#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
Daniel Stenbergcedba882006-01-18 11:09:06 +0000135
Jens Arnold4f1ca132006-10-21 00:24:54 +0000136#define STAR_QUIT BUTTON_POWER
Jens Arnold29361ab2008-03-22 10:24:28 +0000137#define STAR_LEFT BUTTON_LEFT
138#define STAR_RIGHT BUTTON_RIGHT
Jens Arnold4f1ca132006-10-21 00:24:54 +0000139#define STAR_UP BUTTON_UP
140#define STAR_DOWN BUTTON_DOWN
141#define STAR_TOGGLE_CONTROL BUTTON_SELECT
142#define STAR_LEVEL_UP_PRE BUTTON_REC
143#define STAR_LEVEL_UP (BUTTON_REC|BUTTON_REL)
144#define STAR_LEVEL_DOWN_PRE BUTTON_REC
Jens Arnoldb10f2f92006-10-21 00:38:45 +0000145#define STAR_LEVEL_DOWN (BUTTON_REC|BUTTON_REPEAT)
Jens Arnold4f1ca132006-10-21 00:24:54 +0000146#define STAR_LEVEL_REPEAT BUTTON_PLAY
147#define STAR_MENU_RUN BUTTON_RIGHT
148#define STAR_MENU_RUN2 BUTTON_SELECT
Daniel Stenbergcedba882006-01-18 11:09:06 +0000149
Marcoen Hirschberg338e2bb2006-02-24 15:42:52 +0000150#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
151
Marcoen Hirschberga7168fe2007-05-19 23:38:09 +0000152#define STAR_QUIT BUTTON_POWER
Jens Arnold29361ab2008-03-22 10:24:28 +0000153#define STAR_LEFT BUTTON_LEFT
154#define STAR_RIGHT BUTTON_RIGHT
Jens Arnold4f1ca132006-10-21 00:24:54 +0000155#define STAR_UP BUTTON_UP
156#define STAR_DOWN BUTTON_DOWN
Marcoen Hirschberga7168fe2007-05-19 23:38:09 +0000157#define STAR_TOGGLE_CONTROL BUTTON_SELECT
158#define STAR_LEVEL_UP BUTTON_VOL_UP
159#define STAR_LEVEL_DOWN BUTTON_VOL_DOWN
160#define STAR_LEVEL_REPEAT BUTTON_A
161#define STAR_MENU_RUN BUTTON_SELECT
Marcoen Hirschberg338e2bb2006-02-24 15:42:52 +0000162
Marianne Arnold12ddb8e2007-09-20 10:49:48 +0000163#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
164(CONFIG_KEYPAD == SANSA_C200_PAD)
Barry Wardell24f4a2a2006-10-26 13:38:09 +0000165
166#define STAR_QUIT BUTTON_POWER
Jens Arnold29361ab2008-03-22 10:24:28 +0000167#define STAR_LEFT BUTTON_LEFT
168#define STAR_RIGHT BUTTON_RIGHT
Barry Wardell24f4a2a2006-10-26 13:38:09 +0000169#define STAR_UP BUTTON_UP
170#define STAR_DOWN BUTTON_DOWN
Daniel Ankers17676672007-01-03 23:53:22 +0000171#define STAR_TOGGLE_CONTROL BUTTON_SELECT
172#define STAR_LEVEL_UP (BUTTON_SELECT | BUTTON_RIGHT)
173#define STAR_LEVEL_DOWN (BUTTON_SELECT | BUTTON_LEFT)
174#define STAR_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_DOWN)
175#define STAR_MENU_RUN BUTTON_SELECT
Barry Wardell24f4a2a2006-10-26 13:38:09 +0000176
177
Daniel Stenberg1e88be52006-08-03 20:17:25 +0000178#elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
179
Jens Arnold4f1ca132006-10-21 00:24:54 +0000180#define STAR_QUIT BUTTON_POWER
Jens Arnold29361ab2008-03-22 10:24:28 +0000181#define STAR_LEFT BUTTON_LEFT
182#define STAR_RIGHT BUTTON_RIGHT
Jens Arnold4f1ca132006-10-21 00:24:54 +0000183#define STAR_UP BUTTON_SCROLL_UP
184#define STAR_DOWN BUTTON_SCROLL_DOWN
185#define STAR_TOGGLE_CONTROL BUTTON_REW
186#define STAR_LEVEL_UP (BUTTON_PLAY | BUTTON_SCROLL_UP)
187#define STAR_LEVEL_DOWN (BUTTON_PLAY | BUTTON_SCROLL_DOWN)
188#define STAR_LEVEL_REPEAT (BUTTON_PLAY | BUTTON_RIGHT)
189#define STAR_MENU_RUN BUTTON_FF
Daniel Stenberg1e88be52006-08-03 20:17:25 +0000190
Will Robertson8215b342008-02-17 12:23:02 +0000191#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
192
193#define STAR_QUIT BUTTON_BACK
Jens Arnold29361ab2008-03-22 10:24:28 +0000194#define STAR_LEFT BUTTON_LEFT
195#define STAR_RIGHT BUTTON_RIGHT
Will Robertson8215b342008-02-17 12:23:02 +0000196#define STAR_UP BUTTON_UP
197#define STAR_DOWN BUTTON_DOWN
198#define STAR_TOGGLE_CONTROL BUTTON_SELECT
199#define STAR_LEVEL_UP BUTTON_VOL_UP
200#define STAR_LEVEL_DOWN BUTTON_VOL_DOWN
201#define STAR_LEVEL_REPEAT BUTTON_MENU
202#define STAR_MENU_RUN BUTTON_SELECT
203
Robert Kuklad6c8b572008-03-01 22:55:09 +0000204#elif (CONFIG_KEYPAD == MROBE100_PAD)
205
206#define STAR_QUIT BUTTON_POWER
Jens Arnold29361ab2008-03-22 10:24:28 +0000207#define STAR_LEFT BUTTON_LEFT
208#define STAR_RIGHT BUTTON_RIGHT
Robert Kuklad6c8b572008-03-01 22:55:09 +0000209#define STAR_UP BUTTON_UP
210#define STAR_DOWN BUTTON_DOWN
211#define STAR_TOGGLE_CONTROL BUTTON_SELECT
212#define STAR_LEVEL_UP BUTTON_PLAY
213#define STAR_LEVEL_DOWN BUTTON_MENU
214#define STAR_LEVEL_REPEAT BUTTON_DISPLAY
215#define STAR_MENU_RUN BUTTON_SELECT
216
Jens Arnold29361ab2008-03-22 10:24:28 +0000217#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
218
219#define STAR_QUIT BUTTON_RC_REC
220#define STAR_LEFT BUTTON_RC_REW
221#define STAR_RIGHT BUTTON_RC_FF
222#define STAR_UP BUTTON_RC_VOL_UP
223#define STAR_DOWN BUTTON_RC_VOL_DOWN
224#define STAR_TOGGLE_CONTROL BUTTON_RC_MODE
225#define STAR_LEVEL_UP (BUTTON_RC_PLAY|BUTTON_RC_VOL_UP)
226#define STAR_LEVEL_DOWN (BUTTON_RC_PLAY|BUTTON_RC_VOL_DOWN)
227#define STAR_LEVEL_REPEAT (BUTTON_RC_PLAY|BUTTON_RC_MENU)
228#define STAR_MENU_RUN BUTTON_RC_FF
229
Rob Purchase554d7ed2008-03-22 22:03:34 +0000230#elif (CONFIG_KEYPAD == COWOND2_PAD)
231
232#define STAR_QUIT BUTTON_POWER
Rob Purchase297e0502008-04-27 15:30:19 +0000233#define STAR_QUIT_NAME "[POWER]"
Rob Purchase554d7ed2008-03-22 22:03:34 +0000234#define STAR_MENU_RUN BUTTON_MENU
235
Robert Kuklad6c8b572008-03-01 22:55:09 +0000236#else
237#error No keymap defined!
Jens Arnold2afdf952004-10-22 00:22:07 +0000238#endif
239
Rob Purchase297e0502008-04-27 15:30:19 +0000240#ifdef HAVE_TOUCHPAD
241//#ifndef STAR_QUIT
242//#define STAR_QUIT BUTTON_TOPLEFT
243//#define STAR_QUIT_NAME "[TOPLEFT]"
244//#endif
245#ifndef STAR_MENU_RUN
246#define STAR_MENU_RUN BUTTON_TOPRIGHT
247#endif
248#ifndef STAR_LEFT
249#define STAR_LEFT BUTTON_MIDLEFT
250#endif
251#ifndef STAR_RIGHT
252#define STAR_RIGHT BUTTON_MIDRIGHT
253#endif
254#ifndef STAR_UP
255#define STAR_UP BUTTON_TOPMIDDLE
256#endif
257#ifndef STAR_DOWN
258#define STAR_DOWN BUTTON_BOTTOMMIDDLE
259#endif
260#ifndef STAR_TOGGLE_CONTROL
261#define STAR_TOGGLE_CONTROL BUTTON_CENTER
262#define STAR_TOGGLE_CONTROL_NAME "[CENTER]"
263#endif
264#ifndef STAR_LEVEL_UP
265#define STAR_LEVEL_UP BUTTON_TOPLEFT
266#define STAR_LEVEL_UP_NAME "[TOPLEFT]"
267#endif
268#ifndef STAR_LEVEL_DOWN
269#define STAR_LEVEL_DOWN BUTTON_BOTTOMLEFT
270#define STAR_LEVEL_DOWN_NAME "[BOTTOMLEFT]"
271#endif
272#ifndef STAR_LEVEL_REPEAT
273#define STAR_LEVEL_REPEAT BUTTON_BOTTOMRIGHT
274#define STAR_LEVEL_REPEAT_NAME "[BOTTOMRIGHT]"
275#endif
276#endif
277
Jens Arnold2afdf952004-10-22 00:22:07 +0000278/* function returns because of USB? */
279static bool usb_detected = false;
280
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000281/* position of the ball */
282static int ball_x, ball_y;
283
284/* position of the block */
285static int block_x, block_y;
286
287/* number of stars to get to finish the level */
288static int star_count;
289
290/* the object we control : ball or block */
291static int control;
292
293/* the current board */
294static char board[STAR_HEIGHT][STAR_WIDTH];
295
Jens Arnold4f1ca132006-10-21 00:24:54 +0000296#include "star_tiles.h"
Antoine Cellerier40a92ea2006-06-10 20:39:33 +0000297
Jens Arnold4f1ca132006-10-21 00:24:54 +0000298#define TILE_WIDTH BMPWIDTH_star_tiles
299#define TILE_HEIGHT (BMPHEIGHT_star_tiles/5)
300#define STAR_OFFSET_X ((LCD_WIDTH - STAR_WIDTH * TILE_WIDTH) / 2)
301#define STAR_OFFSET_Y ((LCD_HEIGHT - STAR_HEIGHT * TILE_HEIGHT - MAX(TILE_HEIGHT, 8)) / 2)
Antoine Cellerier40a92ea2006-06-10 20:39:33 +0000302
Jens Arnold4f1ca132006-10-21 00:24:54 +0000303#define WALL 0
304#define SPACE 1
305#define BLOCK 2
306#define STAR 3
307#define BALL 4
Antoine Cellerier40a92ea2006-06-10 20:39:33 +0000308
Tom Rossc7f5ccc2007-03-28 07:33:18 +0000309#define MENU_START 0
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000310
311/* char font size */
312static int char_width = -1;
313static int char_height = -1;
314
Steve Bavin65265772008-05-13 09:57:56 +0000315static const struct plugin_api* rb;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000316
317/* this arrays contains a group of levels loaded into memory */
Zakk Robertsec216ac2006-06-03 19:24:10 +0000318static unsigned char* levels =
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000319"****************\n"
320"*X**........o*x*\n"
321"*..........o.***\n"
322"*.......**o....*\n"
323"*...**.o......**\n"
324"**.o..o.....o..*\n"
325"*.o......o**.o.*\n"
326"*.....**o.....o*\n"
327"****************\n"
328"\n"
329".*..*.*.*...*.**\n"
330"*...o.........X*\n"
331"...*o..*o...o...\n"
332"*.*.o.....o..*.*\n"
333"......*...o...*.\n"
334"*....*x*..o....*\n"
335"...*..*.*...*oo*\n"
336"*.............*.\n"
337".*..*........*..\n"
338"\n"
339"****************\n"
340"*...........o*x*\n"
341"*...**......**X*\n"
342"*...*o.........*\n"
343"*.o.....o**...o*\n"
344"*.*o..o..o*..o**\n"
345"*.**o.*o..o.o***\n"
346"*o....**o......*\n"
347"****************\n"
348"\n"
349"****************\n"
350"*............*x*\n"
351"*.....*........*\n"
352"**o*o.o*o*o*o*o*\n"
353"*.*.*o.o*.*.*.**\n"
354"**o*o*o.o*o*o*o*\n"
355"*.....*........*\n"
356"*...*.......*X.*\n"
357"****************\n"
358"\n"
359".**************.\n"
360"*X..*...*..*...*\n"
361"*..*o.*.o..o.*.*\n"
362"**......*..*...*\n"
363"*o.*o*........**\n"
364"**.....*.o.*...*\n"
365"*o*..*.*.*...*x*\n"
366"*...*....o*..*o*\n"
367".**************.\n"
368"\n"
369"....************\n"
370"...*...o...*o.o*\n"
371"..*....o....*.**\n"
372".*.....o.......*\n"
373"*X.....o.......*\n"
374"**.....o..*...**\n"
375"*......o....*..*\n"
376"*x.*...o..**o..*\n"
377"****************\n"
378"\n"
379"****************\n"
380"*..............*\n"
381".**.***..*o.**o*\n"
382".*o..*o.*.*.*.*.\n"
383"..*..*..***.**..\n"
384".**..*..*o*.*o**\n"
385"*..............*\n"
386"*..X*o....x..*o*\n"
387"****************\n"
388"\n"
389"***************.\n"
390"*..o**.........*\n"
391"*..*o..**.o....*\n"
392"*..o**.*.*o....*\n"
393"**.....**..*o*.*\n"
394"**.*.......o*o.*\n"
395"*oxo*...o..*X*.*\n"
396"**.............*\n"
397".***************\n"
398"\n"
399"..*.***********.\n"
400".*o*o......*..X*\n"
401"*o.o*....o....*.\n"
402".*.*..o**..o*..*\n"
403"*..*o.*oxo....o*\n"
404"*.....o**.....*.\n"
405"*o*o.........*..\n"
406"*...........*...\n"
407".***********....\n"
408"\n"
409"....***********.\n"
410"*****.o........*\n"
411"*...x.***o.o*.o*\n"
412"*.o...*o.*o...*.\n"
413"*.....*..o..*.o*\n"
414"*o*o..*.o*..*X*.\n"
415".*o...***..***..\n"
416"*.........*.*.*.\n"
417".*********..*..*\n"
418"\n"
419"****************\n"
420"*......*......X*\n"
421"*..*oo.....oo.**\n"
422"**...o...**...o*\n"
423"*o....*o*oo..***\n"
424"**.**....**....*\n"
425"*o..o*.o....x.o*\n"
426"**o***....*...**\n"
427"***************.\n"
428"\n"
429"**.....**..****.\n"
430"*X*****o.***.o**\n"
431"*....oo.....o..*\n"
432"*.**..**o..*o*.*\n"
433"*.*.o.*.*o.**..*\n"
434"*.**..**...*x*.*\n"
435"*.....o........*\n"
436"*........o.....*\n"
437"****************\n"
438"\n"
439".**************.\n"
440"*.X*........o.**\n"
441"*.*...*o...o**.*\n"
442"*.......o....*.*\n"
443"*.o..........*o*\n"
444"*.*......o.....*\n"
445"**......o.o..*o*\n"
446"*x..*....o.*.*.*\n"
447".**************.\n"
448"\n"
449"****************\n"
450"*o*o........o*o*\n"
451"*.o*X......**..*\n"
452"*.x........o...*\n"
453"*........o*....*\n"
454"*......o.......*\n"
455"*.o*........*..*\n"
456"*o*o........o*o*\n"
457"****************\n"
458"\n"
459".******.********\n"
460"*.....o*.....o.*\n"
461"*.*.o.*..*...o.*\n"
462"*..X*...*oo.*o.*\n"
463".*.*...*.o..x*.*\n"
464"*o.......*..*o.*\n"
465".*......o.....*.\n"
466"*o............o*\n"
467"****************\n"
468"\n"
469"****************\n"
470"**.x*o.o......o*\n"
471"*o.Xo*o.......**\n"
472"**.***........**\n"
473"**.....o*o*....*\n"
474"*oo.......o*o..*\n"
475"**.o....****o..*\n"
476"**o*..*........*\n"
477"****************\n"
478"\n"
479"****************\n"
480"*.o*........*X.*\n"
481"*.*..o*oo*o..*.*\n"
482"*....*o**o*.o..*\n"
483"*.o*.......o*..*\n"
484"*..o*o....o*...*\n"
485"*.*..*.**o*..*.*\n"
486"*....o.*o...x..*\n"
487"****************\n"
488"\n"
489"****************\n"
490"*.o....o..x*...*\n"
491"*..*o*o...*o...*\n"
492"*...*o*....*o..*\n"
493"*...o..*...o*o.*\n"
494"*.*o*...*.o*...*\n"
495"*.o*o.*.o.*....*\n"
496"*o*X..*.....*..*\n"
497"****************\n"
498"\n"
499"****************\n"
500"*o...**.....**o*\n"
501"*.*..*......*o.*\n"
502"*.o*...o**..o..*\n"
503"*.*....*o......*\n"
504"*....*...o*....*\n"
505"*.**.o*.**o..*x*\n"
506"*.o*.*o.....**X*\n"
507"****************\n"
508"\n"
509"****************\n"
510"*...o*o........*\n"
511"**o..o*.**o...**\n"
512"*.*.*.o...*..*.*\n"
513"*.x.*..**..*.Xo*\n"
514"*.*..*...o.*.*.*\n"
515"**...o**.*o..o**\n"
516"*........o*o...*\n"
517"****************";
518
519/**
520 * Display text.
521 */
Jens Arnold4f1ca132006-10-21 00:24:54 +0000522void star_display_text(char *str, bool waitkey)
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000523{
524 int chars_by_line;
525 int lines_by_screen;
526 int chars_for_line;
527 int current_line = 0;
528 int first_char_index = 0;
529 char *ptr_char;
530 char *ptr_line;
531 int i;
532 char line[255];
533 int key;
Jens Arnold2afdf952004-10-22 00:22:07 +0000534 bool go_on;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000535
536 rb->lcd_clear_display();
537
538 chars_by_line = LCD_WIDTH / char_width;
539 lines_by_screen = LCD_HEIGHT / char_height;
540
541 do
542 {
543 ptr_char = str + first_char_index;
544 chars_for_line = 0;
545 i = 0;
546 ptr_line = line;
547 while (i < chars_by_line)
548 {
549 switch (*ptr_char)
550 {
551 case '\t':
552 case ' ':
553 *(ptr_line++) = ' ';
554 case '\n':
555 case '\0':
556 chars_for_line = i;
557 break;
558
559 default:
560 *(ptr_line++) = *ptr_char;
561 }
562 if (*ptr_char == '\n' || *ptr_char == '\0')
563 break;
564 ptr_char++;
565 i++;
566 }
567
568 if (chars_for_line == 0)
569 chars_for_line = i;
570
571 line[chars_for_line] = '\0';
572
Jens Arnold4f1ca132006-10-21 00:24:54 +0000573 /* test if we have cut a word. If it is the case we don't have to */
Daniel Stenberg220fafd2006-03-03 08:14:44 +0000574 /* skip the space */
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000575 if (i == chars_by_line && chars_for_line == chars_by_line)
576 first_char_index += chars_for_line;
577 else
578 first_char_index += chars_for_line + 1;
579
Daniel Stenberg220fafd2006-03-03 08:14:44 +0000580 /* print the line on the screen */
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000581 rb->lcd_putsxy(0, current_line * char_height, line);
582
Daniel Stenberg220fafd2006-03-03 08:14:44 +0000583 /* if the number of line showed on the screen is equals to the */
584 /* maximum number of line we can show, we wait for a key pressed to */
585 /* clear and show the remaining text. */
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000586 current_line++;
587 if (current_line == lines_by_screen || *ptr_char == '\0')
588 {
589 current_line = 0;
590 rb->lcd_update();
Jens Arnold2afdf952004-10-22 00:22:07 +0000591 go_on = false;
592 while (waitkey && !go_on)
593 {
594 key = rb->button_get(true);
595 switch (key)
596 {
Shachar Liberman078e44e2006-08-10 17:21:01 +0000597 case STAR_QUIT:
Jens Arnold29361ab2008-03-22 10:24:28 +0000598 case STAR_LEFT:
Dave Chapman54d44c82005-12-14 01:31:37 +0000599 case STAR_DOWN:
Jens Arnold2afdf952004-10-22 00:22:07 +0000600 go_on = true;
601 break;
Zakk Robertsec216ac2006-06-03 19:24:10 +0000602
Jens Arnold2afdf952004-10-22 00:22:07 +0000603 default:
604 if (rb->default_event_handler(key) == SYS_USB_CONNECTED)
605 {
606 usb_detected = true;
607 go_on = true;
608 break;
609 }
610 }
611 }
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000612 rb->lcd_clear_display();
613 }
614 } while (*ptr_char != '\0');
615}
616
617/**
618 * Do a pretty transition from one level to another.
619 */
620static void star_transition_update(void)
Zakk Robertsec216ac2006-06-03 19:24:10 +0000621{
Antoine Celleriere8c94d82007-06-06 21:10:48 +0000622 const int center_x = LCD_WIDTH / 2;
623 const int center_y = LCD_HEIGHT / 2;
Jens Arnold4f1ca132006-10-21 00:24:54 +0000624 int x = 0;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000625 int y = 0;
Jens Arnold4f1ca132006-10-21 00:24:54 +0000626#if LCD_WIDTH >= LCD_HEIGHT
Antoine Celleriere8c94d82007-06-06 21:10:48 +0000627#if defined(IPOD_VIDEO)
628 const int step = 4;
629#else
630 const int step = 1;
631#endif
632 const int lcd_demi_width = LCD_WIDTH / 2;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000633 int var_y = 0;
634
Antoine Celleriere8c94d82007-06-06 21:10:48 +0000635 for (; x < lcd_demi_width ; x+=step)
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000636 {
637 var_y += LCD_HEIGHT;
638 if (var_y > LCD_WIDTH)
639 {
640 var_y -= LCD_WIDTH;
Antoine Celleriere8c94d82007-06-06 21:10:48 +0000641 y+=step;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000642 }
Antoine Cellerierc05ba512007-10-15 21:00:57 +0000643 if( x )
644 {
645 rb->lcd_update_rect(center_x - x, center_y - y, x*2, step);
646 rb->lcd_update_rect(center_x - x, center_y + y - step, x*2, step);
647 }
648 if( y )
649 {
650 rb->lcd_update_rect(center_x - x, center_y - y, step, y*2);
651 rb->lcd_update_rect(center_x + x - step, center_y - y, step, y*2);
652 }
Antoine Cellerierfb3c0662006-06-11 13:25:44 +0000653 STAR_SLEEP
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000654 }
Jens Arnold4f1ca132006-10-21 00:24:54 +0000655#else
656 int lcd_demi_height = LCD_HEIGHT / 2;
657 int var_x = 0;
658
659 for (; y < lcd_demi_height ; y++)
660 {
661 var_x += LCD_WIDTH;
662 if (var_x > LCD_HEIGHT)
663 {
664 var_x -= LCD_HEIGHT;
665 x++;
666 }
Antoine Cellerierc05ba512007-10-15 21:00:57 +0000667 if( x )
668 {
669 rb->lcd_update_rect(center_x - x, center_y - y, x * 2, 1);
670 rb->lcd_update_rect(center_x - x, center_y + y - 1, x * 2, 1);
671 }
672 if( y )
673 {
674 rb->lcd_update_rect(center_x - x, center_y - y, 1, y * 2);
675 rb->lcd_update_rect(center_x + x - 1, center_y - y, 1, y * 2);
676 }
Jens Arnold4f1ca132006-10-21 00:24:54 +0000677 STAR_SLEEP
678 }
679#endif
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000680 rb->lcd_update();
681}
682
683/**
684 * Display information board of the current level.
685 */
Tom Rossc7f5ccc2007-03-28 07:33:18 +0000686static void star_display_board_info(int current_level)
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000687{
Jens Arnold4f1ca132006-10-21 00:24:54 +0000688 int label_pos_y, tile_pos_y;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000689 char str_info[32];
690
Jens Arnold4f1ca132006-10-21 00:24:54 +0000691 if (TILE_HEIGHT > char_height)
692 {
693 tile_pos_y = LCD_HEIGHT - TILE_HEIGHT;
694 label_pos_y = tile_pos_y + (TILE_HEIGHT - char_height) / 2;
695 }
Antoine Cellerier40a92ea2006-06-10 20:39:33 +0000696 else
Jens Arnold4f1ca132006-10-21 00:24:54 +0000697 {
698 label_pos_y = LCD_HEIGHT - char_height;
699 tile_pos_y = label_pos_y + (char_height - TILE_HEIGHT) / 2;
700 }
Antoine Celleriere8c94d82007-06-06 21:10:48 +0000701
Jens Arnold4f1ca132006-10-21 00:24:54 +0000702 rb->snprintf(str_info, sizeof(str_info), "L:%02d", current_level + 1);
703 rb->lcd_putsxy(STAR_OFFSET_X, label_pos_y, str_info);
704 rb->snprintf(str_info, sizeof(str_info), "S:%02d", star_count);
705 rb->lcd_putsxy(LCD_WIDTH/2 - 2 * char_width, label_pos_y, str_info);
706 rb->lcd_putsxy(STAR_OFFSET_X + (STAR_WIDTH-1) * TILE_WIDTH - 2 * char_width,
707 label_pos_y, "C:");
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000708
Jens Arnold4f1ca132006-10-21 00:24:54 +0000709 rb->lcd_bitmap_part(star_tiles, 0, control == STAR_CONTROL_BALL ?
710 BALL*TILE_HEIGHT : BLOCK*TILE_HEIGHT, TILE_WIDTH,
711 STAR_OFFSET_X + (STAR_WIDTH-1) * TILE_WIDTH,
712 tile_pos_y, TILE_WIDTH, TILE_HEIGHT);
Antoine Cellerier40a92ea2006-06-10 20:39:33 +0000713
Jens Arnold4f1ca132006-10-21 00:24:54 +0000714 rb->lcd_update_rect(0, MIN(label_pos_y, tile_pos_y), LCD_WIDTH,
715 MAX(TILE_HEIGHT, char_height));
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000716}
717
718
719/**
720 * Load a level into board array.
721 */
722static int star_load_level(int current_level)
723{
724 int x, y;
725 char *ptr_tab;
Antoine Celleriere8c94d82007-06-06 21:10:48 +0000726
Tom Rossc7f5ccc2007-03-28 07:33:18 +0000727 if (current_level < 0)
728 current_level = 0;
729 else if (current_level > STAR_LEVEL_COUNT-1)
730 current_level = STAR_LEVEL_COUNT-1;
Antoine Celleriere8c94d82007-06-06 21:10:48 +0000731
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000732
733 ptr_tab = levels + current_level * STAR_LEVEL_SIZE;
734 control = STAR_CONTROL_BALL;
735 star_count = 0;
736
737 rb->lcd_clear_display();
738
739 for (y = 0 ; y < STAR_HEIGHT ; y++)
740 {
741 for (x = 0 ; x < STAR_WIDTH ; x++)
742 {
743 board[y][x] = *ptr_tab;
744 switch (*ptr_tab)
745 {
Jens Arnold4f1ca132006-10-21 00:24:54 +0000746# define DRAW_TILE( a ) \
747 rb->lcd_bitmap_part( star_tiles, 0, \
748 a*TILE_HEIGHT, TILE_WIDTH, \
749 STAR_OFFSET_X + x * TILE_WIDTH, \
750 STAR_OFFSET_Y + y * TILE_HEIGHT, \
751 TILE_WIDTH, TILE_HEIGHT);
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000752 case STAR_VOID:
Jens Arnold4f1ca132006-10-21 00:24:54 +0000753 DRAW_TILE( SPACE );
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000754 break;
755
756 case STAR_WALL:
Jens Arnold4f1ca132006-10-21 00:24:54 +0000757 DRAW_TILE( WALL );
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000758 break;
759
760 case STAR_STAR:
Jens Arnold4f1ca132006-10-21 00:24:54 +0000761 DRAW_TILE( STAR );
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000762 star_count++;
763 break;
764
765 case STAR_BALL:
766 ball_x = x;
767 ball_y = y;
Jens Arnold4f1ca132006-10-21 00:24:54 +0000768 DRAW_TILE( BALL );
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000769 break;
770
771
772 case STAR_BLOCK:
773 block_x = x;
774 block_y = y;
Jens Arnold4f1ca132006-10-21 00:24:54 +0000775 DRAW_TILE( BLOCK );
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000776 break;
777 }
778 ptr_tab++;
779 }
780 ptr_tab++;
781 }
Tom Rossc7f5ccc2007-03-28 07:33:18 +0000782 star_display_board_info(current_level);
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000783 star_transition_update();
784 return 1;
785}
786
Jens Arnold4f1ca132006-10-21 00:24:54 +0000787static void star_animate_tile(int tile_no, int start_x, int start_y,
788 int delta_x, int delta_y)
789{
790 int i;
Antoine Celleriere8c94d82007-06-06 21:10:48 +0000791
Jens Arnold4f1ca132006-10-21 00:24:54 +0000792 if (delta_x != 0) /* horizontal */
793 {
794 for (i = 1 ; i <= TILE_WIDTH ; i++)
795 {
796 STAR_SLEEP
797 rb->lcd_bitmap_part(star_tiles, 0, SPACE * TILE_HEIGHT, TILE_WIDTH,
798 start_x, start_y, TILE_WIDTH, TILE_HEIGHT);
799 rb->lcd_bitmap_part(star_tiles, 0, tile_no * TILE_HEIGHT, TILE_WIDTH,
800 start_x + delta_x * i, start_y, TILE_WIDTH, TILE_HEIGHT);
801 rb->lcd_update_rect(start_x + delta_x * i - (delta_x>0?1:0),
802 start_y, TILE_WIDTH + 1, TILE_HEIGHT);
803 }
804 }
805 else /* vertical */
806 {
807 for (i = 1 ; i <= TILE_HEIGHT ; i++)
808 {
809 STAR_SLEEP
810 rb->lcd_bitmap_part(star_tiles, 0, SPACE * TILE_HEIGHT, TILE_WIDTH,
811 start_x, start_y, TILE_WIDTH, TILE_HEIGHT);
812 rb->lcd_bitmap_part(star_tiles, 0, tile_no * TILE_HEIGHT, TILE_WIDTH,
813 start_x, start_y + delta_y * i, TILE_WIDTH, TILE_HEIGHT);
814 rb->lcd_update_rect(start_x, start_y + delta_y * i - (delta_y>0?1:0),
815 TILE_WIDTH, TILE_HEIGHT + 1);
816 }
817 }
818}
819
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000820/**
821 * Run the game.
822 */
Tom Rossc7f5ccc2007-03-28 07:33:18 +0000823static int star_run_game(int current_level)
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000824{
825 int move_x = 0;
826 int move_y = 0;
Jens Arnold2afdf952004-10-22 00:22:07 +0000827 int key;
828 int lastkey = BUTTON_NONE;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000829
830 int label_offset_y;
831
832 label_offset_y = LCD_HEIGHT - char_height;
833
834 if (!star_load_level(current_level))
835 return 0;
836
837 while (true)
838 {
839 move_x = 0;
840 move_y = 0;
841
Jens Arnold2afdf952004-10-22 00:22:07 +0000842 while ((move_x == 0) && (move_y == 0))
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000843 {
Jens Arnold2afdf952004-10-22 00:22:07 +0000844 key = rb->button_get(true);
845 switch (key)
846 {
Kevin Ferrare0e027bd2006-06-30 16:43:47 +0000847#ifdef STAR_RC_QUIT
848 case STAR_RC_QUIT:
849#endif
Jens Arnold2afdf952004-10-22 00:22:07 +0000850 case STAR_QUIT:
Shachar Liberman078e44e2006-08-10 17:21:01 +0000851 return -1;
Zakk Robertsec216ac2006-06-03 19:24:10 +0000852
Jens Arnold29361ab2008-03-22 10:24:28 +0000853 case STAR_LEFT:
Jens Arnold2afdf952004-10-22 00:22:07 +0000854 move_x = -1;
855 break;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000856
Jens Arnold29361ab2008-03-22 10:24:28 +0000857 case STAR_RIGHT:
Jens Arnold2afdf952004-10-22 00:22:07 +0000858 move_x = 1;
859 break;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000860
Dave Chapman54d44c82005-12-14 01:31:37 +0000861 case STAR_UP:
Jens Arnold2afdf952004-10-22 00:22:07 +0000862 move_y = -1;
863 break;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000864
Dave Chapman54d44c82005-12-14 01:31:37 +0000865 case STAR_DOWN:
Jens Arnold2afdf952004-10-22 00:22:07 +0000866 move_y = 1;
867 break;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000868
Jens Arnold2afdf952004-10-22 00:22:07 +0000869 case STAR_LEVEL_DOWN:
Jens Arnold4f1ca132006-10-21 00:24:54 +0000870#ifdef STAR_LEVEL_DOWN_PRE
871 if (lastkey != STAR_LEVEL_DOWN_PRE)
872 break;
873#endif
Jens Arnold2afdf952004-10-22 00:22:07 +0000874 if (current_level > 0)
875 {
876 current_level--;
877 star_load_level(current_level);
878 }
879 break;
880
881 case STAR_LEVEL_REPEAT:
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000882 star_load_level(current_level);
Jens Arnold2afdf952004-10-22 00:22:07 +0000883 break;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000884
Jens Arnold2afdf952004-10-22 00:22:07 +0000885 case STAR_LEVEL_UP:
Jens Arnold4f1ca132006-10-21 00:24:54 +0000886#ifdef STAR_LEVEL_UP_PRE
887 if (lastkey != STAR_LEVEL_UP_PRE)
888 break;
889#endif
Jens Arnold2afdf952004-10-22 00:22:07 +0000890 if (current_level < STAR_LEVEL_COUNT - 1)
891 {
892 current_level++;
893 star_load_level(current_level);
894 }
895 break;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000896
Jens Arnold2afdf952004-10-22 00:22:07 +0000897 case STAR_TOGGLE_CONTROL:
898#ifdef STAR_TOGGLE_CONTROL_PRE
899 if (lastkey != STAR_TOGGLE_CONTROL_PRE)
900 break;
901#endif
902#ifdef STAR_TOGGLE_CONTROL2
903 case STAR_TOGGLE_CONTROL2:
904#endif
905 if (control == STAR_CONTROL_BALL)
906 control = STAR_CONTROL_BLOCK;
907 else
908 control = STAR_CONTROL_BALL;
Tom Rossc7f5ccc2007-03-28 07:33:18 +0000909 star_display_board_info(current_level);
Jens Arnold2afdf952004-10-22 00:22:07 +0000910 break;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000911
Jens Arnold2afdf952004-10-22 00:22:07 +0000912 default:
913 if (rb->default_event_handler(key) == SYS_USB_CONNECTED)
914 {
915 usb_detected = true;
916 return 0;
917 }
918 break;
919 }
920 if (key != BUTTON_NONE)
921 lastkey = key;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000922 }
923
924 if (control == STAR_CONTROL_BALL)
925 {
926 board[ball_y][ball_x] = STAR_VOID;
927 while ((board[ball_y + move_y][ball_x + move_x] == STAR_VOID
928 || board[ball_y + move_y][ball_x + move_x] == STAR_STAR))
929
930 {
Jens Arnold4f1ca132006-10-21 00:24:54 +0000931 star_animate_tile(BALL, STAR_OFFSET_X + ball_x * TILE_WIDTH,
932 STAR_OFFSET_Y + ball_y * TILE_HEIGHT,
933 move_x, move_y);
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000934 ball_x += move_x;
935 ball_y += move_y;
936
937 if (board[ball_y][ball_x] == STAR_STAR)
938 {
939 board[ball_y][ball_x] = STAR_VOID;
940 star_count--;
941
Tom Rossc7f5ccc2007-03-28 07:33:18 +0000942 star_display_board_info(current_level);
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000943 }
944 }
945 board[ball_y][ball_x] = STAR_BALL;
946 }
947 else
948 {
949 board[block_y][block_x] = STAR_VOID;
950 while (board[block_y + move_y][block_x + move_x] == STAR_VOID)
951 {
Jens Arnold4f1ca132006-10-21 00:24:54 +0000952 star_animate_tile(BLOCK, STAR_OFFSET_X + block_x * TILE_WIDTH,
953 STAR_OFFSET_Y + block_y * TILE_HEIGHT,
954 move_x, move_y);
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000955 block_x += move_x;
956 block_y += move_y;
957 }
958 board[block_y][block_x] = STAR_BLOCK;
959 }
960
961 if (star_count == 0)
962 {
963 current_level++;
964 if (current_level == STAR_LEVEL_COUNT)
965 {
966 rb->lcd_clear_display();
Barry Wardell53c3eeb2006-10-06 16:20:57 +0000967 star_display_text("Congratulations!", true);
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000968 rb->lcd_update();
Antoine Celleriere8c94d82007-06-06 21:10:48 +0000969
Barry Wardell53c3eeb2006-10-06 16:20:57 +0000970 /* There is no such level as STAR_LEVEL_COUNT so it can't be the
971 * current_level */
972 current_level--;
Björn Stenberg020ab8f2003-06-29 21:10:27 +0000973 return 1;
974 }
975 star_load_level(current_level);
976 }
977 }
978}
979
980/**
981 * Display the choice menu.
982 */
983static int star_menu(void)
984{
Tom Rossc7f5ccc2007-03-28 07:33:18 +0000985 int selection, level=1;
986 bool menu_quit = false;
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000987 struct viewport vp[NB_SCREENS];
Tom Rossc7f5ccc2007-03-28 07:33:18 +0000988 /* get the size of char */
989 rb->lcd_getstringsize("a", &char_width, &char_height);
Antoine Celleriere8c94d82007-06-06 21:10:48 +0000990
Tom Rossc7f5ccc2007-03-28 07:33:18 +0000991 MENUITEM_STRINGLIST(menu,"Star Menu",NULL,"Play","Choose Level",
Antoine Celleriere8c94d82007-06-06 21:10:48 +0000992 "Information","Keys","Quit");
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000993 FOR_NB_SCREENS(selection)
994 {
995 rb->viewport_set_defaults(&vp[selection], selection);
996 /* we are hiding the statusbar so fix the height also */
Jonathan Gordon476d2892008-05-18 10:19:21 +0000997 vp[selection].y = 0;
998 vp[selection].height = rb->screens[selection]->height;
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000999#if LCD_DEPTH > 1
1000 if (rb->screens[selection]->depth > 1)
1001 {
1002 vp->bg_pattern = LCD_BLACK;
1003 vp->fg_pattern = LCD_WHITE;
1004 }
1005#endif
1006 }
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001007 while(!menu_quit)
Björn Stenberg020ab8f2003-06-29 21:10:27 +00001008 {
Jonathan Gordon5ca15392008-03-26 03:35:24 +00001009 switch(rb->do_menu(&menu, &selection, vp, true))
Björn Stenberg020ab8f2003-06-29 21:10:27 +00001010 {
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001011 case 0:
1012 menu_quit = true;
Zakk Robertsec216ac2006-06-03 19:24:10 +00001013 break;
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001014 case 1:
Antoine Celleriere8c94d82007-06-06 21:10:48 +00001015 rb->set_int("Level", "", UNIT_INT, &level,
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001016 NULL, 1, 1, STAR_LEVEL_COUNT, NULL );
Zakk Robertsec216ac2006-06-03 19:24:10 +00001017 break;
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001018 case 2:
1019 star_display_text(
1020 "INFO\n\n"
1021 "Take all the stars to go to the next level. "
1022 "You can toggle control with the block to "
1023 "use it as a mobile wall. The block cannot "
1024 "take stars.", true);
1025 break;
1026 case 3:
Jens Arnold2afdf952004-10-22 00:22:07 +00001027#if CONFIG_KEYPAD == RECORDER_PAD
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001028 star_display_text("KEYS\n\n"
1029 "[ON] Toggle Ctl.\n"
1030 "[OFF] Exit\n"
1031 "[F1] Prev. level\n"
1032 "[F2] Reset level\n"
1033 "[F3] Next level", true);
Jens Arnold2afdf952004-10-22 00:22:07 +00001034#elif CONFIG_KEYPAD == ONDIO_PAD
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001035 star_display_text("KEYS\n\n"
1036 "[MODE] Toggle Ctl\n"
1037 "[OFF] Exit\n"
1038 "[M <] Prev. level\n"
1039 "[M ^] Reset level\n"
1040 "[M >] Next level", true);
Antoine Cellerier2d4cfa82006-07-27 22:28:48 +00001041#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001042 star_display_text("KEYS\n\n"
1043 "[MODE/NAVI] Toggle Ctrl\n"
1044 "[OFF] Exit\n"
1045 "[ON + LEFT] Prev. level\n"
1046 "[ON + NAVI] Reset level\n"
1047 "[ON + RIGHT] Next level", true);
Jens Arnoldb7013222007-07-27 09:57:27 +00001048#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1049 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001050 star_display_text("KEYS\n\n"
1051 "[SELECT] Toggle Ctl\n"
1052 "[S + MENU] Exit\n"
1053 "[S <] Prev. level\n"
1054 "[S + PLAY] Reset level\n"
1055 "[S >] Next level", true);
Jens Arnold85a226d2007-03-16 23:02:39 +00001056#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001057 star_display_text("KEYS\n\n"
1058 "[SELECT] Toggle Ctl\n"
1059 "[POWER] Exit\n"
1060 "[REC..] Prev. level\n"
1061 "[PLAY] Reset level\n"
1062 "[REC] Next level", true);
Antoine Cellerier2d4cfa82006-07-27 22:28:48 +00001063#elif CONFIG_KEYPAD == GIGABEAT_PAD
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001064 star_display_text("KEYS\n\n"
1065 "[MENU] Toggle Control\n"
1066 "[A] Exit\n"
1067 "[PWR+DOWN] Prev. level\n"
1068 "[PWR+RIGHT] Reset level\n"
1069 "[PWR+UP] Next level", true);
Barry Wardell6fdd4b02006-10-18 00:20:07 +00001070#elif CONFIG_KEYPAD == IRIVER_H10_PAD
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001071 star_display_text("KEYS\n\n"
1072 "[REW] Toggle Ctl\n"
1073 "[POWER] Exit\n"
1074 "[PLAY+DOWN] Prev. level\n"
1075 "[PLAY+RIGHT] Reset level\n"
1076 "[PLAY+UP] Next level", true);
Jens Arnold2afdf952004-10-22 00:22:07 +00001077#endif
Rob Purchase297e0502008-04-27 15:30:19 +00001078#ifdef HAVE_TOUCHPAD
1079 star_display_text("KEYS\n\n"
1080 STAR_TOGGLE_CONTROL_NAME " Toggle Control\n"
1081 STAR_QUIT_NAME " Exit\n"
1082 STAR_LEVEL_DOWN_NAME " Prev. level\n"
1083 STAR_LEVEL_REPEAT_NAME " Reset level\n"
1084 STAR_LEVEL_UP_NAME " Next level", true);
1085#endif
Zakk Robertsec216ac2006-06-03 19:24:10 +00001086 break;
Björn Stenberg020ab8f2003-06-29 21:10:27 +00001087 default:
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001088 menu_quit = true;
Jens Arnold2afdf952004-10-22 00:22:07 +00001089 break;
Björn Stenberg020ab8f2003-06-29 21:10:27 +00001090 }
Björn Stenberg020ab8f2003-06-29 21:10:27 +00001091 }
Antoine Celleriere8c94d82007-06-06 21:10:48 +00001092
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001093 if (selection == MENU_START)
1094 {
1095 rb->lcd_setfont(FONT_SYSFIXED);
1096 rb->lcd_getstringsize("a", &char_width, &char_height);
1097 level--;
1098 star_run_game(level);
1099 }
Antoine Celleriere8c94d82007-06-06 21:10:48 +00001100
Tom Rossc7f5ccc2007-03-28 07:33:18 +00001101 return PLUGIN_OK;
Björn Stenberg020ab8f2003-06-29 21:10:27 +00001102}
1103
1104/**
1105 * Main entry point
1106 */
Steve Bavin65265772008-05-13 09:57:56 +00001107enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
Björn Stenberg020ab8f2003-06-29 21:10:27 +00001108{
Björn Stenberg020ab8f2003-06-29 21:10:27 +00001109 (void)parameter;
1110 rb = api;
1111
Antoine Celleriera3220812006-07-27 22:04:07 +00001112#if LCD_DEPTH > 1
Karl Kurbjund6b0c972006-11-15 06:14:27 +00001113 rb->lcd_set_backdrop(NULL);
Antoine Cellerier40a92ea2006-06-10 20:39:33 +00001114 rb->lcd_set_background( LCD_BLACK );
1115 rb->lcd_set_foreground( LCD_WHITE );
1116#endif
1117
Björn Stenberg020ab8f2003-06-29 21:10:27 +00001118 /* display choice menu */
1119 return star_menu();
1120}
1121
1122#endif