Don't rebuild the dependency file on 'make reconf'. Build type and target won't chang...
[kugel-rb.git] / apps / plugins / brickmania.c
blob15c1641e3fa7c7d2565d8c55265fc7d895f2e886
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"
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) || \
107 (CONFIG_KEYPAD == SANSA_FUZE_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_C200_PAD || \
121 CONFIG_KEYPAD == SANSA_CLIP_PAD || \
122 CONFIG_KEYPAD == SANSA_M200_PAD
124 #define QUIT BUTTON_POWER
125 #define LEFT BUTTON_LEFT
126 #define RIGHT BUTTON_RIGHT
127 #define ALTLEFT BUTTON_VOL_DOWN
128 #define ALTRIGHT BUTTON_VOL_UP
129 #define SELECT BUTTON_SELECT
130 #define UP BUTTON_UP
131 #define DOWN BUTTON_DOWN
134 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
136 #define QUIT BUTTON_POWER
137 #define LEFT BUTTON_LEFT
138 #define RIGHT BUTTON_RIGHT
139 #define SELECT BUTTON_PLAY
140 #define UP BUTTON_SCROLL_UP
141 #define DOWN BUTTON_SCROLL_DOWN
143 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
145 #define QUIT BUTTON_BACK
146 #define LEFT BUTTON_LEFT
147 #define RIGHT BUTTON_RIGHT
148 #define SELECT BUTTON_SELECT
149 #define UP BUTTON_UP
150 #define DOWN BUTTON_DOWN
152 #elif (CONFIG_KEYPAD == MROBE100_PAD)
154 #define QUIT BUTTON_POWER
155 #define LEFT BUTTON_LEFT
156 #define RIGHT BUTTON_RIGHT
157 #define SELECT BUTTON_SELECT
158 #define UP BUTTON_UP
159 #define DOWN BUTTON_DOWN
161 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
163 #define QUIT BUTTON_RC_REC
164 #define LEFT BUTTON_RC_REW
165 #define RIGHT BUTTON_RC_FF
166 #define SELECT BUTTON_RC_PLAY
167 #define UP BUTTON_RC_VOL_UP
168 #define DOWN BUTTON_RC_VOL_DOWN
170 #define RC_QUIT BUTTON_REC
172 #elif CONFIG_KEYPAD == COWOND2_PAD
173 #define QUIT BUTTON_POWER
175 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
177 #define QUIT BUTTON_BACK
178 #define LEFT BUTTON_LEFT
179 #define RIGHT BUTTON_RIGHT
180 #define SELECT BUTTON_SELECT
181 #define UP BUTTON_UP
182 #define DOWN BUTTON_DOWN
184 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
186 #define QUIT BUTTON_POWER
187 #define LEFT BUTTON_LEFT
188 #define RIGHT BUTTON_RIGHT
189 #define SELECT BUTTON_SELECT
190 #define UP BUTTON_UP
191 #define DOWN BUTTON_DOWN
193 #else
194 #error No keymap defined!
195 #endif
197 #ifdef HAVE_TOUCHSCREEN
198 #ifndef LEFT
199 #define LEFT BUTTON_MIDLEFT
200 #endif
201 #ifndef RIGHT
202 #define RIGHT BUTTON_MIDRIGHT
203 #endif
204 #ifndef SELECT
205 #define SELECT BUTTON_CENTER
206 #endif
207 #ifndef UP
208 #define UP BUTTON_TOPMIDDLE
209 #endif
210 #ifndef DOWN
211 #define DOWN BUTTON_BOTTOMMIDDLE
212 #endif
213 #endif
215 #ifndef SCROLL_FWD /* targets without scroll wheel*/
216 #define SCROLL_FWD(x) (0)
217 #define SCROLL_BACK(x) (0)
218 #endif
221 enum menu_items {
222 BM_START,
223 BM_SEL_START,
224 BM_RESUME,
225 BM_SEL_RESUME,
226 BM_NO_RESUME,
227 BM_HELP,
228 BM_SEL_HELP,
229 BM_QUIT,
230 BM_SEL_QUIT,
233 #include "pluginbitmaps/brickmania_pads.h"
234 #include "pluginbitmaps/brickmania_bricks.h"
235 #include "pluginbitmaps/brickmania_powerups.h"
236 #include "pluginbitmaps/brickmania_ball.h"
237 #include "pluginbitmaps/brickmania_menu_items.h"
238 #include "pluginbitmaps/brickmania_gameover.h"
240 #define PAD_WIDTH BMPWIDTH_brickmania_pads
241 #define PAD_HEIGHT (BMPHEIGHT_brickmania_pads/3)
242 #define BRICK_HEIGHT (BMPHEIGHT_brickmania_bricks/7)
243 #define BRICK_WIDTH BMPWIDTH_brickmania_bricks
244 #define LEFTMARGIN ((LCD_WIDTH-10*BRICK_WIDTH)/2)
245 #define POWERUP_HEIGHT (BMPHEIGHT_brickmania_powerups/7)
246 #define POWERUP_WIDTH BMPWIDTH_brickmania_powerups
247 #define BALL BMPHEIGHT_brickmania_ball
248 #define HALFBALL ((BALL+1)/2)
249 #define MENU_ITEMXOFS ((LCD_WIDTH - BMPWIDTH_brickmania_menu_items)/2)
250 #define MENU_ITEMHEIGHT (BMPHEIGHT_brickmania_menu_items/9)
251 #define MENU_ITEMWIDTH BMPWIDTH_brickmania_menu_items
252 #define GAMEOVER_WIDTH BMPWIDTH_brickmania_gameover
253 #define GAMEOVER_HEIGHT BMPHEIGHT_brickmania_gameover
255 #if LCD_DEPTH > 1 /* currently no background bmp for mono screens */
256 #include "pluginbitmaps/brickmania_menu_bg.h"
257 #define MENU_BGHEIGHT BMPHEIGHT_brickmania_menu_bg
258 #define MENU_BGWIDTH BMPWIDTH_brickmania_menu_bg
259 #endif
261 #ifdef HAVE_LCD_COLOR /* currently no transparency for non-colour */
262 #include "pluginbitmaps/brickmania_break.h"
263 #endif
265 #if (LCD_WIDTH == 320) && (LCD_HEIGHT == 240)
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 #define TOPMARGIN 30
275 #define BMPYOFS_start 110
276 #define HIGHSCORE_XPOS 57
277 #define HIGHSCORE_YPOS 88
279 #define STRINGPOS_FINISH 140
280 #define STRINGPOS_CONGRATS 157
281 #define STRINGPOS_NAVI 150
282 #define STRINGPOS_FLIP 150
284 #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176)
286 /* The time (in ms) for one iteration through the game loop - decrease this
287 to speed up the game - note that current_tick is (currently) only accurate
288 to 10ms.
290 #define CYCLETIME 30
292 /* Offsets for LCDS > 220x176 */
294 #define GAMESCREEN_HEIGHT 176
295 #define TOPMARGIN 30
297 #define XOFS ((LCD_WIDTH-220)/BRICK_WIDTH/2)*BRICK_WIDTH
298 #define YOFS ((LCD_HEIGHT-176)/BRICK_HEIGHT/2)*BRICK_HEIGHT
300 #define BMPYOFS_start (78+YOFS)
301 #define HIGHSCORE_XPOS (17+XOFS)
302 #define HIGHSCORE_YPOS (56+YOFS)
304 #define STRINGPOS_FINISH 140
305 #define STRINGPOS_CONGRATS 157
306 #define STRINGPOS_NAVI 150
307 #define STRINGPOS_FLIP 150
309 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
310 /* The time (in ms) for one iteration through the game loop - decrease this
311 to speed up the game - note that current_tick is (currently) only accurate
312 to 10ms.
314 #define CYCLETIME 50
316 #define TOPMARGIN 21
318 #if LCD_DEPTH > 2
319 #define BMPYOFS_start 58
320 #else
321 #define BMPYOFS_start 66
322 #endif
323 #define HIGHSCORE_XPOS 10
324 #define HIGHSCORE_YPOS 38
326 #define STRINGPOS_FINISH 110
327 #define STRINGPOS_CONGRATS 100
328 #define STRINGPOS_NAVI 100
329 #define STRINGPOS_FLIP 100
331 #elif (LCD_WIDTH == 132) && (LCD_HEIGHT == 80)
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 TOPMARGIN 10
341 #define BMPYOFS_start 30
342 #define HIGHSCORE_XPOS 68
343 #define HIGHSCORE_YPOS 8
345 #define STRINGPOS_FINISH 55
346 #define STRINGPOS_CONGRATS 45
347 #define STRINGPOS_NAVI 60
348 #define STRINGPOS_FLIP 60
350 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128)
352 /* The time (in ms) for one iteration through the game loop - decrease this
353 to speed up the game - note that current_tick is (currently) only accurate
354 to 10ms.
356 #define CYCLETIME 50
358 #define GAMESCREEN_HEIGHT 100
359 #define TOPMARGIN 15
361 #define BMPYOFS_start 70
362 #define HIGHSCORE_XPOS 8
363 #define HIGHSCORE_YPOS 36
365 #define STRINGPOS_FINISH 55
366 #define STRINGPOS_CONGRATS 45
367 #define STRINGPOS_NAVI 60
368 #define STRINGPOS_FLIP 60
370 /* iPod Mini */
371 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
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 51
381 #define HIGHSCORE_XPOS 73
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 /* iAudio M3 */
390 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 96)
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 50
397 #define TOPMARGIN 10
399 #define BMPYOFS_start 42
400 #define HIGHSCORE_XPOS 65
401 #define HIGHSCORE_YPOS 25
403 #define STRINGPOS_FINISH 54
404 #define STRINGPOS_CONGRATS 44
405 #define STRINGPOS_NAVI 44
406 #define STRINGPOS_FLIP 44
408 /* Archos / Sansa Clip / Sansa m200 */
409 #elif ((LCD_WIDTH == 112) | (LCD_WIDTH == 128)) && (LCD_HEIGHT == 64)
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.
414 #define CYCLETIME 75
416 #define TOPMARGIN 10
418 #define BMPYOFS_start 22
419 #define HIGHSCORE_XPOS 0
420 #define HIGHSCORE_YPOS 0
422 #define STRINGPOS_FINISH 54
423 #define STRINGPOS_CONGRATS 44
424 #define STRINGPOS_NAVI 44
425 #define STRINGPOS_FLIP 44
427 /* nano and sansa */
428 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT >= 132) && (LCD_DEPTH==16)
429 /* The time (in ms) for one iteration through the game loop - decrease this
430 to speed up the game - note that current_tick is (currently) only accurate
431 to 10ms.
434 #define CYCLETIME 30
436 #define GAMESCREEN_HEIGHT 132
437 #define TOPMARGIN 21
439 #define BMPYOFS_start 58
440 #define HIGHSCORE_XPOS 7
441 #define HIGHSCORE_YPOS 36
443 #define STRINGPOS_FINISH 110
444 #define STRINGPOS_CONGRATS 110
445 #define STRINGPOS_NAVI 100
446 #define STRINGPOS_FLIP 100
448 #else
449 #error Unsupported LCD Size
450 #endif
453 #ifndef GAMESCREEN_HEIGHT
454 #define GAMESCREEN_HEIGHT LCD_HEIGHT
455 #endif
457 /* calculate menu item offsets from the first defined and the height*/
458 #define BMPYOFS_resume (BMPYOFS_start + MENU_ITEMHEIGHT)
459 #define BMPYOFS_help (BMPYOFS_start + 2*MENU_ITEMHEIGHT)
460 #define BMPYOFS_quit (BMPYOFS_start + 3*MENU_ITEMHEIGHT)
462 /*calculate paddle y-position */
463 #if GAMESCREEN_HEIGHT >= 128
464 #define PAD_POS_Y GAMESCREEN_HEIGHT -PAD_HEIGHT - 2
465 #else
466 #define PAD_POS_Y GAMESCREEN_HEIGHT -PAD_HEIGHT - 1
467 #endif
470 #ifdef HAVE_TOUCHSCREEN
471 #include "lib/touchscreen.h"
473 static struct ts_mapping main_menu_items[4] =
475 {MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
476 {MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
477 {MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
478 {MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH, MENU_ITEMHEIGHT}
480 static struct ts_mappings main_menu = {main_menu_items, 4};
481 #endif
484 int levels_num = 29;
486 static unsigned char levels[29][8][10] = {
487 { /* level1 */
488 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
489 {0x2,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x2},
490 {0x0,0x2,0x1,0x0,0x0,0x0,0x0,0x1,0x2,0x0},
491 {0x0,0x0,0x2,0x1,0x0,0x0,0x1,0x2,0x0,0x0},
492 {0x0,0x0,0x0,0x2,0x1,0x1,0x2,0x0,0x0,0x0},
493 {0x7,0x0,0x0,0x7,0x2,0x2,0x7,0x0,0x0,0x7},
494 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
495 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
497 { /* level2 */
498 {0x0,0x0,0x7,0x7,0x1,0x1,0x7,0x7,0x0,0x0},
499 {0x0,0x1,0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x0},
500 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
501 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1},
502 {0x1,0x1,0x2,0x1,0x0,0x0,0x1,0x2,0x1,0x1},
503 {0x1,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x2,0x1},
504 {0x0,0x1,0x2,0x0,0x0,0x0,0x0,0x2,0x1,0x0},
505 {0x0,0x0,0x1,0x2,0x2,0x2,0x2,0x1,0x0,0x0}
507 { /* level3 */
508 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
509 {0x3,0x23,0x23,0x3,0x0,0x0,0x2,0x22,0x22,0x2},
510 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
511 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
512 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
513 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6},
514 {0x5,0x25,0x25,0x5,0x0,0x0,0x6,0x26,0x26,0x6},
515 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6}
517 { /* level4 */
518 {0x0,0x0,0x0,0x27,0x27,0x27,0x27,0x0,0x0,0x0},
519 {0x0,0x0,0x0,0x27,0x7,0x7,0x27,0x0,0x0,0x0},
520 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
521 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
522 {0x26,0x6,0x0,0x2,0x2,0x2,0x2,0x0,0x6,0x26},
523 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
524 {0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0},
525 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1}
527 { /* level5 */
528 {0x1,0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4},
529 {0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0},
530 {0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5},
531 {0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5,0x5},
532 {0x0,0x33,0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0},
533 {0x3,0x33,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x36},
534 {0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x6,0x36},
535 {0x0,0x24,0x24,0x0,0x25,0x25,0x0,0x26,0x26,0x0}
537 { /* level6 */
538 {0x0,0x1,0x3,0x7,0x7,0x7,0x7,0x3,0x1,0x0},
539 {0x3,0x1,0x3,0x7,0x0,0x0,0x7,0x3,0x1,0x3},
540 {0x3,0x1,0x3,0x7,0x7,0x7,0x7,0x3,0x1,0x3},
541 {0x0,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x0},
542 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5},
543 {0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5},
544 {0x0,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x0},
545 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
547 { /* level7 */
548 {0x0,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x0},
549 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
550 {0x6,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x6},
551 {0x6,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x6},
552 {0x6,0x6,0x6,0x0,0x0,0x0,0x0,0x6,0x6,0x6},
553 {0x0,0x0,0x0,0x1,0x1,0x1,0x1,0x0,0x0,0x0},
554 {0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0},
555 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
557 { /* level8 */
558 {0x0,0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x0},
559 {0x0,0x0,0x0,0x4,0x0,0x0,0x4,0x0,0x0,0x0},
560 {0x6,0x6,0x0,0x2,0x32,0x32,0x2,0x0,0x6,0x6},
561 {0x0,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x0,0x0},
562 {0x0,0x6,0x6,0x0,0x0,0x0,0x0,0x6,0x6,0x0},
563 {0x0,0x0,0x0,0x5,0x25,0x25,0x5,0x0,0x0,0x0},
564 {0x0,0x5,0x5,0x25,0x5,0x5,0x25,0x5,0x5,0x0},
565 {0x5,0x5,0x25,0x5,0x5,0x5,0x5,0x25,0x5,0x5}
567 { /* level9 */
568 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
569 {0x2,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x2},
570 {0x2,0x0,0x3,0x0,0x1,0x1,0x0,0x3,0x0,0x2},
571 {0x2,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x2},
572 {0x2,0x0,0x1,0x0,0x3,0x3,0x0,0x1,0x0,0x2},
573 {0x2,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x2},
574 {0x2,0x2,0x0,0x0,0x1,0x1,0x0,0x0,0x2,0x2},
575 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
577 { /* level10 */
578 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
579 {0x0,0x5,0x0,0x5,0x0,0x5,0x0,0x5,0x0,0x5},
580 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
581 {0x0,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x0},
582 {0x0,0x0,0x0,0x4,0x1,0x1,0x4,0x0,0x0,0x0},
583 {0x0,0x0,0x3,0x4,0x1,0x1,0x4,0x3,0x0,0x0},
584 {0x0,0x2,0x3,0x4,0x1,0x1,0x4,0x3,0x2,0x0},
585 {0x1,0x2,0x3,0x4,0x1,0x1,0x4,0x3,0x2,0x1}
587 { /* level11 */
588 {0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3},
589 {0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x2},
590 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
591 {0x2,0x0,0x0,0x0,0x7,0x7,0x0,0x0,0x0,0x2},
592 {0x2,0x0,0x0,0x7,0x7,0x7,0x7,0x0,0x0,0x2},
593 {0x0,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x0},
594 {0x0,0x2,0x0,0x1,0x0,0x0,0x1,0x0,0x2,0x0},
595 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5}
597 { /* level 12 */
598 {0x2,0x1,0x3,0x1,0x0,0x0,0x1,0x3,0x1,0x2},
599 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1},
600 {0x1,0x1,0x1,0x0,0x1,0x1,0x0,0x1,0x1,0x1},
601 {0x0,0x1,0x0,0x1,0x6,0x6,0x1,0x0,0x1,0x0},
602 {0x0,0x0,0x1,0x1,0x6,0x6,0x1,0x1,0x0,0x0},
603 {0x1,0x1,0x1,0x7,0x0,0x0,0x7,0x1,0x1,0x1},
604 {0x1,0x1,0x7,0x1,0x0,0x0,0x1,0x7,0x1,0x1},
605 {0x2,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x2,0x2}
607 {/* levell13 */
608 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
609 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
610 {0x2,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x0,0x2},
611 {0x2,0x0,0x2,0x3,0x3,0x3,0x3,0x3,0x0,0x2},
612 {0x2,0x0,0x2,0x4,0x4,0x4,0x4,0x4,0x0,0x2},
613 {0x2,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
614 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
615 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
617 {/* level14 */
618 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
619 {0x4,0x4,0x4,0x4,0x2,0x2,0x4,0x4,0x4,0x4},
620 {0x4,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x4},
621 {0x4,0x0,0x0,0x2,0x3,0x3,0x2,0x0,0x0,0x4},
622 {0x4,0x0,0x2,0x23,0x3,0x3,0x23,0x2,0x0,0x4},
623 {0x4,0x0,0x2,0x22,0x2,0x2,0x22,0x2,0x0,0x4},
624 {0x4,0x0,0x6,0x21,0x5,0x5,0x21,0x6,0x0,0x4},
625 {0x4,0x6,0x1,0x1,0x5,0x5,0x1,0x1,0x6,0x4}
627 {/* level 15 */
628 {0x4,0x4,0x4,0x4,0x4,0x3,0x3,0x3,0x3,0x3},
629 {0x2,0x2,0x1,0x1,0x1,0x1,0x1,0x5,0x0,0x0},
630 {0x2,0x2,0x1,0x1,0x1,0x0,0x1,0x6,0x0,0x0},
631 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x5,0x0,0x0},
632 {0x2,0x1,0x2,0x2,0x2,0x1,0x1,0x6,0x0,0x0},
633 {0x2,0x1,0x2,0x2,0x2,0x1,0x3,0x5,0x3,0x0},
634 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x6,0x0,0x0},
635 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
637 {/* level 16 (Rockbox) by ts-x */
638 {0x2,0x2,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
639 {0x2,0x0,0x3,0x0,0x3,0x4,0x0,0x5,0x5,0x0},
640 {0x2,0x0,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
641 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
642 {0x6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
643 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0},
644 {0x7,0x0,0x7,0x1,0x0,0x1,0x0,0x2,0x0,0x0},
645 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0}
647 {/* level 17 (Alien) by ts-x */
648 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
649 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
650 {0x1,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x1},
651 {0x2,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x2},
652 {0x1,0x0,0x1,0x2,0x2,0x2,0x2,0x1,0x0,0x1},
653 {0x2,0x0,0x0,0x1,0x2,0x2,0x1,0x0,0x0,0x2},
654 {0x2,0x1,0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x2},
655 {0x2,0x2,0x1,0x0,0x1,0x1,0x0,0x1,0x2,0x2}
657 {/* level 18 (Tetris) by ts-x */
658 {0x0,0x2,0x0,0x0,0x3,0x4,0x0,0x2,0x2,0x0},
659 {0x0,0x2,0x7,0x0,0x3,0x4,0x0,0x2,0x2,0x0},
660 {0x2,0x2,0x7,0x0,0x3,0x4,0x0,0x6,0x2,0x2},
661 {0x2,0x2,0x7,0x7,0x3,0x4,0x0,0x6,0x2,0x2},
662 {0x2,0x1,0x7,0x7,0x3,0x4,0x4,0x6,0x5,0x5},
663 {0x2,0x1,0x0,0x7,0x3,0x4,0x4,0x6,0x5,0x5},
664 {0x1,0x1,0x1,0x7,0x3,0x0,0x6,0x6,0x5,0x5},
665 {0x1,0x1,0x1,0x0,0x3,0x0,0x6,0x6,0x5,0x5}
667 { /* level 19 (Stalactites) by ts-x */
668 {0x5,0x2,0x6,0x3,0x4,0x7,0x5,0x3,0x1,0x2},
669 {0x5,0x2,0x6,0x3,0x4,0x7,0x5,0x3,0x1,0x2},
670 {0x5,0x0,0x6,0x3,0x4,0x7,0x5,0x0,0x1,0x2},
671 {0x5,0x2,0x6,0x3,0x4,0x0,0x5,0x3,0x1,0x2},
672 {0x5,0x0,0x6,0x0,0x4,0x7,0x5,0x0,0x1,0x0},
673 {0x5,0x0,0x0,0x3,0x4,0x0,0x0,0x0,0x1,0x2},
674 {0x0,0x0,0x6,0x0,0x0,0x0,0x5,0x0,0x0,0x0},
675 {0x5,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x1,0x0}
677 { /* level 20 (Maze) by ts-x */
678 {0x1,0x1,0x21,0x1,0x1,0x1,0x1,0x1,0x1,0x21},
679 {0x1,0x0,0x0,0x3,0x0,0x0,0x3,0x1,0x31,0x1},
680 {0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x31,0x0,0x1},
681 {0x21,0x0,0x21,0x3,0x0,0x3,0x0,0x3,0x0,0x2},
682 {0x1,0x0,0x1,0x21,0x0,0x12,0x0,0x0,0x0,0x0},
683 {0x31,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x3,0x0},
684 {0x1,0x0,0x1,0x0,0x1,0x1,0x31,0x1,0x1,0x2},
685 {0x22,0x0,0x2,0x1,0x1,0x1,0x1,0x1,0x1,0x21}
687 { /* level 21 (Dentist) by ts-x */
688 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0},
689 {0x2,0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x2,0x2},
690 {0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x2},
691 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x6,0x0,0x2},
692 {0x2,0x0,0x6,0x0,0x6,0x0,0x0,0x0,0x0,0x2},
693 {0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x2},
694 {0x2,0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x2,0x2},
695 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0}
697 { /* level 22 (Spider) by ts-x */
698 {0x31,0x3,0x1,0x1,0x0,0x0,0x1,0x1,0x3,0x31},
699 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
700 {0x33,0x1,0x1,0x36,0x1,0x1,0x36,0x1,0x1,0x33},
701 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
702 {0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x1,0x0,0x0},
703 {0x21,0x3,0x1,0x21,0x2,0x2,0x21,0x1,0x3,0x21},
704 {0x0,0x0,0x0,0x1,0x21,0x1,0x1,0x0,0x0,0x0},
705 {0x3,0x1,0x3,0x1,0x0,0x0,0x1,0x3,0x1,0x3}
707 { /* level 23 (Pool) by ts-x */
708 {0x0,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x7,0x0},
709 {0x0,0x0,0x5,0x0,0x2,0x0,0x0,0x0,0x2,0x0},
710 {0x7,0x3,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x7},
711 {0x7,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x0,0x7},
712 {0x7,0x0,0x4,0x0,0x0,0x3,0x0,0x0,0x0,0x7},
713 {0x7,0x0,0x0,0x6,0x0,0x0,0x0,0x0,0x4,0x7},
714 {0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
715 {0x0,0x7,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x0}
717 { /* level 24 (Vorbis Fish) by ts-x */
718 {0x0,0x0,0x4,0x4,0x5,0x5,0x5,0x0,0x0,0x5},
719 {0x0,0x4,0x6,0x4,0x4,0x5,0x5,0x5,0x0,0x5},
720 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x5,0x5,0x5},
721 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x4,0x5,0x5},
722 {0x0,0x5,0x6,0x4,0x4,0x5,0x5,0x4,0x5,0x0},
723 {0x5,0x5,0x4,0x4,0x5,0x5,0x5,0x4,0x5,0x5},
724 {0x5,0x4,0x4,0x4,0x5,0x5,0x4,0x4,0x5,0x5},
725 {0x0,0x0,0x4,0x4,0x4,0x4,0x4,0x5,0x0,0x5}
727 {/* level 25 (Rainbow) by ts-x */
728 {0x0,0x4,0x1,0x0,0x0,0x0,0x0,0x1,0x4,0x0},
729 {0x24,0x1,0x3,0x1,0x0,0x0,0x21,0x3,0x1,0x24},
730 {0x1,0x23,0x5,0x3,0x1,0x21,0x3,0x5,0x3,0x21},
731 {0x3,0x5,0x6,0x5,0x3,0x3,0x5,0x6,0x5,0x3},
732 {0x5,0x6,0x7,0x6,0x5,0x5,0x6,0x7,0x6,0x5},
733 {0x6,0x7,0x2,0x27,0x6,0x6,0x27,0x2,0x7,0x6},
734 {0x7,0x2,0x0,0x2,0x27,0x27,0x2,0x0,0x2,0x7},
735 {0x32,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x32}
737 { /* level 26 (Bowtie) by ts-x */
738 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5},
739 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
740 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
741 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
742 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
743 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
744 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
745 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5}
747 { /* level 27 (Frog) by ts-x */
748 {0x0,0x5,0x25,0x0,0x0,0x0,0x0,0x25,0x5,0x0},
749 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5},
750 {0x25,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x25},
751 {0x5,0x0,0x3,0x0,0x6,0x6,0x0,0x3,0x0,0x5},
752 {0x5,0x0,0x31,0x0,0x6,0x6,0x0,0x31,0x0,0x5},
753 {0x5,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x5},
754 {0x5,0x5,0x5,0x35,0x0,0x0,0x35,0x5,0x5,0x5},
755 {0x0,0x25,0x5,0x0,0x4,0x4,0x0,0x5,0x25,0x0}
757 { /* level 28 (DigDug) by ts-x */
758 {0x35,0x5,0x5,0x25,0x0,0x25,0x25,0x5,0x5,0x35},
759 {0x6,0x0,0x0,0x6,0x0,0x6,0x6,0x0,0x0,0x6},
760 {0x7,0x0,0x37,0x37,0x0,0x37,0x37,0x7,0x0,0x7},
761 {0x7,0x0,0x7,0x0,0x0,0x0,0x7,0x7,0x7,0x7},
762 {0x4,0x4,0x4,0x24,0x0,0x24,0x4,0x0,0x0,0x4},
763 {0x4,0x4,0x0,0x0,0x0,0x4,0x4,0x0,0x4,0x4},
764 {0x24,0x24,0x4,0x4,0x4,0x4,0x0,0x0,0x24,0x4},
765 {0x1,0x1,0x1,0x1,0x1,0x1,0x21,0x21,0x1,0x1}
767 { /* TheEnd */
768 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
769 {0x22,0x22,0x26,0x0,0x0,0x26,0x24,0x24,0x0,0x0},
770 {0x22,0x0,0x26,0x26,0x0,0x26,0x24,0x0,0x24,0x0},
771 {0x22,0x22,0x26,0x26,0x0,0x26,0x24,0x0,0x24,0x0},
772 {0x22,0x22,0x26,0x0,0x26,0x26,0x24,0x0,0x24,0x0},
773 {0x22,0x0,0x26,0x0,0x26,0x26,0x24,0x0,0x24,0x0},
774 {0x22,0x22,0x26,0x0,0x0,0x26,0x24,0x24,0x0,0x0},
775 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
779 #define MAX_BALLS 10
780 int pad_pos_x;
781 int x[MAX_BALLS],y[MAX_BALLS];
782 int life;
783 int start_game,con_game;
784 int pad_type;
785 int score=0,vscore=0;
786 bool flip_sides=false;
787 int cur_level=0;
788 int brick_on_board=0;
789 int used_balls=1;
791 typedef struct cube {
792 int powertop;
793 int power;
794 char poweruse;
795 char used;
796 int color;
797 int hits;
798 int hiteffect;
799 } cube;
800 cube brick[80];
802 typedef struct balls {
803 int pos_x;
804 int pos_y;
805 int y;
806 int tempy;
807 int x;
808 int tempx;
809 bool glue;
810 } balls;
812 balls ball[MAX_BALLS];
814 typedef struct sfire {
815 int top;
816 int left;
817 } sfire;
818 sfire fire[30];
821 int highscore;
822 #define MAX_POINTS 200000 /* i dont think it needs to be more */
823 static struct configdata config[] =
825 {TYPE_INT, 0, MAX_POINTS, { .int_p = &highscore }, "highscore", NULL}
828 void int_game(int new_game)
830 int i,j;
832 pad_pos_x=LCD_WIDTH/2-PAD_WIDTH/2;
834 for(i=0;i<MAX_BALLS;i++) {
835 ball[i].x=0;
836 ball[i].y=0;
837 ball[i].tempy=0;
838 ball[i].tempx=0;
839 ball[i].pos_y=PAD_POS_Y-BALL;
840 ball[i].pos_x=pad_pos_x+(PAD_WIDTH/2)-2;
841 ball[i].glue=false;
844 used_balls=1;
845 start_game =1;
846 con_game =0;
847 pad_type=0;
849 flip_sides=false;
851 if (new_game==1)
852 brick_on_board=0;
854 for(i=0;i<=7;i++) {
855 for(j=0;j<=9;j++) {
856 brick[i*10+j].poweruse=(levels[cur_level][i][j]==0?0:1);
857 if (i*10+j<=30)
858 fire[i*10+j].top=-8;
859 if (new_game==1) {
860 brick[i*10+j].power=rb->rand()%25;
861 /* +8 make the game with less powerups */
863 brick[i*10+j].hits=levels[cur_level][i][j]>=10?
864 levels[cur_level][i][j]/16-1:0;
865 brick[i*10+j].hiteffect=0;
866 brick[i*10+j].powertop=TOPMARGIN+i*BRICK_HEIGHT+BRICK_HEIGHT;
867 brick[i*10+j].used=(levels[cur_level][i][j]==0?0:1);
868 brick[i*10+j].color=(levels[cur_level][i][j]>=10?
869 levels[cur_level][i][j]%16:
870 levels[cur_level][i][j])-1;
871 if (levels[cur_level][i][j]!=0)
872 brick_on_board++;
878 int sw,i,w;
880 /* sleep timer counting the score */
881 void sleep (int secs)
883 bool done=false;
884 char s[20];
885 int count=0;
887 while (!done) {
889 if (vscore<score) {
890 vscore++;
891 rb->snprintf(s, sizeof(s), "%d", vscore);
892 rb->lcd_getstringsize(s, &sw, &w);
893 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
894 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
895 #else
896 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s);
897 #endif
898 rb->lcd_update_rect(0,0,LCD_WIDTH,w+2);
899 } else {
900 if (count==0)
901 count=*rb->current_tick+HZ*secs;
902 if (*rb->current_tick>=count)
903 done=true;
905 rb->yield();
910 #define HIGH_SCORE "brickmania.score"
911 #define MENU_LENGTH 4
912 int game_menu(int when)
914 int button,cur=0;
915 char str[10];
916 rb->lcd_clear_display();
917 #if LCD_DEPTH > 1 /* currently no background bmp for mono screens */
918 rb->lcd_bitmap(brickmania_menu_bg, 0, 0, MENU_BGWIDTH, MENU_BGHEIGHT);
919 #endif
920 while (true) {
921 for(i=0;i<MENU_LENGTH;i++) {
922 #ifdef HAVE_LCD_COLOR
923 if (cur==0)
924 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
925 MENU_ITEMHEIGHT * BM_SEL_START, MENU_ITEMWIDTH,
926 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
927 MENU_ITEMHEIGHT);
928 else
929 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
930 MENU_ITEMHEIGHT * BM_START, MENU_ITEMWIDTH,
931 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
932 MENU_ITEMHEIGHT);
934 if (when==1) {
935 if (cur==1)
936 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
937 MENU_ITEMHEIGHT * BM_SEL_RESUME, MENU_ITEMWIDTH,
938 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
939 MENU_ITEMHEIGHT);
940 else
941 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
942 MENU_ITEMHEIGHT * BM_RESUME, MENU_ITEMWIDTH,
943 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
944 MENU_ITEMHEIGHT);
946 } else {
947 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
948 MENU_ITEMHEIGHT * BM_NO_RESUME, MENU_ITEMWIDTH,
949 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
950 MENU_ITEMHEIGHT);
954 if (cur==2)
955 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
956 MENU_ITEMHEIGHT * BM_SEL_HELP, MENU_ITEMWIDTH,
957 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
958 MENU_ITEMHEIGHT);
959 else
960 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
961 MENU_ITEMHEIGHT * BM_HELP, MENU_ITEMWIDTH,
962 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
963 MENU_ITEMHEIGHT);
965 if (cur==3)
966 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
967 MENU_ITEMHEIGHT * BM_SEL_QUIT, MENU_ITEMWIDTH,
968 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
969 MENU_ITEMHEIGHT);
970 else
971 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
972 MENU_ITEMHEIGHT * BM_QUIT, MENU_ITEMWIDTH,
973 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
974 MENU_ITEMHEIGHT);
975 #else
976 if (cur==0)
977 rb->lcd_bitmap_part(brickmania_menu_items, 0,
978 MENU_ITEMHEIGHT * BM_SEL_START, MENU_ITEMWIDTH,
979 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
980 MENU_ITEMHEIGHT);
981 else
982 rb->lcd_bitmap_part(brickmania_menu_items, 0,
983 MENU_ITEMHEIGHT * BM_START, MENU_ITEMWIDTH,
984 MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH,
985 MENU_ITEMHEIGHT);
987 if (when==1) {
988 if (cur==1)
989 rb->lcd_bitmap_part(brickmania_menu_items, 0,
990 MENU_ITEMHEIGHT * BM_SEL_RESUME, MENU_ITEMWIDTH,
991 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
992 MENU_ITEMHEIGHT);
993 else
994 rb->lcd_bitmap_part(brickmania_menu_items, 0,
995 MENU_ITEMHEIGHT * BM_RESUME, MENU_ITEMWIDTH,
996 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
997 MENU_ITEMHEIGHT);
999 } else {
1000 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1001 MENU_ITEMHEIGHT * BM_NO_RESUME, MENU_ITEMWIDTH,
1002 MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH,
1003 MENU_ITEMHEIGHT);
1007 if (cur==2)
1008 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1009 MENU_ITEMHEIGHT * BM_SEL_HELP, MENU_ITEMWIDTH,
1010 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
1011 MENU_ITEMHEIGHT);
1012 else
1013 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1014 MENU_ITEMHEIGHT * BM_HELP, MENU_ITEMWIDTH,
1015 MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH,
1016 MENU_ITEMHEIGHT);
1018 if (cur==3)
1019 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1020 MENU_ITEMHEIGHT * BM_SEL_QUIT, MENU_ITEMWIDTH,
1021 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
1022 MENU_ITEMHEIGHT);
1023 else
1024 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1025 MENU_ITEMHEIGHT * BM_QUIT, MENU_ITEMWIDTH,
1026 MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH,
1027 MENU_ITEMHEIGHT);
1028 #endif
1030 rb->lcd_set_drawmode(DRMODE_FG);
1031 /* high score */
1032 #ifdef HAVE_LCD_COLOR
1033 rb->lcd_set_background(LCD_RGBPACK(0,0,140));
1034 rb->lcd_set_foreground(LCD_WHITE);
1035 #endif
1036 rb->lcd_putsxy(HIGHSCORE_XPOS, HIGHSCORE_YPOS, "High Score");
1037 rb->snprintf(str, sizeof(str), "%d", highscore);
1038 rb->lcd_getstringsize("High Score", &sw, NULL);
1039 rb->lcd_getstringsize(str, &w, NULL);
1040 rb->lcd_putsxy(HIGHSCORE_XPOS+sw/2-w/2, HIGHSCORE_YPOS+9, str);
1041 rb->lcd_set_drawmode(DRMODE_SOLID);
1043 rb->lcd_update();
1045 button = rb->button_get(true);
1046 #ifdef HAVE_TOUCHSCREEN
1047 if(button & BUTTON_TOUCHSCREEN)
1049 unsigned int result = touchscreen_map(&main_menu, rb->button_get_data() >> 16, rb->button_get_data() & 0xffff);
1050 if(result != (unsigned)-1 && button & BUTTON_REL)
1052 if(cur == (signed)result)
1053 button = SELECT;
1054 cur = result;
1057 #endif
1058 switch(button) {
1059 case UP:
1060 case UP | BUTTON_REPEAT:
1061 if (cur==0)
1062 cur = MENU_LENGTH-1;
1063 else
1064 cur--;
1065 if (when==0 && cur==1) {
1066 cur = 0;
1068 break;
1070 case DOWN:
1071 case DOWN | BUTTON_REPEAT:
1072 if (cur==MENU_LENGTH-1)
1073 cur = 0;
1074 else
1075 cur++;
1076 if (when==0 && cur==1) {
1077 cur=2;
1079 break;
1081 case RIGHT:
1082 case SELECT:
1083 if (cur==0) {
1084 score=0;
1085 vscore=0;
1086 return 0;
1087 } else if (cur==1 && when==1) {
1088 return 1;
1089 } else if (cur==2) {
1090 return 2;
1091 } else if (cur==3) {
1092 return 3;
1094 break;
1095 #ifdef RC_QUIT
1096 case RC_QUIT:
1097 #endif
1098 case QUIT:
1099 return 3;
1100 break;
1102 default:
1103 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1104 return 3;
1105 break;
1108 rb->yield();
1112 int help(int when)
1114 int w,h;
1115 int button;
1116 int xoffset=0;
1117 int yoffset=0;
1118 /* set the maximum x and y in the helpscreen
1119 dont forget to update, if you change text */
1120 int maxY=180;
1121 int maxX=215;
1123 while(true) {
1124 #ifdef HAVE_LCD_COLOR
1125 rb->lcd_set_background(LCD_BLACK);
1126 rb->lcd_clear_display();
1127 rb->lcd_set_background(LCD_BLACK);
1128 rb->lcd_set_foreground(LCD_WHITE);
1129 #else
1130 rb->lcd_clear_display();
1131 #endif
1133 rb->lcd_getstringsize("BrickMania", &w, &h);
1134 rb->lcd_putsxy(LCD_WIDTH/2-w/2+xoffset, 1+yoffset, "BrickMania");
1136 #ifdef HAVE_LCD_COLOR
1137 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1138 rb->lcd_putsxy(1+xoffset, 1*(h+2)+yoffset,"Aim");
1139 rb->lcd_set_foreground(LCD_WHITE);
1140 #else
1141 rb->lcd_putsxy(1+xoffset, 1*(h+2)+yoffset,"Aim");
1142 #endif
1143 rb->lcd_putsxy(1+xoffset, 2*(h+2)+yoffset,
1144 "destroy all the bricks by bouncing");
1145 rb->lcd_putsxy(1+xoffset, 3*(h+2)+yoffset,
1146 "the ball of them using the paddle.");
1147 #ifdef HAVE_LCD_COLOR
1148 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1149 rb->lcd_putsxy(1+xoffset, 5*(h+2)+yoffset,"Controls");
1150 rb->lcd_set_foreground(LCD_WHITE);
1151 #else
1152 rb->lcd_putsxy(1+xoffset, 5*(h+2)+yoffset,"Controls");
1153 #endif
1154 rb->lcd_putsxy(1+xoffset, 6*(h+2)+yoffset,"< & > Move the paddle");
1155 #if CONFIG_KEYPAD == ONDIO_PAD
1156 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1157 "MENU Releases the ball/Fire!");
1158 #elif (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1159 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1160 "PLAY Releases the ball/Fire!");
1161 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
1162 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1163 "NAVI Releases the ball/Fire!");
1164 #else
1165 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1166 "SELECT Releases the ball/Fire!");
1167 #endif
1168 #if CONFIG_KEYPAD == IAUDIO_M3_PAD
1169 rb->lcd_putsxy(1+xoffset, 8*(h+2)+yoffset, "REC Opens menu/Quit");
1170 #else
1171 rb->lcd_putsxy(1+xoffset, 8*(h+2)+yoffset, "STOP Opens menu/Quit");
1172 #endif
1173 #ifdef HAVE_LCD_COLOR
1174 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1175 rb->lcd_putsxy(1+xoffset, 10*(h+2)+yoffset, "Specials");
1176 rb->lcd_set_foreground(LCD_WHITE);
1177 #else
1178 rb->lcd_putsxy(1+xoffset, 10*(h+2)+yoffset, "Specials");
1179 #endif
1180 rb->lcd_putsxy(1+xoffset, 11*(h+2)+yoffset,
1181 "N Normal:returns paddle to normal");
1182 rb->lcd_putsxy(1+xoffset, 12*(h+2)+yoffset, "D DIE!:loses a life");
1183 rb->lcd_putsxy(1+xoffset, 13*(h+2)+yoffset,
1184 "L Life:gains a life/power up");
1185 rb->lcd_putsxy(1+xoffset, 14*(h+2)+yoffset,
1186 "F Fire:allows you to shoot bricks");
1187 rb->lcd_putsxy(1+xoffset, 15*(h+2)+yoffset,
1188 "G Glue:ball sticks to paddle");
1189 rb->lcd_putsxy(1+xoffset, 16*(h+2)+yoffset,
1190 "B Ball:generates another ball");
1191 rb->lcd_putsxy(1+xoffset, 17*(h+2)+yoffset,
1192 "FL Flip:flips left / right movement");
1193 rb->lcd_update();
1195 button=rb->button_get(true);
1196 switch (button) {
1197 #ifdef RC_QUIT
1198 case RC_QUIT:
1199 #endif
1200 #ifdef HAVE_TOUCHSCREEN
1201 case BUTTON_TOUCHSCREEN:
1202 #endif
1203 case QUIT:
1204 switch (game_menu(when)) {
1205 case 0:
1206 cur_level=0;
1207 life=2;
1208 int_game(1);
1209 break;
1210 case 1:
1211 con_game=1;
1212 break;
1213 case 2:
1214 if (help(when)==1)
1215 return 1;
1216 break;
1217 case 3:
1218 return 1;
1219 break;
1221 return 0;
1222 break;
1223 case LEFT:
1224 case LEFT | BUTTON_REPEAT:
1225 #ifdef ALTLEFT
1226 case ALTLEFT:
1227 case ALTLEFT | BUTTON_REPEAT:
1228 #endif
1229 if( xoffset<0)
1230 xoffset+=2;
1231 break;
1232 case RIGHT:
1233 case RIGHT | BUTTON_REPEAT:
1234 #ifdef ALTRIGHT
1235 case ALTRIGHT:
1236 case ALTRIGHT | BUTTON_REPEAT:
1237 #endif
1238 if(xoffset+maxX > LCD_WIDTH)
1239 xoffset-=2;
1240 break;
1241 case UP:
1242 case UP | BUTTON_REPEAT:
1243 if(yoffset <0)
1244 yoffset+=2;
1245 break;
1246 case DOWN:
1247 case DOWN | BUTTON_REPEAT:
1248 if(yoffset+maxY > LCD_HEIGHT)
1249 yoffset-=2;
1250 break;
1252 default:
1253 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1254 return 1;
1255 break;
1258 rb->yield();
1260 return 0;
1263 int pad_check(int ballxc, int mode, int pon ,int ballnum)
1265 /* pon: positive(1) or negative(0) */
1267 if (mode==0) {
1268 if (pon == 0)
1269 return -ballxc;
1270 else
1271 return ballxc;
1272 } else {
1273 if (ball[ballnum].x > 0)
1274 return ballxc;
1275 else
1276 return ballxc*-1;
1280 int fire_space(void)
1282 int t;
1283 for(t=0;t<=30;t++)
1284 if (fire[t].top+7 < 0)
1285 return t;
1287 return 0;
1290 int game_loop(void)
1292 int j,i,k,bricky,brickx;
1293 char s[30];
1294 int sec_count=0,num_count=10;
1295 int end;
1297 rb->srand( *rb->current_tick );
1299 configfile_load(HIGH_SCORE,config,1,0);
1301 switch(game_menu(0)) {
1302 case 0:
1303 cur_level = 0;
1304 life = 2;
1305 int_game(1);
1306 break;
1307 case 1:
1308 con_game = 1;
1309 break;
1310 case 2:
1311 if (help(0) == 1) return 1;
1312 break;
1313 case 3:
1314 return 1;
1315 break;
1318 while(true) {
1319 /* Convert CYCLETIME (in ms) to HZ */
1320 end = *rb->current_tick + (CYCLETIME * HZ) / 1000;
1322 if (life >= 0) {
1323 #ifdef HAVE_LCD_COLOR
1324 rb->lcd_set_background(LCD_BLACK);
1325 rb->lcd_set_drawmode(DRMODE_SOLID);
1326 rb->lcd_clear_display();
1327 rb->lcd_set_background(LCD_BLACK);
1328 #if LCD_HEIGHT > GAMESCREEN_HEIGHT
1329 rb->lcd_set_foreground(rb->global_settings->bg_color);
1330 rb->lcd_fillrect(0, GAMESCREEN_HEIGHT, LCD_WIDTH,
1331 LCD_HEIGHT - GAMESCREEN_HEIGHT);
1332 #endif
1333 rb->lcd_set_foreground(LCD_WHITE);
1334 #else
1335 rb->lcd_clear_display();
1336 #endif
1338 if (flip_sides) {
1339 if (*rb->current_tick>=sec_count) {
1340 sec_count=*rb->current_tick+HZ;
1341 if (num_count!=0)
1342 num_count--;
1343 else
1344 flip_sides=false;
1346 rb->snprintf(s, sizeof(s), "%d", num_count);
1347 rb->lcd_getstringsize(s, &sw, NULL);
1348 rb->lcd_putsxy(LCD_WIDTH/2-2, STRINGPOS_FLIP, s);
1351 /* write life num */
1352 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1353 rb->snprintf(s, sizeof(s), "L:%d", life);
1354 rb->lcd_putsxy(0, 0, s);
1355 #else
1356 rb->snprintf(s, sizeof(s), "Life: %d", life);
1357 rb->lcd_putsxy(2, 2, s);
1358 #endif
1360 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1361 rb->snprintf(s, sizeof(s), "L%d", cur_level+1);
1362 rb->lcd_getstringsize(s, &sw, NULL);
1363 rb->lcd_putsxy(LCD_WIDTH-sw, 0, s);
1364 #else
1365 rb->snprintf(s, sizeof(s), "Level %d", cur_level+1);
1366 rb->lcd_getstringsize(s, &sw, NULL);
1367 rb->lcd_putsxy(LCD_WIDTH-sw-2, 2, s);
1368 #endif
1370 if (vscore<score) vscore++;
1371 rb->snprintf(s, sizeof(s), "%d", vscore);
1372 rb->lcd_getstringsize(s, &sw, NULL);
1373 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1374 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
1375 #else
1376 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s);
1377 #endif
1379 /* continue game */
1380 if (con_game== 1 && start_game!=1) {
1381 #if CONFIG_KEYPAD == ONDIO_PAD
1382 rb->snprintf(s, sizeof(s), "MENU To Continue");
1383 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
1384 rb->snprintf(s, sizeof(s), "Press NAVI To Continue");
1385 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
1386 rb->snprintf(s, sizeof(s), "PLAY To Continue");
1387 #else
1388 rb->snprintf(s, sizeof(s), "Press SELECT To Continue");
1389 #endif
1390 rb->lcd_getstringsize(s, &sw, NULL);
1391 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_NAVI, s);
1393 sec_count=*rb->current_tick+HZ;
1396 /* draw the ball */
1397 for(i=0;i<used_balls;i++)
1398 rb->lcd_bitmap(brickmania_ball,ball[i].pos_x, ball[i].pos_y,
1399 BALL, BALL);
1401 if (brick_on_board==0)
1402 brick_on_board--;
1404 /* if the pad is fire */
1405 for(i=0;i<=30;i++) {
1406 if (fire[i].top+7>0) {
1407 if (con_game!=1)
1408 fire[i].top-=4;
1409 rb->lcd_vline(fire[i].left, fire[i].top, fire[i].top+7);
1413 /* the bricks */
1414 for (i=0;i<=7;i++) {
1415 for (j=0;j<=9;j++) {
1416 if (brick[i*10+j].power<7) {
1417 if (brick[i*10+j].poweruse==2) {
1418 if (con_game!=1)
1419 brick[i*10+j].powertop+=2;
1420 rb->lcd_bitmap_part(brickmania_powerups,0,
1421 POWERUP_HEIGHT*brick[i*10+j
1422 ].power,
1423 POWERUP_WIDTH,
1424 LEFTMARGIN+j*BRICK_WIDTH+
1425 (BRICK_WIDTH/2-
1426 POWERUP_WIDTH/2),
1427 brick[i*10+j].powertop,
1428 POWERUP_WIDTH,
1429 POWERUP_HEIGHT);
1433 if ((pad_pos_x<LEFTMARGIN+j*BRICK_WIDTH+5 &&
1434 pad_pos_x+PAD_WIDTH>LEFTMARGIN+j*BRICK_WIDTH+5) &&
1435 brick[i*10+j].powertop+6>=PAD_POS_Y &&
1436 brick[i*10+j].poweruse==2) {
1437 switch(brick[i*10+j].power) {
1438 case 0:
1439 life++;
1440 score+=50;
1441 break;
1442 case 1:
1443 life--;
1444 if (life>=0) {
1445 int_game(0);
1446 sleep(2);
1448 break;
1449 case 2:
1450 score+=34;
1451 pad_type=1;
1452 break;
1453 case 3:
1454 score+=47;
1455 pad_type=2;
1456 for(k=0;k<used_balls;k++)
1457 ball[k].glue=false;
1458 break;
1459 case 4:
1460 score+=23;
1461 pad_type=0;
1462 for(k=0;k<used_balls;k++)
1463 ball[k].glue=false;
1464 flip_sides=false;
1465 break;
1466 case 5:
1467 score+=23;
1468 sec_count=*rb->current_tick+HZ;
1469 num_count=10;
1470 flip_sides=!flip_sides;
1471 break;
1472 case 6:
1473 score+=23;
1474 used_balls++;
1475 ball[used_balls-1].x= rb->rand()%1 == 0 ?
1476 -1 : 1;
1477 ball[used_balls-1].y= -4;
1478 break;
1480 brick[i*10+j].poweruse=1;
1483 if (brick[i*10+j].powertop>PAD_POS_Y)
1484 brick[i*10+j].poweruse=1;
1486 brickx=LEFTMARGIN+j*BRICK_WIDTH;
1487 bricky=TOPMARGIN+i*BRICK_HEIGHT;
1488 if (pad_type==2) {
1489 for (k=0;k<=30;k++) {
1490 if (fire[k].top+7>0) {
1491 if (brick[i*10+j].used==1 &&
1492 (fire[k].left+1 >= brickx &&
1493 fire[k].left+1 <= brickx+BRICK_WIDTH) &&
1494 (bricky+BRICK_HEIGHT>fire[k].top)) {
1495 score+=13;
1496 fire[k].top=-16;
1497 if (brick[i*10+j].hits > 0) {
1498 brick[i*10+j].hits--;
1499 brick[i*10+j].hiteffect++;
1500 score+=3;
1502 else {
1503 brick[i*10+j].used=0;
1504 if (brick[i*10+j].power!=10)
1505 brick[i*10+j].poweruse=2;
1506 brick_on_board--;
1513 if (brick[i*10+j].used==1) {
1514 rb->lcd_bitmap_part(brickmania_bricks,0,
1515 BRICK_HEIGHT*brick[i*10+j].color,
1516 BRICK_WIDTH,
1517 LEFTMARGIN+j*BRICK_WIDTH,
1518 TOPMARGIN+i*BRICK_HEIGHT,
1519 BRICK_WIDTH, BRICK_HEIGHT);
1520 #ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */
1521 if (brick[i*10+j].hiteffect>0)
1522 rb->lcd_bitmap_transparent_part(brickmania_break,
1524 BRICK_HEIGHT*brick[i*10+j].hiteffect,
1525 BRICK_WIDTH,
1526 LEFTMARGIN+j*BRICK_WIDTH,
1527 TOPMARGIN+i*BRICK_HEIGHT,
1528 BRICK_WIDTH,
1529 BRICK_HEIGHT);
1530 #endif
1533 for(k=0;k<used_balls;k++) {
1534 if (ball[k].pos_y <160) {
1535 if (brick[i*10+j].used==1) {
1536 if ((ball[k].pos_x+ball[k].x+HALFBALL >=
1537 brickx &&
1538 ball[k].pos_x+ball[k].x+HALFBALL <=
1539 brickx+BRICK_WIDTH) &&
1540 ((bricky-4<ball[k].pos_y+BALL &&
1541 bricky>ball[k].pos_y+BALL) ||
1542 (bricky+4>ball[k].pos_y+BALL+BALL &&
1543 bricky<ball[k].pos_y+BALL+BALL)) &&
1544 (ball[k].y >0)) {
1545 ball[k].tempy=bricky-ball[k].pos_y-BALL;
1547 else if ((ball[k].pos_x+ball[k].x+HALFBALL >=
1548 brickx &&
1549 ball[k].pos_x+ball[k].x+HALFBALL <=
1550 brickx+BRICK_WIDTH) &&
1551 ((bricky+BRICK_HEIGHT+4>ball[k].pos_y &&
1552 bricky+BRICK_HEIGHT<ball[k].pos_y) ||
1553 (bricky+BRICK_HEIGHT-4<ball[k].pos_y-BALL &&
1554 bricky+BRICK_HEIGHT>ball[k].pos_y-BALL)) &&
1555 (ball[k].y <0)) {
1556 ball[k].tempy=
1557 -(ball[k].pos_y-(bricky+BRICK_HEIGHT));
1560 if ((ball[k].pos_y+HALFBALL >=
1561 bricky &&
1562 ball[k].pos_y+HALFBALL <=
1563 bricky+BRICK_HEIGHT) &&
1564 ((brickx-4<ball[k].pos_x+BALL &&
1565 brickx>ball[k].pos_x+BALL) ||
1566 (brickx+4>ball[k].pos_x+BALL+BALL &&
1567 brickx<ball[k].pos_x+BALL+BALL)) &&
1568 (ball[k].x >0)) {
1569 ball[k].tempx=brickx-ball[k].pos_x-BALL;
1571 else if ((ball[k].pos_y+ball[k].y+HALFBALL >=
1572 bricky &&
1573 ball[k].pos_y+ball[k].y+HALFBALL <=
1574 bricky+BRICK_HEIGHT) &&
1575 ((brickx+BRICK_WIDTH+4>ball[k].pos_x &&
1576 brickx+BRICK_WIDTH<ball[k].pos_x) ||
1577 (brickx+BRICK_WIDTH-4<ball[k].pos_x-
1578 BALL &&
1579 brickx+BRICK_WIDTH>ball[k].pos_x-
1580 BALL)) && (ball[k].x <0)) {
1581 ball[k].tempx=
1582 -(ball[k].pos_x-(brickx+BRICK_WIDTH));
1585 if ((ball[k].pos_x+HALFBALL >= brickx &&
1586 ball[k].pos_x+HALFBALL <=
1587 brickx+BRICK_WIDTH) &&
1588 ((bricky+BRICK_HEIGHT==ball[k].pos_y) ||
1589 (bricky+BRICK_HEIGHT-6<=ball[k].pos_y &&
1590 bricky+BRICK_HEIGHT>ball[k].pos_y)) &&
1591 (ball[k].y <0)) { /* bottom line */
1592 if (brick[i*10+j].hits > 0) {
1593 brick[i*10+j].hits--;
1594 brick[i*10+j].hiteffect++;
1595 score+=2;
1597 else {
1598 brick[i*10+j].used=0;
1599 if (brick[i*10+j].power!=10)
1600 brick[i*10+j].poweruse=2;
1603 ball[k].y = ball[k].y*-1;
1605 else if ((ball[k].pos_x+HALFBALL >= brickx &&
1606 ball[k].pos_x+HALFBALL <=
1607 brickx+BRICK_WIDTH) &&
1608 ((bricky==ball[k].pos_y+BALL) ||
1609 (bricky+6>=ball[k].pos_y+BALL &&
1610 bricky<ball[k].pos_y+BALL)) &&
1611 (ball[k].y >0)) { /* top line */
1612 if (brick[i*10+j].hits > 0) {
1613 brick[i*10+j].hits--;
1614 brick[i*10+j].hiteffect++;
1615 score+=2;
1617 else {
1618 brick[i*10+j].used=0;
1619 if (brick[i*10+j].power!=10)
1620 brick[i*10+j].poweruse=2;
1623 ball[k].y = ball[k].y*-1;
1626 if ((ball[k].pos_y+HALFBALL >= bricky &&
1627 ball[k].pos_y+HALFBALL <=
1628 bricky+BRICK_HEIGHT) &&
1629 ((brickx==ball[k].pos_x+BALL) ||
1630 (brickx+6>=ball[k].pos_x+BALL &&
1631 brickx<ball[k].pos_x+BALL)) &&
1632 (ball[k].x > 0)) { /* left line */
1633 if (brick[i*10+j].hits > 0) {
1634 brick[i*10+j].hits--;
1635 brick[i*10+j].hiteffect++;
1636 score+=2;
1638 else {
1639 brick[i*10+j].used=0;
1640 if (brick[i*10+j].power!=10)
1641 brick[i*10+j].poweruse=2;
1643 ball[k].x = ball[k].x*-1;
1646 else if ((ball[k].pos_y+HALFBALL >= bricky &&
1647 ball[k].pos_y+HALFBALL <=
1648 bricky+BRICK_HEIGHT) &&
1649 ((brickx+BRICK_WIDTH==
1650 ball[k].pos_x) ||
1651 (brickx+BRICK_WIDTH-6<=
1652 ball[k].pos_x &&
1653 brickx+BRICK_WIDTH>
1654 ball[k].pos_x)) &&
1655 (ball[k].x < 0)) { /* Right line */
1656 if (brick[i*10+j].hits > 0) {
1657 brick[i*10+j].hits--;
1658 brick[i*10+j].hiteffect++;
1659 score+=2;
1661 else {
1662 brick[i*10+j].used=0;
1663 if (brick[i*10+j].power!=10)
1664 brick[i*10+j].poweruse=2;
1667 ball[k].x = ball[k].x*-1;
1670 if (brick[i*10+j].used==0) {
1671 brick_on_board--;
1672 score+=8;
1676 } /* for k */
1677 } /* for j */
1678 } /* for i */
1680 /* draw the pad */
1681 rb->lcd_bitmap_part(brickmania_pads,0,pad_type*PAD_HEIGHT,
1682 PAD_WIDTH,pad_pos_x, PAD_POS_Y, PAD_WIDTH,
1683 PAD_HEIGHT);
1685 for(k=0;k<used_balls;k++) {
1687 if ((ball[k].pos_x >= pad_pos_x &&
1688 ball[k].pos_x <= pad_pos_x+PAD_WIDTH) &&
1689 (PAD_POS_Y-4<ball[k].pos_y+BALL &&
1690 PAD_POS_Y>ball[k].pos_y+BALL) && (ball[k].y >0))
1691 ball[k].tempy=PAD_POS_Y-ball[k].pos_y-BALL;
1692 else if ((4>ball[k].pos_y && 0<ball[k].pos_y) &&
1693 (ball[k].y <0))
1694 ball[k].tempy=-ball[k].pos_y;
1695 if ((LCD_WIDTH-4<ball[k].pos_x+BALL &&
1696 LCD_WIDTH>ball[k].pos_x+BALL) && (ball[k].x >0))
1697 ball[k].tempx=LCD_WIDTH-ball[k].pos_x-BALL;
1698 else if ((4>ball[k].pos_x && 0<ball[k].pos_x) &&
1699 (ball[k].x <0))
1700 ball[k].tempx=-ball[k].pos_x;
1702 /* top line */
1703 if (ball[k].pos_y<= 0)
1704 ball[k].y = ball[k].y*-1;
1705 /* bottom line */
1706 else if (ball[k].pos_y+BALL >= GAMESCREEN_HEIGHT) {
1707 if (used_balls>1) {
1708 used_balls--;
1709 ball[k].pos_x = ball[used_balls].pos_x;
1710 ball[k].pos_y = ball[used_balls].pos_y;
1711 ball[k].y = ball[used_balls].y;
1712 ball[k].tempy = ball[used_balls].tempy;
1713 ball[k].x = ball[used_balls].x;
1714 ball[k].tempx = ball[used_balls].tempx;
1715 ball[k].glue = ball[used_balls].glue;
1717 ball[used_balls].x=0;
1718 ball[used_balls].y=0;
1719 ball[used_balls].tempy=0;
1720 ball[used_balls].tempx=0;
1721 ball[used_balls].pos_y=PAD_POS_Y-BALL;
1722 ball[used_balls].pos_x=pad_pos_x+(PAD_WIDTH/2)-2;
1724 k--;
1725 continue;
1726 } else {
1727 life--;
1728 if (life>=0) {
1729 int_game(0);
1730 sleep(2);
1735 /* left line ,right line */
1736 if ((ball[k].pos_x <= 0) ||
1737 (ball[k].pos_x+BALL >= LCD_WIDTH)) {
1738 ball[k].x = ball[k].x*-1;
1739 ball[k].pos_x = ball[k].pos_x <= 0 ? 0 : LCD_WIDTH-BALL;
1742 if ((ball[k].pos_y+BALL >= PAD_POS_Y &&
1743 (ball[k].pos_x >= pad_pos_x &&
1744 ball[k].pos_x <= pad_pos_x+PAD_WIDTH)) &&
1745 start_game != 1 && !ball[k].glue) {
1747 if ((ball[k].pos_x+HALFBALL >= pad_pos_x &&
1748 ball[k].pos_x+HALFBALL <=
1749 pad_pos_x+(PAD_WIDTH/2/4)) ||
1750 (ball[k].pos_x +HALFBALL>=
1751 pad_pos_x+(PAD_WIDTH-(PAD_WIDTH/2/4)) &&
1752 ball[k].pos_x+HALFBALL <= pad_pos_x+PAD_WIDTH)) {
1754 ball[k].y = -2;
1755 if (ball[k].pos_x != 0 &&
1756 ball[k].pos_x+BALL!=LCD_WIDTH)
1757 ball[k].x = pad_check(6,0,ball[k].pos_x+2<=
1758 pad_pos_x+(PAD_WIDTH/2)?
1759 0:1,k);
1762 else if ((ball[k].pos_x+HALFBALL >=
1763 pad_pos_x+(PAD_WIDTH/2/4) &&
1764 ball[k].pos_x+HALFBALL <=
1765 pad_pos_x+2*(PAD_WIDTH/2/4)) ||
1766 (ball[k].pos_x+HALFBALL >=
1767 pad_pos_x+(PAD_WIDTH-2*(PAD_WIDTH/2/4)) &&
1768 ball[k].pos_x+HALFBALL <=
1769 pad_pos_x+(PAD_WIDTH-(PAD_WIDTH/2/4)) )) {
1771 ball[k].y = -3;
1772 if (ball[k].pos_x != 0 &&
1773 ball[k].pos_x+BALL!=LCD_WIDTH)
1774 ball[k].x = pad_check(4,0,ball[k].pos_x+2<=
1775 pad_pos_x+(PAD_WIDTH/2)?
1776 0:1,k);
1779 else if ((ball[k].pos_x+HALFBALL >=
1780 pad_pos_x+2*(PAD_WIDTH/2/4) &&
1781 ball[k].pos_x+HALFBALL <=
1782 pad_pos_x+3*(PAD_WIDTH/2/4)) ||
1783 (ball[k].pos_x+2 >=
1784 pad_pos_x+(PAD_WIDTH-3*(PAD_WIDTH/2/4)) &&
1785 ball[k].pos_x+2 <=
1786 pad_pos_x+ ((PAD_WIDTH/2)-2*(PAD_WIDTH/2/4)) )) {
1788 ball[k].y = -4;
1789 if (ball[k].pos_x != 0 &&
1790 ball[k].pos_x+BALL!=LCD_WIDTH)
1791 ball[k].x = pad_check(3,0,ball[k].pos_x+2<=
1792 pad_pos_x+(PAD_WIDTH/2)?
1793 0:1,k);
1796 else if ((ball[k].pos_x+HALFBALL >=
1797 pad_pos_x+3*(PAD_WIDTH/2/4) &&
1798 ball[k].pos_x+HALFBALL <=
1799 pad_pos_x+4*(PAD_WIDTH/2/4)-2) ||
1800 (ball[k].pos_x+2 >= pad_pos_x+(PAD_WIDTH/2+2) &&
1801 ball[k].pos_x+2 <=
1802 pad_pos_x+(PAD_WIDTH-3*(PAD_WIDTH/2/4)) )) {
1804 ball[k].y = -4;
1805 if (ball[k].pos_x != 0 &&
1806 ball[k].pos_x+BALL!=LCD_WIDTH)
1807 ball[k].x = pad_check(2,1,0,k);
1810 else {
1811 ball[k].y = -4;
1815 if (!ball[k].glue) {
1816 ball[k].pos_x+=ball[k].tempx!=0?ball[k].tempx:ball[k].x;
1817 ball[k].pos_y+=ball[k].tempy!=0?ball[k].tempy:ball[k].y;
1819 ball[k].tempy=0;
1820 ball[k].tempx=0;
1823 if (ball[k].pos_y+5 >= PAD_POS_Y &&
1824 (pad_type==1 && !ball[k].glue) &&
1825 (ball[k].pos_x >= pad_pos_x &&
1826 ball[k].pos_x <= pad_pos_x+PAD_WIDTH)) {
1827 ball[k].y=0;
1828 ball[k].pos_y=PAD_POS_Y-BALL;
1829 ball[k].glue=true;
1831 } /* for k */
1833 rb->lcd_update();
1835 if (brick_on_board < 0) {
1836 if (cur_level+1<levels_num) {
1837 cur_level++;
1838 score+=100;
1839 int_game(1);
1840 sleep(2);
1842 else {
1843 rb->lcd_getstringsize("Congratulations!", &sw, NULL);
1844 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_CONGRATS,
1845 "Congratulations!");
1846 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1847 rb->lcd_getstringsize("No more levels", &sw, NULL);
1848 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_FINISH,
1849 "No more levels");
1850 #else
1851 rb->lcd_getstringsize("You have finished the game!",
1852 &sw, NULL);
1853 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_FINISH,
1854 "You have finished the game!");
1855 #endif
1856 vscore=score;
1857 rb->lcd_update();
1858 if (score>highscore) {
1859 sleep(2);
1860 highscore=score;
1861 rb->splash(HZ*2, "New High Score");
1863 else {
1864 sleep(3);
1867 switch(game_menu(0)) {
1868 case 0:
1869 life=2;
1870 cur_level=0;
1871 int_game(1);
1872 break;
1873 case 1:
1874 con_game=1;
1875 break;
1876 case 2:
1877 if (help(0)==1) return 1;
1878 break;
1879 case 3:
1880 return 1;
1881 break;
1886 int move_button,button;
1887 int button_right,button_left;
1888 button=rb->button_get(false);
1890 #if defined(HAS_BUTTON_HOLD) && !defined(HAVE_REMOTE_LCD_AS_MAIN)
1891 /* FIXME: Should probably check remote hold here */
1892 if (rb->button_hold())
1893 button = QUIT;
1894 #endif
1896 #ifdef HAVE_TOUCHSCREEN
1897 if(button & BUTTON_TOUCHSCREEN)
1899 short touch_x, touch_y;
1900 touch_x = rb->button_get_data() >> 16;
1901 touch_y = rb->button_get_data() & 0xffff;
1902 if(touch_y >= PAD_POS_Y && touch_y <= PAD_POS_Y+PAD_HEIGHT)
1904 pad_pos_x += (flip_sides ? -1 : 1) * ( (touch_x-pad_pos_x-PAD_WIDTH/2) / 4 );
1906 if(pad_pos_x < 0)
1907 pad_pos_x = 0;
1908 else if(pad_pos_x+PAD_WIDTH > LCD_WIDTH)
1909 pad_pos_x = LCD_WIDTH-PAD_WIDTH;
1910 for(k=0;k<used_balls;k++)
1911 if ((start_game==1 || ball[k].glue))
1912 ball[k].pos_x = pad_pos_x+PAD_WIDTH/2;
1915 if(button & BUTTON_REL)
1916 button = SELECT;
1918 else
1920 #endif
1921 move_button=rb->button_status();
1922 #ifdef ALTRIGHT
1923 button_right=((move_button & RIGHT) || (move_button & ALTRIGHT));
1924 button_left=((move_button & LEFT) || (move_button & ALTLEFT));
1925 #else
1926 button_right=((move_button & RIGHT) || (SCROLL_FWD(button)));
1927 button_left=((move_button & LEFT) || (SCROLL_BACK(button)));
1928 #endif
1929 if ((con_game== 1 && start_game!=1) && (button_right || button_left))
1930 continue;
1931 if ((button_right && flip_sides==false) ||
1932 (button_left && flip_sides==true)) {
1933 if (pad_pos_x+8+PAD_WIDTH > LCD_WIDTH) {
1934 for(k=0;k<used_balls;k++)
1935 if (start_game==1 || ball[k].glue)
1936 ball[k].pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
1937 pad_pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
1939 else {
1940 for(k=0;k<used_balls;k++)
1941 if ((start_game==1 || ball[k].glue))
1942 ball[k].pos_x+=8;
1943 pad_pos_x+=8;
1946 else if ((button_left && flip_sides==false) ||
1947 (button_right && flip_sides==true)) {
1948 if (pad_pos_x-8 < 0) {
1949 for(k=0;k<used_balls;k++)
1950 if (start_game==1 || ball[k].glue)
1951 ball[k].pos_x-=pad_pos_x;
1952 pad_pos_x-=pad_pos_x;
1954 else {
1955 for(k=0;k<used_balls;k++)
1956 if (start_game==1 || ball[k].glue)
1957 ball[k].pos_x-=8;
1958 pad_pos_x-=8;
1961 #ifdef HAVE_TOUCHSCREEN
1963 #endif
1966 switch(button) {
1967 case UP:
1968 case SELECT:
1969 if (start_game==1 && con_game!=1 && pad_type!=1) {
1970 for(k=0;k<used_balls;k++) {
1971 ball[k].y=-4;
1972 ball[k].x=pad_pos_x+(PAD_WIDTH/2)-2>=
1973 LCD_WIDTH/2?2:-2;
1975 start_game =0;
1977 else if (pad_type==1) {
1978 for(k=0;k<used_balls;k++) {
1979 if (ball[k].glue)
1980 ball[k].glue=false;
1981 else if (start_game==1) {
1982 ball[k].x = x[k];
1983 ball[k].y = y[k];
1987 if (start_game!=1 && con_game==1) {
1988 start_game =0;
1989 con_game=0;
1991 } else if (pad_type==2 && con_game!=1) {
1992 int tfire;
1993 tfire=fire_space();
1994 fire[tfire].top=PAD_POS_Y-7;
1995 fire[tfire].left=pad_pos_x+1;
1996 tfire=fire_space();
1997 fire[tfire].top=PAD_POS_Y-7;
1998 fire[tfire].left=pad_pos_x+PAD_WIDTH-1;
1999 } else if (con_game==1 && start_game!=1) {
2000 for(k=0;k<used_balls;k++) {
2001 ball[k].x=x[k];
2002 ball[k].y=y[k];
2004 con_game=0;
2006 break;
2007 #ifdef RC_QUIT
2008 case RC_QUIT:
2009 #endif
2010 case QUIT:
2011 switch(game_menu(1)) {
2012 case 0:
2013 life=2;
2014 cur_level=0;
2015 int_game(1);
2016 break;
2017 case 1:
2018 for(k=0;k<used_balls;k++)
2019 if (ball[k].x!=0 && ball[k].y !=0)
2020 con_game=1;
2021 break;
2022 case 2:
2023 if (help(1)==1)
2024 return 1;
2025 break;
2026 case 3:
2027 return 1;
2028 break;
2031 for(k=0;k<used_balls;k++) {
2032 if (ball[k].x!=0)
2033 x[k]=ball[k].x;
2034 ball[k].x=0;
2035 if (ball[k].y!=0)
2036 y[k]=ball[k].y;
2037 ball[k].y=0;
2040 break;
2042 default:
2043 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
2044 return 1;
2045 break;
2048 else {
2049 #ifdef HAVE_LCD_COLOR
2050 rb->lcd_bitmap_transparent(brickmania_gameover,
2051 (LCD_WIDTH - GAMEOVER_WIDTH)/2,
2052 (GAMESCREEN_HEIGHT - GAMEOVER_HEIGHT)/2,
2053 GAMEOVER_WIDTH,GAMEOVER_HEIGHT);
2054 #else /* greyscale and mono */
2055 rb->lcd_bitmap(brickmania_gameover,(LCD_WIDTH - GAMEOVER_WIDTH)/2,
2056 (GAMESCREEN_HEIGHT - GAMEOVER_HEIGHT)/2,
2057 GAMEOVER_WIDTH,GAMEOVER_HEIGHT);
2058 #endif
2059 rb->lcd_update();
2060 if (score>highscore) {
2061 sleep(2);
2062 highscore=score;
2063 rb->splash(HZ*2, "New High Score");
2064 } else {
2065 sleep(3);
2068 for(k=0;k<used_balls;k++) {
2069 ball[k].x=0;
2070 ball[k].y=0;
2073 switch(game_menu(0)) {
2074 case 0:
2075 cur_level=0;
2076 life=2;
2077 int_game(1);
2078 break;
2079 case 1:
2080 con_game=1;
2081 break;
2082 case 2:
2083 if (help(0)==1)
2084 return 1;
2085 break;
2086 case 3:
2087 return 1;
2088 break;
2091 if (end > *rb->current_tick)
2092 rb->sleep(end-*rb->current_tick);
2093 else
2094 rb->yield();
2098 /* this is the plugin entry point */
2099 enum plugin_status plugin_start(const void* parameter)
2101 (void)parameter;
2103 rb->lcd_setfont(FONT_SYSFIXED);
2104 #if LCD_DEPTH > 1
2105 rb->lcd_set_backdrop(NULL);
2106 #endif
2107 /* Turn off backlight timeout */
2108 backlight_force_on(); /* backlight control in lib/helper.c */
2110 /* now go ahead and have fun! */
2111 while (game_loop()!=1);
2113 configfile_save(HIGH_SCORE,config,1,0);
2115 /* Restore user's original backlight setting */
2116 rb->lcd_setfont(FONT_UI);
2117 /* Turn on backlight timeout (revert to settings) */
2118 backlight_use_settings(); /* backlight control in lib/helper.c */
2120 return PLUGIN_OK;