PP502x: Add some important information about CPU/COP_CTL register to the header glean...
[Rockbox.git] / apps / plugins / brickmania.c
blobcc1951915187cfe33065a7106982c474d544c7e5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005, 2006 Ben Basha (Paprica)
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "plugin.h"
21 #include "configfile.h" /* Part of libplugin */
23 PLUGIN_HEADER
26 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
28 #define QUIT BUTTON_OFF
29 #define LEFT BUTTON_LEFT
30 #define RIGHT BUTTON_RIGHT
31 #define SELECT BUTTON_SELECT
32 #define UP BUTTON_UP
33 #define DOWN BUTTON_DOWN
35 #define RC_QUIT BUTTON_RC_STOP
37 /* Only iPod have scroll events */
38 #define SCROLL_FWD(x) (0)
39 #define SCROLL_BACK(x) (0)
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
50 /* Only iPod have scroll events */
51 #define SCROLL_FWD(x) (0)
52 #define SCROLL_BACK(x) (0)
54 #elif CONFIG_KEYPAD == RECORDER_PAD
56 #define QUIT BUTTON_OFF
57 #define LEFT BUTTON_LEFT
58 #define RIGHT BUTTON_RIGHT
59 #define SELECT BUTTON_PLAY
60 #define UP BUTTON_UP
61 #define DOWN BUTTON_DOWN
63 /* Only iPod have scroll events */
64 #define SCROLL_FWD(x) (0)
65 #define SCROLL_BACK(x) (0)
67 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
69 #define QUIT BUTTON_OFF
70 #define LEFT BUTTON_LEFT
71 #define RIGHT BUTTON_RIGHT
72 #define SELECT BUTTON_SELECT
73 #define UP BUTTON_UP
74 #define DOWN BUTTON_DOWN
76 /* Only iPod have scroll events */
77 #define SCROLL_FWD(x) (0)
78 #define SCROLL_BACK(x) (0)
80 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
81 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
82 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
84 #define QUIT BUTTON_MENU
85 #define LEFT BUTTON_LEFT
86 #define RIGHT BUTTON_RIGHT
87 #define SELECT BUTTON_SELECT
88 #define UP BUTTON_SCROLL_BACK
89 #define DOWN BUTTON_SCROLL_FWD
91 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD)
92 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK)
94 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
96 #define QUIT BUTTON_POWER
97 #define LEFT BUTTON_LEFT
98 #define RIGHT BUTTON_RIGHT
99 #define SELECT BUTTON_SELECT
100 #define UP BUTTON_UP
101 #define DOWN BUTTON_DOWN
103 #define SCROLL_FWD(x) (0)
104 #define SCROLL_BACK(x) (0)
106 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD /* grayscale at the moment */
108 #define QUIT BUTTON_POWER
109 #define LEFT BUTTON_LEFT
110 #define RIGHT BUTTON_RIGHT
111 #define SELECT BUTTON_PLAY
112 #define UP BUTTON_UP
113 #define DOWN BUTTON_DOWN
115 /* Only iPod have scroll events */
116 #define SCROLL_FWD(x) (0)
117 #define SCROLL_BACK(x) (0)
119 #elif CONFIG_KEYPAD == SANSA_E200_PAD
121 #define QUIT BUTTON_POWER
122 #define LEFT BUTTON_LEFT
123 #define RIGHT BUTTON_RIGHT
124 #define SELECT BUTTON_SELECT
125 #define UP BUTTON_SCROLL_UP
126 #define DOWN BUTTON_SCROLL_DOWN
128 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_DOWN)
129 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_UP)
131 #elif CONFIG_KEYPAD == IRIVER_H10_PAD /* grayscale at the moment */
133 #define QUIT BUTTON_POWER
134 #define LEFT BUTTON_LEFT
135 #define RIGHT BUTTON_RIGHT
136 #define SELECT BUTTON_PLAY
137 #define UP BUTTON_SCROLL_UP
138 #define DOWN BUTTON_SCROLL_DOWN
140 /* Only iPod have scroll events */
141 #define SCROLL_FWD(x) (0)
142 #define SCROLL_BACK(x) (0)
144 #else
145 #error Unsupported keypad
146 #endif
148 static struct plugin_api* rb;
150 enum menu_items {
151 BM_START,
152 BM_SEL_START,
153 BM_RESUME,
154 BM_SEL_RESUME,
155 BM_NO_RESUME,
156 BM_HELP,
157 BM_SEL_HELP,
158 BM_QUIT,
159 BM_SEL_QUIT,
162 /* External bitmaps */
163 #if (LCD_WIDTH != 112) && (LCD_HEIGHT != 64)
164 extern const fb_data brickmania_menu_bg[];
165 extern const fb_data brickmania_gameover[];
166 #endif
167 extern const fb_data brickmania_menu_items[];
168 extern const fb_data brickmania_ball[];
169 #ifdef HAVE_LCD_COLOR
170 extern const fb_data brickmania_break[];
171 #endif
173 /* normal, glue, fire */
174 extern const fb_data brickmania_pads[];
176 /* +life, -life, glue, fire, normal */
177 extern const fb_data brickmania_powerups[];
179 /* purple, red, blue, pink, green, yellow orange */
180 extern const fb_data brickmania_bricks[];
182 #if (LCD_WIDTH == 320) && (LCD_HEIGHT == 240)
184 /* The time (in ms) for one iteration through the game loop - decrease this
185 to speed up the game - note that current_tick is (currently) only accurate
186 to 10ms.
188 #define CYCLETIME 30
190 #define GAMESCREEN_HEIGHT LCD_HEIGHT
192 #define PAD_WIDTH 56
193 #define PAD_HEIGHT 7
194 #define PAD_POS_Y LCD_HEIGHT - 7
195 #define BRICK_HEIGHT 12
196 #define BRICK_WIDTH 32
197 #define BALL 5
198 #define HALFBALL 3
199 #define LEFTMARGIN 0
200 #define TOPMARGIN 30
202 #define MENU_BMPHEIGHT 20
203 #define MENU_BMPWIDTH 112
205 #define BMPHEIGHT_powerup 10
206 #define BMPWIDTH_powerup 16
208 #define BMPHEIGHT_menu LCD_HEIGHT
209 #define BMPWIDTH_menu LCD_WIDTH
211 #define BMPXOFS_start 105
212 #define BMPYOFS_start 110
213 #define BMPXOFS_resume 112
214 #define BMPYOFS_resume 132
215 #define BMPXOFS_help 142
216 #define BMPYOFS_help 150
217 #define BMPXOFS_quit 143
218 #define BMPYOFS_quit 170
219 #define HIGHSCORE_XPOS 57
220 #define HIGHSCORE_YPOS 88
222 #define STRINGPOS_finsh 140
223 #define STRINGPOS_congrats 157
224 #define STRINGPOS_navi 150
225 #define STRINGPOS_flipsides 150
227 #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176)
229 /* The time (in ms) for one iteration through the game loop - decrease this
230 to speed up the game - note that current_tick is (currently) only accurate
231 to 10ms.
233 #define CYCLETIME 30
235 /* Offsets for LCDS > 220x176 */
237 #define GAMESCREEN_HEIGHT 176
239 #define PAD_WIDTH 40
240 #define PAD_HEIGHT 5
241 #define PAD_POS_Y GAMESCREEN_HEIGHT - 7
242 #define BRICK_HEIGHT 8
243 #define BRICK_WIDTH 21
244 #define BALL 5
245 #define HALFBALL 3
246 #define LEFTMARGIN (LCD_WIDTH-220)/2 + 5
247 #define TOPMARGIN 30
249 #define XOFS ((LCD_WIDTH-220)/BRICK_WIDTH/2)*BRICK_WIDTH
250 #define YOFS ((LCD_HEIGHT-176)/BRICK_HEIGHT/2)*BRICK_HEIGHT
252 #define MENU_BMPHEIGHT 20
253 #define MENU_BMPWIDTH 112
255 #define BMPHEIGHT_powerup 6
256 #define BMPWIDTH_powerup 10
258 #define BMPHEIGHT_menu LCD_HEIGHT
259 #define BMPWIDTH_menu LCD_WIDTH
261 #define BMPXOFS_start (55+XOFS)
262 #define BMPYOFS_start (78+YOFS)
263 #define BMPXOFS_resume (62+XOFS)
264 #define BMPYOFS_resume (100+YOFS)
265 #define BMPXOFS_help (92+XOFS)
266 #define BMPYOFS_help (118+YOFS)
267 #define BMPXOFS_quit (93+XOFS)
268 #define BMPYOFS_quit (138+YOFS)
269 #define HIGHSCORE_XPOS (7+XOFS)
270 #define HIGHSCORE_YPOS (56+YOFS)
272 #define STRINGPOS_finsh 140
273 #define STRINGPOS_congrats 157
274 #define STRINGPOS_navi 150
275 #define STRINGPOS_flipsides 150
277 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
278 /* The time (in ms) for one iteration through the game loop - decrease this
279 to speed up the game - note that current_tick is (currently) only accurate
280 to 10ms.
282 #define CYCLETIME 50
284 #define GAMESCREEN_HEIGHT LCD_HEIGHT
286 #define PAD_WIDTH 30
287 #define PAD_HEIGHT 5
288 #define PAD_POS_Y LCD_HEIGHT - 7
289 #define BRICK_HEIGHT 7
290 #define BRICK_WIDTH 15
291 #define BALL 5
292 #define HALFBALL 3
293 #define LEFTMARGIN 5
294 #define TOPMARGIN 21
296 #define MENU_BMPHEIGHT 17
297 #define MENU_BMPWIDTH 88
299 #define BMPHEIGHT_powerup 6
300 #define BMPWIDTH_powerup 10
302 #if LCD_DEPTH == 16
303 #define BMPHEIGHT_menu 128
304 #else
305 #define BMPHEIGHT_menu 45
306 #endif
307 #define BMPWIDTH_menu 160
309 #if LCD_DEPTH == 16
310 #define BMPXOFS_start 38
311 #define BMPYOFS_start 56
312 #define BMPXOFS_resume 42
313 #define BMPYOFS_resume 72
314 #define BMPXOFS_help 65
315 #define BMPYOFS_help 85
316 #define BMPXOFS_quit 66
317 #define BMPYOFS_quit 99
318 #else
319 #define BMPXOFS_start 34
320 #define BMPYOFS_start 64
321 #define BMPXOFS_resume 38
322 #define BMPYOFS_resume 77
323 #define BMPXOFS_help 64
324 #define BMPYOFS_help 90
325 #define BMPXOFS_quit 64
326 #define BMPYOFS_quit 103
327 #endif
328 #define HIGHSCORE_XPOS 7
329 #define HIGHSCORE_YPOS 36
331 #define STRINGPOS_finsh 110
332 #define STRINGPOS_congrats 100
333 #define STRINGPOS_navi 100
334 #define STRINGPOS_flipsides 100
336 /* iPod Mini */
337 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
338 /* The time (in ms) for one iteration through the game loop - decrease this
339 to speed up the game - note that current_tick is (currently) only accurate
340 to 10ms.
342 #define CYCLETIME 50
344 #define GAMESCREEN_HEIGHT LCD_HEIGHT
346 #define PAD_WIDTH 30
347 #define PAD_HEIGHT 5
348 #define PAD_POS_Y LCD_HEIGHT - 5
349 #define BRICK_HEIGHT 7
350 #define BRICK_WIDTH 13
351 #define BALL 5
352 #define HALFBALL 3
353 #define LEFTMARGIN 4
354 #define TOPMARGIN 10
356 #define MENU_BMPHEIGHT 17
357 #define MENU_BMPWIDTH 88
359 #define BMPHEIGHT_powerup 6
360 #define BMPWIDTH_powerup 10
362 #define BMPHEIGHT_menu 45
363 #define BMPWIDTH_menu 160
365 #define BMPXOFS_start 28
366 #define BMPYOFS_start 41
367 #define BMPXOFS_resume 33
368 #define BMPYOFS_resume 58
369 #define BMPXOFS_help 56
370 #define BMPYOFS_help 74
371 #define BMPXOFS_quit 56
372 #define BMPYOFS_quit 90
373 #define HIGHSCORE_XPOS 76
374 #define HIGHSCORE_YPOS 22
376 #define STRINGPOS_finsh 54
377 #define STRINGPOS_congrats 44
378 #define STRINGPOS_navi 44
379 #define STRINGPOS_flipsides 44
382 #elif (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
383 /* The time (in ms) for one iteration through the game loop - decrease this
384 to speed up the game - note that current_tick is (currently) only accurate
385 to 10ms.
387 #define CYCLETIME 75
389 #define GAMESCREEN_HEIGHT LCD_HEIGHT
391 #define PAD_WIDTH 30
392 #define PAD_HEIGHT 3
393 #define PAD_POS_Y LCD_HEIGHT - 5
394 #define BRICK_HEIGHT 4
395 #define BRICK_WIDTH 11
396 #define BALL 3
397 #define HALFBALL 2
398 #define LEFTMARGIN 1
399 #define TOPMARGIN 10
401 #define MENU_BMPHEIGHT 9
402 #define MENU_BMPWIDTH 80
404 #define BMPHEIGHT_powerup 6
405 #define BMPWIDTH_powerup 7
407 #define BMPXOFS_start 12
408 #define BMPYOFS_start 20
409 #define BMPXOFS_resume 18
410 #define BMPYOFS_resume 31
411 #define BMPXOFS_help 39
412 #define BMPYOFS_help 42
413 #define BMPXOFS_quit 40
414 #define BMPYOFS_quit 53
415 #define HIGHSCORE_XPOS 0
416 #define HIGHSCORE_YPOS 0
418 #define STRINGPOS_finsh 54
419 #define STRINGPOS_congrats 44
420 #define STRINGPOS_navi 44
421 #define STRINGPOS_flipsides 44
423 /* nano and sansa */
424 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT >= 132) && (LCD_DEPTH==16)
425 /* The time (in ms) for one iteration through the game loop - decrease this
426 to speed up the game - note that current_tick is (currently) only accurate
427 to 10ms.
430 #define CYCLETIME 30
432 #if (LCD_HEIGHT == 220)
433 #define GAMESCREEN_HEIGHT 132
434 #else
435 #define GAMESCREEN_HEIGHT LCD_HEIGHT
436 #endif
438 #define PAD_WIDTH 40
439 #define PAD_HEIGHT 5
440 #define PAD_POS_Y GAMESCREEN_HEIGHT - 7
441 #define BRICK_HEIGHT 7
442 #define BRICK_WIDTH 17
443 #define BALL 5
444 #define HALFBALL 3
445 #define LEFTMARGIN 3
446 #define TOPMARGIN 21
448 #define MENU_BMPHEIGHT 16
449 #define MENU_BMPWIDTH 89
451 #define BMPHEIGHT_powerup 6
452 #define BMPWIDTH_powerup 10
454 #define BMPHEIGHT_menu 132
455 #define BMPWIDTH_menu 176
457 #define BMPXOFS_start 44
458 #define BMPYOFS_start 58
459 #define BMPXOFS_resume 50
460 #define BMPYOFS_resume 75
461 #define BMPXOFS_help 74
462 #define BMPYOFS_help 89
463 #define BMPXOFS_quit 75
464 #define BMPYOFS_quit 104
465 #define HIGHSCORE_XPOS 7
466 #define HIGHSCORE_YPOS 36
468 #define STRINGPOS_finsh 110
469 #define STRINGPOS_congrats 110
470 #define STRINGPOS_navi 100
471 #define STRINGPOS_flipsides 100
473 #else
474 #error Unsupported LCD Size
475 #endif
477 int levels_num = 29;
479 static unsigned char levels[29][8][10] = {
480 { /* level1 */
481 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
482 {0x2,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x2},
483 {0x0,0x2,0x1,0x0,0x0,0x0,0x0,0x1,0x2,0x0},
484 {0x0,0x0,0x2,0x1,0x0,0x0,0x1,0x2,0x0,0x0},
485 {0x0,0x0,0x0,0x2,0x1,0x1,0x2,0x0,0x0,0x0},
486 {0x7,0x0,0x0,0x7,0x2,0x2,0x7,0x0,0x0,0x7},
487 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
488 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
490 { /* level2 */
491 {0x0,0x0,0x7,0x7,0x1,0x1,0x7,0x7,0x0,0x0},
492 {0x0,0x1,0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x0},
493 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
494 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1},
495 {0x1,0x1,0x2,0x1,0x0,0x0,0x1,0x2,0x1,0x1},
496 {0x1,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x2,0x1},
497 {0x0,0x1,0x2,0x0,0x0,0x0,0x0,0x2,0x1,0x0},
498 {0x0,0x0,0x1,0x2,0x2,0x2,0x2,0x1,0x0,0x0}
500 { /* level3 */
501 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
502 {0x3,0x23,0x23,0x3,0x0,0x0,0x2,0x22,0x22,0x2},
503 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
504 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
505 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
506 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6},
507 {0x5,0x25,0x25,0x5,0x0,0x0,0x6,0x26,0x26,0x6},
508 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6}
510 { /* level4 */
511 {0x0,0x0,0x0,0x27,0x27,0x27,0x27,0x0,0x0,0x0},
512 {0x0,0x0,0x0,0x27,0x7,0x7,0x27,0x0,0x0,0x0},
513 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
514 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
515 {0x26,0x6,0x0,0x2,0x2,0x2,0x2,0x0,0x6,0x26},
516 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
517 {0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0},
518 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1}
520 { /* level5 */
521 {0x1,0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4},
522 {0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0},
523 {0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5},
524 {0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5,0x5},
525 {0x0,0x33,0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0},
526 {0x3,0x33,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x36},
527 {0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x6,0x36},
528 {0x0,0x24,0x24,0x0,0x25,0x25,0x0,0x26,0x26,0x0}
530 { /* level6 */
531 {0x0,0x1,0x3,0x7,0x7,0x7,0x7,0x3,0x1,0x0},
532 {0x3,0x1,0x3,0x7,0x0,0x0,0x7,0x3,0x1,0x3},
533 {0x3,0x1,0x3,0x7,0x7,0x7,0x7,0x3,0x1,0x3},
534 {0x0,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x0},
535 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5},
536 {0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5},
537 {0x0,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x0},
538 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
540 { /* level7 */
541 {0x0,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x0},
542 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
543 {0x6,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x6},
544 {0x6,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x6},
545 {0x6,0x6,0x6,0x0,0x0,0x0,0x0,0x6,0x6,0x6},
546 {0x0,0x0,0x0,0x1,0x1,0x1,0x1,0x0,0x0,0x0},
547 {0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0},
548 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
550 { /* level8 */
551 {0x0,0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x0},
552 {0x0,0x0,0x0,0x4,0x0,0x0,0x4,0x0,0x0,0x0},
553 {0x6,0x6,0x0,0x2,0x32,0x32,0x2,0x0,0x6,0x6},
554 {0x0,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x0,0x0},
555 {0x0,0x6,0x6,0x0,0x0,0x0,0x0,0x6,0x6,0x0},
556 {0x0,0x0,0x0,0x5,0x25,0x25,0x5,0x0,0x0,0x0},
557 {0x0,0x5,0x5,0x25,0x5,0x5,0x25,0x5,0x5,0x0},
558 {0x5,0x5,0x25,0x5,0x5,0x5,0x5,0x25,0x5,0x5}
560 { /* level9 */
561 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
562 {0x2,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x2},
563 {0x2,0x0,0x3,0x0,0x1,0x1,0x0,0x3,0x0,0x2},
564 {0x2,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x2},
565 {0x2,0x0,0x1,0x0,0x3,0x3,0x0,0x1,0x0,0x2},
566 {0x2,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x2},
567 {0x2,0x2,0x0,0x0,0x1,0x1,0x0,0x0,0x2,0x2},
568 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
570 { /* level10 */
571 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
572 {0x0,0x5,0x0,0x5,0x0,0x5,0x0,0x5,0x0,0x5},
573 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
574 {0x0,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x0},
575 {0x0,0x0,0x0,0x4,0x1,0x1,0x4,0x0,0x0,0x0},
576 {0x0,0x0,0x3,0x4,0x1,0x1,0x4,0x3,0x0,0x0},
577 {0x0,0x2,0x3,0x4,0x1,0x1,0x4,0x3,0x2,0x0},
578 {0x1,0x2,0x3,0x4,0x1,0x1,0x4,0x3,0x2,0x1}
580 { /* level11 */
581 {0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3},
582 {0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x2},
583 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
584 {0x2,0x0,0x0,0x0,0x7,0x7,0x0,0x0,0x0,0x2},
585 {0x2,0x0,0x0,0x7,0x7,0x7,0x7,0x0,0x0,0x2},
586 {0x0,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x0},
587 {0x0,0x2,0x0,0x1,0x0,0x0,0x1,0x0,0x2,0x0},
588 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5}
590 { /* level 12 */
591 {0x2,0x1,0x3,0x1,0x0,0x0,0x1,0x3,0x1,0x2},
592 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1},
593 {0x1,0x1,0x1,0x0,0x1,0x1,0x0,0x1,0x1,0x1},
594 {0x0,0x1,0x0,0x1,0x6,0x6,0x1,0x0,0x1,0x0},
595 {0x0,0x0,0x1,0x1,0x6,0x6,0x1,0x1,0x0,0x0},
596 {0x1,0x1,0x1,0x7,0x0,0x0,0x7,0x1,0x1,0x1},
597 {0x1,0x1,0x7,0x1,0x0,0x0,0x1,0x7,0x1,0x1},
598 {0x2,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x2,0x2}
600 {/* levell13 */
601 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
602 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
603 {0x2,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x0,0x2},
604 {0x2,0x0,0x2,0x3,0x3,0x3,0x3,0x3,0x0,0x2},
605 {0x2,0x0,0x2,0x4,0x4,0x4,0x4,0x4,0x0,0x2},
606 {0x2,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
607 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
608 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
610 {/* level14 */
611 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
612 {0x4,0x4,0x4,0x4,0x2,0x2,0x4,0x4,0x4,0x4},
613 {0x4,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x4},
614 {0x4,0x0,0x0,0x2,0x3,0x3,0x2,0x0,0x0,0x4},
615 {0x4,0x0,0x2,0x23,0x3,0x3,0x23,0x2,0x0,0x4},
616 {0x4,0x0,0x2,0x22,0x2,0x2,0x22,0x2,0x0,0x4},
617 {0x4,0x0,0x6,0x21,0x5,0x5,0x21,0x6,0x0,0x4},
618 {0x4,0x6,0x1,0x1,0x5,0x5,0x1,0x1,0x6,0x4}
620 {/* level 15 */
621 {0x4,0x4,0x4,0x4,0x4,0x3,0x3,0x3,0x3,0x3},
622 {0x2,0x2,0x1,0x1,0x1,0x1,0x1,0x5,0x0,0x0},
623 {0x2,0x2,0x1,0x1,0x1,0x0,0x1,0x6,0x0,0x0},
624 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x5,0x0,0x0},
625 {0x2,0x1,0x2,0x2,0x2,0x1,0x1,0x6,0x0,0x0},
626 {0x2,0x1,0x2,0x2,0x2,0x1,0x3,0x5,0x3,0x0},
627 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x6,0x0,0x0},
628 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
630 {/* level 16 (Rockbox) by ts-x */
631 {0x2,0x2,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
632 {0x2,0x0,0x3,0x0,0x3,0x4,0x0,0x5,0x5,0x0},
633 {0x2,0x0,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
634 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
635 {0x6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
636 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0},
637 {0x7,0x0,0x7,0x1,0x0,0x1,0x0,0x2,0x0,0x0},
638 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0}
640 {/* level 17 (Alien) by ts-x */
641 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
642 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
643 {0x1,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x1},
644 {0x2,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x2},
645 {0x1,0x0,0x1,0x2,0x2,0x2,0x2,0x1,0x0,0x1},
646 {0x2,0x0,0x0,0x1,0x2,0x2,0x1,0x0,0x0,0x2},
647 {0x2,0x1,0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x2},
648 {0x2,0x2,0x1,0x0,0x1,0x1,0x0,0x1,0x2,0x2}
650 {/* level 18 (Tetris) by ts-x */
651 {0x0,0x2,0x0,0x0,0x3,0x4,0x0,0x2,0x2,0x0},
652 {0x0,0x2,0x7,0x0,0x3,0x4,0x0,0x2,0x2,0x0},
653 {0x2,0x2,0x7,0x0,0x3,0x4,0x0,0x6,0x2,0x2},
654 {0x2,0x2,0x7,0x7,0x3,0x4,0x0,0x6,0x2,0x2},
655 {0x2,0x1,0x7,0x7,0x3,0x4,0x4,0x6,0x5,0x5},
656 {0x2,0x1,0x0,0x7,0x3,0x4,0x4,0x6,0x5,0x5},
657 {0x1,0x1,0x1,0x7,0x3,0x0,0x6,0x6,0x5,0x5},
658 {0x1,0x1,0x1,0x0,0x3,0x0,0x6,0x6,0x5,0x5}
660 { /* level 19 (Stalactites) by ts-x */
661 {0x5,0x2,0x6,0x3,0x4,0x7,0x5,0x3,0x1,0x2},
662 {0x5,0x2,0x6,0x3,0x4,0x7,0x5,0x3,0x1,0x2},
663 {0x5,0x0,0x6,0x3,0x4,0x7,0x5,0x0,0x1,0x2},
664 {0x5,0x2,0x6,0x3,0x4,0x0,0x5,0x3,0x1,0x2},
665 {0x5,0x0,0x6,0x0,0x4,0x7,0x5,0x0,0x1,0x0},
666 {0x5,0x0,0x0,0x3,0x4,0x0,0x0,0x0,0x1,0x2},
667 {0x0,0x0,0x6,0x0,0x0,0x0,0x5,0x0,0x0,0x0},
668 {0x5,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x1,0x0}
670 { /* level 20 (Maze) by ts-x */
671 {0x1,0x1,0x21,0x1,0x1,0x1,0x1,0x1,0x1,0x21},
672 {0x1,0x0,0x0,0x3,0x0,0x0,0x3,0x1,0x31,0x1},
673 {0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x31,0x0,0x1},
674 {0x21,0x0,0x21,0x3,0x0,0x3,0x0,0x3,0x0,0x2},
675 {0x1,0x0,0x1,0x21,0x0,0x12,0x0,0x0,0x0,0x0},
676 {0x31,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x3,0x0},
677 {0x1,0x0,0x1,0x0,0x1,0x1,0x31,0x1,0x1,0x2},
678 {0x22,0x0,0x2,0x1,0x1,0x1,0x1,0x1,0x1,0x21}
680 { /* level 21 (Dentist) by ts-x */
681 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0},
682 {0x2,0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x2,0x2},
683 {0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x2},
684 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x6,0x0,0x2},
685 {0x2,0x0,0x6,0x0,0x6,0x0,0x0,0x0,0x0,0x2},
686 {0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x2},
687 {0x2,0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x2,0x2},
688 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0}
690 { /* level 22 (Spider) by ts-x */
691 {0x31,0x3,0x1,0x1,0x0,0x0,0x1,0x1,0x3,0x31},
692 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
693 {0x33,0x1,0x1,0x36,0x1,0x1,0x36,0x1,0x1,0x33},
694 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
695 {0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x1,0x0,0x0},
696 {0x21,0x3,0x1,0x21,0x2,0x2,0x21,0x1,0x3,0x21},
697 {0x0,0x0,0x0,0x1,0x21,0x1,0x1,0x0,0x0,0x0},
698 {0x3,0x1,0x3,0x1,0x0,0x0,0x1,0x3,0x1,0x3}
700 { /* level 23 (Pool) by ts-x */
701 {0x0,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x7,0x0},
702 {0x0,0x0,0x5,0x0,0x2,0x0,0x0,0x0,0x2,0x0},
703 {0x7,0x3,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x7},
704 {0x7,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x0,0x7},
705 {0x7,0x0,0x4,0x0,0x0,0x3,0x0,0x0,0x0,0x7},
706 {0x7,0x0,0x0,0x6,0x0,0x0,0x0,0x0,0x4,0x7},
707 {0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
708 {0x0,0x7,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x0}
710 { /* level 24 (Vorbis Fish) by ts-x */
711 {0x0,0x0,0x4,0x4,0x5,0x5,0x5,0x0,0x0,0x5},
712 {0x0,0x4,0x6,0x4,0x4,0x5,0x5,0x5,0x0,0x5},
713 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x5,0x5,0x5},
714 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x4,0x5,0x5},
715 {0x0,0x5,0x6,0x4,0x4,0x5,0x5,0x4,0x5,0x0},
716 {0x5,0x5,0x4,0x4,0x5,0x5,0x5,0x4,0x5,0x5},
717 {0x5,0x4,0x4,0x4,0x5,0x5,0x4,0x4,0x5,0x5},
718 {0x0,0x0,0x4,0x4,0x4,0x4,0x4,0x5,0x0,0x5}
720 {/* level 25 (Rainbow) by ts-x */
721 {0x0,0x4,0x1,0x0,0x0,0x0,0x0,0x1,0x4,0x0},
722 {0x24,0x1,0x3,0x1,0x0,0x0,0x21,0x3,0x1,0x24},
723 {0x1,0x23,0x5,0x3,0x1,0x21,0x3,0x5,0x3,0x21},
724 {0x3,0x5,0x6,0x5,0x3,0x3,0x5,0x6,0x5,0x3},
725 {0x5,0x6,0x7,0x6,0x5,0x5,0x6,0x7,0x6,0x5},
726 {0x6,0x7,0x2,0x27,0x6,0x6,0x27,0x2,0x7,0x6},
727 {0x7,0x2,0x0,0x2,0x27,0x27,0x2,0x0,0x2,0x7},
728 {0x32,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x32}
730 { /* level 26 (Bowtie) by ts-x */
731 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5},
732 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
733 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
734 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
735 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
736 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
737 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
738 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5}
740 { /* level 27 (Frog) by ts-x */
741 {0x0,0x5,0x25,0x0,0x0,0x0,0x0,0x25,0x5,0x0},
742 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5},
743 {0x25,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x25},
744 {0x5,0x0,0x3,0x0,0x6,0x6,0x0,0x3,0x0,0x5},
745 {0x5,0x0,0x31,0x0,0x6,0x6,0x0,0x31,0x0,0x5},
746 {0x5,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x5},
747 {0x5,0x5,0x5,0x35,0x0,0x0,0x35,0x5,0x5,0x5},
748 {0x0,0x25,0x5,0x0,0x4,0x4,0x0,0x5,0x25,0x0}
750 { /* level 28 (DigDug) by ts-x */
751 {0x35,0x5,0x5,0x25,0x0,0x25,0x25,0x5,0x5,0x35},
752 {0x6,0x0,0x0,0x6,0x0,0x6,0x6,0x0,0x0,0x6},
753 {0x7,0x0,0x37,0x37,0x0,0x37,0x37,0x7,0x0,0x7},
754 {0x7,0x0,0x7,0x0,0x0,0x0,0x7,0x7,0x7,0x7},
755 {0x4,0x4,0x4,0x24,0x0,0x24,0x4,0x0,0x0,0x4},
756 {0x4,0x4,0x0,0x0,0x0,0x4,0x4,0x0,0x4,0x4},
757 {0x24,0x24,0x4,0x4,0x4,0x4,0x0,0x0,0x24,0x4},
758 {0x1,0x1,0x1,0x1,0x1,0x1,0x21,0x21,0x1,0x1}
760 { /* TheEnd */
761 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
762 {0x22,0x22,0x26,0x0,0x0,0x26,0x24,0x24,0x0,0x0},
763 {0x22,0x0,0x26,0x26,0x0,0x26,0x24,0x0,0x24,0x0},
764 {0x22,0x22,0x26,0x26,0x0,0x26,0x24,0x0,0x24,0x0},
765 {0x22,0x22,0x26,0x0,0x26,0x26,0x24,0x0,0x24,0x0},
766 {0x22,0x0,0x26,0x0,0x26,0x26,0x24,0x0,0x24,0x0},
767 {0x22,0x22,0x26,0x0,0x0,0x26,0x24,0x24,0x0,0x0},
768 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
772 #define MAX_BALLS 10
773 int pad_pos_x;
774 int x[MAX_BALLS],y[MAX_BALLS];
775 int life;
776 int start_game,con_game;
777 int pad_type;
778 int score=0,vscore=0;
779 bool flip_sides=false;
780 int cur_level=0;
781 int brick_on_board=0;
782 int used_balls=1;
784 typedef struct cube {
785 int powertop;
786 int power;
787 char poweruse;
788 char used;
789 int color;
790 int hits;
791 int hiteffect;
792 } cube;
793 cube brick[80];
795 typedef struct balls {
796 int pos_x;
797 int pos_y;
798 int y;
799 int tempy;
800 int x;
801 int tempx;
802 bool glue;
803 } balls;
805 balls ball[MAX_BALLS];
807 typedef struct sfire {
808 int top;
809 int left;
810 } sfire;
811 sfire fire[30];
814 int highscore;
815 #define MAX_POINTS 200000 /* i dont think it needs to be more */
816 static struct configdata config[] =
818 {TYPE_INT, 0, MAX_POINTS, &highscore, "highscore", NULL, NULL}
821 void int_game(int new_game)
823 int i,j;
825 pad_pos_x=LCD_WIDTH/2-PAD_WIDTH/2;
827 for(i=0;i<MAX_BALLS;i++) {
828 ball[i].x=0;
829 ball[i].y=0;
830 ball[i].tempy=0;
831 ball[i].tempx=0;
832 ball[i].pos_y=PAD_POS_Y-BALL;
833 ball[i].pos_x=pad_pos_x+(PAD_WIDTH/2)-2;
834 ball[i].glue=false;
837 used_balls=1;
838 start_game =1;
839 con_game =0;
840 pad_type=0;
842 flip_sides=false;
844 if (new_game==1)
845 brick_on_board=0;
847 for(i=0;i<=7;i++) {
848 for(j=0;j<=9;j++) {
849 brick[i*10+j].poweruse=(levels[cur_level][i][j]==0?0:1);
850 if (i*10+j<=30)
851 fire[i*10+j].top=-8;
852 if (new_game==1) {
853 brick[i*10+j].power=rb->rand()%25;
854 /* +8 make the game with less powerups */
856 brick[i*10+j].hits=levels[cur_level][i][j]>=10?
857 levels[cur_level][i][j]/16-1:0;
858 brick[i*10+j].hiteffect=0;
859 brick[i*10+j].powertop=TOPMARGIN+i*BRICK_HEIGHT+BRICK_HEIGHT;
860 brick[i*10+j].used=(levels[cur_level][i][j]==0?0:1);
861 brick[i*10+j].color=(levels[cur_level][i][j]>=10?
862 levels[cur_level][i][j]%16:
863 levels[cur_level][i][j])-1;
864 if (levels[cur_level][i][j]!=0)
865 brick_on_board++;
871 int sw,i,w;
873 /* sleep timer counting the score */
874 void sleep (int secs)
876 bool done=false;
877 char s[20];
878 int count=0;
880 while (!done) {
882 if (vscore<score) {
883 vscore++;
884 rb->snprintf(s, sizeof(s), "%d", vscore);
885 rb->lcd_getstringsize(s, &sw, &w);
886 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
887 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
888 #else
889 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s);
890 #endif
891 rb->lcd_update_rect(0,0,LCD_WIDTH,w+2);
892 } else {
893 if (count==0)
894 count=*rb->current_tick+HZ*secs;
895 if (*rb->current_tick>=count)
896 done=true;
898 rb->yield();
903 #define HIGH_SCORE "brickmania.score"
904 #define MENU_LENGTH 4
905 int game_menu(int when)
907 int button,cur=0;
908 char str[10];
909 rb->lcd_clear_display();
910 #if (LCD_WIDTH != 112) && (LCD_HEIGHT != 64)
911 rb->lcd_bitmap(brickmania_menu_bg, 0, 0, BMPWIDTH_menu, BMPHEIGHT_menu);
912 #endif
913 while (true) {
914 for(i=0;i<MENU_LENGTH;i++) {
915 #ifdef HAVE_LCD_COLOR
916 if (cur==0)
917 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
918 MENU_BMPHEIGHT * BM_SEL_START, MENU_BMPWIDTH,
919 BMPXOFS_start, BMPYOFS_start, MENU_BMPWIDTH,
920 MENU_BMPHEIGHT);
921 else
922 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
923 MENU_BMPHEIGHT * BM_START, MENU_BMPWIDTH,
924 BMPXOFS_start, BMPYOFS_start, MENU_BMPWIDTH,
925 MENU_BMPHEIGHT);
927 if (when==1) {
928 if (cur==1)
929 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
930 MENU_BMPHEIGHT * BM_SEL_RESUME, MENU_BMPWIDTH,
931 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
932 MENU_BMPHEIGHT);
933 else
934 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
935 MENU_BMPHEIGHT * BM_RESUME, MENU_BMPWIDTH,
936 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
937 MENU_BMPHEIGHT);
939 } else {
940 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
941 MENU_BMPHEIGHT * BM_NO_RESUME, MENU_BMPWIDTH,
942 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
943 MENU_BMPHEIGHT);
947 if (cur==2)
948 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
949 MENU_BMPHEIGHT * BM_SEL_HELP, MENU_BMPWIDTH,
950 BMPXOFS_help, BMPYOFS_help, MENU_BMPWIDTH,
951 MENU_BMPHEIGHT);
952 else
953 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
954 MENU_BMPHEIGHT * BM_HELP, MENU_BMPWIDTH,
955 BMPXOFS_help, BMPYOFS_help, MENU_BMPWIDTH,
956 MENU_BMPHEIGHT);
958 if (cur==3)
959 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
960 MENU_BMPHEIGHT * BM_SEL_QUIT, MENU_BMPWIDTH,
961 BMPXOFS_quit, BMPYOFS_quit, MENU_BMPWIDTH,
962 MENU_BMPHEIGHT);
963 else
964 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
965 MENU_BMPHEIGHT * BM_QUIT, MENU_BMPWIDTH,
966 BMPXOFS_quit, BMPYOFS_quit, MENU_BMPWIDTH,
967 MENU_BMPHEIGHT);
968 #else
969 if (cur==0)
970 rb->lcd_bitmap_part(brickmania_menu_items, 0,
971 MENU_BMPHEIGHT * BM_SEL_START, MENU_BMPWIDTH,
972 BMPXOFS_start, BMPYOFS_start, MENU_BMPWIDTH,
973 MENU_BMPHEIGHT);
974 else
975 rb->lcd_bitmap_part(brickmania_menu_items, 0,
976 MENU_BMPHEIGHT * BM_START, MENU_BMPWIDTH,
977 BMPXOFS_start, BMPYOFS_start, MENU_BMPWIDTH,
978 MENU_BMPHEIGHT);
980 if (when==1) {
981 if (cur==1)
982 rb->lcd_bitmap_part(brickmania_menu_items, 0,
983 MENU_BMPHEIGHT * BM_SEL_RESUME, MENU_BMPWIDTH,
984 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
985 MENU_BMPHEIGHT);
986 else
987 rb->lcd_bitmap_part(brickmania_menu_items, 0,
988 MENU_BMPHEIGHT * BM_RESUME, MENU_BMPWIDTH,
989 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
990 MENU_BMPHEIGHT);
992 } else {
993 rb->lcd_bitmap_part(brickmania_menu_items, 0,
994 MENU_BMPHEIGHT * BM_NO_RESUME, MENU_BMPWIDTH,
995 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
996 MENU_BMPHEIGHT);
1000 if (cur==2)
1001 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1002 MENU_BMPHEIGHT * BM_SEL_HELP, MENU_BMPWIDTH,
1003 BMPXOFS_help, BMPYOFS_help, MENU_BMPWIDTH,
1004 MENU_BMPHEIGHT);
1005 else
1006 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1007 MENU_BMPHEIGHT * BM_HELP, MENU_BMPWIDTH,
1008 BMPXOFS_help, BMPYOFS_help, MENU_BMPWIDTH,
1009 MENU_BMPHEIGHT);
1011 if (cur==3)
1012 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1013 MENU_BMPHEIGHT * BM_SEL_QUIT, MENU_BMPWIDTH,
1014 BMPXOFS_quit, BMPYOFS_quit, MENU_BMPWIDTH,
1015 MENU_BMPHEIGHT);
1016 else
1017 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1018 MENU_BMPHEIGHT * BM_QUIT, MENU_BMPWIDTH,
1019 BMPXOFS_quit, BMPYOFS_quit, MENU_BMPWIDTH,
1020 MENU_BMPHEIGHT);
1021 #endif
1023 rb->lcd_set_drawmode(DRMODE_FG);
1024 /* high score */
1025 #ifdef HAVE_LCD_COLOR
1026 rb->lcd_set_background(LCD_RGBPACK(0,0,140));
1027 rb->lcd_set_foreground(LCD_WHITE);
1028 #endif
1029 rb->lcd_putsxy(HIGHSCORE_XPOS, HIGHSCORE_YPOS, "High Score");
1030 rb->snprintf(str, sizeof(str), "%d", highscore);
1031 rb->lcd_getstringsize("High Score", &sw, NULL);
1032 rb->lcd_getstringsize(str, &w, NULL);
1033 rb->lcd_putsxy(HIGHSCORE_XPOS+sw/2-w/2, HIGHSCORE_YPOS+9, str);
1034 rb->lcd_set_drawmode(DRMODE_SOLID);
1036 rb->lcd_update();
1038 button = rb->button_get(true);
1039 switch(button) {
1040 case UP:
1041 case UP | BUTTON_REPEAT:
1042 if (cur==0)
1043 cur = MENU_LENGTH-1;
1044 else
1045 cur--;
1046 if (when==0 && cur==1) {
1047 cur = 0;
1049 break;
1051 case DOWN:
1052 case DOWN | BUTTON_REPEAT:
1053 if (cur==MENU_LENGTH-1)
1054 cur = 0;
1055 else
1056 cur++;
1057 if (when==0 && cur==1) {
1058 cur=2;
1060 break;
1062 case RIGHT:
1063 case SELECT:
1064 if (cur==0) {
1065 score=0;
1066 vscore=0;
1067 return 0;
1068 } else if (cur==1 && when==1) {
1069 return 1;
1070 } else if (cur==2) {
1071 return 2;
1072 } else if (cur==3) {
1073 return 3;
1075 break;
1076 #ifdef RC_QUIT
1077 case RC_QUIT:
1078 #endif
1079 case QUIT:
1080 return 3;
1081 break;
1083 default:
1084 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1085 return 3;
1086 break;
1091 int help(int when)
1093 int w,h;
1094 int button;
1095 int xoffset=0;
1096 int yoffset=0;
1097 /* set the maximum x and y in the helpscreen
1098 dont forget to update, if you change text */
1099 int maxY=180;
1100 int maxX=215;
1102 while(true) {
1103 #ifdef HAVE_LCD_COLOR
1104 rb->lcd_set_background(LCD_BLACK);
1105 rb->lcd_clear_display();
1106 rb->lcd_set_background(LCD_BLACK);
1107 rb->lcd_set_foreground(LCD_WHITE);
1108 #else
1109 rb->lcd_clear_display();
1110 #endif
1112 rb->lcd_getstringsize("BrickMania", &w, &h);
1113 rb->lcd_putsxy(LCD_WIDTH/2-w/2+xoffset, 1+yoffset, "BrickMania");
1115 #ifdef HAVE_LCD_COLOR
1116 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1117 rb->lcd_putsxy(1+xoffset, 1*(h+2)+yoffset,"Aim");
1118 rb->lcd_set_foreground(LCD_WHITE);
1119 #else
1120 rb->lcd_putsxy(1+xoffset, 1*(h+2)+yoffset,"Aim");
1121 #endif
1122 rb->lcd_putsxy(1+xoffset, 2*(h+2)+yoffset,
1123 "destroy all the bricks by bouncing");
1124 rb->lcd_putsxy(1+xoffset, 3*(h+2)+yoffset,
1125 "the ball of them using the paddle.");
1126 #ifdef HAVE_LCD_COLOR
1127 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1128 rb->lcd_putsxy(1+xoffset, 5*(h+2)+yoffset,"Controls");
1129 rb->lcd_set_foreground(LCD_WHITE);
1130 #else
1131 rb->lcd_putsxy(1+xoffset, 5*(h+2)+yoffset,"Controls");
1132 #endif
1133 rb->lcd_putsxy(1+xoffset, 6*(h+2)+yoffset,"< & > Move the paddle");
1134 #if CONFIG_KEYPAD == ONDIO_PAD
1135 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1136 "MENU Releases the ball/Fire!");
1137 #elif CONFIG_KEYPAD == RECORDER_PAD
1138 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1139 "PLAY Releases the ball/Fire!");
1140 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
1141 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1142 "NAVI Releases the ball/Fire!");
1143 #else
1144 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1145 "SELECT Releases the ball/Fire!");
1146 #endif
1147 rb->lcd_putsxy(1+xoffset, 8*(h+2)+yoffset, "STOP Opens menu/Quit");
1148 #ifdef HAVE_LCD_COLOR
1149 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1150 rb->lcd_putsxy(1+xoffset, 10*(h+2)+yoffset, "Specials");
1151 rb->lcd_set_foreground(LCD_WHITE);
1152 #else
1153 rb->lcd_putsxy(1+xoffset, 10*(h+2)+yoffset, "Specials");
1154 #endif
1155 rb->lcd_putsxy(1+xoffset, 11*(h+2)+yoffset,
1156 "N Normal:returns paddle to normal");
1157 rb->lcd_putsxy(1+xoffset, 12*(h+2)+yoffset, "D DIE!:loses a life");
1158 rb->lcd_putsxy(1+xoffset, 13*(h+2)+yoffset,
1159 "L Life:gains a life/power up");
1160 rb->lcd_putsxy(1+xoffset, 14*(h+2)+yoffset,
1161 "F Fire:allows you to shoot bricks");
1162 rb->lcd_putsxy(1+xoffset, 15*(h+2)+yoffset,
1163 "G Glue:ball sticks to paddle");
1164 rb->lcd_putsxy(1+xoffset, 16*(h+2)+yoffset,
1165 "B Ball:generates another ball");
1166 rb->lcd_putsxy(1+xoffset, 17*(h+2)+yoffset,
1167 "FL Flip:flips left / right movement");
1168 rb->lcd_update();
1170 button=rb->button_get(true);
1171 switch (button) {
1172 #ifdef RC_QUIT
1173 case RC_QUIT:
1174 #endif
1175 case QUIT:
1176 switch (game_menu(when)) {
1177 case 0:
1178 cur_level=0;
1179 life=2;
1180 int_game(1);
1181 break;
1182 case 1:
1183 con_game=1;
1184 break;
1185 case 2:
1186 if (help(when)==1)
1187 return 1;
1188 break;
1189 case 3:
1190 return 1;
1191 break;
1193 return 0;
1194 break;
1195 case LEFT:
1196 case LEFT | BUTTON_REPEAT:
1197 if( xoffset<0)
1198 xoffset+=2;
1199 break;
1200 case RIGHT:
1201 case RIGHT | BUTTON_REPEAT:
1202 if(xoffset+maxX > LCD_WIDTH)
1203 xoffset-=2;
1204 break;
1205 case UP:
1206 case UP | BUTTON_REPEAT:
1207 if(yoffset <0)
1208 yoffset+=2;
1209 break;
1210 case DOWN:
1211 case DOWN | BUTTON_REPEAT:
1212 if(yoffset+maxY > LCD_HEIGHT)
1213 yoffset-=2;
1214 break;
1216 default:
1217 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1218 return 1;
1219 break;
1222 return 0;
1225 int pad_check(int ballxc, int mode, int pon ,int ballnum)
1227 /* pon: positive(1) or negative(0) */
1229 if (mode==0) {
1230 if (pon == 0)
1231 return -ballxc;
1232 else
1233 return ballxc;
1234 } else {
1235 if (ball[ballnum].x > 0)
1236 return ballxc;
1237 else
1238 return ballxc*-1;
1242 int fire_space(void)
1244 int t;
1245 for(t=0;t<=30;t++)
1246 if (fire[t].top+7 < 0)
1247 return t;
1249 return 0;
1252 int game_loop(void)
1254 int j,i,k,bricky,brickx;
1255 char s[30];
1256 int sec_count=0,num_count=10;
1257 int end;
1259 rb->srand( *rb->current_tick );
1261 configfile_init(rb);
1262 configfile_load(HIGH_SCORE,config,1,0);
1264 switch(game_menu(0)) {
1265 case 0:
1266 cur_level = 0;
1267 life = 2;
1268 int_game(1);
1269 break;
1270 case 1:
1271 con_game = 1;
1272 break;
1273 case 2:
1274 if (help(0) == 1) return 1;
1275 break;
1276 case 3:
1277 return 1;
1278 break;
1281 while(true) {
1282 /* Convert CYCLETIME (in ms) to HZ */
1283 end = *rb->current_tick + (CYCLETIME * HZ) / 1000;
1285 if (life >= 0) {
1286 #ifdef HAVE_LCD_COLOR
1287 rb->lcd_set_background(LCD_BLACK);
1288 rb->lcd_set_drawmode(DRMODE_SOLID);
1289 rb->lcd_clear_display();
1290 rb->lcd_set_background(LCD_BLACK);
1291 #if LCD_HEIGHT > GAMESCREEN_HEIGHT
1292 rb->lcd_set_foreground(rb->global_settings->bg_color);
1293 rb->lcd_fillrect(0, GAMESCREEN_HEIGHT, LCD_WIDTH,
1294 LCD_HEIGHT - GAMESCREEN_HEIGHT);
1295 #endif
1296 rb->lcd_set_foreground(LCD_WHITE);
1297 #else
1298 rb->lcd_clear_display();
1299 #endif
1301 if (flip_sides) {
1302 if (*rb->current_tick>=sec_count) {
1303 sec_count=*rb->current_tick+HZ;
1304 if (num_count!=0)
1305 num_count--;
1306 else
1307 flip_sides=false;
1309 rb->snprintf(s, sizeof(s), "%d", num_count);
1310 rb->lcd_getstringsize(s, &sw, NULL);
1311 rb->lcd_putsxy(LCD_WIDTH/2-2, STRINGPOS_flipsides, s);
1314 /* write life num */
1315 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1316 rb->snprintf(s, sizeof(s), "L:%d", life);
1317 rb->lcd_putsxy(0, 0, s);
1318 #else
1319 rb->snprintf(s, sizeof(s), "Life: %d", life);
1320 rb->lcd_putsxy(2, 2, s);
1321 #endif
1323 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1324 rb->snprintf(s, sizeof(s), "L%d", cur_level+1);
1325 rb->lcd_getstringsize(s, &sw, NULL);
1326 rb->lcd_putsxy(LCD_WIDTH-sw, 0, s);
1327 #else
1328 rb->snprintf(s, sizeof(s), "Level %d", cur_level+1);
1329 rb->lcd_getstringsize(s, &sw, NULL);
1330 rb->lcd_putsxy(LCD_WIDTH-sw-2, 2, s);
1331 #endif
1333 if (vscore<score) vscore++;
1334 rb->snprintf(s, sizeof(s), "%d", vscore);
1335 rb->lcd_getstringsize(s, &sw, NULL);
1336 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1337 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
1338 #else
1339 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s);
1340 #endif
1342 /* continue game */
1343 if (con_game== 1 && start_game!=1) {
1344 #if CONFIG_KEYPAD == ONDIO_PAD
1345 rb->snprintf(s, sizeof(s), "MENU To Continue");
1346 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
1347 rb->snprintf(s, sizeof(s), "Press NAVI To Continue");
1348 #else
1349 rb->snprintf(s, sizeof(s), "Press SELECT To Continue");
1350 #endif
1351 rb->lcd_getstringsize(s, &sw, NULL);
1352 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_navi, s);
1354 sec_count=*rb->current_tick+HZ;
1357 /* draw the ball */
1358 for(i=0;i<used_balls;i++)
1359 rb->lcd_bitmap(brickmania_ball,ball[i].pos_x, ball[i].pos_y,
1360 BALL, BALL);
1362 if (brick_on_board==0)
1363 brick_on_board--;
1365 /* if the pad is fire */
1366 for(i=0;i<=30;i++) {
1367 if (fire[i].top+7>0) {
1368 if (con_game!=1)
1369 fire[i].top-=4;
1370 rb->lcd_vline(fire[i].left, fire[i].top, fire[i].top+7);
1374 /* the bricks */
1375 for (i=0;i<=7;i++) {
1376 for (j=0;j<=9;j++) {
1377 if (brick[i*10+j].power<7) {
1378 if (brick[i*10+j].poweruse==2) {
1379 if (con_game!=1)
1380 brick[i*10+j].powertop+=2;
1381 rb->lcd_bitmap_part(brickmania_powerups,0,
1382 BMPHEIGHT_powerup*brick[i*10+j
1383 ].power,
1384 BMPWIDTH_powerup,
1385 LEFTMARGIN+j*BRICK_WIDTH+
1386 (BRICK_WIDTH/2-
1387 BMPWIDTH_powerup/2),
1388 brick[i*10+j].powertop,
1389 BMPWIDTH_powerup,
1390 BMPHEIGHT_powerup);
1394 if ((pad_pos_x<LEFTMARGIN+j*BRICK_WIDTH+5 &&
1395 pad_pos_x+PAD_WIDTH>LEFTMARGIN+j*BRICK_WIDTH+5) &&
1396 brick[i*10+j].powertop+6>=PAD_POS_Y &&
1397 brick[i*10+j].poweruse==2) {
1398 switch(brick[i*10+j].power) {
1399 case 0:
1400 life++;
1401 score+=50;
1402 break;
1403 case 1:
1404 life--;
1405 if (life>=0) {
1406 int_game(0);
1407 sleep(2);
1409 break;
1410 case 2:
1411 score+=34;
1412 pad_type=1;
1413 break;
1414 case 3:
1415 score+=47;
1416 pad_type=2;
1417 for(k=0;k<used_balls;k++)
1418 ball[k].glue=false;
1419 break;
1420 case 4:
1421 score+=23;
1422 pad_type=0;
1423 for(k=0;k<used_balls;k++)
1424 ball[k].glue=false;
1425 flip_sides=false;
1426 break;
1427 case 5:
1428 score+=23;
1429 sec_count=*rb->current_tick+HZ;
1430 num_count=10;
1431 flip_sides=!flip_sides;
1432 break;
1433 case 6:
1434 score+=23;
1435 used_balls++;
1436 ball[used_balls-1].x= rb->rand()%1 == 0 ?
1437 -1 : 1;
1438 ball[used_balls-1].y= -4;
1439 break;
1441 brick[i*10+j].poweruse=1;
1444 if (brick[i*10+j].powertop>PAD_POS_Y)
1445 brick[i*10+j].poweruse=1;
1447 brickx=LEFTMARGIN+j*BRICK_WIDTH;
1448 bricky=TOPMARGIN+i*BRICK_HEIGHT;
1449 if (pad_type==2) {
1450 for (k=0;k<=30;k++) {
1451 if (fire[k].top+7>0) {
1452 if (brick[i*10+j].used==1 &&
1453 (fire[k].left+1 >= brickx &&
1454 fire[k].left+1 <= brickx+BRICK_WIDTH) &&
1455 (bricky+BRICK_HEIGHT>fire[k].top)) {
1456 score+=13;
1457 fire[k].top=-16;
1458 if (brick[i*10+j].hits > 0) {
1459 brick[i*10+j].hits--;
1460 brick[i*10+j].hiteffect++;
1461 score+=3;
1463 else {
1464 brick[i*10+j].used=0;
1465 if (brick[i*10+j].power!=10)
1466 brick[i*10+j].poweruse=2;
1467 brick_on_board--;
1474 if (brick[i*10+j].used==1) {
1475 rb->lcd_bitmap_part(brickmania_bricks,0,
1476 BRICK_HEIGHT*brick[i*10+j].color,
1477 BRICK_WIDTH,
1478 LEFTMARGIN+j*BRICK_WIDTH,
1479 TOPMARGIN+i*BRICK_HEIGHT,
1480 BRICK_WIDTH, BRICK_HEIGHT);
1481 #ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */
1482 if (brick[i*10+j].hiteffect>0)
1483 rb->lcd_bitmap_transparent_part(brickmania_break,
1485 BRICK_HEIGHT*brick[i*10+j].hiteffect,
1486 BRICK_WIDTH,
1487 LEFTMARGIN+j*BRICK_WIDTH,
1488 TOPMARGIN+i*BRICK_HEIGHT,
1489 BRICK_WIDTH,
1490 BRICK_HEIGHT);
1491 #endif
1494 for(k=0;k<used_balls;k++) {
1495 if (ball[k].pos_y <160) {
1496 if (brick[i*10+j].used==1) {
1497 if ((ball[k].pos_x+ball[k].x+HALFBALL >=
1498 brickx &&
1499 ball[k].pos_x+ball[k].x+HALFBALL <=
1500 brickx+BRICK_WIDTH) &&
1501 ((bricky-4<ball[k].pos_y+BALL &&
1502 bricky>ball[k].pos_y+BALL) ||
1503 (bricky+4>ball[k].pos_y+BALL+BALL &&
1504 bricky<ball[k].pos_y+BALL+BALL)) &&
1505 (ball[k].y >0)) {
1506 ball[k].tempy=bricky-ball[k].pos_y-BALL;
1508 else if ((ball[k].pos_x+ball[k].x+HALFBALL >=
1509 brickx &&
1510 ball[k].pos_x+ball[k].x+HALFBALL <=
1511 brickx+BRICK_WIDTH) &&
1512 ((bricky+BRICK_HEIGHT+4>ball[k].pos_y &&
1513 bricky+BRICK_HEIGHT<ball[k].pos_y) ||
1514 (bricky+BRICK_HEIGHT-4<ball[k].pos_y-BALL &&
1515 bricky+BRICK_HEIGHT>ball[k].pos_y-BALL)) &&
1516 (ball[k].y <0)) {
1517 ball[k].tempy=
1518 -(ball[k].pos_y-(bricky+BRICK_HEIGHT));
1521 if ((ball[k].pos_y+HALFBALL >=
1522 bricky &&
1523 ball[k].pos_y+HALFBALL <=
1524 bricky+BRICK_HEIGHT) &&
1525 ((brickx-4<ball[k].pos_x+BALL &&
1526 brickx>ball[k].pos_x+BALL) ||
1527 (brickx+4>ball[k].pos_x+BALL+BALL &&
1528 brickx<ball[k].pos_x+BALL+BALL)) &&
1529 (ball[k].x >0)) {
1530 ball[k].tempx=brickx-ball[k].pos_x-BALL;
1532 else if ((ball[k].pos_y+ball[k].y+HALFBALL >=
1533 bricky &&
1534 ball[k].pos_y+ball[k].y+HALFBALL <=
1535 bricky+BRICK_HEIGHT) &&
1536 ((brickx+BRICK_WIDTH+4>ball[k].pos_x &&
1537 brickx+BRICK_WIDTH<ball[k].pos_x) ||
1538 (brickx+BRICK_WIDTH-4<ball[k].pos_x-
1539 BALL &&
1540 brickx+BRICK_WIDTH>ball[k].pos_x-
1541 BALL)) && (ball[k].x <0)) {
1542 ball[k].tempx=
1543 -(ball[k].pos_x-(brickx+BRICK_WIDTH));
1546 if ((ball[k].pos_x+HALFBALL >= brickx &&
1547 ball[k].pos_x+HALFBALL <=
1548 brickx+BRICK_WIDTH) &&
1549 ((bricky+BRICK_HEIGHT==ball[k].pos_y) ||
1550 (bricky+BRICK_HEIGHT-6<=ball[k].pos_y &&
1551 bricky+BRICK_HEIGHT>ball[k].pos_y)) &&
1552 (ball[k].y <0)) { /* bottom line */
1553 if (brick[i*10+j].hits > 0) {
1554 brick[i*10+j].hits--;
1555 brick[i*10+j].hiteffect++;
1556 score+=2;
1558 else {
1559 brick[i*10+j].used=0;
1560 if (brick[i*10+j].power!=10)
1561 brick[i*10+j].poweruse=2;
1564 ball[k].y = ball[k].y*-1;
1566 else if ((ball[k].pos_x+HALFBALL >= brickx &&
1567 ball[k].pos_x+HALFBALL <=
1568 brickx+BRICK_WIDTH) &&
1569 ((bricky==ball[k].pos_y+BALL) ||
1570 (bricky+6>=ball[k].pos_y+BALL &&
1571 bricky<ball[k].pos_y+BALL)) &&
1572 (ball[k].y >0)) { /* top line */
1573 if (brick[i*10+j].hits > 0) {
1574 brick[i*10+j].hits--;
1575 brick[i*10+j].hiteffect++;
1576 score+=2;
1578 else {
1579 brick[i*10+j].used=0;
1580 if (brick[i*10+j].power!=10)
1581 brick[i*10+j].poweruse=2;
1584 ball[k].y = ball[k].y*-1;
1587 if ((ball[k].pos_y+HALFBALL >= bricky &&
1588 ball[k].pos_y+HALFBALL <=
1589 bricky+BRICK_HEIGHT) &&
1590 ((brickx==ball[k].pos_x+BALL) ||
1591 (brickx+6>=ball[k].pos_x+BALL &&
1592 brickx<ball[k].pos_x+BALL)) &&
1593 (ball[k].x > 0)) { /* left line */
1594 if (brick[i*10+j].hits > 0) {
1595 brick[i*10+j].hits--;
1596 brick[i*10+j].hiteffect++;
1597 score+=2;
1599 else {
1600 brick[i*10+j].used=0;
1601 if (brick[i*10+j].power!=10)
1602 brick[i*10+j].poweruse=2;
1604 ball[k].x = ball[k].x*-1;
1607 else if ((ball[k].pos_y+HALFBALL >= bricky &&
1608 ball[k].pos_y+HALFBALL <=
1609 bricky+BRICK_HEIGHT) &&
1610 ((brickx+BRICK_WIDTH==
1611 ball[k].pos_x) ||
1612 (brickx+BRICK_WIDTH-6<=
1613 ball[k].pos_x &&
1614 brickx+BRICK_WIDTH>
1615 ball[k].pos_x)) &&
1616 (ball[k].x < 0)) { /* Right line */
1617 if (brick[i*10+j].hits > 0) {
1618 brick[i*10+j].hits--;
1619 brick[i*10+j].hiteffect++;
1620 score+=2;
1622 else {
1623 brick[i*10+j].used=0;
1624 if (brick[i*10+j].power!=10)
1625 brick[i*10+j].poweruse=2;
1628 ball[k].x = ball[k].x*-1;
1631 if (brick[i*10+j].used==0) {
1632 brick_on_board--;
1633 score+=8;
1637 } /* for k */
1638 } /* for j */
1639 } /* for i */
1641 /* draw the pad */
1642 rb->lcd_bitmap_part(brickmania_pads,0,pad_type*PAD_HEIGHT,
1643 PAD_WIDTH,pad_pos_x, PAD_POS_Y, PAD_WIDTH,
1644 PAD_HEIGHT);
1646 for(k=0;k<used_balls;k++) {
1648 if ((ball[k].pos_x >= pad_pos_x &&
1649 ball[k].pos_x <= pad_pos_x+PAD_WIDTH) &&
1650 (PAD_POS_Y-4<ball[k].pos_y+BALL &&
1651 PAD_POS_Y>ball[k].pos_y+BALL) && (ball[k].y >0))
1652 ball[k].tempy=PAD_POS_Y-ball[k].pos_y-BALL;
1653 else if ((4>ball[k].pos_y && 0<ball[k].pos_y) &&
1654 (ball[k].y <0))
1655 ball[k].tempy=-ball[k].pos_y;
1656 if ((LCD_WIDTH-4<ball[k].pos_x+BALL &&
1657 LCD_WIDTH>ball[k].pos_x+BALL) && (ball[k].x >0))
1658 ball[k].tempx=LCD_WIDTH-ball[k].pos_x-BALL;
1659 else if ((4>ball[k].pos_x && 0<ball[k].pos_x) &&
1660 (ball[k].x <0))
1661 ball[k].tempx=-ball[k].pos_x;
1663 /* top line */
1664 if (ball[k].pos_y<= 0)
1665 ball[k].y = ball[k].y*-1;
1666 /* bottom line */
1667 else if (ball[k].pos_y+BALL >= GAMESCREEN_HEIGHT) {
1668 if (used_balls>1) {
1669 used_balls--;
1670 ball[k].pos_x = ball[used_balls].pos_x;
1671 ball[k].pos_y = ball[used_balls].pos_y;
1672 ball[k].y = ball[used_balls].y;
1673 ball[k].tempy = ball[used_balls].tempy;
1674 ball[k].x = ball[used_balls].x;
1675 ball[k].tempx = ball[used_balls].tempx;
1676 ball[k].glue = ball[used_balls].glue;
1678 ball[used_balls].x=0;
1679 ball[used_balls].y=0;
1680 ball[used_balls].tempy=0;
1681 ball[used_balls].tempx=0;
1682 ball[used_balls].pos_y=PAD_POS_Y-BALL;
1683 ball[used_balls].pos_x=pad_pos_x+(PAD_WIDTH/2)-2;
1685 k--;
1686 continue;
1687 } else {
1688 life--;
1689 if (life>=0) {
1690 int_game(0);
1691 sleep(2);
1696 /* left line ,right line */
1697 if ((ball[k].pos_x <= 0) ||
1698 (ball[k].pos_x+BALL >= LCD_WIDTH)) {
1699 ball[k].x = ball[k].x*-1;
1700 ball[k].pos_x = ball[k].pos_x <= 0 ? 0 : LCD_WIDTH-BALL;
1703 if ((ball[k].pos_y+BALL >= PAD_POS_Y &&
1704 (ball[k].pos_x >= pad_pos_x &&
1705 ball[k].pos_x <= pad_pos_x+PAD_WIDTH)) &&
1706 start_game != 1 && !ball[k].glue) {
1708 if ((ball[k].pos_x+HALFBALL >= pad_pos_x &&
1709 ball[k].pos_x+HALFBALL <=
1710 pad_pos_x+(PAD_WIDTH/2/4)) ||
1711 (ball[k].pos_x +HALFBALL>=
1712 pad_pos_x+(PAD_WIDTH-(PAD_WIDTH/2/4)) &&
1713 ball[k].pos_x+HALFBALL <= pad_pos_x+PAD_WIDTH)) {
1715 ball[k].y = -2;
1716 if (ball[k].pos_x != 0 &&
1717 ball[k].pos_x+BALL!=LCD_WIDTH)
1718 ball[k].x = pad_check(6,0,ball[k].pos_x+2<=
1719 pad_pos_x+(PAD_WIDTH/2)?
1720 0:1,k);
1723 else if ((ball[k].pos_x+HALFBALL >=
1724 pad_pos_x+(PAD_WIDTH/2/4) &&
1725 ball[k].pos_x+HALFBALL <=
1726 pad_pos_x+2*(PAD_WIDTH/2/4)) ||
1727 (ball[k].pos_x+HALFBALL >=
1728 pad_pos_x+(PAD_WIDTH-2*(PAD_WIDTH/2/4)) &&
1729 ball[k].pos_x+HALFBALL <=
1730 pad_pos_x+(PAD_WIDTH-(PAD_WIDTH/2/4)) )) {
1732 ball[k].y = -3;
1733 if (ball[k].pos_x != 0 &&
1734 ball[k].pos_x+BALL!=LCD_WIDTH)
1735 ball[k].x = pad_check(4,0,ball[k].pos_x+2<=
1736 pad_pos_x+(PAD_WIDTH/2)?
1737 0:1,k);
1740 else if ((ball[k].pos_x+HALFBALL >=
1741 pad_pos_x+2*(PAD_WIDTH/2/4) &&
1742 ball[k].pos_x+HALFBALL <=
1743 pad_pos_x+3*(PAD_WIDTH/2/4)) ||
1744 (ball[k].pos_x+2 >=
1745 pad_pos_x+(PAD_WIDTH-3*(PAD_WIDTH/2/4)) &&
1746 ball[k].pos_x+2 <=
1747 pad_pos_x+ ((PAD_WIDTH/2)-2*(PAD_WIDTH/2/4)) )) {
1749 ball[k].y = -4;
1750 if (ball[k].pos_x != 0 &&
1751 ball[k].pos_x+BALL!=LCD_WIDTH)
1752 ball[k].x = pad_check(3,0,ball[k].pos_x+2<=
1753 pad_pos_x+(PAD_WIDTH/2)?
1754 0:1,k);
1757 else if ((ball[k].pos_x+HALFBALL >=
1758 pad_pos_x+3*(PAD_WIDTH/2/4) &&
1759 ball[k].pos_x+HALFBALL <=
1760 pad_pos_x+4*(PAD_WIDTH/2/4)-2) ||
1761 (ball[k].pos_x+2 >= pad_pos_x+(PAD_WIDTH/2+2) &&
1762 ball[k].pos_x+2 <=
1763 pad_pos_x+(PAD_WIDTH-3*(PAD_WIDTH/2/4)) )) {
1765 ball[k].y = -4;
1766 if (ball[k].pos_x != 0 &&
1767 ball[k].pos_x+BALL!=LCD_WIDTH)
1768 ball[k].x = pad_check(2,1,0,k);
1771 else {
1772 ball[k].y = -4;
1776 if (!ball[k].glue) {
1777 ball[k].pos_x+=ball[k].tempx!=0?ball[k].tempx:ball[k].x;
1778 ball[k].pos_y+=ball[k].tempy!=0?ball[k].tempy:ball[k].y;
1780 ball[k].tempy=0;
1781 ball[k].tempx=0;
1784 if (ball[k].pos_y+5 >= PAD_POS_Y &&
1785 (pad_type==1 && !ball[k].glue) &&
1786 (ball[k].pos_x >= pad_pos_x &&
1787 ball[k].pos_x <= pad_pos_x+PAD_WIDTH)) {
1788 ball[k].y=0;
1789 ball[k].pos_y=PAD_POS_Y-BALL;
1790 ball[k].glue=true;
1792 } /* for k */
1794 rb->lcd_update();
1796 if (brick_on_board < 0) {
1797 if (cur_level+1<levels_num) {
1798 cur_level++;
1799 score+=100;
1800 int_game(1);
1801 sleep(2);
1803 else {
1804 rb->lcd_getstringsize("Congratulations!", &sw, NULL);
1805 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_congrats,
1806 "Congratulations!");
1807 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1808 rb->lcd_getstringsize("No more levels", &sw, NULL);
1809 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_finsh,
1810 "No more levels");
1811 #else
1812 rb->lcd_getstringsize("You have finished the game!",
1813 &sw, NULL);
1814 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_finsh,
1815 "You have finished the game!");
1816 #endif
1817 vscore=score;
1818 rb->lcd_update();
1819 if (score>highscore) {
1820 sleep(2);
1821 highscore=score;
1822 rb->splash(HZ*2, "New High Score");
1824 else {
1825 sleep(3);
1828 switch(game_menu(0)) {
1829 case 0:
1830 life=2;
1831 cur_level=0;
1832 int_game(1);
1833 break;
1834 case 1:
1835 con_game=1;
1836 break;
1837 case 2:
1838 if (help(0)==1) return 1;
1839 break;
1840 case 3:
1841 return 1;
1842 break;
1847 int move_button,button;
1848 int button_right,button_left;
1849 button=rb->button_get(false);
1851 #ifdef HAS_BUTTON_HOLD
1852 if (rb->button_hold())
1853 button = QUIT;
1854 #endif
1856 move_button=rb->button_status();
1858 button_right=((move_button & RIGHT) || (SCROLL_FWD(button)));
1859 button_left=((move_button & LEFT) || (SCROLL_BACK(button)));
1860 if ((con_game== 1 && start_game!=1) && (button_right || button_left))
1861 continue;
1862 if ((button_right && flip_sides==false) ||
1863 (button_left && flip_sides==true)) {
1864 if (pad_pos_x+8+PAD_WIDTH > LCD_WIDTH) {
1865 for(k=0;k<used_balls;k++)
1866 if (start_game==1 || ball[k].glue)
1867 ball[k].pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
1868 pad_pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
1870 else {
1871 for(k=0;k<used_balls;k++)
1872 if ((start_game==1 || ball[k].glue))
1873 ball[k].pos_x+=8;
1874 pad_pos_x+=8;
1877 else if ((button_left && flip_sides==false) ||
1878 (button_right && flip_sides==true)) {
1879 if (pad_pos_x-8 < 0) {
1880 for(k=0;k<used_balls;k++)
1881 if (start_game==1 || ball[k].glue)
1882 ball[k].pos_x-=pad_pos_x;
1883 pad_pos_x-=pad_pos_x;
1885 else {
1886 for(k=0;k<used_balls;k++)
1887 if (start_game==1 || ball[k].glue)
1888 ball[k].pos_x-=8;
1889 pad_pos_x-=8;
1894 switch(button) {
1895 case UP:
1896 case SELECT:
1897 if (start_game==1 && con_game!=1 && pad_type!=1) {
1898 for(k=0;k<used_balls;k++) {
1899 ball[k].y=-4;
1900 ball[k].x=pad_pos_x+(PAD_WIDTH/2)-2>=
1901 LCD_WIDTH/2?2:-2;
1903 start_game =0;
1905 else if (pad_type==1) {
1906 for(k=0;k<used_balls;k++) {
1907 if (ball[k].glue)
1908 ball[k].glue=false;
1909 else if (start_game==1) {
1910 ball[k].x = x[k];
1911 ball[k].y = y[k];
1915 if (start_game!=1 && con_game==1) {
1916 start_game =0;
1917 con_game=0;
1919 } else if (pad_type==2 && con_game!=1) {
1920 int tfire;
1921 tfire=fire_space();
1922 fire[tfire].top=PAD_POS_Y-7;
1923 fire[tfire].left=pad_pos_x+1;
1924 tfire=fire_space();
1925 fire[tfire].top=PAD_POS_Y-7;
1926 fire[tfire].left=pad_pos_x+PAD_WIDTH-1;
1927 } else if (con_game==1 && start_game!=1) {
1928 for(k=0;k<used_balls;k++) {
1929 ball[k].x=x[k];
1930 ball[k].y=y[k];
1932 con_game=0;
1934 break;
1935 #ifdef RC_QUIT
1936 case RC_QUIT:
1937 #endif
1938 case QUIT:
1939 switch(game_menu(1)) {
1940 case 0:
1941 life=2;
1942 cur_level=0;
1943 int_game(1);
1944 break;
1945 case 1:
1946 for(k=0;k<used_balls;k++)
1947 if (ball[k].x!=0 && ball[k].y !=0)
1948 con_game=1;
1949 break;
1950 case 2:
1951 if (help(1)==1)
1952 return 1;
1953 break;
1954 case 3:
1955 return 1;
1956 break;
1959 for(k=0;k<used_balls;k++) {
1960 if (ball[k].x!=0)
1961 x[k]=ball[k].x;
1962 ball[k].x=0;
1963 if (ball[k].y!=0)
1964 y[k]=ball[k].y;
1965 ball[k].y=0;
1968 break;
1970 default:
1971 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1972 return 1;
1973 break;
1976 else {
1977 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1978 rb->splash(HZ*2, "Game Over");
1979 #else
1980 rb->lcd_bitmap(brickmania_gameover,LCD_WIDTH/2-55,LCD_HEIGHT-87,
1981 110,52);
1982 rb->lcd_update();
1983 #endif
1984 if (score>highscore) {
1985 sleep(2);
1986 highscore=score;
1987 rb->splash(HZ*2, "New High Score");
1988 } else {
1989 sleep(3);
1992 for(k=0;k<used_balls;k++) {
1993 ball[k].x=0;
1994 ball[k].y=0;
1997 switch(game_menu(0)) {
1998 case 0:
1999 cur_level=0;
2000 life=2;
2001 int_game(1);
2002 break;
2003 case 1:
2004 con_game=1;
2005 break;
2006 case 2:
2007 if (help(0)==1)
2008 return 1;
2009 break;
2010 case 3:
2011 return 1;
2012 break;
2015 if (end > *rb->current_tick)
2016 rb->sleep(end-*rb->current_tick);
2017 else
2018 rb->yield();
2022 /* this is the plugin entry point */
2023 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
2025 (void)parameter;
2026 rb = api;
2028 rb->lcd_setfont(FONT_SYSFIXED);
2029 #if LCD_DEPTH > 1
2030 rb->lcd_set_backdrop(NULL);
2031 #endif
2032 /* Permanently enable the backlight (unless the user has turned it off) */
2033 if (rb->global_settings->backlight_timeout > 0)
2034 rb->backlight_set_timeout(1);
2036 /* now go ahead and have fun! */
2037 while (game_loop()!=1);
2039 configfile_save(HIGH_SCORE,config,1,0);
2041 /* Restore user's original backlight setting */
2042 rb->lcd_setfont(FONT_UI);
2043 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
2045 return PLUGIN_OK;