very minor code police. also fix a possible but unlikely missed cpu_boost(false)
[Rockbox.git] / apps / plugins / brickmania.c
blobc3cdcad967609cb611ceb6953f9d73c8fa273d47
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005, 2006 Ben Basha (Paprica)
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 ****************************************************************************/
22 #include "plugin.h"
23 #include "configfile.h" /* Part of libplugin */
24 #include "helper.h"
26 PLUGIN_HEADER
29 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
31 #define QUIT BUTTON_OFF
32 #define LEFT BUTTON_LEFT
33 #define RIGHT BUTTON_RIGHT
34 #define SELECT BUTTON_SELECT
35 #define UP BUTTON_UP
36 #define DOWN BUTTON_DOWN
38 #define RC_QUIT BUTTON_RC_STOP
41 #elif CONFIG_KEYPAD == ONDIO_PAD
43 #define QUIT BUTTON_OFF
44 #define LEFT BUTTON_LEFT
45 #define RIGHT BUTTON_RIGHT
46 #define SELECT BUTTON_MENU
47 #define UP BUTTON_UP
48 #define DOWN BUTTON_DOWN
51 #elif CONFIG_KEYPAD == RECORDER_PAD
53 #define QUIT BUTTON_OFF
54 #define LEFT BUTTON_LEFT
55 #define RIGHT BUTTON_RIGHT
56 #define SELECT BUTTON_PLAY
57 #define UP BUTTON_UP
58 #define DOWN BUTTON_DOWN
61 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
63 #define QUIT BUTTON_OFF
64 #define LEFT BUTTON_LEFT
65 #define RIGHT BUTTON_RIGHT
66 #define SELECT BUTTON_SELECT
67 #define UP BUTTON_UP
68 #define DOWN BUTTON_DOWN
71 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
72 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
73 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
75 #define QUIT BUTTON_MENU
76 #define LEFT BUTTON_LEFT
77 #define RIGHT BUTTON_RIGHT
78 #define SELECT BUTTON_SELECT
79 #define UP BUTTON_SCROLL_BACK
80 #define DOWN BUTTON_SCROLL_FWD
82 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD)
83 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK)
86 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
88 #define QUIT BUTTON_POWER
89 #define LEFT BUTTON_LEFT
90 #define RIGHT BUTTON_RIGHT
91 #define SELECT BUTTON_SELECT
92 #define UP BUTTON_UP
93 #define DOWN BUTTON_DOWN
96 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
98 #define QUIT BUTTON_POWER
99 #define LEFT BUTTON_LEFT
100 #define RIGHT BUTTON_RIGHT
101 #define SELECT BUTTON_PLAY
102 #define UP BUTTON_UP
103 #define DOWN BUTTON_DOWN
106 #elif CONFIG_KEYPAD == SANSA_E200_PAD
108 #define QUIT BUTTON_POWER
109 #define LEFT BUTTON_LEFT
110 #define RIGHT BUTTON_RIGHT
111 #define SELECT BUTTON_SELECT
112 #define UP BUTTON_SCROLL_BACK
113 #define DOWN BUTTON_SCROLL_FWD
115 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD)
116 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK)
119 #elif CONFIG_KEYPAD == SANSA_C200_PAD
121 #define QUIT BUTTON_POWER
122 #define LEFT BUTTON_LEFT
123 #define RIGHT BUTTON_RIGHT
124 #define ALTLEFT BUTTON_VOL_DOWN
125 #define ALTRIGHT BUTTON_VOL_UP
126 #define SELECT BUTTON_SELECT
127 #define UP BUTTON_UP
128 #define DOWN BUTTON_DOWN
131 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
133 #define QUIT BUTTON_POWER
134 #define LEFT BUTTON_LEFT
135 #define RIGHT BUTTON_RIGHT
136 #define SELECT BUTTON_PLAY
137 #define UP BUTTON_SCROLL_UP
138 #define DOWN BUTTON_SCROLL_DOWN
140 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
142 #define QUIT BUTTON_BACK
143 #define LEFT BUTTON_LEFT
144 #define RIGHT BUTTON_RIGHT
145 #define SELECT BUTTON_SELECT
146 #define UP BUTTON_UP
147 #define DOWN BUTTON_DOWN
149 #elif (CONFIG_KEYPAD == MROBE100_PAD)
151 #define QUIT BUTTON_POWER
152 #define LEFT BUTTON_LEFT
153 #define RIGHT BUTTON_RIGHT
154 #define SELECT BUTTON_SELECT
155 #define UP BUTTON_UP
156 #define DOWN BUTTON_DOWN
158 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
160 #define QUIT BUTTON_RC_REC
161 #define LEFT BUTTON_RC_REW
162 #define RIGHT BUTTON_RC_FF
163 #define SELECT BUTTON_RC_PLAY
164 #define UP BUTTON_RC_VOL_UP
165 #define DOWN BUTTON_RC_VOL_DOWN
167 #define RC_QUIT BUTTON_REC
169 #elif CONFIG_KEYPAD == COWOND2_PAD
170 #define QUIT BUTTON_POWER
172 #else
173 #error No keymap defined!
174 #endif
176 #ifdef HAVE_TOUCHPAD
177 #ifndef LEFT
178 #define LEFT BUTTON_MIDLEFT
179 #endif
180 #ifndef RIGHT
181 #define RIGHT BUTTON_MIDRIGHT
182 #endif
183 #ifndef SELECT
184 #define SELECT BUTTON_CENTER
185 #endif
186 #ifndef UP
187 #define UP BUTTON_TOPMIDDLE
188 #endif
189 #ifndef DOWN
190 #define DOWN BUTTON_BOTTOMMIDDLE
191 #endif
192 #endif
194 #ifndef SCROLL_FWD /* targets without scroll wheel*/
195 #define SCROLL_FWD(x) (0)
196 #define SCROLL_BACK(x) (0)
197 #endif
200 static const struct plugin_api* rb;
202 enum menu_items {
203 BM_START,
204 BM_SEL_START,
205 BM_RESUME,
206 BM_SEL_RESUME,
207 BM_NO_RESUME,
208 BM_HELP,
209 BM_SEL_HELP,
210 BM_QUIT,
211 BM_SEL_QUIT,
214 #include "brickmania_pads.h"
215 #include "brickmania_bricks.h"
216 #include "brickmania_powerups.h"
217 #include "brickmania_ball.h"
218 #include "brickmania_menu_items.h"
219 #include "brickmania_gameover.h"
221 #define PAD_WIDTH BMPWIDTH_brickmania_pads
222 #define PAD_HEIGHT (BMPHEIGHT_brickmania_pads/3)
223 #define BRICK_HEIGHT (BMPHEIGHT_brickmania_bricks/7)
224 #define BRICK_WIDTH BMPWIDTH_brickmania_bricks
225 #define LEFTMARGIN ((LCD_WIDTH-10*BRICK_WIDTH)/2)
226 #define POWERUP_HEIGHT (BMPHEIGHT_brickmania_powerups/7)
227 #define POWERUP_WIDTH BMPWIDTH_brickmania_powerups
228 #define BALL BMPHEIGHT_brickmania_ball
229 #define HALFBALL ((BALL+1)/2)
230 #define MENU_ITEMXOFS ((LCD_WIDTH - BMPWIDTH_brickmania_menu_items)/2)
231 #define MENU_ITEMHEIGHT (BMPHEIGHT_brickmania_menu_items/9)
232 #define MENU_ITEMWIDTH BMPWIDTH_brickmania_menu_items
233 #define GAMEOVER_WIDTH BMPWIDTH_brickmania_gameover
234 #define GAMEOVER_HEIGHT BMPHEIGHT_brickmania_gameover
236 #if LCD_DEPTH > 1 /* currently no background bmp for mono screens */
237 #include "brickmania_menu_bg.h"
238 #define MENU_BGHEIGHT BMPHEIGHT_brickmania_menu_bg
239 #define MENU_BGWIDTH BMPWIDTH_brickmania_menu_bg
240 #endif
242 #ifdef HAVE_LCD_COLOR /* currently no transparency for non-colour */
243 #include "brickmania_break.h"
244 #endif
246 #if (LCD_WIDTH == 320) && (LCD_HEIGHT == 240)
248 /* The time (in ms) for one iteration through the game loop - decrease this
249 to speed up the game - note that current_tick is (currently) only accurate
250 to 10ms.
252 #define CYCLETIME 30
254 #define TOPMARGIN 30
256 #define BMPYOFS_start 110
257 #define HIGHSCORE_XPOS 57
258 #define HIGHSCORE_YPOS 88
260 #define STRINGPOS_FINISH 140
261 #define STRINGPOS_CONGRATS 157
262 #define STRINGPOS_NAVI 150
263 #define STRINGPOS_FLIP 150
265 #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176)
267 /* The time (in ms) for one iteration through the game loop - decrease this
268 to speed up the game - note that current_tick is (currently) only accurate
269 to 10ms.
271 #define CYCLETIME 30
273 /* Offsets for LCDS > 220x176 */
275 #define GAMESCREEN_HEIGHT 176
276 #define TOPMARGIN 30
278 #define XOFS ((LCD_WIDTH-220)/BRICK_WIDTH/2)*BRICK_WIDTH
279 #define YOFS ((LCD_HEIGHT-176)/BRICK_HEIGHT/2)*BRICK_HEIGHT
281 #define BMPYOFS_start (78+YOFS)
282 #define HIGHSCORE_XPOS (17+XOFS)
283 #define HIGHSCORE_YPOS (56+YOFS)
285 #define STRINGPOS_FINISH 140
286 #define STRINGPOS_CONGRATS 157
287 #define STRINGPOS_NAVI 150
288 #define STRINGPOS_FLIP 150
290 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
291 /* The time (in ms) for one iteration through the game loop - decrease this
292 to speed up the game - note that current_tick is (currently) only accurate
293 to 10ms.
295 #define CYCLETIME 50
297 #define TOPMARGIN 21
299 #if LCD_DEPTH > 2
300 #define BMPYOFS_start 58
301 #else
302 #define BMPYOFS_start 66
303 #endif
304 #define HIGHSCORE_XPOS 10
305 #define HIGHSCORE_YPOS 38
307 #define STRINGPOS_FINISH 110
308 #define STRINGPOS_CONGRATS 100
309 #define STRINGPOS_NAVI 100
310 #define STRINGPOS_FLIP 100
312 #elif (LCD_WIDTH == 132) && (LCD_HEIGHT == 80)
314 /* The time (in ms) for one iteration through the game loop - decrease this
315 to speed up the game - note that current_tick is (currently) only accurate
316 to 10ms.
318 #define CYCLETIME 50
320 #define TOPMARGIN 10
322 #define BMPYOFS_start 30
323 #define HIGHSCORE_XPOS 68
324 #define HIGHSCORE_YPOS 8
326 #define STRINGPOS_FINISH 55
327 #define STRINGPOS_CONGRATS 45
328 #define STRINGPOS_NAVI 60
329 #define STRINGPOS_FLIP 60
331 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128)
333 /* The time (in ms) for one iteration through the game loop - decrease this
334 to speed up the game - note that current_tick is (currently) only accurate
335 to 10ms.
337 #define CYCLETIME 50
339 #define GAMESCREEN_HEIGHT 100
340 #define TOPMARGIN 15
342 #define BMPYOFS_start 70
343 #define HIGHSCORE_XPOS 8
344 #define HIGHSCORE_YPOS 36
346 #define STRINGPOS_FINISH 55
347 #define STRINGPOS_CONGRATS 45
348 #define STRINGPOS_NAVI 60
349 #define STRINGPOS_FLIP 60
351 /* iPod Mini */
352 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
353 /* The time (in ms) for one iteration through the game loop - decrease this
354 to speed up the game - note that current_tick is (currently) only accurate
355 to 10ms.
357 #define CYCLETIME 50
359 #define TOPMARGIN 10
361 #define BMPYOFS_start 51
362 #define HIGHSCORE_XPOS 73
363 #define HIGHSCORE_YPOS 25
365 #define STRINGPOS_FINISH 54
366 #define STRINGPOS_CONGRATS 44
367 #define STRINGPOS_NAVI 44
368 #define STRINGPOS_FLIP 44
370 /* iAudio M3 */
371 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 96)
372 /* The time (in ms) for one iteration through the game loop - decrease this
373 to speed up the game - note that current_tick is (currently) only accurate
374 to 10ms.
376 #define CYCLETIME 50
378 #define TOPMARGIN 10
380 #define BMPYOFS_start 42
381 #define HIGHSCORE_XPOS 65
382 #define HIGHSCORE_YPOS 25
384 #define STRINGPOS_FINISH 54
385 #define STRINGPOS_CONGRATS 44
386 #define STRINGPOS_NAVI 44
387 #define STRINGPOS_FLIP 44
389 /* Archos */
390 #elif (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
391 /* The time (in ms) for one iteration through the game loop - decrease this
392 to speed up the game - note that current_tick is (currently) only accurate
393 to 10ms.
395 #define CYCLETIME 75
397 #define TOPMARGIN 10
399 #define BMPYOFS_start 22
400 #define HIGHSCORE_XPOS 0
401 #define HIGHSCORE_YPOS 0
403 #define STRINGPOS_FINISH 54
404 #define STRINGPOS_CONGRATS 44
405 #define STRINGPOS_NAVI 44
406 #define STRINGPOS_FLIP 44
408 /* nano and sansa */
409 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT >= 132) && (LCD_DEPTH==16)
410 /* The time (in ms) for one iteration through the game loop - decrease this
411 to speed up the game - note that current_tick is (currently) only accurate
412 to 10ms.
415 #define CYCLETIME 30
417 #define GAMESCREEN_HEIGHT 132
418 #define TOPMARGIN 21
420 #define BMPYOFS_start 58
421 #define HIGHSCORE_XPOS 7
422 #define HIGHSCORE_YPOS 36
424 #define STRINGPOS_FINISH 110
425 #define STRINGPOS_CONGRATS 110
426 #define STRINGPOS_NAVI 100
427 #define STRINGPOS_FLIP 100
429 #else
430 #error Unsupported LCD Size
431 #endif
434 #ifndef GAMESCREEN_HEIGHT
435 #define GAMESCREEN_HEIGHT LCD_HEIGHT
436 #endif
438 /* calculate menu item offsets from the first defined and the height*/
439 #define BMPYOFS_resume (BMPYOFS_start + MENU_ITEMHEIGHT)
440 #define BMPYOFS_help (BMPYOFS_start + 2*MENU_ITEMHEIGHT)
441 #define BMPYOFS_quit (BMPYOFS_start + 3*MENU_ITEMHEIGHT)
443 /*calculate paddle y-position */
444 #if GAMESCREEN_HEIGHT >= 128
445 #define PAD_POS_Y GAMESCREEN_HEIGHT -PAD_HEIGHT - 2
446 #else
447 #define PAD_POS_Y GAMESCREEN_HEIGHT -PAD_HEIGHT - 1
448 #endif
451 #ifdef HAVE_TOUCHPAD
452 #include "lib/touchscreen.h"
454 static struct ts_mapping main_menu_items[4] =
456 {MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
457 {MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
458 {MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
459 {MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH, MENU_ITEMHEIGHT}
461 static struct ts_mappings main_menu = {main_menu_items, 4};
462 #endif
465 int levels_num = 29;
467 static unsigned char levels[29][8][10] = {
468 { /* level1 */
469 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
470 {0x2,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x2},
471 {0x0,0x2,0x1,0x0,0x0,0x0,0x0,0x1,0x2,0x0},
472 {0x0,0x0,0x2,0x1,0x0,0x0,0x1,0x2,0x0,0x0},
473 {0x0,0x0,0x0,0x2,0x1,0x1,0x2,0x0,0x0,0x0},
474 {0x7,0x0,0x0,0x7,0x2,0x2,0x7,0x0,0x0,0x7},
475 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
476 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
478 { /* level2 */
479 {0x0,0x0,0x7,0x7,0x1,0x1,0x7,0x7,0x0,0x0},
480 {0x0,0x1,0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x0},
481 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
482 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1},
483 {0x1,0x1,0x2,0x1,0x0,0x0,0x1,0x2,0x1,0x1},
484 {0x1,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x2,0x1},
485 {0x0,0x1,0x2,0x0,0x0,0x0,0x0,0x2,0x1,0x0},
486 {0x0,0x0,0x1,0x2,0x2,0x2,0x2,0x1,0x0,0x0}
488 { /* level3 */
489 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
490 {0x3,0x23,0x23,0x3,0x0,0x0,0x2,0x22,0x22,0x2},
491 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
492 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
493 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
494 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6},
495 {0x5,0x25,0x25,0x5,0x0,0x0,0x6,0x26,0x26,0x6},
496 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6}
498 { /* level4 */
499 {0x0,0x0,0x0,0x27,0x27,0x27,0x27,0x0,0x0,0x0},
500 {0x0,0x0,0x0,0x27,0x7,0x7,0x27,0x0,0x0,0x0},
501 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
502 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
503 {0x26,0x6,0x0,0x2,0x2,0x2,0x2,0x0,0x6,0x26},
504 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
505 {0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0},
506 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1}
508 { /* level5 */
509 {0x1,0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4},
510 {0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0},
511 {0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5},
512 {0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5,0x5},
513 {0x0,0x33,0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0},
514 {0x3,0x33,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x36},
515 {0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x6,0x36},
516 {0x0,0x24,0x24,0x0,0x25,0x25,0x0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,0x3,0x3,0x2,0x0,0x0,0x4},
603 {0x4,0x0,0x2,0x23,0x3,0x3,0x23,0x2,0x0,0x4},
604 {0x4,0x0,0x2,0x22,0x2,0x2,0x22,0x2,0x0,0x4},
605 {0x4,0x0,0x6,0x21,0x5,0x5,0x21,0x6,0x0,0x4},
606 {0x4,0x6,0x1,0x1,0x5,0x5,0x1,0x1,0x6,0x4}
608 {/* level 15 */
609 {0x4,0x4,0x4,0x4,0x4,0x3,0x3,0x3,0x3,0x3},
610 {0x2,0x2,0x1,0x1,0x1,0x1,0x1,0x5,0x0,0x0},
611 {0x2,0x2,0x1,0x1,0x1,0x0,0x1,0x6,0x0,0x0},
612 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x5,0x0,0x0},
613 {0x2,0x1,0x2,0x2,0x2,0x1,0x1,0x6,0x0,0x0},
614 {0x2,0x1,0x2,0x2,0x2,0x1,0x3,0x5,0x3,0x0},
615 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x6,0x0,0x0},
616 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
618 {/* level 16 (Rockbox) by ts-x */
619 {0x2,0x2,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
620 {0x2,0x0,0x3,0x0,0x3,0x4,0x0,0x5,0x5,0x0},
621 {0x2,0x0,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
622 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
623 {0x6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
624 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0},
625 {0x7,0x0,0x7,0x1,0x0,0x1,0x0,0x2,0x0,0x0},
626 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0}
628 {/* level 17 (Alien) by ts-x */
629 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
630 {0x2,0x0,0x0,0x0,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,0x0,0x1,0x0}
658 { /* level 20 (Maze) by ts-x */
659 {0x1,0x1,0x21,0x1,0x1,0x1,0x1,0x1,0x1,0x21},
660 {0x1,0x0,0x0,0x3,0x0,0x0,0x3,0x1,0x31,0x1},
661 {0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x31,0x0,0x1},
662 {0x21,0x0,0x21,0x3,0x0,0x3,0x0,0x3,0x0,0x2},
663 {0x1,0x0,0x1,0x21,0x0,0x12,0x0,0x0,0x0,0x0},
664 {0x31,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x3,0x0},
665 {0x1,0x0,0x1,0x0,0x1,0x1,0x31,0x1,0x1,0x2},
666 {0x22,0x0,0x2,0x1,0x1,0x1,0x1,0x1,0x1,0x21}
668 { /* level 21 (Dentist) by ts-x */
669 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0},
670 {0x2,0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x2,0x2},
671 {0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x2},
672 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x6,0x0,0x2},
673 {0x2,0x0,0x6,0x0,0x6,0x0,0x0,0x0,0x0,0x2},
674 {0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x2},
675 {0x2,0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x2,0x2},
676 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0}
678 { /* level 22 (Spider) by ts-x */
679 {0x31,0x3,0x1,0x1,0x0,0x0,0x1,0x1,0x3,0x31},
680 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
681 {0x33,0x1,0x1,0x36,0x1,0x1,0x36,0x1,0x1,0x33},
682 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
683 {0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x1,0x0,0x0},
684 {0x21,0x3,0x1,0x21,0x2,0x2,0x21,0x1,0x3,0x21},
685 {0x0,0x0,0x0,0x1,0x21,0x1,0x1,0x0,0x0,0x0},
686 {0x3,0x1,0x3,0x1,0x0,0x0,0x1,0x3,0x1,0x3}
688 { /* level 23 (Pool) by ts-x */
689 {0x0,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x7,0x0},
690 {0x0,0x0,0x5,0x0,0x2,0x0,0x0,0x0,0x2,0x0},
691 {0x7,0x3,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x7},
692 {0x7,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x0,0x7},
693 {0x7,0x0,0x4,0x0,0x0,0x3,0x0,0x0,0x0,0x7},
694 {0x7,0x0,0x0,0x6,0x0,0x0,0x0,0x0,0x4,0x7},
695 {0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
696 {0x0,0x7,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x0}
698 { /* level 24 (Vorbis Fish) by ts-x */
699 {0x0,0x0,0x4,0x4,0x5,0x5,0x5,0x0,0x0,0x5},
700 {0x0,0x4,0x6,0x4,0x4,0x5,0x5,0x5,0x0,0x5},
701 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x5,0x5,0x5},
702 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x4,0x5,0x5},
703 {0x0,0x5,0x6,0x4,0x4,0x5,0x5,0x4,0x5,0x0},
704 {0x5,0x5,0x4,0x4,0x5,0x5,0x5,0x4,0x5,0x5},
705 {0x5,0x4,0x4,0x4,0x5,0x5,0x4,0x4,0x5,0x5},
706 {0x0,0x0,0x4,0x4,0x4,0x4,0x4,0x5,0x0,0x5}
708 {/* level 25 (Rainbow) by ts-x */
709 {0x0,0x4,0x1,0x0,0x0,0x0,0x0,0x1,0x4,0x0},
710 {0x24,0x1,0x3,0x1,0x0,0x0,0x21,0x3,0x1,0x24},
711 {0x1,0x23,0x5,0x3,0x1,0x21,0x3,0x5,0x3,0x21},
712 {0x3,0x5,0x6,0x5,0x3,0x3,0x5,0x6,0x5,0x3},
713 {0x5,0x6,0x7,0x6,0x5,0x5,0x6,0x7,0x6,0x5},
714 {0x6,0x7,0x2,0x27,0x6,0x6,0x27,0x2,0x7,0x6},
715 {0x7,0x2,0x0,0x2,0x27,0x27,0x2,0x0,0x2,0x7},
716 {0x32,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x32}
718 { /* level 26 (Bowtie) by ts-x */
719 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5},
720 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
721 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
722 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
723 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
724 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
725 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
726 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5}
728 { /* level 27 (Frog) by ts-x */
729 {0x0,0x5,0x25,0x0,0x0,0x0,0x0,0x25,0x5,0x0},
730 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5},
731 {0x25,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x25},
732 {0x5,0x0,0x3,0x0,0x6,0x6,0x0,0x3,0x0,0x5},
733 {0x5,0x0,0x31,0x0,0x6,0x6,0x0,0x31,0x0,0x5},
734 {0x5,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x5},
735 {0x5,0x5,0x5,0x35,0x0,0x0,0x35,0x5,0x5,0x5},
736 {0x0,0x25,0x5,0x0,0x4,0x4,0x0,0x5,0x25,0x0}
738 { /* level 28 (DigDug) by ts-x */
739 {0x35,0x5,0x5,0x25,0x0,0x25,0x25,0x5,0x5,0x35},
740 {0x6,0x0,0x0,0x6,0x0,0x6,0x6,0x0,0x0,0x6},
741 {0x7,0x0,0x37,0x37,0x0,0x37,0x37,0x7,0x0,0x7},
742 {0x7,0x0,0x7,0x0,0x0,0x0,0x7,0x7,0x7,0x7},
743 {0x4,0x4,0x4,0x24,0x0,0x24,0x4,0x0,0x0,0x4},
744 {0x4,0x4,0x0,0x0,0x0,0x4,0x4,0x0,0x4,0x4},
745 {0x24,0x24,0x4,0x4,0x4,0x4,0x0,0x0,0x24,0x4},
746 {0x1,0x1,0x1,0x1,0x1,0x1,0x21,0x21,0x1,0x1}
748 { /* TheEnd */
749 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
750 {0x22,0x22,0x26,0x0,0x0,0x26,0x24,0x24,0x0,0x0},
751 {0x22,0x0,0x26,0x26,0x0,0x26,0x24,0x0,0x24,0x0},
752 {0x22,0x22,0x26,0x26,0x0,0x26,0x24,0x0,0x24,0x0},
753 {0x22,0x22,0x26,0x0,0x26,0x26,0x24,0x0,0x24,0x0},
754 {0x22,0x0,0x26,0x0,0x26,0x26,0x24,0x0,0x24,0x0},
755 {0x22,0x22,0x26,0x0,0x0,0x26,0x24,0x24,0x0,0x0},
756 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
760 #define MAX_BALLS 10
761 int pad_pos_x;
762 int x[MAX_BALLS],y[MAX_BALLS];
763 int life;
764 int start_game,con_game;
765 int pad_type;
766 int score=0,vscore=0;
767 bool flip_sides=false;
768 int cur_level=0;
769 int brick_on_board=0;
770 int used_balls=1;
772 typedef struct cube {
773 int powertop;
774 int power;
775 char poweruse;
776 char used;
777 int color;
778 int hits;
779 int hiteffect;
780 } cube;
781 cube brick[80];
783 typedef struct balls {
784 int pos_x;
785 int pos_y;
786 int y;
787 int tempy;
788 int x;
789 int tempx;
790 bool glue;
791 } balls;
793 balls ball[MAX_BALLS];
795 typedef struct sfire {
796 int top;
797 int left;
798 } sfire;
799 sfire fire[30];
802 int highscore;
803 #define MAX_POINTS 200000 /* i dont think it needs to be more */
804 static struct configdata config[] =
806 {TYPE_INT, 0, MAX_POINTS, &highscore, "highscore", NULL, NULL}
809 void int_game(int new_game)
811 int i,j;
813 pad_pos_x=LCD_WIDTH/2-PAD_WIDTH/2;
815 for(i=0;i<MAX_BALLS;i++) {
816 ball[i].x=0;
817 ball[i].y=0;
818 ball[i].tempy=0;
819 ball[i].tempx=0;
820 ball[i].pos_y=PAD_POS_Y-BALL;
821 ball[i].pos_x=pad_pos_x+(PAD_WIDTH/2)-2;
822 ball[i].glue=false;
825 used_balls=1;
826 start_game =1;
827 con_game =0;
828 pad_type=0;
830 flip_sides=false;
832 if (new_game==1)
833 brick_on_board=0;
835 for(i=0;i<=7;i++) {
836 for(j=0;j<=9;j++) {
837 brick[i*10+j].poweruse=(levels[cur_level][i][j]==0?0:1);
838 if (i*10+j<=30)
839 fire[i*10+j].top=-8;
840 if (new_game==1) {
841 brick[i*10+j].power=rb->rand()%25;
842 /* +8 make the game with less powerups */
844 brick[i*10+j].hits=levels[cur_level][i][j]>=10?
845 levels[cur_level][i][j]/16-1:0;
846 brick[i*10+j].hiteffect=0;
847 brick[i*10+j].powertop=TOPMARGIN+i*BRICK_HEIGHT+BRICK_HEIGHT;
848 brick[i*10+j].used=(levels[cur_level][i][j]==0?0:1);
849 brick[i*10+j].color=(levels[cur_level][i][j]>=10?
850 levels[cur_level][i][j]%16:
851 levels[cur_level][i][j])-1;
852 if (levels[cur_level][i][j]!=0)
853 brick_on_board++;
859 int sw,i,w;
861 /* sleep timer counting the score */
862 void sleep (int secs)
864 bool done=false;
865 char s[20];
866 int count=0;
868 while (!done) {
870 if (vscore<score) {
871 vscore++;
872 rb->snprintf(s, sizeof(s), "%d", vscore);
873 rb->lcd_getstringsize(s, &sw, &w);
874 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
875 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
876 #else
877 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s);
878 #endif
879 rb->lcd_update_rect(0,0,LCD_WIDTH,w+2);
880 } else {
881 if (count==0)
882 count=*rb->current_tick+HZ*secs;
883 if (*rb->current_tick>=count)
884 done=true;
886 rb->yield();
891 #define HIGH_SCORE "brickmania.score"
892 #define MENU_LENGTH 4
893 int game_menu(int when)
895 int button,cur=0;
896 char str[10];
897 rb->lcd_clear_display();
898 #if LCD_DEPTH > 1 /* currently no background bmp for mono screens */
899 rb->lcd_bitmap(brickmania_menu_bg, 0, 0, MENU_BGWIDTH, MENU_BGHEIGHT);
900 #endif
901 while (true) {
902 for(i=0;i<MENU_LENGTH;i++) {
903 #ifdef HAVE_LCD_COLOR
904 if (cur==0)
905 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
906 MENU_ITEMHEIGHT * BM_SEL_START, MENU_ITEMWIDTH,
907 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
908 MENU_ITEMHEIGHT);
909 else
910 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
911 MENU_ITEMHEIGHT * BM_START, MENU_ITEMWIDTH,
912 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
913 MENU_ITEMHEIGHT);
915 if (when==1) {
916 if (cur==1)
917 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
918 MENU_ITEMHEIGHT * BM_SEL_RESUME, MENU_ITEMWIDTH,
919 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
920 MENU_ITEMHEIGHT);
921 else
922 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
923 MENU_ITEMHEIGHT * BM_RESUME, MENU_ITEMWIDTH,
924 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
925 MENU_ITEMHEIGHT);
927 } else {
928 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
929 MENU_ITEMHEIGHT * BM_NO_RESUME, MENU_ITEMWIDTH,
930 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
931 MENU_ITEMHEIGHT);
935 if (cur==2)
936 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
937 MENU_ITEMHEIGHT * BM_SEL_HELP, MENU_ITEMWIDTH,
938 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
939 MENU_ITEMHEIGHT);
940 else
941 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
942 MENU_ITEMHEIGHT * BM_HELP, MENU_ITEMWIDTH,
943 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
944 MENU_ITEMHEIGHT);
946 if (cur==3)
947 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
948 MENU_ITEMHEIGHT * BM_SEL_QUIT, MENU_ITEMWIDTH,
949 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
950 MENU_ITEMHEIGHT);
951 else
952 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
953 MENU_ITEMHEIGHT * BM_QUIT, MENU_ITEMWIDTH,
954 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
955 MENU_ITEMHEIGHT);
956 #else
957 if (cur==0)
958 rb->lcd_bitmap_part(brickmania_menu_items, 0,
959 MENU_ITEMHEIGHT * BM_SEL_START, MENU_ITEMWIDTH,
960 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
961 MENU_ITEMHEIGHT);
962 else
963 rb->lcd_bitmap_part(brickmania_menu_items, 0,
964 MENU_ITEMHEIGHT * BM_START, MENU_ITEMWIDTH,
965 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
966 MENU_ITEMHEIGHT);
968 if (when==1) {
969 if (cur==1)
970 rb->lcd_bitmap_part(brickmania_menu_items, 0,
971 MENU_ITEMHEIGHT * BM_SEL_RESUME, MENU_ITEMWIDTH,
972 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
973 MENU_ITEMHEIGHT);
974 else
975 rb->lcd_bitmap_part(brickmania_menu_items, 0,
976 MENU_ITEMHEIGHT * BM_RESUME, MENU_ITEMWIDTH,
977 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
978 MENU_ITEMHEIGHT);
980 } else {
981 rb->lcd_bitmap_part(brickmania_menu_items, 0,
982 MENU_ITEMHEIGHT * BM_NO_RESUME, MENU_ITEMWIDTH,
983 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
984 MENU_ITEMHEIGHT);
988 if (cur==2)
989 rb->lcd_bitmap_part(brickmania_menu_items, 0,
990 MENU_ITEMHEIGHT * BM_SEL_HELP, MENU_ITEMWIDTH,
991 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
992 MENU_ITEMHEIGHT);
993 else
994 rb->lcd_bitmap_part(brickmania_menu_items, 0,
995 MENU_ITEMHEIGHT * BM_HELP, MENU_ITEMWIDTH,
996 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
997 MENU_ITEMHEIGHT);
999 if (cur==3)
1000 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1001 MENU_ITEMHEIGHT * BM_SEL_QUIT, MENU_ITEMWIDTH,
1002 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
1003 MENU_ITEMHEIGHT);
1004 else
1005 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1006 MENU_ITEMHEIGHT * BM_QUIT, MENU_ITEMWIDTH,
1007 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
1008 MENU_ITEMHEIGHT);
1009 #endif
1011 rb->lcd_set_drawmode(DRMODE_FG);
1012 /* high score */
1013 #ifdef HAVE_LCD_COLOR
1014 rb->lcd_set_background(LCD_RGBPACK(0,0,140));
1015 rb->lcd_set_foreground(LCD_WHITE);
1016 #endif
1017 rb->lcd_putsxy(HIGHSCORE_XPOS, HIGHSCORE_YPOS, "High Score");
1018 rb->snprintf(str, sizeof(str), "%d", highscore);
1019 rb->lcd_getstringsize("High Score", &sw, NULL);
1020 rb->lcd_getstringsize(str, &w, NULL);
1021 rb->lcd_putsxy(HIGHSCORE_XPOS+sw/2-w/2, HIGHSCORE_YPOS+9, str);
1022 rb->lcd_set_drawmode(DRMODE_SOLID);
1024 rb->lcd_update();
1026 button = rb->button_get(true);
1027 #ifdef HAVE_TOUCHPAD
1028 if(button & BUTTON_TOUCHPAD)
1030 unsigned int result = touchscreen_map(&main_menu, rb->button_get_data() >> 16, rb->button_get_data() & 0xffff);
1031 if(result != (unsigned)-1 && button & BUTTON_REL)
1033 if(cur == (signed)result)
1034 button = SELECT;
1035 cur = result;
1038 #endif
1039 switch(button) {
1040 case UP:
1041 case UP | BUTTON_REPEAT:
1042 if (cur==0)
1043 cur = MENU_LENGTH-1;
1044 else
1045 cur--;
1046 if (when==0 && cur==1) {
1047 cur = 0;
1049 break;
1051 case DOWN:
1052 case DOWN | BUTTON_REPEAT:
1053 if (cur==MENU_LENGTH-1)
1054 cur = 0;
1055 else
1056 cur++;
1057 if (when==0 && cur==1) {
1058 cur=2;
1060 break;
1062 case RIGHT:
1063 case SELECT:
1064 if (cur==0) {
1065 score=0;
1066 vscore=0;
1067 return 0;
1068 } else if (cur==1 && when==1) {
1069 return 1;
1070 } else if (cur==2) {
1071 return 2;
1072 } else if (cur==3) {
1073 return 3;
1075 break;
1076 #ifdef RC_QUIT
1077 case RC_QUIT:
1078 #endif
1079 case QUIT:
1080 return 3;
1081 break;
1083 default:
1084 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1085 return 3;
1086 break;
1091 int help(int when)
1093 int w,h;
1094 int button;
1095 int xoffset=0;
1096 int yoffset=0;
1097 /* set the maximum x and y in the helpscreen
1098 dont forget to update, if you change text */
1099 int maxY=180;
1100 int maxX=215;
1102 while(true) {
1103 #ifdef HAVE_LCD_COLOR
1104 rb->lcd_set_background(LCD_BLACK);
1105 rb->lcd_clear_display();
1106 rb->lcd_set_background(LCD_BLACK);
1107 rb->lcd_set_foreground(LCD_WHITE);
1108 #else
1109 rb->lcd_clear_display();
1110 #endif
1112 rb->lcd_getstringsize("BrickMania", &w, &h);
1113 rb->lcd_putsxy(LCD_WIDTH/2-w/2+xoffset, 1+yoffset, "BrickMania");
1115 #ifdef HAVE_LCD_COLOR
1116 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1117 rb->lcd_putsxy(1+xoffset, 1*(h+2)+yoffset,"Aim");
1118 rb->lcd_set_foreground(LCD_WHITE);
1119 #else
1120 rb->lcd_putsxy(1+xoffset, 1*(h+2)+yoffset,"Aim");
1121 #endif
1122 rb->lcd_putsxy(1+xoffset, 2*(h+2)+yoffset,
1123 "destroy all the bricks by bouncing");
1124 rb->lcd_putsxy(1+xoffset, 3*(h+2)+yoffset,
1125 "the ball of them using the paddle.");
1126 #ifdef HAVE_LCD_COLOR
1127 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1128 rb->lcd_putsxy(1+xoffset, 5*(h+2)+yoffset,"Controls");
1129 rb->lcd_set_foreground(LCD_WHITE);
1130 #else
1131 rb->lcd_putsxy(1+xoffset, 5*(h+2)+yoffset,"Controls");
1132 #endif
1133 rb->lcd_putsxy(1+xoffset, 6*(h+2)+yoffset,"< & > Move the paddle");
1134 #if CONFIG_KEYPAD == ONDIO_PAD
1135 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1136 "MENU Releases the ball/Fire!");
1137 #elif (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1138 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1139 "PLAY Releases the ball/Fire!");
1140 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
1141 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1142 "NAVI Releases the ball/Fire!");
1143 #else
1144 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1145 "SELECT Releases the ball/Fire!");
1146 #endif
1147 #if CONFIG_KEYPAD == IAUDIO_M3_PAD
1148 rb->lcd_putsxy(1+xoffset, 8*(h+2)+yoffset, "REC Opens menu/Quit");
1149 #else
1150 rb->lcd_putsxy(1+xoffset, 8*(h+2)+yoffset, "STOP Opens menu/Quit");
1151 #endif
1152 #ifdef HAVE_LCD_COLOR
1153 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1154 rb->lcd_putsxy(1+xoffset, 10*(h+2)+yoffset, "Specials");
1155 rb->lcd_set_foreground(LCD_WHITE);
1156 #else
1157 rb->lcd_putsxy(1+xoffset, 10*(h+2)+yoffset, "Specials");
1158 #endif
1159 rb->lcd_putsxy(1+xoffset, 11*(h+2)+yoffset,
1160 "N Normal:returns paddle to normal");
1161 rb->lcd_putsxy(1+xoffset, 12*(h+2)+yoffset, "D DIE!:loses a life");
1162 rb->lcd_putsxy(1+xoffset, 13*(h+2)+yoffset,
1163 "L Life:gains a life/power up");
1164 rb->lcd_putsxy(1+xoffset, 14*(h+2)+yoffset,
1165 "F Fire:allows you to shoot bricks");
1166 rb->lcd_putsxy(1+xoffset, 15*(h+2)+yoffset,
1167 "G Glue:ball sticks to paddle");
1168 rb->lcd_putsxy(1+xoffset, 16*(h+2)+yoffset,
1169 "B Ball:generates another ball");
1170 rb->lcd_putsxy(1+xoffset, 17*(h+2)+yoffset,
1171 "FL Flip:flips left / right movement");
1172 rb->lcd_update();
1174 button=rb->button_get(true);
1175 switch (button) {
1176 #ifdef RC_QUIT
1177 case RC_QUIT:
1178 #endif
1179 #ifdef HAVE_TOUCHPAD
1180 case BUTTON_TOUCHPAD:
1181 #endif
1182 case QUIT:
1183 switch (game_menu(when)) {
1184 case 0:
1185 cur_level=0;
1186 life=2;
1187 int_game(1);
1188 break;
1189 case 1:
1190 con_game=1;
1191 break;
1192 case 2:
1193 if (help(when)==1)
1194 return 1;
1195 break;
1196 case 3:
1197 return 1;
1198 break;
1200 return 0;
1201 break;
1202 case LEFT:
1203 case LEFT | BUTTON_REPEAT:
1204 #ifdef ALTLEFT
1205 case ALTLEFT:
1206 case ALTLEFT | BUTTON_REPEAT:
1207 #endif
1208 if( xoffset<0)
1209 xoffset+=2;
1210 break;
1211 case RIGHT:
1212 case RIGHT | BUTTON_REPEAT:
1213 #ifdef ALTRIGHT
1214 case ALTRIGHT:
1215 case ALTRIGHT | BUTTON_REPEAT:
1216 #endif
1217 if(xoffset+maxX > LCD_WIDTH)
1218 xoffset-=2;
1219 break;
1220 case UP:
1221 case UP | BUTTON_REPEAT:
1222 if(yoffset <0)
1223 yoffset+=2;
1224 break;
1225 case DOWN:
1226 case DOWN | BUTTON_REPEAT:
1227 if(yoffset+maxY > LCD_HEIGHT)
1228 yoffset-=2;
1229 break;
1231 default:
1232 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1233 return 1;
1234 break;
1237 return 0;
1240 int pad_check(int ballxc, int mode, int pon ,int ballnum)
1242 /* pon: positive(1) or negative(0) */
1244 if (mode==0) {
1245 if (pon == 0)
1246 return -ballxc;
1247 else
1248 return ballxc;
1249 } else {
1250 if (ball[ballnum].x > 0)
1251 return ballxc;
1252 else
1253 return ballxc*-1;
1257 int fire_space(void)
1259 int t;
1260 for(t=0;t<=30;t++)
1261 if (fire[t].top+7 < 0)
1262 return t;
1264 return 0;
1267 int game_loop(void)
1269 int j,i,k,bricky,brickx;
1270 char s[30];
1271 int sec_count=0,num_count=10;
1272 int end;
1274 rb->srand( *rb->current_tick );
1276 configfile_init(rb);
1277 configfile_load(HIGH_SCORE,config,1,0);
1279 switch(game_menu(0)) {
1280 case 0:
1281 cur_level = 0;
1282 life = 2;
1283 int_game(1);
1284 break;
1285 case 1:
1286 con_game = 1;
1287 break;
1288 case 2:
1289 if (help(0) == 1) return 1;
1290 break;
1291 case 3:
1292 return 1;
1293 break;
1296 while(true) {
1297 /* Convert CYCLETIME (in ms) to HZ */
1298 end = *rb->current_tick + (CYCLETIME * HZ) / 1000;
1300 if (life >= 0) {
1301 #ifdef HAVE_LCD_COLOR
1302 rb->lcd_set_background(LCD_BLACK);
1303 rb->lcd_set_drawmode(DRMODE_SOLID);
1304 rb->lcd_clear_display();
1305 rb->lcd_set_background(LCD_BLACK);
1306 #if LCD_HEIGHT > GAMESCREEN_HEIGHT
1307 rb->lcd_set_foreground(rb->global_settings->bg_color);
1308 rb->lcd_fillrect(0, GAMESCREEN_HEIGHT, LCD_WIDTH,
1309 LCD_HEIGHT - GAMESCREEN_HEIGHT);
1310 #endif
1311 rb->lcd_set_foreground(LCD_WHITE);
1312 #else
1313 rb->lcd_clear_display();
1314 #endif
1316 if (flip_sides) {
1317 if (*rb->current_tick>=sec_count) {
1318 sec_count=*rb->current_tick+HZ;
1319 if (num_count!=0)
1320 num_count--;
1321 else
1322 flip_sides=false;
1324 rb->snprintf(s, sizeof(s), "%d", num_count);
1325 rb->lcd_getstringsize(s, &sw, NULL);
1326 rb->lcd_putsxy(LCD_WIDTH/2-2, STRINGPOS_FLIP, s);
1329 /* write life num */
1330 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1331 rb->snprintf(s, sizeof(s), "L:%d", life);
1332 rb->lcd_putsxy(0, 0, s);
1333 #else
1334 rb->snprintf(s, sizeof(s), "Life: %d", life);
1335 rb->lcd_putsxy(2, 2, s);
1336 #endif
1338 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1339 rb->snprintf(s, sizeof(s), "L%d", cur_level+1);
1340 rb->lcd_getstringsize(s, &sw, NULL);
1341 rb->lcd_putsxy(LCD_WIDTH-sw, 0, s);
1342 #else
1343 rb->snprintf(s, sizeof(s), "Level %d", cur_level+1);
1344 rb->lcd_getstringsize(s, &sw, NULL);
1345 rb->lcd_putsxy(LCD_WIDTH-sw-2, 2, s);
1346 #endif
1348 if (vscore<score) vscore++;
1349 rb->snprintf(s, sizeof(s), "%d", vscore);
1350 rb->lcd_getstringsize(s, &sw, NULL);
1351 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1352 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
1353 #else
1354 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s);
1355 #endif
1357 /* continue game */
1358 if (con_game== 1 && start_game!=1) {
1359 #if CONFIG_KEYPAD == ONDIO_PAD
1360 rb->snprintf(s, sizeof(s), "MENU To Continue");
1361 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
1362 rb->snprintf(s, sizeof(s), "Press NAVI To Continue");
1363 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
1364 rb->snprintf(s, sizeof(s), "PLAY To Continue");
1365 #else
1366 rb->snprintf(s, sizeof(s), "Press SELECT To Continue");
1367 #endif
1368 rb->lcd_getstringsize(s, &sw, NULL);
1369 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_NAVI, s);
1371 sec_count=*rb->current_tick+HZ;
1374 /* draw the ball */
1375 for(i=0;i<used_balls;i++)
1376 rb->lcd_bitmap(brickmania_ball,ball[i].pos_x, ball[i].pos_y,
1377 BALL, BALL);
1379 if (brick_on_board==0)
1380 brick_on_board--;
1382 /* if the pad is fire */
1383 for(i=0;i<=30;i++) {
1384 if (fire[i].top+7>0) {
1385 if (con_game!=1)
1386 fire[i].top-=4;
1387 rb->lcd_vline(fire[i].left, fire[i].top, fire[i].top+7);
1391 /* the bricks */
1392 for (i=0;i<=7;i++) {
1393 for (j=0;j<=9;j++) {
1394 if (brick[i*10+j].power<7) {
1395 if (brick[i*10+j].poweruse==2) {
1396 if (con_game!=1)
1397 brick[i*10+j].powertop+=2;
1398 rb->lcd_bitmap_part(brickmania_powerups,0,
1399 POWERUP_HEIGHT*brick[i*10+j
1400 ].power,
1401 POWERUP_WIDTH,
1402 LEFTMARGIN+j*BRICK_WIDTH+
1403 (BRICK_WIDTH/2-
1404 POWERUP_WIDTH/2),
1405 brick[i*10+j].powertop,
1406 POWERUP_WIDTH,
1407 POWERUP_HEIGHT);
1411 if ((pad_pos_x<LEFTMARGIN+j*BRICK_WIDTH+5 &&
1412 pad_pos_x+PAD_WIDTH>LEFTMARGIN+j*BRICK_WIDTH+5) &&
1413 brick[i*10+j].powertop+6>=PAD_POS_Y &&
1414 brick[i*10+j].poweruse==2) {
1415 switch(brick[i*10+j].power) {
1416 case 0:
1417 life++;
1418 score+=50;
1419 break;
1420 case 1:
1421 life--;
1422 if (life>=0) {
1423 int_game(0);
1424 sleep(2);
1426 break;
1427 case 2:
1428 score+=34;
1429 pad_type=1;
1430 break;
1431 case 3:
1432 score+=47;
1433 pad_type=2;
1434 for(k=0;k<used_balls;k++)
1435 ball[k].glue=false;
1436 break;
1437 case 4:
1438 score+=23;
1439 pad_type=0;
1440 for(k=0;k<used_balls;k++)
1441 ball[k].glue=false;
1442 flip_sides=false;
1443 break;
1444 case 5:
1445 score+=23;
1446 sec_count=*rb->current_tick+HZ;
1447 num_count=10;
1448 flip_sides=!flip_sides;
1449 break;
1450 case 6:
1451 score+=23;
1452 used_balls++;
1453 ball[used_balls-1].x= rb->rand()%1 == 0 ?
1454 -1 : 1;
1455 ball[used_balls-1].y= -4;
1456 break;
1458 brick[i*10+j].poweruse=1;
1461 if (brick[i*10+j].powertop>PAD_POS_Y)
1462 brick[i*10+j].poweruse=1;
1464 brickx=LEFTMARGIN+j*BRICK_WIDTH;
1465 bricky=TOPMARGIN+i*BRICK_HEIGHT;
1466 if (pad_type==2) {
1467 for (k=0;k<=30;k++) {
1468 if (fire[k].top+7>0) {
1469 if (brick[i*10+j].used==1 &&
1470 (fire[k].left+1 >= brickx &&
1471 fire[k].left+1 <= brickx+BRICK_WIDTH) &&
1472 (bricky+BRICK_HEIGHT>fire[k].top)) {
1473 score+=13;
1474 fire[k].top=-16;
1475 if (brick[i*10+j].hits > 0) {
1476 brick[i*10+j].hits--;
1477 brick[i*10+j].hiteffect++;
1478 score+=3;
1480 else {
1481 brick[i*10+j].used=0;
1482 if (brick[i*10+j].power!=10)
1483 brick[i*10+j].poweruse=2;
1484 brick_on_board--;
1491 if (brick[i*10+j].used==1) {
1492 rb->lcd_bitmap_part(brickmania_bricks,0,
1493 BRICK_HEIGHT*brick[i*10+j].color,
1494 BRICK_WIDTH,
1495 LEFTMARGIN+j*BRICK_WIDTH,
1496 TOPMARGIN+i*BRICK_HEIGHT,
1497 BRICK_WIDTH, BRICK_HEIGHT);
1498 #ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */
1499 if (brick[i*10+j].hiteffect>0)
1500 rb->lcd_bitmap_transparent_part(brickmania_break,
1502 BRICK_HEIGHT*brick[i*10+j].hiteffect,
1503 BRICK_WIDTH,
1504 LEFTMARGIN+j*BRICK_WIDTH,
1505 TOPMARGIN+i*BRICK_HEIGHT,
1506 BRICK_WIDTH,
1507 BRICK_HEIGHT);
1508 #endif
1511 for(k=0;k<used_balls;k++) {
1512 if (ball[k].pos_y <160) {
1513 if (brick[i*10+j].used==1) {
1514 if ((ball[k].pos_x+ball[k].x+HALFBALL >=
1515 brickx &&
1516 ball[k].pos_x+ball[k].x+HALFBALL <=
1517 brickx+BRICK_WIDTH) &&
1518 ((bricky-4<ball[k].pos_y+BALL &&
1519 bricky>ball[k].pos_y+BALL) ||
1520 (bricky+4>ball[k].pos_y+BALL+BALL &&
1521 bricky<ball[k].pos_y+BALL+BALL)) &&
1522 (ball[k].y >0)) {
1523 ball[k].tempy=bricky-ball[k].pos_y-BALL;
1525 else if ((ball[k].pos_x+ball[k].x+HALFBALL >=
1526 brickx &&
1527 ball[k].pos_x+ball[k].x+HALFBALL <=
1528 brickx+BRICK_WIDTH) &&
1529 ((bricky+BRICK_HEIGHT+4>ball[k].pos_y &&
1530 bricky+BRICK_HEIGHT<ball[k].pos_y) ||
1531 (bricky+BRICK_HEIGHT-4<ball[k].pos_y-BALL &&
1532 bricky+BRICK_HEIGHT>ball[k].pos_y-BALL)) &&
1533 (ball[k].y <0)) {
1534 ball[k].tempy=
1535 -(ball[k].pos_y-(bricky+BRICK_HEIGHT));
1538 if ((ball[k].pos_y+HALFBALL >=
1539 bricky &&
1540 ball[k].pos_y+HALFBALL <=
1541 bricky+BRICK_HEIGHT) &&
1542 ((brickx-4<ball[k].pos_x+BALL &&
1543 brickx>ball[k].pos_x+BALL) ||
1544 (brickx+4>ball[k].pos_x+BALL+BALL &&
1545 brickx<ball[k].pos_x+BALL+BALL)) &&
1546 (ball[k].x >0)) {
1547 ball[k].tempx=brickx-ball[k].pos_x-BALL;
1549 else if ((ball[k].pos_y+ball[k].y+HALFBALL >=
1550 bricky &&
1551 ball[k].pos_y+ball[k].y+HALFBALL <=
1552 bricky+BRICK_HEIGHT) &&
1553 ((brickx+BRICK_WIDTH+4>ball[k].pos_x &&
1554 brickx+BRICK_WIDTH<ball[k].pos_x) ||
1555 (brickx+BRICK_WIDTH-4<ball[k].pos_x-
1556 BALL &&
1557 brickx+BRICK_WIDTH>ball[k].pos_x-
1558 BALL)) && (ball[k].x <0)) {
1559 ball[k].tempx=
1560 -(ball[k].pos_x-(brickx+BRICK_WIDTH));
1563 if ((ball[k].pos_x+HALFBALL >= brickx &&
1564 ball[k].pos_x+HALFBALL <=
1565 brickx+BRICK_WIDTH) &&
1566 ((bricky+BRICK_HEIGHT==ball[k].pos_y) ||
1567 (bricky+BRICK_HEIGHT-6<=ball[k].pos_y &&
1568 bricky+BRICK_HEIGHT>ball[k].pos_y)) &&
1569 (ball[k].y <0)) { /* bottom line */
1570 if (brick[i*10+j].hits > 0) {
1571 brick[i*10+j].hits--;
1572 brick[i*10+j].hiteffect++;
1573 score+=2;
1575 else {
1576 brick[i*10+j].used=0;
1577 if (brick[i*10+j].power!=10)
1578 brick[i*10+j].poweruse=2;
1581 ball[k].y = ball[k].y*-1;
1583 else if ((ball[k].pos_x+HALFBALL >= brickx &&
1584 ball[k].pos_x+HALFBALL <=
1585 brickx+BRICK_WIDTH) &&
1586 ((bricky==ball[k].pos_y+BALL) ||
1587 (bricky+6>=ball[k].pos_y+BALL &&
1588 bricky<ball[k].pos_y+BALL)) &&
1589 (ball[k].y >0)) { /* top line */
1590 if (brick[i*10+j].hits > 0) {
1591 brick[i*10+j].hits--;
1592 brick[i*10+j].hiteffect++;
1593 score+=2;
1595 else {
1596 brick[i*10+j].used=0;
1597 if (brick[i*10+j].power!=10)
1598 brick[i*10+j].poweruse=2;
1601 ball[k].y = ball[k].y*-1;
1604 if ((ball[k].pos_y+HALFBALL >= bricky &&
1605 ball[k].pos_y+HALFBALL <=
1606 bricky+BRICK_HEIGHT) &&
1607 ((brickx==ball[k].pos_x+BALL) ||
1608 (brickx+6>=ball[k].pos_x+BALL &&
1609 brickx<ball[k].pos_x+BALL)) &&
1610 (ball[k].x > 0)) { /* left line */
1611 if (brick[i*10+j].hits > 0) {
1612 brick[i*10+j].hits--;
1613 brick[i*10+j].hiteffect++;
1614 score+=2;
1616 else {
1617 brick[i*10+j].used=0;
1618 if (brick[i*10+j].power!=10)
1619 brick[i*10+j].poweruse=2;
1621 ball[k].x = ball[k].x*-1;
1624 else if ((ball[k].pos_y+HALFBALL >= bricky &&
1625 ball[k].pos_y+HALFBALL <=
1626 bricky+BRICK_HEIGHT) &&
1627 ((brickx+BRICK_WIDTH==
1628 ball[k].pos_x) ||
1629 (brickx+BRICK_WIDTH-6<=
1630 ball[k].pos_x &&
1631 brickx+BRICK_WIDTH>
1632 ball[k].pos_x)) &&
1633 (ball[k].x < 0)) { /* Right line */
1634 if (brick[i*10+j].hits > 0) {
1635 brick[i*10+j].hits--;
1636 brick[i*10+j].hiteffect++;
1637 score+=2;
1639 else {
1640 brick[i*10+j].used=0;
1641 if (brick[i*10+j].power!=10)
1642 brick[i*10+j].poweruse=2;
1645 ball[k].x = ball[k].x*-1;
1648 if (brick[i*10+j].used==0) {
1649 brick_on_board--;
1650 score+=8;
1654 } /* for k */
1655 } /* for j */
1656 } /* for i */
1658 /* draw the pad */
1659 rb->lcd_bitmap_part(brickmania_pads,0,pad_type*PAD_HEIGHT,
1660 PAD_WIDTH,pad_pos_x, PAD_POS_Y, PAD_WIDTH,
1661 PAD_HEIGHT);
1663 for(k=0;k<used_balls;k++) {
1665 if ((ball[k].pos_x >= pad_pos_x &&
1666 ball[k].pos_x <= pad_pos_x+PAD_WIDTH) &&
1667 (PAD_POS_Y-4<ball[k].pos_y+BALL &&
1668 PAD_POS_Y>ball[k].pos_y+BALL) && (ball[k].y >0))
1669 ball[k].tempy=PAD_POS_Y-ball[k].pos_y-BALL;
1670 else if ((4>ball[k].pos_y && 0<ball[k].pos_y) &&
1671 (ball[k].y <0))
1672 ball[k].tempy=-ball[k].pos_y;
1673 if ((LCD_WIDTH-4<ball[k].pos_x+BALL &&
1674 LCD_WIDTH>ball[k].pos_x+BALL) && (ball[k].x >0))
1675 ball[k].tempx=LCD_WIDTH-ball[k].pos_x-BALL;
1676 else if ((4>ball[k].pos_x && 0<ball[k].pos_x) &&
1677 (ball[k].x <0))
1678 ball[k].tempx=-ball[k].pos_x;
1680 /* top line */
1681 if (ball[k].pos_y<= 0)
1682 ball[k].y = ball[k].y*-1;
1683 /* bottom line */
1684 else if (ball[k].pos_y+BALL >= GAMESCREEN_HEIGHT) {
1685 if (used_balls>1) {
1686 used_balls--;
1687 ball[k].pos_x = ball[used_balls].pos_x;
1688 ball[k].pos_y = ball[used_balls].pos_y;
1689 ball[k].y = ball[used_balls].y;
1690 ball[k].tempy = ball[used_balls].tempy;
1691 ball[k].x = ball[used_balls].x;
1692 ball[k].tempx = ball[used_balls].tempx;
1693 ball[k].glue = ball[used_balls].glue;
1695 ball[used_balls].x=0;
1696 ball[used_balls].y=0;
1697 ball[used_balls].tempy=0;
1698 ball[used_balls].tempx=0;
1699 ball[used_balls].pos_y=PAD_POS_Y-BALL;
1700 ball[used_balls].pos_x=pad_pos_x+(PAD_WIDTH/2)-2;
1702 k--;
1703 continue;
1704 } else {
1705 life--;
1706 if (life>=0) {
1707 int_game(0);
1708 sleep(2);
1713 /* left line ,right line */
1714 if ((ball[k].pos_x <= 0) ||
1715 (ball[k].pos_x+BALL >= LCD_WIDTH)) {
1716 ball[k].x = ball[k].x*-1;
1717 ball[k].pos_x = ball[k].pos_x <= 0 ? 0 : LCD_WIDTH-BALL;
1720 if ((ball[k].pos_y+BALL >= PAD_POS_Y &&
1721 (ball[k].pos_x >= pad_pos_x &&
1722 ball[k].pos_x <= pad_pos_x+PAD_WIDTH)) &&
1723 start_game != 1 && !ball[k].glue) {
1725 if ((ball[k].pos_x+HALFBALL >= pad_pos_x &&
1726 ball[k].pos_x+HALFBALL <=
1727 pad_pos_x+(PAD_WIDTH/2/4)) ||
1728 (ball[k].pos_x +HALFBALL>=
1729 pad_pos_x+(PAD_WIDTH-(PAD_WIDTH/2/4)) &&
1730 ball[k].pos_x+HALFBALL <= pad_pos_x+PAD_WIDTH)) {
1732 ball[k].y = -2;
1733 if (ball[k].pos_x != 0 &&
1734 ball[k].pos_x+BALL!=LCD_WIDTH)
1735 ball[k].x = pad_check(6,0,ball[k].pos_x+2<=
1736 pad_pos_x+(PAD_WIDTH/2)?
1737 0:1,k);
1740 else if ((ball[k].pos_x+HALFBALL >=
1741 pad_pos_x+(PAD_WIDTH/2/4) &&
1742 ball[k].pos_x+HALFBALL <=
1743 pad_pos_x+2*(PAD_WIDTH/2/4)) ||
1744 (ball[k].pos_x+HALFBALL >=
1745 pad_pos_x+(PAD_WIDTH-2*(PAD_WIDTH/2/4)) &&
1746 ball[k].pos_x+HALFBALL <=
1747 pad_pos_x+(PAD_WIDTH-(PAD_WIDTH/2/4)) )) {
1749 ball[k].y = -3;
1750 if (ball[k].pos_x != 0 &&
1751 ball[k].pos_x+BALL!=LCD_WIDTH)
1752 ball[k].x = pad_check(4,0,ball[k].pos_x+2<=
1753 pad_pos_x+(PAD_WIDTH/2)?
1754 0:1,k);
1757 else if ((ball[k].pos_x+HALFBALL >=
1758 pad_pos_x+2*(PAD_WIDTH/2/4) &&
1759 ball[k].pos_x+HALFBALL <=
1760 pad_pos_x+3*(PAD_WIDTH/2/4)) ||
1761 (ball[k].pos_x+2 >=
1762 pad_pos_x+(PAD_WIDTH-3*(PAD_WIDTH/2/4)) &&
1763 ball[k].pos_x+2 <=
1764 pad_pos_x+ ((PAD_WIDTH/2)-2*(PAD_WIDTH/2/4)) )) {
1766 ball[k].y = -4;
1767 if (ball[k].pos_x != 0 &&
1768 ball[k].pos_x+BALL!=LCD_WIDTH)
1769 ball[k].x = pad_check(3,0,ball[k].pos_x+2<=
1770 pad_pos_x+(PAD_WIDTH/2)?
1771 0:1,k);
1774 else if ((ball[k].pos_x+HALFBALL >=
1775 pad_pos_x+3*(PAD_WIDTH/2/4) &&
1776 ball[k].pos_x+HALFBALL <=
1777 pad_pos_x+4*(PAD_WIDTH/2/4)-2) ||
1778 (ball[k].pos_x+2 >= pad_pos_x+(PAD_WIDTH/2+2) &&
1779 ball[k].pos_x+2 <=
1780 pad_pos_x+(PAD_WIDTH-3*(PAD_WIDTH/2/4)) )) {
1782 ball[k].y = -4;
1783 if (ball[k].pos_x != 0 &&
1784 ball[k].pos_x+BALL!=LCD_WIDTH)
1785 ball[k].x = pad_check(2,1,0,k);
1788 else {
1789 ball[k].y = -4;
1793 if (!ball[k].glue) {
1794 ball[k].pos_x+=ball[k].tempx!=0?ball[k].tempx:ball[k].x;
1795 ball[k].pos_y+=ball[k].tempy!=0?ball[k].tempy:ball[k].y;
1797 ball[k].tempy=0;
1798 ball[k].tempx=0;
1801 if (ball[k].pos_y+5 >= PAD_POS_Y &&
1802 (pad_type==1 && !ball[k].glue) &&
1803 (ball[k].pos_x >= pad_pos_x &&
1804 ball[k].pos_x <= pad_pos_x+PAD_WIDTH)) {
1805 ball[k].y=0;
1806 ball[k].pos_y=PAD_POS_Y-BALL;
1807 ball[k].glue=true;
1809 } /* for k */
1811 rb->lcd_update();
1813 if (brick_on_board < 0) {
1814 if (cur_level+1<levels_num) {
1815 cur_level++;
1816 score+=100;
1817 int_game(1);
1818 sleep(2);
1820 else {
1821 rb->lcd_getstringsize("Congratulations!", &sw, NULL);
1822 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_CONGRATS,
1823 "Congratulations!");
1824 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1825 rb->lcd_getstringsize("No more levels", &sw, NULL);
1826 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_FINISH,
1827 "No more levels");
1828 #else
1829 rb->lcd_getstringsize("You have finished the game!",
1830 &sw, NULL);
1831 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_FINISH,
1832 "You have finished the game!");
1833 #endif
1834 vscore=score;
1835 rb->lcd_update();
1836 if (score>highscore) {
1837 sleep(2);
1838 highscore=score;
1839 rb->splash(HZ*2, "New High Score");
1841 else {
1842 sleep(3);
1845 switch(game_menu(0)) {
1846 case 0:
1847 life=2;
1848 cur_level=0;
1849 int_game(1);
1850 break;
1851 case 1:
1852 con_game=1;
1853 break;
1854 case 2:
1855 if (help(0)==1) return 1;
1856 break;
1857 case 3:
1858 return 1;
1859 break;
1864 int move_button,button;
1865 int button_right,button_left;
1866 button=rb->button_get(false);
1868 #if defined(HAS_BUTTON_HOLD) && !defined(HAVE_REMOTE_LCD_AS_MAIN)
1869 /* FIXME: Should probably check remote hold here */
1870 if (rb->button_hold())
1871 button = QUIT;
1872 #endif
1874 #ifdef HAVE_TOUCHPAD
1875 if(button & BUTTON_TOUCHPAD)
1877 short touch_x, touch_y;
1878 touch_x = rb->button_get_data() >> 16;
1879 touch_y = rb->button_get_data() & 0xffff;
1880 if(touch_y >= PAD_POS_Y && touch_y <= PAD_POS_Y+PAD_HEIGHT)
1882 pad_pos_x += (flip_sides ? -1 : 1) * ( (touch_x-pad_pos_x-PAD_WIDTH/2) / 4 );
1884 if(pad_pos_x < 0)
1885 pad_pos_x = 0;
1886 else if(pad_pos_x+PAD_WIDTH > LCD_WIDTH)
1887 pad_pos_x = LCD_WIDTH-PAD_WIDTH;
1888 for(k=0;k<used_balls;k++)
1889 if ((start_game==1 || ball[k].glue))
1890 ball[k].pos_x = pad_pos_x+PAD_WIDTH/2;
1893 if(button & BUTTON_REL)
1894 button = SELECT;
1896 else
1898 #endif
1899 move_button=rb->button_status();
1900 #ifdef ALTRIGHT
1901 button_right=((move_button & RIGHT) || (move_button & ALTRIGHT));
1902 button_left=((move_button & LEFT) || (move_button & ALTLEFT));
1903 #else
1904 button_right=((move_button & RIGHT) || (SCROLL_FWD(button)));
1905 button_left=((move_button & LEFT) || (SCROLL_BACK(button)));
1906 #endif
1907 if ((con_game== 1 && start_game!=1) && (button_right || button_left))
1908 continue;
1909 if ((button_right && flip_sides==false) ||
1910 (button_left && flip_sides==true)) {
1911 if (pad_pos_x+8+PAD_WIDTH > LCD_WIDTH) {
1912 for(k=0;k<used_balls;k++)
1913 if (start_game==1 || ball[k].glue)
1914 ball[k].pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
1915 pad_pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
1917 else {
1918 for(k=0;k<used_balls;k++)
1919 if ((start_game==1 || ball[k].glue))
1920 ball[k].pos_x+=8;
1921 pad_pos_x+=8;
1924 else if ((button_left && flip_sides==false) ||
1925 (button_right && flip_sides==true)) {
1926 if (pad_pos_x-8 < 0) {
1927 for(k=0;k<used_balls;k++)
1928 if (start_game==1 || ball[k].glue)
1929 ball[k].pos_x-=pad_pos_x;
1930 pad_pos_x-=pad_pos_x;
1932 else {
1933 for(k=0;k<used_balls;k++)
1934 if (start_game==1 || ball[k].glue)
1935 ball[k].pos_x-=8;
1936 pad_pos_x-=8;
1939 #ifdef HAVE_TOUCHPAD
1941 #endif
1944 switch(button) {
1945 case UP:
1946 case SELECT:
1947 if (start_game==1 && con_game!=1 && pad_type!=1) {
1948 for(k=0;k<used_balls;k++) {
1949 ball[k].y=-4;
1950 ball[k].x=pad_pos_x+(PAD_WIDTH/2)-2>=
1951 LCD_WIDTH/2?2:-2;
1953 start_game =0;
1955 else if (pad_type==1) {
1956 for(k=0;k<used_balls;k++) {
1957 if (ball[k].glue)
1958 ball[k].glue=false;
1959 else if (start_game==1) {
1960 ball[k].x = x[k];
1961 ball[k].y = y[k];
1965 if (start_game!=1 && con_game==1) {
1966 start_game =0;
1967 con_game=0;
1969 } else if (pad_type==2 && con_game!=1) {
1970 int tfire;
1971 tfire=fire_space();
1972 fire[tfire].top=PAD_POS_Y-7;
1973 fire[tfire].left=pad_pos_x+1;
1974 tfire=fire_space();
1975 fire[tfire].top=PAD_POS_Y-7;
1976 fire[tfire].left=pad_pos_x+PAD_WIDTH-1;
1977 } else if (con_game==1 && start_game!=1) {
1978 for(k=0;k<used_balls;k++) {
1979 ball[k].x=x[k];
1980 ball[k].y=y[k];
1982 con_game=0;
1984 break;
1985 #ifdef RC_QUIT
1986 case RC_QUIT:
1987 #endif
1988 case QUIT:
1989 switch(game_menu(1)) {
1990 case 0:
1991 life=2;
1992 cur_level=0;
1993 int_game(1);
1994 break;
1995 case 1:
1996 for(k=0;k<used_balls;k++)
1997 if (ball[k].x!=0 && ball[k].y !=0)
1998 con_game=1;
1999 break;
2000 case 2:
2001 if (help(1)==1)
2002 return 1;
2003 break;
2004 case 3:
2005 return 1;
2006 break;
2009 for(k=0;k<used_balls;k++) {
2010 if (ball[k].x!=0)
2011 x[k]=ball[k].x;
2012 ball[k].x=0;
2013 if (ball[k].y!=0)
2014 y[k]=ball[k].y;
2015 ball[k].y=0;
2018 break;
2020 default:
2021 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
2022 return 1;
2023 break;
2026 else {
2027 #ifdef HAVE_LCD_COLOR
2028 rb->lcd_bitmap_transparent(brickmania_gameover,
2029 (LCD_WIDTH - GAMEOVER_WIDTH)/2,
2030 (GAMESCREEN_HEIGHT - GAMEOVER_HEIGHT)/2,
2031 GAMEOVER_WIDTH,GAMEOVER_HEIGHT);
2032 #else /* greyscale and mono */
2033 rb->lcd_bitmap(brickmania_gameover,(LCD_WIDTH - GAMEOVER_WIDTH)/2,
2034 (GAMESCREEN_HEIGHT - GAMEOVER_HEIGHT)/2,
2035 GAMEOVER_WIDTH,GAMEOVER_HEIGHT);
2036 #endif
2037 rb->lcd_update();
2038 if (score>highscore) {
2039 sleep(2);
2040 highscore=score;
2041 rb->splash(HZ*2, "New High Score");
2042 } else {
2043 sleep(3);
2046 for(k=0;k<used_balls;k++) {
2047 ball[k].x=0;
2048 ball[k].y=0;
2051 switch(game_menu(0)) {
2052 case 0:
2053 cur_level=0;
2054 life=2;
2055 int_game(1);
2056 break;
2057 case 1:
2058 con_game=1;
2059 break;
2060 case 2:
2061 if (help(0)==1)
2062 return 1;
2063 break;
2064 case 3:
2065 return 1;
2066 break;
2069 if (end > *rb->current_tick)
2070 rb->sleep(end-*rb->current_tick);
2071 else
2072 rb->yield();
2076 /* this is the plugin entry point */
2077 enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
2079 (void)parameter;
2080 rb = api;
2082 rb->lcd_setfont(FONT_SYSFIXED);
2083 #if LCD_DEPTH > 1
2084 rb->lcd_set_backdrop(NULL);
2085 #endif
2086 /* Turn off backlight timeout */
2087 backlight_force_on(rb); /* backlight control in lib/helper.c */
2089 /* now go ahead and have fun! */
2090 while (game_loop()!=1);
2092 configfile_save(HIGH_SCORE,config,1,0);
2094 /* Restore user's original backlight setting */
2095 rb->lcd_setfont(FONT_UI);
2096 /* Turn on backlight timeout (revert to settings) */
2097 backlight_use_settings(rb); /* backlight control in lib/helper.c */
2099 return PLUGIN_OK;