fix wrong score recording.
[kugel-rb.git] / apps / plugins / brickmania.c
blobf0229b4f8b682eadaba28b611b3ca736d129d882
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 "lib/configfile.h" /* Part of libplugin */
24 #include "lib/helper.h"
25 #include "lib/display_text.h"
27 PLUGIN_HEADER
30 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
32 #define QUIT BUTTON_OFF
33 #define LEFT BUTTON_LEFT
34 #define RIGHT BUTTON_RIGHT
35 #define SELECT BUTTON_SELECT
36 #define UP BUTTON_UP
37 #define DOWN BUTTON_DOWN
39 #define RC_QUIT BUTTON_RC_STOP
42 #elif CONFIG_KEYPAD == ONDIO_PAD
44 #define QUIT BUTTON_OFF
45 #define LEFT BUTTON_LEFT
46 #define RIGHT BUTTON_RIGHT
47 #define SELECT BUTTON_MENU
48 #define UP BUTTON_UP
49 #define DOWN BUTTON_DOWN
52 #elif CONFIG_KEYPAD == RECORDER_PAD
54 #define QUIT BUTTON_OFF
55 #define LEFT BUTTON_LEFT
56 #define RIGHT BUTTON_RIGHT
57 #define SELECT BUTTON_PLAY
58 #define UP BUTTON_UP
59 #define DOWN BUTTON_DOWN
62 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
64 #define QUIT BUTTON_OFF
65 #define LEFT BUTTON_LEFT
66 #define RIGHT BUTTON_RIGHT
67 #define SELECT BUTTON_SELECT
68 #define UP BUTTON_UP
69 #define DOWN BUTTON_DOWN
72 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
73 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
74 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
76 #define QUIT BUTTON_MENU
77 #define LEFT BUTTON_LEFT
78 #define RIGHT BUTTON_RIGHT
79 #define SELECT BUTTON_SELECT
80 #define UP BUTTON_SCROLL_BACK
81 #define DOWN BUTTON_SCROLL_FWD
83 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD)
84 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK)
87 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
89 #define QUIT BUTTON_POWER
90 #define LEFT BUTTON_LEFT
91 #define RIGHT BUTTON_RIGHT
92 #define SELECT BUTTON_SELECT
93 #define UP BUTTON_UP
94 #define DOWN BUTTON_DOWN
97 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
99 #define QUIT BUTTON_POWER
100 #define LEFT BUTTON_LEFT
101 #define RIGHT BUTTON_RIGHT
102 #define SELECT BUTTON_PLAY
103 #define UP BUTTON_UP
104 #define DOWN BUTTON_DOWN
107 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
109 #define QUIT BUTTON_POWER
110 #define LEFT BUTTON_LEFT
111 #define RIGHT BUTTON_RIGHT
112 #define SELECT BUTTON_SELECT
113 #define UP BUTTON_SCROLL_BACK
114 #define DOWN BUTTON_SCROLL_FWD
116 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD)
117 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK)
120 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
122 #define QUIT (BUTTON_HOME|BUTTON_REPEAT)
123 #define LEFT BUTTON_LEFT
124 #define RIGHT BUTTON_RIGHT
125 #define SELECT BUTTON_SELECT
126 #define UP BUTTON_SCROLL_BACK
127 #define DOWN BUTTON_SCROLL_FWD
129 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD)
130 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK)
133 #elif CONFIG_KEYPAD == SANSA_C200_PAD || \
134 CONFIG_KEYPAD == SANSA_CLIP_PAD || \
135 CONFIG_KEYPAD == SANSA_M200_PAD
137 #define QUIT BUTTON_POWER
138 #define LEFT BUTTON_LEFT
139 #define RIGHT BUTTON_RIGHT
140 #define ALTLEFT BUTTON_VOL_DOWN
141 #define ALTRIGHT BUTTON_VOL_UP
142 #define SELECT BUTTON_SELECT
143 #define UP BUTTON_UP
144 #define DOWN BUTTON_DOWN
147 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
149 #define QUIT BUTTON_POWER
150 #define LEFT BUTTON_LEFT
151 #define RIGHT BUTTON_RIGHT
152 #define SELECT BUTTON_PLAY
153 #define UP BUTTON_SCROLL_UP
154 #define DOWN BUTTON_SCROLL_DOWN
156 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
158 #define QUIT BUTTON_BACK
159 #define LEFT BUTTON_LEFT
160 #define RIGHT BUTTON_RIGHT
161 #define SELECT BUTTON_SELECT
162 #define UP BUTTON_UP
163 #define DOWN BUTTON_DOWN
165 #elif (CONFIG_KEYPAD == MROBE100_PAD)
167 #define QUIT BUTTON_POWER
168 #define LEFT BUTTON_LEFT
169 #define RIGHT BUTTON_RIGHT
170 #define SELECT BUTTON_SELECT
171 #define UP BUTTON_UP
172 #define DOWN BUTTON_DOWN
174 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
176 #define QUIT BUTTON_RC_REC
177 #define LEFT BUTTON_RC_REW
178 #define RIGHT BUTTON_RC_FF
179 #define SELECT BUTTON_RC_PLAY
180 #define UP BUTTON_RC_VOL_UP
181 #define DOWN BUTTON_RC_VOL_DOWN
183 #define RC_QUIT BUTTON_REC
185 #elif CONFIG_KEYPAD == COWOND2_PAD
186 #define QUIT BUTTON_POWER
188 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
190 #define QUIT BUTTON_BACK
191 #define LEFT BUTTON_LEFT
192 #define RIGHT BUTTON_RIGHT
193 #define SELECT BUTTON_SELECT
194 #define UP BUTTON_UP
195 #define DOWN BUTTON_DOWN
197 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
199 #define QUIT BUTTON_POWER
200 #define LEFT BUTTON_LEFT
201 #define RIGHT BUTTON_RIGHT
202 #define SELECT BUTTON_SELECT
203 #define UP BUTTON_UP
204 #define DOWN BUTTON_DOWN
206 #elif CONFIG_KEYPAD == ONDAVX747_PAD
207 #define QUIT BUTTON_POWER
208 #define LEFT BUTTON_VOL_DOWN
209 #define RIGHT BUTTON_VOL_UP
210 #define SELECT BUTTON_MENU
212 #elif CONFIG_KEYPAD == MROBE500_PAD
213 #define QUIT BUTTON_POWER
215 #else
216 #error No keymap defined!
217 #endif
219 #ifdef HAVE_TOUCHSCREEN
220 #ifndef LEFT
221 #define LEFT BUTTON_MIDLEFT
222 #endif
223 #ifndef RIGHT
224 #define RIGHT BUTTON_MIDRIGHT
225 #endif
226 #ifndef SELECT
227 #define SELECT BUTTON_CENTER
228 #endif
229 #ifndef UP
230 #define UP BUTTON_TOPMIDDLE
231 #endif
232 #ifndef DOWN
233 #define DOWN BUTTON_BOTTOMMIDDLE
234 #endif
235 #endif
237 #ifndef SCROLL_FWD /* targets without scroll wheel*/
238 #define SCROLL_FWD(x) (0)
239 #define SCROLL_BACK(x) (0)
240 #endif
243 enum menu_items {
244 BM_START,
245 BM_SEL_START,
246 BM_RESUME,
247 BM_SEL_RESUME,
248 BM_NO_RESUME,
249 BM_HELP,
250 BM_SEL_HELP,
251 BM_QUIT,
252 BM_SEL_QUIT,
255 #include "pluginbitmaps/brickmania_pads.h"
256 #include "pluginbitmaps/brickmania_bricks.h"
257 #include "pluginbitmaps/brickmania_powerups.h"
258 #include "pluginbitmaps/brickmania_ball.h"
259 #include "pluginbitmaps/brickmania_menu_items.h"
260 #include "pluginbitmaps/brickmania_gameover.h"
262 #define PAD_WIDTH BMPWIDTH_brickmania_pads
263 #define PAD_HEIGHT (BMPHEIGHT_brickmania_pads/3)
264 #define BRICK_HEIGHT (BMPHEIGHT_brickmania_bricks/7)
265 #define BRICK_WIDTH BMPWIDTH_brickmania_bricks
266 #define LEFTMARGIN ((LCD_WIDTH-10*BRICK_WIDTH)/2)
267 #define POWERUP_HEIGHT (BMPHEIGHT_brickmania_powerups/7)
268 #define POWERUP_WIDTH BMPWIDTH_brickmania_powerups
269 #define BALL BMPHEIGHT_brickmania_ball
270 #define HALFBALL ((BALL+1)/2)
271 #define MENU_ITEMXOFS ((LCD_WIDTH - BMPWIDTH_brickmania_menu_items)/2)
272 #define MENU_ITEMHEIGHT (BMPHEIGHT_brickmania_menu_items/9)
273 #define MENU_ITEMWIDTH BMPWIDTH_brickmania_menu_items
274 #define GAMEOVER_WIDTH BMPWIDTH_brickmania_gameover
275 #define GAMEOVER_HEIGHT BMPHEIGHT_brickmania_gameover
277 #if LCD_DEPTH > 1 /* currently no background bmp for mono screens */
278 #include "pluginbitmaps/brickmania_menu_bg.h"
279 #define MENU_BGHEIGHT BMPHEIGHT_brickmania_menu_bg
280 #define MENU_BGWIDTH BMPWIDTH_brickmania_menu_bg
281 #endif
283 #ifdef HAVE_LCD_COLOR /* currently no transparency for non-colour */
284 #include "pluginbitmaps/brickmania_break.h"
285 #endif
287 #if ((LCD_WIDTH == 320) || (LCD_WIDTH == 400)) && (LCD_HEIGHT == 240)
289 /* The time (in ms) for one iteration through the game loop - decrease this
290 to speed up the game - note that current_tick is (currently) only accurate
291 to 10ms.
293 #define CYCLETIME 30
295 #define TOPMARGIN 30
297 #define BMPYOFS_start 110
298 #define HIGHSCORE_XPOS 57
299 #define HIGHSCORE_YPOS 88
301 #define STRINGPOS_FINISH 140
302 #define STRINGPOS_CONGRATS 157
303 #define STRINGPOS_NAVI 150
304 #define STRINGPOS_FLIP 150
306 #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176)
308 /* The time (in ms) for one iteration through the game loop - decrease this
309 to speed up the game - note that current_tick is (currently) only accurate
310 to 10ms.
312 #define CYCLETIME 30
314 /* Offsets for LCDS > 220x176 */
316 #define GAMESCREEN_HEIGHT 176
317 #define TOPMARGIN 30
319 #define XOFS ((LCD_WIDTH-220)/BRICK_WIDTH/2)*BRICK_WIDTH
320 #define YOFS ((LCD_HEIGHT-176)/BRICK_HEIGHT/2)*BRICK_HEIGHT
322 #define BMPYOFS_start (78+YOFS)
323 #define HIGHSCORE_XPOS (17+XOFS)
324 #define HIGHSCORE_YPOS (56+YOFS)
326 #define STRINGPOS_FINISH 140
327 #define STRINGPOS_CONGRATS 157
328 #define STRINGPOS_NAVI 150
329 #define STRINGPOS_FLIP 150
331 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
332 /* The time (in ms) for one iteration through the game loop - decrease this
333 to speed up the game - note that current_tick is (currently) only accurate
334 to 10ms.
336 #define CYCLETIME 50
338 #define TOPMARGIN 21
340 #if LCD_DEPTH > 2
341 #define BMPYOFS_start 58
342 #else
343 #define BMPYOFS_start 66
344 #endif
345 #define HIGHSCORE_XPOS 10
346 #define HIGHSCORE_YPOS 38
348 #define STRINGPOS_FINISH 110
349 #define STRINGPOS_CONGRATS 100
350 #define STRINGPOS_NAVI 100
351 #define STRINGPOS_FLIP 100
353 #elif (LCD_WIDTH == 132) && (LCD_HEIGHT == 80)
355 /* The time (in ms) for one iteration through the game loop - decrease this
356 to speed up the game - note that current_tick is (currently) only accurate
357 to 10ms.
359 #define CYCLETIME 50
361 #define TOPMARGIN 10
363 #define BMPYOFS_start 30
364 #define HIGHSCORE_XPOS 68
365 #define HIGHSCORE_YPOS 8
367 #define STRINGPOS_FINISH 55
368 #define STRINGPOS_CONGRATS 45
369 #define STRINGPOS_NAVI 60
370 #define STRINGPOS_FLIP 60
372 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128)
374 /* The time (in ms) for one iteration through the game loop - decrease this
375 to speed up the game - note that current_tick is (currently) only accurate
376 to 10ms.
378 #define CYCLETIME 50
380 #define GAMESCREEN_HEIGHT 100
381 #define TOPMARGIN 15
383 #define BMPYOFS_start 70
384 #define HIGHSCORE_XPOS 8
385 #define HIGHSCORE_YPOS 36
387 #define STRINGPOS_FINISH 55
388 #define STRINGPOS_CONGRATS 45
389 #define STRINGPOS_NAVI 60
390 #define STRINGPOS_FLIP 60
392 /* iPod Mini */
393 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
394 /* The time (in ms) for one iteration through the game loop - decrease this
395 to speed up the game - note that current_tick is (currently) only accurate
396 to 10ms.
398 #define CYCLETIME 50
400 #define TOPMARGIN 10
402 #define BMPYOFS_start 51
403 #define HIGHSCORE_XPOS 73
404 #define HIGHSCORE_YPOS 25
406 #define STRINGPOS_FINISH 54
407 #define STRINGPOS_CONGRATS 44
408 #define STRINGPOS_NAVI 44
409 #define STRINGPOS_FLIP 44
411 /* iAudio M3 */
412 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 96)
413 /* The time (in ms) for one iteration through the game loop - decrease this
414 to speed up the game - note that current_tick is (currently) only accurate
415 to 10ms.
417 #define CYCLETIME 50
419 #define TOPMARGIN 10
421 #define BMPYOFS_start 42
422 #define HIGHSCORE_XPOS 65
423 #define HIGHSCORE_YPOS 25
425 #define STRINGPOS_FINISH 54
426 #define STRINGPOS_CONGRATS 44
427 #define STRINGPOS_NAVI 44
428 #define STRINGPOS_FLIP 44
430 /* Archos / Sansa Clip / Sansa m200 */
431 #elif ((LCD_WIDTH == 112) | (LCD_WIDTH == 128)) && (LCD_HEIGHT == 64)
432 /* The time (in ms) for one iteration through the game loop - decrease this
433 to speed up the game - note that current_tick is (currently) only accurate
434 to 10ms.
436 #define CYCLETIME 75
438 #define TOPMARGIN 10
440 #define BMPYOFS_start 22
441 #define HIGHSCORE_XPOS 0
442 #define HIGHSCORE_YPOS 0
444 #define STRINGPOS_FINISH 54
445 #define STRINGPOS_CONGRATS 44
446 #define STRINGPOS_NAVI 44
447 #define STRINGPOS_FLIP 44
449 /* nano and sansa */
450 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT >= 132) && (LCD_DEPTH==16)
451 /* The time (in ms) for one iteration through the game loop - decrease this
452 to speed up the game - note that current_tick is (currently) only accurate
453 to 10ms.
456 #define CYCLETIME 30
458 #define GAMESCREEN_HEIGHT 132
459 #define TOPMARGIN 21
461 #define BMPYOFS_start 58
462 #define HIGHSCORE_XPOS 7
463 #define HIGHSCORE_YPOS 36
465 #define STRINGPOS_FINISH 110
466 #define STRINGPOS_CONGRATS 110
467 #define STRINGPOS_NAVI 100
468 #define STRINGPOS_FLIP 100
470 #else
471 #error Unsupported LCD Size
472 #endif
475 #ifndef GAMESCREEN_HEIGHT
476 #define GAMESCREEN_HEIGHT LCD_HEIGHT
477 #endif
479 /* calculate menu item offsets from the first defined and the height*/
480 #define BMPYOFS_resume (BMPYOFS_start + MENU_ITEMHEIGHT)
481 #define BMPYOFS_help (BMPYOFS_start + 2*MENU_ITEMHEIGHT)
482 #define BMPYOFS_quit (BMPYOFS_start + 3*MENU_ITEMHEIGHT)
484 /*calculate paddle y-position */
485 #if GAMESCREEN_HEIGHT >= 128
486 #define PAD_POS_Y GAMESCREEN_HEIGHT -PAD_HEIGHT - 2
487 #else
488 #define PAD_POS_Y GAMESCREEN_HEIGHT -PAD_HEIGHT - 1
489 #endif
492 #ifdef HAVE_TOUCHSCREEN
493 #include "lib/touchscreen.h"
495 static struct ts_mapping main_menu_items[4] =
497 {MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
498 {MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
499 {MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
500 {MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH, MENU_ITEMHEIGHT}
502 static struct ts_mappings main_menu = {main_menu_items, 4};
503 #endif
506 int levels_num = 29;
508 static unsigned char levels[29][8][10] = {
509 { /* level1 */
510 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
511 {0x2,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x2},
512 {0x0,0x2,0x1,0x0,0x0,0x0,0x0,0x1,0x2,0x0},
513 {0x0,0x0,0x2,0x1,0x0,0x0,0x1,0x2,0x0,0x0},
514 {0x0,0x0,0x0,0x2,0x1,0x1,0x2,0x0,0x0,0x0},
515 {0x7,0x0,0x0,0x7,0x2,0x2,0x7,0x0,0x0,0x7},
516 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
517 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
519 { /* level2 */
520 {0x0,0x0,0x7,0x7,0x1,0x1,0x7,0x7,0x0,0x0},
521 {0x0,0x1,0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x0},
522 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
523 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1},
524 {0x1,0x1,0x2,0x1,0x0,0x0,0x1,0x2,0x1,0x1},
525 {0x1,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x2,0x1},
526 {0x0,0x1,0x2,0x0,0x0,0x0,0x0,0x2,0x1,0x0},
527 {0x0,0x0,0x1,0x2,0x2,0x2,0x2,0x1,0x0,0x0}
529 { /* level3 */
530 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
531 {0x3,0x23,0x23,0x3,0x0,0x0,0x2,0x22,0x22,0x2},
532 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
533 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
534 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
535 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6},
536 {0x5,0x25,0x25,0x5,0x0,0x0,0x6,0x26,0x26,0x6},
537 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6}
539 { /* level4 */
540 {0x0,0x0,0x0,0x27,0x27,0x27,0x27,0x0,0x0,0x0},
541 {0x0,0x0,0x0,0x27,0x7,0x7,0x27,0x0,0x0,0x0},
542 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
543 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
544 {0x26,0x6,0x0,0x2,0x2,0x2,0x2,0x0,0x6,0x26},
545 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
546 {0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0},
547 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1}
549 { /* level5 */
550 {0x1,0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4},
551 {0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0},
552 {0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5},
553 {0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5,0x5},
554 {0x0,0x33,0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0},
555 {0x3,0x33,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x36},
556 {0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x6,0x36},
557 {0x0,0x24,0x24,0x0,0x25,0x25,0x0,0x26,0x26,0x0}
559 { /* level6 */
560 {0x0,0x1,0x3,0x7,0x7,0x7,0x7,0x3,0x1,0x0},
561 {0x3,0x1,0x3,0x7,0x0,0x0,0x7,0x3,0x1,0x3},
562 {0x3,0x1,0x3,0x7,0x7,0x7,0x7,0x3,0x1,0x3},
563 {0x0,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x0},
564 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5},
565 {0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5},
566 {0x0,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x0},
567 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
569 { /* level7 */
570 {0x0,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x0},
571 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
572 {0x6,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x6},
573 {0x6,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x6},
574 {0x6,0x6,0x6,0x0,0x0,0x0,0x0,0x6,0x6,0x6},
575 {0x0,0x0,0x0,0x1,0x1,0x1,0x1,0x0,0x0,0x0},
576 {0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0},
577 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
579 { /* level8 */
580 {0x0,0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x0},
581 {0x0,0x0,0x0,0x4,0x0,0x0,0x4,0x0,0x0,0x0},
582 {0x6,0x6,0x0,0x2,0x32,0x32,0x2,0x0,0x6,0x6},
583 {0x0,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x0,0x0},
584 {0x0,0x6,0x6,0x0,0x0,0x0,0x0,0x6,0x6,0x0},
585 {0x0,0x0,0x0,0x5,0x25,0x25,0x5,0x0,0x0,0x0},
586 {0x0,0x5,0x5,0x25,0x5,0x5,0x25,0x5,0x5,0x0},
587 {0x5,0x5,0x25,0x5,0x5,0x5,0x5,0x25,0x5,0x5}
589 { /* level9 */
590 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
591 {0x2,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x2},
592 {0x2,0x0,0x3,0x0,0x1,0x1,0x0,0x3,0x0,0x2},
593 {0x2,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x2},
594 {0x2,0x0,0x1,0x0,0x3,0x3,0x0,0x1,0x0,0x2},
595 {0x2,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x2},
596 {0x2,0x2,0x0,0x0,0x1,0x1,0x0,0x0,0x2,0x2},
597 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
599 { /* level10 */
600 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
601 {0x0,0x5,0x0,0x5,0x0,0x5,0x0,0x5,0x0,0x5},
602 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
603 {0x0,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x0},
604 {0x0,0x0,0x0,0x4,0x1,0x1,0x4,0x0,0x0,0x0},
605 {0x0,0x0,0x3,0x4,0x1,0x1,0x4,0x3,0x0,0x0},
606 {0x0,0x2,0x3,0x4,0x1,0x1,0x4,0x3,0x2,0x0},
607 {0x1,0x2,0x3,0x4,0x1,0x1,0x4,0x3,0x2,0x1}
609 { /* level11 */
610 {0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3},
611 {0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x2},
612 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
613 {0x2,0x0,0x0,0x0,0x7,0x7,0x0,0x0,0x0,0x2},
614 {0x2,0x0,0x0,0x7,0x7,0x7,0x7,0x0,0x0,0x2},
615 {0x0,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x0},
616 {0x0,0x2,0x0,0x1,0x0,0x0,0x1,0x0,0x2,0x0},
617 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5}
619 { /* level 12 */
620 {0x2,0x1,0x3,0x1,0x0,0x0,0x1,0x3,0x1,0x2},
621 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1},
622 {0x1,0x1,0x1,0x0,0x1,0x1,0x0,0x1,0x1,0x1},
623 {0x0,0x1,0x0,0x1,0x6,0x6,0x1,0x0,0x1,0x0},
624 {0x0,0x0,0x1,0x1,0x6,0x6,0x1,0x1,0x0,0x0},
625 {0x1,0x1,0x1,0x7,0x0,0x0,0x7,0x1,0x1,0x1},
626 {0x1,0x1,0x7,0x1,0x0,0x0,0x1,0x7,0x1,0x1},
627 {0x2,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x2,0x2}
629 {/* levell13 */
630 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
631 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
632 {0x2,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x0,0x2},
633 {0x2,0x0,0x2,0x3,0x3,0x3,0x3,0x3,0x0,0x2},
634 {0x2,0x0,0x2,0x4,0x4,0x4,0x4,0x4,0x0,0x2},
635 {0x2,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
636 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
637 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
639 {/* level14 */
640 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
641 {0x4,0x4,0x4,0x4,0x2,0x2,0x4,0x4,0x4,0x4},
642 {0x4,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x4},
643 {0x4,0x0,0x0,0x2,0x3,0x3,0x2,0x0,0x0,0x4},
644 {0x4,0x0,0x2,0x23,0x3,0x3,0x23,0x2,0x0,0x4},
645 {0x4,0x0,0x2,0x22,0x2,0x2,0x22,0x2,0x0,0x4},
646 {0x4,0x0,0x6,0x21,0x5,0x5,0x21,0x6,0x0,0x4},
647 {0x4,0x6,0x1,0x1,0x5,0x5,0x1,0x1,0x6,0x4}
649 {/* level 15 */
650 {0x4,0x4,0x4,0x4,0x4,0x3,0x3,0x3,0x3,0x3},
651 {0x2,0x2,0x1,0x1,0x1,0x1,0x1,0x5,0x0,0x0},
652 {0x2,0x2,0x1,0x1,0x1,0x0,0x1,0x6,0x0,0x0},
653 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x5,0x0,0x0},
654 {0x2,0x1,0x2,0x2,0x2,0x1,0x1,0x6,0x0,0x0},
655 {0x2,0x1,0x2,0x2,0x2,0x1,0x3,0x5,0x3,0x0},
656 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x6,0x0,0x0},
657 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
659 {/* level 16 (Rockbox) by ts-x */
660 {0x2,0x2,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
661 {0x2,0x0,0x3,0x0,0x3,0x4,0x0,0x5,0x5,0x0},
662 {0x2,0x0,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
663 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
664 {0x6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
665 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0},
666 {0x7,0x0,0x7,0x1,0x0,0x1,0x0,0x2,0x0,0x0},
667 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0}
669 {/* level 17 (Alien) by ts-x */
670 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
671 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
672 {0x1,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x1},
673 {0x2,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x2},
674 {0x1,0x0,0x1,0x2,0x2,0x2,0x2,0x1,0x0,0x1},
675 {0x2,0x0,0x0,0x1,0x2,0x2,0x1,0x0,0x0,0x2},
676 {0x2,0x1,0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x2},
677 {0x2,0x2,0x1,0x0,0x1,0x1,0x0,0x1,0x2,0x2}
679 {/* level 18 (Tetris) by ts-x */
680 {0x0,0x2,0x0,0x0,0x3,0x4,0x0,0x2,0x2,0x0},
681 {0x0,0x2,0x7,0x0,0x3,0x4,0x0,0x2,0x2,0x0},
682 {0x2,0x2,0x7,0x0,0x3,0x4,0x0,0x6,0x2,0x2},
683 {0x2,0x2,0x7,0x7,0x3,0x4,0x0,0x6,0x2,0x2},
684 {0x2,0x1,0x7,0x7,0x3,0x4,0x4,0x6,0x5,0x5},
685 {0x2,0x1,0x0,0x7,0x3,0x4,0x4,0x6,0x5,0x5},
686 {0x1,0x1,0x1,0x7,0x3,0x0,0x6,0x6,0x5,0x5},
687 {0x1,0x1,0x1,0x0,0x3,0x0,0x6,0x6,0x5,0x5}
689 { /* level 19 (Stalactites) by ts-x */
690 {0x5,0x2,0x6,0x3,0x4,0x7,0x5,0x3,0x1,0x2},
691 {0x5,0x2,0x6,0x3,0x4,0x7,0x5,0x3,0x1,0x2},
692 {0x5,0x0,0x6,0x3,0x4,0x7,0x5,0x0,0x1,0x2},
693 {0x5,0x2,0x6,0x3,0x4,0x0,0x5,0x3,0x1,0x2},
694 {0x5,0x0,0x6,0x0,0x4,0x7,0x5,0x0,0x1,0x0},
695 {0x5,0x0,0x0,0x3,0x4,0x0,0x0,0x0,0x1,0x2},
696 {0x0,0x0,0x6,0x0,0x0,0x0,0x5,0x0,0x0,0x0},
697 {0x5,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x1,0x0}
699 { /* level 20 (Maze) by ts-x */
700 {0x1,0x1,0x21,0x1,0x1,0x1,0x1,0x1,0x1,0x21},
701 {0x1,0x0,0x0,0x3,0x0,0x0,0x3,0x1,0x31,0x1},
702 {0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x31,0x0,0x1},
703 {0x21,0x0,0x21,0x3,0x0,0x3,0x0,0x3,0x0,0x2},
704 {0x1,0x0,0x1,0x21,0x0,0x12,0x0,0x0,0x0,0x0},
705 {0x31,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x3,0x0},
706 {0x1,0x0,0x1,0x0,0x1,0x1,0x31,0x1,0x1,0x2},
707 {0x22,0x0,0x2,0x1,0x1,0x1,0x1,0x1,0x1,0x21}
709 { /* level 21 (Dentist) by ts-x */
710 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0},
711 {0x2,0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x2,0x2},
712 {0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x2},
713 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x6,0x0,0x2},
714 {0x2,0x0,0x6,0x0,0x6,0x0,0x0,0x0,0x0,0x2},
715 {0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x2},
716 {0x2,0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x2,0x2},
717 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0}
719 { /* level 22 (Spider) by ts-x */
720 {0x31,0x3,0x1,0x1,0x0,0x0,0x1,0x1,0x3,0x31},
721 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
722 {0x33,0x1,0x1,0x36,0x1,0x1,0x36,0x1,0x1,0x33},
723 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
724 {0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x1,0x0,0x0},
725 {0x21,0x3,0x1,0x21,0x2,0x2,0x21,0x1,0x3,0x21},
726 {0x0,0x0,0x0,0x1,0x21,0x1,0x1,0x0,0x0,0x0},
727 {0x3,0x1,0x3,0x1,0x0,0x0,0x1,0x3,0x1,0x3}
729 { /* level 23 (Pool) by ts-x */
730 {0x0,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x7,0x0},
731 {0x0,0x0,0x5,0x0,0x2,0x0,0x0,0x0,0x2,0x0},
732 {0x7,0x3,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x7},
733 {0x7,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x0,0x7},
734 {0x7,0x0,0x4,0x0,0x0,0x3,0x0,0x0,0x0,0x7},
735 {0x7,0x0,0x0,0x6,0x0,0x0,0x0,0x0,0x4,0x7},
736 {0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
737 {0x0,0x7,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x0}
739 { /* level 24 (Vorbis Fish) by ts-x */
740 {0x0,0x0,0x4,0x4,0x5,0x5,0x5,0x0,0x0,0x5},
741 {0x0,0x4,0x6,0x4,0x4,0x5,0x5,0x5,0x0,0x5},
742 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x5,0x5,0x5},
743 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x4,0x5,0x5},
744 {0x0,0x5,0x6,0x4,0x4,0x5,0x5,0x4,0x5,0x0},
745 {0x5,0x5,0x4,0x4,0x5,0x5,0x5,0x4,0x5,0x5},
746 {0x5,0x4,0x4,0x4,0x5,0x5,0x4,0x4,0x5,0x5},
747 {0x0,0x0,0x4,0x4,0x4,0x4,0x4,0x5,0x0,0x5}
749 {/* level 25 (Rainbow) by ts-x */
750 {0x0,0x4,0x1,0x0,0x0,0x0,0x0,0x1,0x4,0x0},
751 {0x24,0x1,0x3,0x1,0x0,0x0,0x21,0x3,0x1,0x24},
752 {0x1,0x23,0x5,0x3,0x1,0x21,0x3,0x5,0x3,0x21},
753 {0x3,0x5,0x6,0x5,0x3,0x3,0x5,0x6,0x5,0x3},
754 {0x5,0x6,0x7,0x6,0x5,0x5,0x6,0x7,0x6,0x5},
755 {0x6,0x7,0x2,0x27,0x6,0x6,0x27,0x2,0x7,0x6},
756 {0x7,0x2,0x0,0x2,0x27,0x27,0x2,0x0,0x2,0x7},
757 {0x32,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x32}
759 { /* level 26 (Bowtie) by ts-x */
760 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5},
761 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
762 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
763 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
764 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
765 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
766 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
767 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5}
769 { /* level 27 (Frog) by ts-x */
770 {0x0,0x5,0x25,0x0,0x0,0x0,0x0,0x25,0x5,0x0},
771 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5},
772 {0x25,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x25},
773 {0x5,0x0,0x3,0x0,0x6,0x6,0x0,0x3,0x0,0x5},
774 {0x5,0x0,0x31,0x0,0x6,0x6,0x0,0x31,0x0,0x5},
775 {0x5,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x5},
776 {0x5,0x5,0x5,0x35,0x0,0x0,0x35,0x5,0x5,0x5},
777 {0x0,0x25,0x5,0x0,0x4,0x4,0x0,0x5,0x25,0x0}
779 { /* level 28 (DigDug) by ts-x */
780 {0x35,0x5,0x5,0x25,0x0,0x25,0x25,0x5,0x5,0x35},
781 {0x6,0x0,0x0,0x6,0x0,0x6,0x6,0x0,0x0,0x6},
782 {0x7,0x0,0x37,0x37,0x0,0x37,0x37,0x7,0x0,0x7},
783 {0x7,0x0,0x7,0x0,0x0,0x0,0x7,0x7,0x7,0x7},
784 {0x4,0x4,0x4,0x24,0x0,0x24,0x4,0x0,0x0,0x4},
785 {0x4,0x4,0x0,0x0,0x0,0x4,0x4,0x0,0x4,0x4},
786 {0x24,0x24,0x4,0x4,0x4,0x4,0x0,0x0,0x24,0x4},
787 {0x1,0x1,0x1,0x1,0x1,0x1,0x21,0x21,0x1,0x1}
789 { /* TheEnd */
790 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
791 {0x22,0x22,0x26,0x0,0x0,0x26,0x24,0x24,0x0,0x0},
792 {0x22,0x0,0x26,0x26,0x0,0x26,0x24,0x0,0x24,0x0},
793 {0x22,0x22,0x26,0x26,0x0,0x26,0x24,0x0,0x24,0x0},
794 {0x22,0x22,0x26,0x0,0x26,0x26,0x24,0x0,0x24,0x0},
795 {0x22,0x0,0x26,0x0,0x26,0x26,0x24,0x0,0x24,0x0},
796 {0x22,0x22,0x26,0x0,0x0,0x26,0x24,0x24,0x0,0x0},
797 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
801 #define MAX_BALLS 10
802 int pad_pos_x;
803 int x[MAX_BALLS],y[MAX_BALLS];
804 int life;
805 int start_game,con_game;
806 int pad_type;
807 int score=0,vscore=0;
808 bool flip_sides=false;
809 int cur_level=0;
810 int brick_on_board=0;
811 int used_balls=1;
813 typedef struct cube {
814 int powertop;
815 int power;
816 char poweruse;
817 char used;
818 int color;
819 int hits;
820 int hiteffect;
821 } cube;
822 cube brick[80];
824 typedef struct balls {
825 int pos_x;
826 int pos_y;
827 int y;
828 int tempy;
829 int x;
830 int tempx;
831 bool glue;
832 } balls;
834 balls ball[MAX_BALLS];
836 typedef struct sfire {
837 int top;
838 int left;
839 } sfire;
840 sfire fire[30];
843 int highscore;
844 #define MAX_POINTS 200000 /* i dont think it needs to be more */
845 static struct configdata config[] =
847 {TYPE_INT, 0, MAX_POINTS, { .int_p = &highscore }, "highscore", NULL}
850 void int_game(int new_game)
852 int i,j;
854 pad_pos_x=LCD_WIDTH/2-PAD_WIDTH/2;
856 for(i=0;i<MAX_BALLS;i++) {
857 ball[i].x=0;
858 ball[i].y=0;
859 ball[i].tempy=0;
860 ball[i].tempx=0;
861 ball[i].pos_y=PAD_POS_Y-BALL;
862 ball[i].pos_x=pad_pos_x+(PAD_WIDTH/2)-2;
863 ball[i].glue=false;
866 used_balls=1;
867 start_game =1;
868 con_game =0;
869 pad_type=0;
871 flip_sides=false;
873 if (new_game==1)
874 brick_on_board=0;
876 for(i=0;i<=7;i++) {
877 for(j=0;j<=9;j++) {
878 brick[i*10+j].poweruse=(levels[cur_level][i][j]==0?0:1);
879 if (i*10+j<=30)
880 fire[i*10+j].top=-8;
881 if (new_game==1) {
882 brick[i*10+j].power=rb->rand()%25;
883 /* +8 make the game with less powerups */
885 brick[i*10+j].hits=levels[cur_level][i][j]>=10?
886 levels[cur_level][i][j]/16-1:0;
887 brick[i*10+j].hiteffect=0;
888 brick[i*10+j].powertop=TOPMARGIN+i*BRICK_HEIGHT+BRICK_HEIGHT;
889 brick[i*10+j].used=(levels[cur_level][i][j]==0?0:1);
890 brick[i*10+j].color=(levels[cur_level][i][j]>=10?
891 levels[cur_level][i][j]%16:
892 levels[cur_level][i][j])-1;
893 if (levels[cur_level][i][j]!=0)
894 brick_on_board++;
900 int sw,i,w;
902 /* sleep timer counting the score */
903 void sleep (int secs)
905 bool done=false;
906 char s[20];
907 int count=0;
909 while (!done) {
911 if (vscore<score) {
912 vscore++;
913 rb->snprintf(s, sizeof(s), "%d", vscore);
914 rb->lcd_getstringsize(s, &sw, &w);
915 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
916 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
917 #else
918 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s);
919 #endif
920 rb->lcd_update_rect(0,0,LCD_WIDTH,w+2);
921 } else {
922 if (count==0)
923 count=*rb->current_tick+HZ*secs;
924 if (*rb->current_tick>=count)
925 done=true;
927 rb->yield();
932 #define HIGH_SCORE "brickmania.score"
933 #define MENU_LENGTH 4
934 int game_menu(int when)
936 int button,cur=0;
937 char str[10];
938 rb->lcd_clear_display();
939 #if LCD_DEPTH > 1 /* currently no background bmp for mono screens */
940 rb->lcd_bitmap(brickmania_menu_bg, 0, 0, MENU_BGWIDTH, MENU_BGHEIGHT);
941 #endif
942 while (true) {
943 for(i=0;i<MENU_LENGTH;i++) {
944 #ifdef HAVE_LCD_COLOR
945 if (cur==0)
946 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
947 MENU_ITEMHEIGHT * BM_SEL_START, MENU_ITEMWIDTH,
948 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
949 MENU_ITEMHEIGHT);
950 else
951 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
952 MENU_ITEMHEIGHT * BM_START, MENU_ITEMWIDTH,
953 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
954 MENU_ITEMHEIGHT);
956 if (when==1) {
957 if (cur==1)
958 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
959 MENU_ITEMHEIGHT * BM_SEL_RESUME, MENU_ITEMWIDTH,
960 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
961 MENU_ITEMHEIGHT);
962 else
963 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
964 MENU_ITEMHEIGHT * BM_RESUME, MENU_ITEMWIDTH,
965 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
966 MENU_ITEMHEIGHT);
968 } else {
969 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
970 MENU_ITEMHEIGHT * BM_NO_RESUME, MENU_ITEMWIDTH,
971 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
972 MENU_ITEMHEIGHT);
976 if (cur==2)
977 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
978 MENU_ITEMHEIGHT * BM_SEL_HELP, MENU_ITEMWIDTH,
979 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
980 MENU_ITEMHEIGHT);
981 else
982 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
983 MENU_ITEMHEIGHT * BM_HELP, MENU_ITEMWIDTH,
984 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
985 MENU_ITEMHEIGHT);
987 if (cur==3)
988 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
989 MENU_ITEMHEIGHT * BM_SEL_QUIT, MENU_ITEMWIDTH,
990 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
991 MENU_ITEMHEIGHT);
992 else
993 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
994 MENU_ITEMHEIGHT * BM_QUIT, MENU_ITEMWIDTH,
995 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
996 MENU_ITEMHEIGHT);
997 #else
998 if (cur==0)
999 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1000 MENU_ITEMHEIGHT * BM_SEL_START, MENU_ITEMWIDTH,
1001 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
1002 MENU_ITEMHEIGHT);
1003 else
1004 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1005 MENU_ITEMHEIGHT * BM_START, MENU_ITEMWIDTH,
1006 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
1007 MENU_ITEMHEIGHT);
1009 if (when==1) {
1010 if (cur==1)
1011 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1012 MENU_ITEMHEIGHT * BM_SEL_RESUME, MENU_ITEMWIDTH,
1013 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
1014 MENU_ITEMHEIGHT);
1015 else
1016 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1017 MENU_ITEMHEIGHT * BM_RESUME, MENU_ITEMWIDTH,
1018 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
1019 MENU_ITEMHEIGHT);
1021 } else {
1022 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1023 MENU_ITEMHEIGHT * BM_NO_RESUME, MENU_ITEMWIDTH,
1024 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
1025 MENU_ITEMHEIGHT);
1029 if (cur==2)
1030 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1031 MENU_ITEMHEIGHT * BM_SEL_HELP, MENU_ITEMWIDTH,
1032 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
1033 MENU_ITEMHEIGHT);
1034 else
1035 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1036 MENU_ITEMHEIGHT * BM_HELP, MENU_ITEMWIDTH,
1037 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
1038 MENU_ITEMHEIGHT);
1040 if (cur==3)
1041 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1042 MENU_ITEMHEIGHT * BM_SEL_QUIT, MENU_ITEMWIDTH,
1043 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
1044 MENU_ITEMHEIGHT);
1045 else
1046 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1047 MENU_ITEMHEIGHT * BM_QUIT, MENU_ITEMWIDTH,
1048 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
1049 MENU_ITEMHEIGHT);
1050 #endif
1052 rb->lcd_set_drawmode(DRMODE_FG);
1053 /* high score */
1054 #ifdef HAVE_LCD_COLOR
1055 rb->lcd_set_background(LCD_RGBPACK(0,0,140));
1056 rb->lcd_set_foreground(LCD_WHITE);
1057 #endif
1058 rb->lcd_putsxy(HIGHSCORE_XPOS, HIGHSCORE_YPOS, "High Score");
1059 rb->snprintf(str, sizeof(str), "%d", highscore);
1060 rb->lcd_getstringsize("High Score", &sw, NULL);
1061 rb->lcd_getstringsize(str, &w, NULL);
1062 rb->lcd_putsxy(HIGHSCORE_XPOS+sw/2-w/2, HIGHSCORE_YPOS+9, str);
1063 rb->lcd_set_drawmode(DRMODE_SOLID);
1065 rb->lcd_update();
1067 button = rb->button_get(true);
1068 #ifdef HAVE_TOUCHSCREEN
1069 if(button & BUTTON_TOUCHSCREEN)
1071 unsigned int result = touchscreen_map(&main_menu, rb->button_get_data() >> 16, rb->button_get_data() & 0xffff);
1072 if(result != (unsigned)-1 && button & BUTTON_REL)
1074 if(cur == (signed)result)
1075 button = SELECT;
1076 cur = result;
1079 #endif
1080 switch(button) {
1081 case UP:
1082 case UP | BUTTON_REPEAT:
1083 if (cur==0)
1084 cur = MENU_LENGTH-1;
1085 else
1086 cur--;
1087 if (when==0 && cur==1) {
1088 cur = 0;
1090 break;
1092 case DOWN:
1093 case DOWN | BUTTON_REPEAT:
1094 if (cur==MENU_LENGTH-1)
1095 cur = 0;
1096 else
1097 cur++;
1098 if (when==0 && cur==1) {
1099 cur=2;
1101 break;
1103 case RIGHT:
1104 case SELECT:
1105 if (cur==0) {
1106 score=0;
1107 vscore=0;
1108 return 0;
1109 } else if (cur==1 && when==1) {
1110 return 1;
1111 } else if (cur==2) {
1112 return 2;
1113 } else if (cur==3) {
1114 return 3;
1116 break;
1117 #ifdef RC_QUIT
1118 case RC_QUIT:
1119 #endif
1120 case QUIT:
1121 return 3;
1122 break;
1124 default:
1125 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1126 return 3;
1127 break;
1130 rb->yield();
1134 int help(void)
1136 int button;
1137 #define WORDS (sizeof help_text / sizeof (char*))
1138 static char* help_text[] = {
1139 "BrickMania", "", "Aim", "",
1140 "Destroy", "all", "the", "bricks", "by", "bouncing",
1141 "the", "ball", "of", "them", "using", "the", "paddle.", "", "",
1142 "Controls", "",
1143 "< & >", "Move", "the", "paddle", "",
1144 #if CONFIG_KEYPAD == ONDIO_PAD
1145 "MENU",
1146 #elif (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1147 "PLAY",
1148 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
1149 "NAVI",
1150 #else
1151 "SELECT",
1152 #endif
1153 "Releases", "the", "ball/", "Fire!", "",
1154 #if CONFIG_KEYPAD == IAUDIO_M3_PAD
1155 "REC",
1156 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
1157 (CONFIG_KEYPAD == CREATIVEZVM_PAD)
1158 "BACK",
1159 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
1160 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1161 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
1162 "MENU",
1163 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
1164 (CONFIG_KEYPAD == IRIVER_H300_PAD) || \
1165 (CONFIG_KEYPAD == ONDIO_PAD) || \
1166 (CONFIG_KEYPAD == RECORDER_PAD) || \
1167 (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
1168 "STOP",
1169 #else
1170 "POWER",
1171 #endif
1172 "Opens", "menu/", "Quit", "", "",
1173 "Specials", "",
1174 "N", "Normal:", "returns", "paddle", "to", "normal", "",
1175 "D", "DIE!:", "loses", "a", "life", "",
1176 "L", "Life:", "gains", "a", "life/", "power", "up", "",
1177 "F", "Fire:", "allows", "you", "to", "shoot", "bricks", "",
1178 "G", "Glue:", "ball", "sticks", "to", "paddle", "",
1179 "B", "Ball:", "generates", "another", "ball", "",
1180 "FL", "Flip:", "flips", "left /", "right", "movement",
1182 static struct style_text formation[]={
1183 { 0, TEXT_CENTER|TEXT_UNDERLINE },
1184 { 2, C_RED },
1185 { 19, C_RED },
1186 { 38, C_RED },
1187 { 40, C_BLUE },
1188 { 47, C_RED },
1189 { 53, C_GREEN },
1190 { 61, C_ORANGE },
1191 { 69, C_GREEN },
1192 { 76, C_YELLOW },
1193 { 82, C_RED },
1194 { -1, 0 }
1197 #ifdef HAVE_LCD_COLOR
1198 rb->lcd_set_background(LCD_BLACK);
1199 rb->lcd_set_foreground(LCD_WHITE);
1200 #endif
1202 rb->lcd_setfont(FONT_UI);
1203 if (display_text(WORDS, help_text, formation, NULL))
1204 return 1;
1205 do {
1206 button = rb->button_get(true);
1207 if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
1208 return 1;
1209 } while( ( button == BUTTON_NONE )
1210 || ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
1211 rb->lcd_setfont(FONT_SYSFIXED);
1212 return 0;
1215 int pad_check(int ballxc, int mode, int pon ,int ballnum)
1217 /* pon: positive(1) or negative(0) */
1219 if (mode==0) {
1220 if (pon == 0)
1221 return -ballxc;
1222 else
1223 return ballxc;
1224 } else {
1225 if (ball[ballnum].x > 0)
1226 return ballxc;
1227 else
1228 return ballxc*-1;
1232 int fire_space(void)
1234 int t;
1235 for(t=0;t<=30;t++)
1236 if (fire[t].top+7 < 0)
1237 return t;
1239 return 0;
1242 int game_loop(void)
1244 int j,i,k,bricky,brickx;
1245 char s[30];
1246 int sec_count=0,num_count=10;
1247 int end;
1249 switch(game_menu(0)) {
1250 case 0:
1251 cur_level = 0;
1252 life = 2;
1253 int_game(1);
1254 break;
1255 case 1:
1256 con_game = 1;
1257 break;
1258 case 2:
1259 return help();
1260 break;
1261 case 3:
1262 return 1;
1263 break;
1266 while(true) {
1267 /* Convert CYCLETIME (in ms) to HZ */
1268 end = *rb->current_tick + (CYCLETIME * HZ) / 1000;
1270 if (life >= 0) {
1271 #ifdef HAVE_LCD_COLOR
1272 rb->lcd_set_background(LCD_BLACK);
1273 rb->lcd_set_drawmode(DRMODE_SOLID);
1274 rb->lcd_clear_display();
1275 rb->lcd_set_background(LCD_BLACK);
1276 #if LCD_HEIGHT > GAMESCREEN_HEIGHT
1277 rb->lcd_set_foreground(rb->global_settings->bg_color);
1278 rb->lcd_fillrect(0, GAMESCREEN_HEIGHT, LCD_WIDTH,
1279 LCD_HEIGHT - GAMESCREEN_HEIGHT);
1280 #endif
1281 rb->lcd_set_foreground(LCD_WHITE);
1282 #else
1283 rb->lcd_clear_display();
1284 #endif
1286 if (flip_sides) {
1287 if (*rb->current_tick>=sec_count) {
1288 sec_count=*rb->current_tick+HZ;
1289 if (num_count!=0)
1290 num_count--;
1291 else
1292 flip_sides=false;
1294 rb->snprintf(s, sizeof(s), "%d", num_count);
1295 rb->lcd_getstringsize(s, &sw, NULL);
1296 rb->lcd_putsxy(LCD_WIDTH/2-2, STRINGPOS_FLIP, s);
1299 /* write life num */
1300 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1301 rb->snprintf(s, sizeof(s), "L:%d", life);
1302 rb->lcd_putsxy(0, 0, s);
1303 #else
1304 rb->snprintf(s, sizeof(s), "Life: %d", life);
1305 rb->lcd_putsxy(2, 2, s);
1306 #endif
1308 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1309 rb->snprintf(s, sizeof(s), "L%d", cur_level+1);
1310 rb->lcd_getstringsize(s, &sw, NULL);
1311 rb->lcd_putsxy(LCD_WIDTH-sw, 0, s);
1312 #else
1313 rb->snprintf(s, sizeof(s), "Level %d", cur_level+1);
1314 rb->lcd_getstringsize(s, &sw, NULL);
1315 rb->lcd_putsxy(LCD_WIDTH-sw-2, 2, s);
1316 #endif
1318 if (vscore<score) vscore++;
1319 rb->snprintf(s, sizeof(s), "%d", vscore);
1320 rb->lcd_getstringsize(s, &sw, NULL);
1321 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1322 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
1323 #else
1324 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s);
1325 #endif
1327 /* continue game */
1328 if (con_game== 1 && start_game!=1) {
1329 #if CONFIG_KEYPAD == ONDIO_PAD
1330 rb->snprintf(s, sizeof(s), "MENU To Continue");
1331 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
1332 rb->snprintf(s, sizeof(s), "Press NAVI To Continue");
1333 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
1334 rb->snprintf(s, sizeof(s), "PLAY To Continue");
1335 #else
1336 rb->snprintf(s, sizeof(s), "Press SELECT To Continue");
1337 #endif
1338 rb->lcd_getstringsize(s, &sw, NULL);
1339 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_NAVI, s);
1341 sec_count=*rb->current_tick+HZ;
1344 /* draw the ball */
1345 for(i=0;i<used_balls;i++)
1346 rb->lcd_bitmap(brickmania_ball,ball[i].pos_x, ball[i].pos_y,
1347 BALL, BALL);
1349 if (brick_on_board==0)
1350 brick_on_board--;
1352 /* if the pad is fire */
1353 for(i=0;i<=30;i++) {
1354 if (fire[i].top+7>0) {
1355 if (con_game!=1)
1356 fire[i].top-=4;
1357 rb->lcd_vline(fire[i].left, fire[i].top, fire[i].top+7);
1361 /* the bricks */
1362 for (i=0;i<=7;i++) {
1363 for (j=0;j<=9;j++) {
1364 if (brick[i*10+j].power<7) {
1365 if (brick[i*10+j].poweruse==2) {
1366 if (con_game!=1)
1367 brick[i*10+j].powertop+=2;
1368 rb->lcd_bitmap_part(brickmania_powerups,0,
1369 POWERUP_HEIGHT*brick[i*10+j
1370 ].power,
1371 POWERUP_WIDTH,
1372 LEFTMARGIN+j*BRICK_WIDTH+
1373 (BRICK_WIDTH/2-
1374 POWERUP_WIDTH/2),
1375 brick[i*10+j].powertop,
1376 POWERUP_WIDTH,
1377 POWERUP_HEIGHT);
1381 if ((pad_pos_x<LEFTMARGIN+j*BRICK_WIDTH+5 &&
1382 pad_pos_x+PAD_WIDTH>LEFTMARGIN+j*BRICK_WIDTH+5) &&
1383 brick[i*10+j].powertop+6>=PAD_POS_Y &&
1384 brick[i*10+j].poweruse==2) {
1385 switch(brick[i*10+j].power) {
1386 case 0:
1387 life++;
1388 score+=50;
1389 break;
1390 case 1:
1391 life--;
1392 if (life>=0) {
1393 int_game(0);
1394 sleep(2);
1396 break;
1397 case 2:
1398 score+=34;
1399 pad_type=1;
1400 break;
1401 case 3:
1402 score+=47;
1403 pad_type=2;
1404 for(k=0;k<used_balls;k++)
1405 ball[k].glue=false;
1406 break;
1407 case 4:
1408 score+=23;
1409 pad_type=0;
1410 for(k=0;k<used_balls;k++)
1411 ball[k].glue=false;
1412 flip_sides=false;
1413 break;
1414 case 5:
1415 score+=23;
1416 sec_count=*rb->current_tick+HZ;
1417 num_count=10;
1418 flip_sides=!flip_sides;
1419 break;
1420 case 6:
1421 score+=23;
1422 used_balls++;
1423 ball[used_balls-1].x= rb->rand()%1 == 0 ?
1424 -1 : 1;
1425 ball[used_balls-1].y= -4;
1426 break;
1428 brick[i*10+j].poweruse=1;
1431 if (brick[i*10+j].powertop>PAD_POS_Y)
1432 brick[i*10+j].poweruse=1;
1434 brickx=LEFTMARGIN+j*BRICK_WIDTH;
1435 bricky=TOPMARGIN+i*BRICK_HEIGHT;
1436 if (pad_type==2) {
1437 for (k=0;k<=30;k++) {
1438 if (fire[k].top+7>0) {
1439 if (brick[i*10+j].used==1 &&
1440 (fire[k].left+1 >= brickx &&
1441 fire[k].left+1 <= brickx+BRICK_WIDTH) &&
1442 (bricky+BRICK_HEIGHT>fire[k].top)) {
1443 score+=13;
1444 fire[k].top=-16;
1445 if (brick[i*10+j].hits > 0) {
1446 brick[i*10+j].hits--;
1447 brick[i*10+j].hiteffect++;
1448 score+=3;
1450 else {
1451 brick[i*10+j].used=0;
1452 if (brick[i*10+j].power!=10)
1453 brick[i*10+j].poweruse=2;
1454 brick_on_board--;
1461 if (brick[i*10+j].used==1) {
1462 rb->lcd_bitmap_part(brickmania_bricks,0,
1463 BRICK_HEIGHT*brick[i*10+j].color,
1464 BRICK_WIDTH,
1465 LEFTMARGIN+j*BRICK_WIDTH,
1466 TOPMARGIN+i*BRICK_HEIGHT,
1467 BRICK_WIDTH, BRICK_HEIGHT);
1468 #ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */
1469 if (brick[i*10+j].hiteffect>0)
1470 rb->lcd_bitmap_transparent_part(brickmania_break,
1472 BRICK_HEIGHT*brick[i*10+j].hiteffect,
1473 BRICK_WIDTH,
1474 LEFTMARGIN+j*BRICK_WIDTH,
1475 TOPMARGIN+i*BRICK_HEIGHT,
1476 BRICK_WIDTH,
1477 BRICK_HEIGHT);
1478 #endif
1481 for(k=0;k<used_balls;k++) {
1482 if (ball[k].pos_y <160) {
1483 if (brick[i*10+j].used==1) {
1484 if ((ball[k].pos_x+ball[k].x+HALFBALL >=
1485 brickx &&
1486 ball[k].pos_x+ball[k].x+HALFBALL <=
1487 brickx+BRICK_WIDTH) &&
1488 ((bricky-4<ball[k].pos_y+BALL &&
1489 bricky>ball[k].pos_y+BALL) ||
1490 (bricky+4>ball[k].pos_y+BALL+BALL &&
1491 bricky<ball[k].pos_y+BALL+BALL)) &&
1492 (ball[k].y >0)) {
1493 ball[k].tempy=bricky-ball[k].pos_y-BALL;
1495 else if ((ball[k].pos_x+ball[k].x+HALFBALL >=
1496 brickx &&
1497 ball[k].pos_x+ball[k].x+HALFBALL <=
1498 brickx+BRICK_WIDTH) &&
1499 ((bricky+BRICK_HEIGHT+4>ball[k].pos_y &&
1500 bricky+BRICK_HEIGHT<ball[k].pos_y) ||
1501 (bricky+BRICK_HEIGHT-4<ball[k].pos_y-BALL &&
1502 bricky+BRICK_HEIGHT>ball[k].pos_y-BALL)) &&
1503 (ball[k].y <0)) {
1504 ball[k].tempy=
1505 -(ball[k].pos_y-(bricky+BRICK_HEIGHT));
1508 if ((ball[k].pos_y+HALFBALL >=
1509 bricky &&
1510 ball[k].pos_y+HALFBALL <=
1511 bricky+BRICK_HEIGHT) &&
1512 ((brickx-4<ball[k].pos_x+BALL &&
1513 brickx>ball[k].pos_x+BALL) ||
1514 (brickx+4>ball[k].pos_x+BALL+BALL &&
1515 brickx<ball[k].pos_x+BALL+BALL)) &&
1516 (ball[k].x >0)) {
1517 ball[k].tempx=brickx-ball[k].pos_x-BALL;
1519 else if ((ball[k].pos_y+ball[k].y+HALFBALL >=
1520 bricky &&
1521 ball[k].pos_y+ball[k].y+HALFBALL <=
1522 bricky+BRICK_HEIGHT) &&
1523 ((brickx+BRICK_WIDTH+4>ball[k].pos_x &&
1524 brickx+BRICK_WIDTH<ball[k].pos_x) ||
1525 (brickx+BRICK_WIDTH-4<ball[k].pos_x-
1526 BALL &&
1527 brickx+BRICK_WIDTH>ball[k].pos_x-
1528 BALL)) && (ball[k].x <0)) {
1529 ball[k].tempx=
1530 -(ball[k].pos_x-(brickx+BRICK_WIDTH));
1533 if ((ball[k].pos_x+HALFBALL >= brickx &&
1534 ball[k].pos_x+HALFBALL <=
1535 brickx+BRICK_WIDTH) &&
1536 ((bricky+BRICK_HEIGHT==ball[k].pos_y) ||
1537 (bricky+BRICK_HEIGHT-6<=ball[k].pos_y &&
1538 bricky+BRICK_HEIGHT>ball[k].pos_y)) &&
1539 (ball[k].y <0)) { /* bottom line */
1540 if (brick[i*10+j].hits > 0) {
1541 brick[i*10+j].hits--;
1542 brick[i*10+j].hiteffect++;
1543 score+=2;
1545 else {
1546 brick[i*10+j].used=0;
1547 if (brick[i*10+j].power!=10)
1548 brick[i*10+j].poweruse=2;
1551 ball[k].y = ball[k].y*-1;
1553 else if ((ball[k].pos_x+HALFBALL >= brickx &&
1554 ball[k].pos_x+HALFBALL <=
1555 brickx+BRICK_WIDTH) &&
1556 ((bricky==ball[k].pos_y+BALL) ||
1557 (bricky+6>=ball[k].pos_y+BALL &&
1558 bricky<ball[k].pos_y+BALL)) &&
1559 (ball[k].y >0)) { /* top line */
1560 if (brick[i*10+j].hits > 0) {
1561 brick[i*10+j].hits--;
1562 brick[i*10+j].hiteffect++;
1563 score+=2;
1565 else {
1566 brick[i*10+j].used=0;
1567 if (brick[i*10+j].power!=10)
1568 brick[i*10+j].poweruse=2;
1571 ball[k].y = ball[k].y*-1;
1574 if ((ball[k].pos_y+HALFBALL >= bricky &&
1575 ball[k].pos_y+HALFBALL <=
1576 bricky+BRICK_HEIGHT) &&
1577 ((brickx==ball[k].pos_x+BALL) ||
1578 (brickx+6>=ball[k].pos_x+BALL &&
1579 brickx<ball[k].pos_x+BALL)) &&
1580 (ball[k].x > 0)) { /* left line */
1581 if (brick[i*10+j].hits > 0) {
1582 brick[i*10+j].hits--;
1583 brick[i*10+j].hiteffect++;
1584 score+=2;
1586 else {
1587 brick[i*10+j].used=0;
1588 if (brick[i*10+j].power!=10)
1589 brick[i*10+j].poweruse=2;
1591 ball[k].x = ball[k].x*-1;
1594 else if ((ball[k].pos_y+HALFBALL >= bricky &&
1595 ball[k].pos_y+HALFBALL <=
1596 bricky+BRICK_HEIGHT) &&
1597 ((brickx+BRICK_WIDTH==
1598 ball[k].pos_x) ||
1599 (brickx+BRICK_WIDTH-6<=
1600 ball[k].pos_x &&
1601 brickx+BRICK_WIDTH>
1602 ball[k].pos_x)) &&
1603 (ball[k].x < 0)) { /* Right line */
1604 if (brick[i*10+j].hits > 0) {
1605 brick[i*10+j].hits--;
1606 brick[i*10+j].hiteffect++;
1607 score+=2;
1609 else {
1610 brick[i*10+j].used=0;
1611 if (brick[i*10+j].power!=10)
1612 brick[i*10+j].poweruse=2;
1615 ball[k].x = ball[k].x*-1;
1618 if (brick[i*10+j].used==0) {
1619 brick_on_board--;
1620 score+=8;
1624 } /* for k */
1625 } /* for j */
1626 } /* for i */
1628 /* draw the pad */
1629 rb->lcd_bitmap_part(brickmania_pads,0,pad_type*PAD_HEIGHT,
1630 PAD_WIDTH,pad_pos_x, PAD_POS_Y, PAD_WIDTH,
1631 PAD_HEIGHT);
1633 for(k=0;k<used_balls;k++) {
1635 if ((ball[k].pos_x >= pad_pos_x &&
1636 ball[k].pos_x <= pad_pos_x+PAD_WIDTH) &&
1637 (PAD_POS_Y-4<ball[k].pos_y+BALL &&
1638 PAD_POS_Y>ball[k].pos_y+BALL) && (ball[k].y >0))
1639 ball[k].tempy=PAD_POS_Y-ball[k].pos_y-BALL;
1640 else if ((4>ball[k].pos_y && 0<ball[k].pos_y) &&
1641 (ball[k].y <0))
1642 ball[k].tempy=-ball[k].pos_y;
1643 if ((LCD_WIDTH-4<ball[k].pos_x+BALL &&
1644 LCD_WIDTH>ball[k].pos_x+BALL) && (ball[k].x >0))
1645 ball[k].tempx=LCD_WIDTH-ball[k].pos_x-BALL;
1646 else if ((4>ball[k].pos_x && 0<ball[k].pos_x) &&
1647 (ball[k].x <0))
1648 ball[k].tempx=-ball[k].pos_x;
1650 /* top line */
1651 if (ball[k].pos_y<= 0)
1652 ball[k].y = ball[k].y*-1;
1653 /* bottom line */
1654 else if (ball[k].pos_y+BALL >= GAMESCREEN_HEIGHT) {
1655 if (used_balls>1) {
1656 used_balls--;
1657 ball[k].pos_x = ball[used_balls].pos_x;
1658 ball[k].pos_y = ball[used_balls].pos_y;
1659 ball[k].y = ball[used_balls].y;
1660 ball[k].tempy = ball[used_balls].tempy;
1661 ball[k].x = ball[used_balls].x;
1662 ball[k].tempx = ball[used_balls].tempx;
1663 ball[k].glue = ball[used_balls].glue;
1665 ball[used_balls].x=0;
1666 ball[used_balls].y=0;
1667 ball[used_balls].tempy=0;
1668 ball[used_balls].tempx=0;
1669 ball[used_balls].pos_y=PAD_POS_Y-BALL;
1670 ball[used_balls].pos_x=pad_pos_x+(PAD_WIDTH/2)-2;
1672 k--;
1673 continue;
1674 } else {
1675 life--;
1676 if (life>=0) {
1677 int_game(0);
1678 sleep(2);
1683 /* left line ,right line */
1684 if ((ball[k].pos_x <= 0) ||
1685 (ball[k].pos_x+BALL >= LCD_WIDTH)) {
1686 ball[k].x = ball[k].x*-1;
1687 ball[k].pos_x = ball[k].pos_x <= 0 ? 0 : LCD_WIDTH-BALL;
1690 if ((ball[k].pos_y+BALL >= PAD_POS_Y &&
1691 (ball[k].pos_x >= pad_pos_x &&
1692 ball[k].pos_x <= pad_pos_x+PAD_WIDTH)) &&
1693 start_game != 1 && !ball[k].glue) {
1695 if ((ball[k].pos_x+HALFBALL >= pad_pos_x &&
1696 ball[k].pos_x+HALFBALL <=
1697 pad_pos_x+(PAD_WIDTH/2/4)) ||
1698 (ball[k].pos_x +HALFBALL>=
1699 pad_pos_x+(PAD_WIDTH-(PAD_WIDTH/2/4)) &&
1700 ball[k].pos_x+HALFBALL <= pad_pos_x+PAD_WIDTH)) {
1702 ball[k].y = -2;
1703 if (ball[k].pos_x != 0 &&
1704 ball[k].pos_x+BALL!=LCD_WIDTH)
1705 ball[k].x = pad_check(6,0,ball[k].pos_x+2<=
1706 pad_pos_x+(PAD_WIDTH/2)?
1707 0:1,k);
1710 else if ((ball[k].pos_x+HALFBALL >=
1711 pad_pos_x+(PAD_WIDTH/2/4) &&
1712 ball[k].pos_x+HALFBALL <=
1713 pad_pos_x+2*(PAD_WIDTH/2/4)) ||
1714 (ball[k].pos_x+HALFBALL >=
1715 pad_pos_x+(PAD_WIDTH-2*(PAD_WIDTH/2/4)) &&
1716 ball[k].pos_x+HALFBALL <=
1717 pad_pos_x+(PAD_WIDTH-(PAD_WIDTH/2/4)) )) {
1719 ball[k].y = -3;
1720 if (ball[k].pos_x != 0 &&
1721 ball[k].pos_x+BALL!=LCD_WIDTH)
1722 ball[k].x = pad_check(4,0,ball[k].pos_x+2<=
1723 pad_pos_x+(PAD_WIDTH/2)?
1724 0:1,k);
1727 else if ((ball[k].pos_x+HALFBALL >=
1728 pad_pos_x+2*(PAD_WIDTH/2/4) &&
1729 ball[k].pos_x+HALFBALL <=
1730 pad_pos_x+3*(PAD_WIDTH/2/4)) ||
1731 (ball[k].pos_x+2 >=
1732 pad_pos_x+(PAD_WIDTH-3*(PAD_WIDTH/2/4)) &&
1733 ball[k].pos_x+2 <=
1734 pad_pos_x+ ((PAD_WIDTH/2)-2*(PAD_WIDTH/2/4)) )) {
1736 ball[k].y = -4;
1737 if (ball[k].pos_x != 0 &&
1738 ball[k].pos_x+BALL!=LCD_WIDTH)
1739 ball[k].x = pad_check(3,0,ball[k].pos_x+2<=
1740 pad_pos_x+(PAD_WIDTH/2)?
1741 0:1,k);
1744 else if ((ball[k].pos_x+HALFBALL >=
1745 pad_pos_x+3*(PAD_WIDTH/2/4) &&
1746 ball[k].pos_x+HALFBALL <=
1747 pad_pos_x+4*(PAD_WIDTH/2/4)-2) ||
1748 (ball[k].pos_x+2 >= pad_pos_x+(PAD_WIDTH/2+2) &&
1749 ball[k].pos_x+2 <=
1750 pad_pos_x+(PAD_WIDTH-3*(PAD_WIDTH/2/4)) )) {
1752 ball[k].y = -4;
1753 if (ball[k].pos_x != 0 &&
1754 ball[k].pos_x+BALL!=LCD_WIDTH)
1755 ball[k].x = pad_check(2,1,0,k);
1758 else {
1759 ball[k].y = -4;
1763 if (!ball[k].glue) {
1764 ball[k].pos_x+=ball[k].tempx!=0?ball[k].tempx:ball[k].x;
1765 ball[k].pos_y+=ball[k].tempy!=0?ball[k].tempy:ball[k].y;
1767 ball[k].tempy=0;
1768 ball[k].tempx=0;
1771 if (ball[k].pos_y+5 >= PAD_POS_Y &&
1772 (pad_type==1 && !ball[k].glue) &&
1773 (ball[k].pos_x >= pad_pos_x &&
1774 ball[k].pos_x <= pad_pos_x+PAD_WIDTH)) {
1775 ball[k].y=0;
1776 ball[k].pos_y=PAD_POS_Y-BALL;
1777 ball[k].glue=true;
1779 } /* for k */
1781 rb->lcd_update();
1783 if (brick_on_board < 0) {
1784 if (cur_level+1<levels_num) {
1785 cur_level++;
1786 score+=100;
1787 int_game(1);
1788 sleep(2);
1790 else {
1791 rb->lcd_getstringsize("Congratulations!", &sw, NULL);
1792 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_CONGRATS,
1793 "Congratulations!");
1794 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1795 rb->lcd_getstringsize("No more levels", &sw, NULL);
1796 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_FINISH,
1797 "No more levels");
1798 #else
1799 rb->lcd_getstringsize("You have finished the game!",
1800 &sw, NULL);
1801 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_FINISH,
1802 "You have finished the game!");
1803 #endif
1804 vscore=score;
1805 rb->lcd_update();
1806 if (score>highscore) {
1807 sleep(2);
1808 highscore=score;
1809 rb->splash(HZ*2, "New High Score");
1811 else {
1812 sleep(3);
1815 return 0;
1819 int move_button,button;
1820 int button_right,button_left;
1821 button=rb->button_get(false);
1823 #if defined(HAS_BUTTON_HOLD) && !defined(HAVE_REMOTE_LCD_AS_MAIN)
1824 /* FIXME: Should probably check remote hold here */
1825 if (rb->button_hold())
1826 button = QUIT;
1827 #endif
1829 #ifdef HAVE_TOUCHSCREEN
1830 if(button & BUTTON_TOUCHSCREEN)
1832 short touch_x, touch_y;
1833 touch_x = rb->button_get_data() >> 16;
1834 touch_y = rb->button_get_data() & 0xffff;
1835 if(touch_y >= PAD_POS_Y && touch_y <= PAD_POS_Y+PAD_HEIGHT)
1837 pad_pos_x += (flip_sides ? -1 : 1) * ( (touch_x-pad_pos_x-PAD_WIDTH/2) / 4 );
1839 if(pad_pos_x < 0)
1840 pad_pos_x = 0;
1841 else if(pad_pos_x+PAD_WIDTH > LCD_WIDTH)
1842 pad_pos_x = LCD_WIDTH-PAD_WIDTH;
1843 for(k=0;k<used_balls;k++)
1844 if ((start_game==1 || ball[k].glue))
1845 ball[k].pos_x = pad_pos_x+PAD_WIDTH/2;
1848 if(button & BUTTON_REL)
1849 button = SELECT;
1851 else
1853 #endif
1854 move_button=rb->button_status();
1855 #ifdef ALTRIGHT
1856 button_right=((move_button & RIGHT) || (move_button & ALTRIGHT));
1857 button_left=((move_button & LEFT) || (move_button & ALTLEFT));
1858 #else
1859 button_right=((move_button & RIGHT) || (SCROLL_FWD(button)));
1860 button_left=((move_button & LEFT) || (SCROLL_BACK(button)));
1861 #endif
1862 if ((con_game== 1 && start_game!=1) && (button_right || button_left))
1863 continue;
1864 if ((button_right && flip_sides==false) ||
1865 (button_left && flip_sides==true)) {
1866 if (pad_pos_x+8+PAD_WIDTH > LCD_WIDTH) {
1867 for(k=0;k<used_balls;k++)
1868 if (start_game==1 || ball[k].glue)
1869 ball[k].pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
1870 pad_pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
1872 else {
1873 for(k=0;k<used_balls;k++)
1874 if ((start_game==1 || ball[k].glue))
1875 ball[k].pos_x+=8;
1876 pad_pos_x+=8;
1879 else if ((button_left && flip_sides==false) ||
1880 (button_right && flip_sides==true)) {
1881 if (pad_pos_x-8 < 0) {
1882 for(k=0;k<used_balls;k++)
1883 if (start_game==1 || ball[k].glue)
1884 ball[k].pos_x-=pad_pos_x;
1885 pad_pos_x-=pad_pos_x;
1887 else {
1888 for(k=0;k<used_balls;k++)
1889 if (start_game==1 || ball[k].glue)
1890 ball[k].pos_x-=8;
1891 pad_pos_x-=8;
1894 #ifdef HAVE_TOUCHSCREEN
1896 #endif
1899 switch(button) {
1900 case UP:
1901 case SELECT:
1902 if (start_game==1 && con_game!=1 && pad_type!=1) {
1903 for(k=0;k<used_balls;k++) {
1904 ball[k].y=-4;
1905 ball[k].x=pad_pos_x+(PAD_WIDTH/2)-2>=
1906 LCD_WIDTH/2?2:-2;
1908 start_game =0;
1910 else if (pad_type==1) {
1911 for(k=0;k<used_balls;k++) {
1912 if (ball[k].glue)
1913 ball[k].glue=false;
1914 else if (start_game==1) {
1915 ball[k].x = x[k];
1916 ball[k].y = y[k];
1920 if (start_game!=1 && con_game==1) {
1921 start_game =0;
1922 con_game=0;
1924 } else if (pad_type==2 && con_game!=1) {
1925 int tfire;
1926 tfire=fire_space();
1927 fire[tfire].top=PAD_POS_Y-7;
1928 fire[tfire].left=pad_pos_x+1;
1929 tfire=fire_space();
1930 fire[tfire].top=PAD_POS_Y-7;
1931 fire[tfire].left=pad_pos_x+PAD_WIDTH-1;
1932 } else if (con_game==1 && start_game!=1) {
1933 for(k=0;k<used_balls;k++) {
1934 ball[k].x=x[k];
1935 ball[k].y=y[k];
1937 con_game=0;
1939 break;
1940 #ifdef RC_QUIT
1941 case RC_QUIT:
1942 #endif
1943 case QUIT:
1944 while(1) {
1945 switch(game_menu(1)) {
1946 case 0:
1947 life=2;
1948 cur_level=0;
1949 int_game(1);
1950 break;
1951 case 1:
1952 for(k=0;k<used_balls;k++)
1953 if (ball[k].x!=0 && ball[k].y !=0)
1954 con_game=1;
1955 break;
1956 case 2:
1957 if (help()==1)
1958 return 1;
1959 continue;
1960 break;
1961 case 3:
1962 return 1;
1963 break;
1965 break;
1968 for(k=0;k<used_balls;k++) {
1969 if (ball[k].x!=0)
1970 x[k]=ball[k].x;
1971 ball[k].x=0;
1972 if (ball[k].y!=0)
1973 y[k]=ball[k].y;
1974 ball[k].y=0;
1977 break;
1979 default:
1980 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1981 return 1;
1982 break;
1985 else {
1986 #ifdef HAVE_LCD_COLOR
1987 rb->lcd_bitmap_transparent(brickmania_gameover,
1988 (LCD_WIDTH - GAMEOVER_WIDTH)/2,
1989 (GAMESCREEN_HEIGHT - GAMEOVER_HEIGHT)/2,
1990 GAMEOVER_WIDTH,GAMEOVER_HEIGHT);
1991 #else /* greyscale and mono */
1992 rb->lcd_bitmap(brickmania_gameover,(LCD_WIDTH - GAMEOVER_WIDTH)/2,
1993 (GAMESCREEN_HEIGHT - GAMEOVER_HEIGHT)/2,
1994 GAMEOVER_WIDTH,GAMEOVER_HEIGHT);
1995 #endif
1996 rb->lcd_update();
1997 if (score>highscore) {
1998 sleep(2);
1999 highscore=score;
2000 rb->splash(HZ*2, "New High Score");
2001 } else {
2002 sleep(3);
2005 for(k=0;k<used_balls;k++) {
2006 ball[k].x=0;
2007 ball[k].y=0;
2010 return 0;
2012 if (end > *rb->current_tick)
2013 rb->sleep(end-*rb->current_tick);
2014 else
2015 rb->yield();
2019 /* this is the plugin entry point */
2020 enum plugin_status plugin_start(const void* parameter)
2022 (void)parameter;
2024 rb->lcd_setfont(FONT_SYSFIXED);
2025 #if LCD_DEPTH > 1
2026 rb->lcd_set_backdrop(NULL);
2027 #endif
2028 /* Turn off backlight timeout */
2029 backlight_force_on(); /* backlight control in lib/helper.c */
2031 rb->srand( *rb->current_tick );
2033 configfile_load(HIGH_SCORE,config,1,0);
2035 /* now go ahead and have fun! */
2036 while (game_loop()!=1);
2038 configfile_save(HIGH_SCORE,config,1,0);
2040 /* Restore user's original backlight setting */
2041 rb->lcd_setfont(FONT_UI);
2042 /* Turn on backlight timeout (revert to settings) */
2043 backlight_use_settings(); /* backlight control in lib/helper.c */
2045 return PLUGIN_OK;