A couple more tweaks
[Rockbox.git] / apps / plugins / brickmania.c
blobd4b774a93d418de7da88df37a888b7a132f506ad
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 */
22 #include "helper.h"
24 PLUGIN_HEADER
27 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
29 #define QUIT BUTTON_OFF
30 #define LEFT BUTTON_LEFT
31 #define RIGHT BUTTON_RIGHT
32 #define SELECT BUTTON_SELECT
33 #define UP BUTTON_UP
34 #define DOWN BUTTON_DOWN
36 #define RC_QUIT BUTTON_RC_STOP
38 /* Only iPod have scroll events */
39 #define SCROLL_FWD(x) (0)
40 #define SCROLL_BACK(x) (0)
42 #elif CONFIG_KEYPAD == ONDIO_PAD
44 #define QUIT BUTTON_OFF
45 #define LEFT BUTTON_LEFT
46 #define RIGHT BUTTON_RIGHT
47 #define SELECT BUTTON_MENU
48 #define UP BUTTON_UP
49 #define DOWN BUTTON_DOWN
51 /* Only iPod have scroll events */
52 #define SCROLL_FWD(x) (0)
53 #define SCROLL_BACK(x) (0)
55 #elif CONFIG_KEYPAD == RECORDER_PAD
57 #define QUIT BUTTON_OFF
58 #define LEFT BUTTON_LEFT
59 #define RIGHT BUTTON_RIGHT
60 #define SELECT BUTTON_PLAY
61 #define UP BUTTON_UP
62 #define DOWN BUTTON_DOWN
64 /* Only iPod have scroll events */
65 #define SCROLL_FWD(x) (0)
66 #define SCROLL_BACK(x) (0)
68 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
70 #define QUIT BUTTON_OFF
71 #define LEFT BUTTON_LEFT
72 #define RIGHT BUTTON_RIGHT
73 #define SELECT BUTTON_SELECT
74 #define UP BUTTON_UP
75 #define DOWN BUTTON_DOWN
77 /* Only iPod have scroll events */
78 #define SCROLL_FWD(x) (0)
79 #define SCROLL_BACK(x) (0)
81 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
82 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
83 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
85 #define QUIT BUTTON_MENU
86 #define LEFT BUTTON_LEFT
87 #define RIGHT BUTTON_RIGHT
88 #define SELECT BUTTON_SELECT
89 #define UP BUTTON_SCROLL_BACK
90 #define DOWN BUTTON_SCROLL_FWD
92 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD)
93 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK)
95 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
97 #define QUIT BUTTON_POWER
98 #define LEFT BUTTON_LEFT
99 #define RIGHT BUTTON_RIGHT
100 #define SELECT BUTTON_SELECT
101 #define UP BUTTON_UP
102 #define DOWN BUTTON_DOWN
104 #define SCROLL_FWD(x) (0)
105 #define SCROLL_BACK(x) (0)
107 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD /* grayscale at the moment */
109 #define QUIT BUTTON_POWER
110 #define LEFT BUTTON_LEFT
111 #define RIGHT BUTTON_RIGHT
112 #define SELECT BUTTON_PLAY
113 #define UP BUTTON_UP
114 #define DOWN BUTTON_DOWN
116 /* Only iPod have scroll events */
117 #define SCROLL_FWD(x) (0)
118 #define SCROLL_BACK(x) (0)
120 #elif CONFIG_KEYPAD == SANSA_E200_PAD
122 #define QUIT BUTTON_POWER
123 #define LEFT BUTTON_LEFT
124 #define RIGHT BUTTON_RIGHT
125 #define SELECT BUTTON_SELECT
126 #define UP BUTTON_SCROLL_UP
127 #define DOWN BUTTON_SCROLL_DOWN
129 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_DOWN)
130 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_UP)
132 #elif CONFIG_KEYPAD == IRIVER_H10_PAD /* grayscale at the moment */
134 #define QUIT BUTTON_POWER
135 #define LEFT BUTTON_LEFT
136 #define RIGHT BUTTON_RIGHT
137 #define SELECT BUTTON_PLAY
138 #define UP BUTTON_SCROLL_UP
139 #define DOWN BUTTON_SCROLL_DOWN
141 /* Only iPod have scroll events */
142 #define SCROLL_FWD(x) (0)
143 #define SCROLL_BACK(x) (0)
145 #else
146 #error Unsupported keypad
147 #endif
149 static struct plugin_api* rb;
151 enum menu_items {
152 BM_START,
153 BM_SEL_START,
154 BM_RESUME,
155 BM_SEL_RESUME,
156 BM_NO_RESUME,
157 BM_HELP,
158 BM_SEL_HELP,
159 BM_QUIT,
160 BM_SEL_QUIT,
163 /* External bitmaps */
164 #if (LCD_WIDTH != 112) && (LCD_HEIGHT != 64)
165 extern const fb_data brickmania_menu_bg[];
166 extern const fb_data brickmania_gameover[];
167 #endif
168 extern const fb_data brickmania_menu_items[];
169 extern const fb_data brickmania_ball[];
170 #ifdef HAVE_LCD_COLOR
171 extern const fb_data brickmania_break[];
172 #endif
174 /* normal, glue, fire */
175 extern const fb_data brickmania_pads[];
177 /* +life, -life, glue, fire, normal */
178 extern const fb_data brickmania_powerups[];
180 /* purple, red, blue, pink, green, yellow orange */
181 extern const fb_data brickmania_bricks[];
183 #if (LCD_WIDTH == 320) && (LCD_HEIGHT == 240)
185 /* The time (in ms) for one iteration through the game loop - decrease this
186 to speed up the game - note that current_tick is (currently) only accurate
187 to 10ms.
189 #define CYCLETIME 30
191 #define GAMESCREEN_HEIGHT LCD_HEIGHT
193 #define PAD_WIDTH 56
194 #define PAD_HEIGHT 7
195 #define PAD_POS_Y LCD_HEIGHT - 7
196 #define BRICK_HEIGHT 12
197 #define BRICK_WIDTH 32
198 #define BALL 5
199 #define HALFBALL 3
200 #define LEFTMARGIN 0
201 #define TOPMARGIN 30
203 #define MENU_BMPHEIGHT 20
204 #define MENU_BMPWIDTH 112
206 #define BMPHEIGHT_powerup 10
207 #define BMPWIDTH_powerup 16
209 #define BMPHEIGHT_menu LCD_HEIGHT
210 #define BMPWIDTH_menu LCD_WIDTH
212 #define BMPXOFS_start 105
213 #define BMPYOFS_start 110
214 #define BMPXOFS_resume 112
215 #define BMPYOFS_resume 132
216 #define BMPXOFS_help 142
217 #define BMPYOFS_help 150
218 #define BMPXOFS_quit 143
219 #define BMPYOFS_quit 170
220 #define HIGHSCORE_XPOS 57
221 #define HIGHSCORE_YPOS 88
223 #define STRINGPOS_finsh 140
224 #define STRINGPOS_congrats 157
225 #define STRINGPOS_navi 150
226 #define STRINGPOS_flipsides 150
228 #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176)
230 /* The time (in ms) for one iteration through the game loop - decrease this
231 to speed up the game - note that current_tick is (currently) only accurate
232 to 10ms.
234 #define CYCLETIME 30
236 /* Offsets for LCDS > 220x176 */
238 #define GAMESCREEN_HEIGHT 176
240 #define PAD_WIDTH 40
241 #define PAD_HEIGHT 5
242 #define PAD_POS_Y GAMESCREEN_HEIGHT - 7
243 #define BRICK_HEIGHT 8
244 #define BRICK_WIDTH 21
245 #define BALL 5
246 #define HALFBALL 3
247 #define LEFTMARGIN (LCD_WIDTH-220)/2 + 5
248 #define TOPMARGIN 30
250 #define XOFS ((LCD_WIDTH-220)/BRICK_WIDTH/2)*BRICK_WIDTH
251 #define YOFS ((LCD_HEIGHT-176)/BRICK_HEIGHT/2)*BRICK_HEIGHT
253 #define MENU_BMPHEIGHT 20
254 #define MENU_BMPWIDTH 112
256 #define BMPHEIGHT_powerup 6
257 #define BMPWIDTH_powerup 10
259 #define BMPHEIGHT_menu LCD_HEIGHT
260 #define BMPWIDTH_menu LCD_WIDTH
262 #define BMPXOFS_start (55+XOFS)
263 #define BMPYOFS_start (78+YOFS)
264 #define BMPXOFS_resume (62+XOFS)
265 #define BMPYOFS_resume (100+YOFS)
266 #define BMPXOFS_help (92+XOFS)
267 #define BMPYOFS_help (118+YOFS)
268 #define BMPXOFS_quit (93+XOFS)
269 #define BMPYOFS_quit (138+YOFS)
270 #define HIGHSCORE_XPOS (7+XOFS)
271 #define HIGHSCORE_YPOS (56+YOFS)
273 #define STRINGPOS_finsh 140
274 #define STRINGPOS_congrats 157
275 #define STRINGPOS_navi 150
276 #define STRINGPOS_flipsides 150
278 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
279 /* The time (in ms) for one iteration through the game loop - decrease this
280 to speed up the game - note that current_tick is (currently) only accurate
281 to 10ms.
283 #define CYCLETIME 50
285 #define GAMESCREEN_HEIGHT LCD_HEIGHT
287 #define PAD_WIDTH 30
288 #define PAD_HEIGHT 5
289 #define PAD_POS_Y LCD_HEIGHT - 7
290 #define BRICK_HEIGHT 7
291 #define BRICK_WIDTH 15
292 #define BALL 5
293 #define HALFBALL 3
294 #define LEFTMARGIN 5
295 #define TOPMARGIN 21
297 #define MENU_BMPHEIGHT 17
298 #define MENU_BMPWIDTH 88
300 #define BMPHEIGHT_powerup 6
301 #define BMPWIDTH_powerup 10
303 #if LCD_DEPTH == 16
304 #define BMPHEIGHT_menu 128
305 #else
306 #define BMPHEIGHT_menu 45
307 #endif
308 #define BMPWIDTH_menu 160
310 #if LCD_DEPTH == 16
311 #define BMPXOFS_start 38
312 #define BMPYOFS_start 56
313 #define BMPXOFS_resume 42
314 #define BMPYOFS_resume 72
315 #define BMPXOFS_help 65
316 #define BMPYOFS_help 85
317 #define BMPXOFS_quit 66
318 #define BMPYOFS_quit 99
319 #else
320 #define BMPXOFS_start 34
321 #define BMPYOFS_start 64
322 #define BMPXOFS_resume 38
323 #define BMPYOFS_resume 77
324 #define BMPXOFS_help 64
325 #define BMPYOFS_help 90
326 #define BMPXOFS_quit 64
327 #define BMPYOFS_quit 103
328 #endif
329 #define HIGHSCORE_XPOS 7
330 #define HIGHSCORE_YPOS 36
332 #define STRINGPOS_finsh 110
333 #define STRINGPOS_congrats 100
334 #define STRINGPOS_navi 100
335 #define STRINGPOS_flipsides 100
337 /* iPod Mini */
338 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
339 /* The time (in ms) for one iteration through the game loop - decrease this
340 to speed up the game - note that current_tick is (currently) only accurate
341 to 10ms.
343 #define CYCLETIME 50
345 #define GAMESCREEN_HEIGHT LCD_HEIGHT
347 #define PAD_WIDTH 30
348 #define PAD_HEIGHT 5
349 #define PAD_POS_Y LCD_HEIGHT - 5
350 #define BRICK_HEIGHT 7
351 #define BRICK_WIDTH 13
352 #define BALL 5
353 #define HALFBALL 3
354 #define LEFTMARGIN 4
355 #define TOPMARGIN 10
357 #define MENU_BMPHEIGHT 17
358 #define MENU_BMPWIDTH 88
360 #define BMPHEIGHT_powerup 6
361 #define BMPWIDTH_powerup 10
363 #define BMPHEIGHT_menu 45
364 #define BMPWIDTH_menu 160
366 #define BMPXOFS_start 28
367 #define BMPYOFS_start 41
368 #define BMPXOFS_resume 33
369 #define BMPYOFS_resume 58
370 #define BMPXOFS_help 56
371 #define BMPYOFS_help 74
372 #define BMPXOFS_quit 56
373 #define BMPYOFS_quit 90
374 #define HIGHSCORE_XPOS 76
375 #define HIGHSCORE_YPOS 22
377 #define STRINGPOS_finsh 54
378 #define STRINGPOS_congrats 44
379 #define STRINGPOS_navi 44
380 #define STRINGPOS_flipsides 44
383 #elif (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
384 /* The time (in ms) for one iteration through the game loop - decrease this
385 to speed up the game - note that current_tick is (currently) only accurate
386 to 10ms.
388 #define CYCLETIME 75
390 #define GAMESCREEN_HEIGHT LCD_HEIGHT
392 #define PAD_WIDTH 30
393 #define PAD_HEIGHT 3
394 #define PAD_POS_Y LCD_HEIGHT - 5
395 #define BRICK_HEIGHT 4
396 #define BRICK_WIDTH 11
397 #define BALL 3
398 #define HALFBALL 2
399 #define LEFTMARGIN 1
400 #define TOPMARGIN 10
402 #define MENU_BMPHEIGHT 9
403 #define MENU_BMPWIDTH 80
405 #define BMPHEIGHT_powerup 6
406 #define BMPWIDTH_powerup 7
408 #define BMPXOFS_start 12
409 #define BMPYOFS_start 20
410 #define BMPXOFS_resume 18
411 #define BMPYOFS_resume 31
412 #define BMPXOFS_help 39
413 #define BMPYOFS_help 42
414 #define BMPXOFS_quit 40
415 #define BMPYOFS_quit 53
416 #define HIGHSCORE_XPOS 0
417 #define HIGHSCORE_YPOS 0
419 #define STRINGPOS_finsh 54
420 #define STRINGPOS_congrats 44
421 #define STRINGPOS_navi 44
422 #define STRINGPOS_flipsides 44
424 /* nano and sansa */
425 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT >= 132) && (LCD_DEPTH==16)
426 /* The time (in ms) for one iteration through the game loop - decrease this
427 to speed up the game - note that current_tick is (currently) only accurate
428 to 10ms.
431 #define CYCLETIME 30
433 #if (LCD_HEIGHT == 220)
434 #define GAMESCREEN_HEIGHT 132
435 #else
436 #define GAMESCREEN_HEIGHT LCD_HEIGHT
437 #endif
439 #define PAD_WIDTH 40
440 #define PAD_HEIGHT 5
441 #define PAD_POS_Y GAMESCREEN_HEIGHT - 7
442 #define BRICK_HEIGHT 7
443 #define BRICK_WIDTH 17
444 #define BALL 5
445 #define HALFBALL 3
446 #define LEFTMARGIN 3
447 #define TOPMARGIN 21
449 #define MENU_BMPHEIGHT 16
450 #define MENU_BMPWIDTH 89
452 #define BMPHEIGHT_powerup 6
453 #define BMPWIDTH_powerup 10
455 #define BMPHEIGHT_menu 132
456 #define BMPWIDTH_menu 176
458 #define BMPXOFS_start 44
459 #define BMPYOFS_start 58
460 #define BMPXOFS_resume 50
461 #define BMPYOFS_resume 75
462 #define BMPXOFS_help 74
463 #define BMPYOFS_help 89
464 #define BMPXOFS_quit 75
465 #define BMPYOFS_quit 104
466 #define HIGHSCORE_XPOS 7
467 #define HIGHSCORE_YPOS 36
469 #define STRINGPOS_finsh 110
470 #define STRINGPOS_congrats 110
471 #define STRINGPOS_navi 100
472 #define STRINGPOS_flipsides 100
474 #else
475 #error Unsupported LCD Size
476 #endif
478 int levels_num = 29;
480 static unsigned char levels[29][8][10] = {
481 { /* level1 */
482 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
483 {0x2,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x2},
484 {0x0,0x2,0x1,0x0,0x0,0x0,0x0,0x1,0x2,0x0},
485 {0x0,0x0,0x2,0x1,0x0,0x0,0x1,0x2,0x0,0x0},
486 {0x0,0x0,0x0,0x2,0x1,0x1,0x2,0x0,0x0,0x0},
487 {0x7,0x0,0x0,0x7,0x2,0x2,0x7,0x0,0x0,0x7},
488 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
489 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
491 { /* level2 */
492 {0x0,0x0,0x7,0x7,0x1,0x1,0x7,0x7,0x0,0x0},
493 {0x0,0x1,0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x0},
494 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
495 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1},
496 {0x1,0x1,0x2,0x1,0x0,0x0,0x1,0x2,0x1,0x1},
497 {0x1,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x2,0x1},
498 {0x0,0x1,0x2,0x0,0x0,0x0,0x0,0x2,0x1,0x0},
499 {0x0,0x0,0x1,0x2,0x2,0x2,0x2,0x1,0x0,0x0}
501 { /* level3 */
502 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
503 {0x3,0x23,0x23,0x3,0x0,0x0,0x2,0x22,0x22,0x2},
504 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
505 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
506 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
507 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6},
508 {0x5,0x25,0x25,0x5,0x0,0x0,0x6,0x26,0x26,0x6},
509 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6}
511 { /* level4 */
512 {0x0,0x0,0x0,0x27,0x27,0x27,0x27,0x0,0x0,0x0},
513 {0x0,0x0,0x0,0x27,0x7,0x7,0x27,0x0,0x0,0x0},
514 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
515 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
516 {0x26,0x6,0x0,0x2,0x2,0x2,0x2,0x0,0x6,0x26},
517 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
518 {0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0},
519 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1}
521 { /* level5 */
522 {0x1,0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4},
523 {0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0},
524 {0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5},
525 {0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5,0x5},
526 {0x0,0x33,0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0},
527 {0x3,0x33,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x36},
528 {0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x6,0x36},
529 {0x0,0x24,0x24,0x0,0x25,0x25,0x0,0x26,0x26,0x0}
531 { /* level6 */
532 {0x0,0x1,0x3,0x7,0x7,0x7,0x7,0x3,0x1,0x0},
533 {0x3,0x1,0x3,0x7,0x0,0x0,0x7,0x3,0x1,0x3},
534 {0x3,0x1,0x3,0x7,0x7,0x7,0x7,0x3,0x1,0x3},
535 {0x0,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x0},
536 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5},
537 {0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5},
538 {0x0,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x0},
539 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
541 { /* level7 */
542 {0x0,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x0},
543 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
544 {0x6,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x6},
545 {0x6,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x6},
546 {0x6,0x6,0x6,0x0,0x0,0x0,0x0,0x6,0x6,0x6},
547 {0x0,0x0,0x0,0x1,0x1,0x1,0x1,0x0,0x0,0x0},
548 {0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0},
549 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
551 { /* level8 */
552 {0x0,0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x0},
553 {0x0,0x0,0x0,0x4,0x0,0x0,0x4,0x0,0x0,0x0},
554 {0x6,0x6,0x0,0x2,0x32,0x32,0x2,0x0,0x6,0x6},
555 {0x0,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x0,0x0},
556 {0x0,0x6,0x6,0x0,0x0,0x0,0x0,0x6,0x6,0x0},
557 {0x0,0x0,0x0,0x5,0x25,0x25,0x5,0x0,0x0,0x0},
558 {0x0,0x5,0x5,0x25,0x5,0x5,0x25,0x5,0x5,0x0},
559 {0x5,0x5,0x25,0x5,0x5,0x5,0x5,0x25,0x5,0x5}
561 { /* level9 */
562 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
563 {0x2,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x2},
564 {0x2,0x0,0x3,0x0,0x1,0x1,0x0,0x3,0x0,0x2},
565 {0x2,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x2},
566 {0x2,0x0,0x1,0x0,0x3,0x3,0x0,0x1,0x0,0x2},
567 {0x2,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x2},
568 {0x2,0x2,0x0,0x0,0x1,0x1,0x0,0x0,0x2,0x2},
569 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
571 { /* level10 */
572 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
573 {0x0,0x5,0x0,0x5,0x0,0x5,0x0,0x5,0x0,0x5},
574 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
575 {0x0,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x0},
576 {0x0,0x0,0x0,0x4,0x1,0x1,0x4,0x0,0x0,0x0},
577 {0x0,0x0,0x3,0x4,0x1,0x1,0x4,0x3,0x0,0x0},
578 {0x0,0x2,0x3,0x4,0x1,0x1,0x4,0x3,0x2,0x0},
579 {0x1,0x2,0x3,0x4,0x1,0x1,0x4,0x3,0x2,0x1}
581 { /* level11 */
582 {0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3},
583 {0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x2},
584 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
585 {0x2,0x0,0x0,0x0,0x7,0x7,0x0,0x0,0x0,0x2},
586 {0x2,0x0,0x0,0x7,0x7,0x7,0x7,0x0,0x0,0x2},
587 {0x0,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x0},
588 {0x0,0x2,0x0,0x1,0x0,0x0,0x1,0x0,0x2,0x0},
589 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5}
591 { /* level 12 */
592 {0x2,0x1,0x3,0x1,0x0,0x0,0x1,0x3,0x1,0x2},
593 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1},
594 {0x1,0x1,0x1,0x0,0x1,0x1,0x0,0x1,0x1,0x1},
595 {0x0,0x1,0x0,0x1,0x6,0x6,0x1,0x0,0x1,0x0},
596 {0x0,0x0,0x1,0x1,0x6,0x6,0x1,0x1,0x0,0x0},
597 {0x1,0x1,0x1,0x7,0x0,0x0,0x7,0x1,0x1,0x1},
598 {0x1,0x1,0x7,0x1,0x0,0x0,0x1,0x7,0x1,0x1},
599 {0x2,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x2,0x2}
601 {/* levell13 */
602 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
603 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
604 {0x2,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x0,0x2},
605 {0x2,0x0,0x2,0x3,0x3,0x3,0x3,0x3,0x0,0x2},
606 {0x2,0x0,0x2,0x4,0x4,0x4,0x4,0x4,0x0,0x2},
607 {0x2,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
608 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
609 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
611 {/* level14 */
612 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
613 {0x4,0x4,0x4,0x4,0x2,0x2,0x4,0x4,0x4,0x4},
614 {0x4,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x4},
615 {0x4,0x0,0x0,0x2,0x3,0x3,0x2,0x0,0x0,0x4},
616 {0x4,0x0,0x2,0x23,0x3,0x3,0x23,0x2,0x0,0x4},
617 {0x4,0x0,0x2,0x22,0x2,0x2,0x22,0x2,0x0,0x4},
618 {0x4,0x0,0x6,0x21,0x5,0x5,0x21,0x6,0x0,0x4},
619 {0x4,0x6,0x1,0x1,0x5,0x5,0x1,0x1,0x6,0x4}
621 {/* level 15 */
622 {0x4,0x4,0x4,0x4,0x4,0x3,0x3,0x3,0x3,0x3},
623 {0x2,0x2,0x1,0x1,0x1,0x1,0x1,0x5,0x0,0x0},
624 {0x2,0x2,0x1,0x1,0x1,0x0,0x1,0x6,0x0,0x0},
625 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x5,0x0,0x0},
626 {0x2,0x1,0x2,0x2,0x2,0x1,0x1,0x6,0x0,0x0},
627 {0x2,0x1,0x2,0x2,0x2,0x1,0x3,0x5,0x3,0x0},
628 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x6,0x0,0x0},
629 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
631 {/* level 16 (Rockbox) by ts-x */
632 {0x2,0x2,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
633 {0x2,0x0,0x3,0x0,0x3,0x4,0x0,0x5,0x5,0x0},
634 {0x2,0x0,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
635 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
636 {0x6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
637 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0},
638 {0x7,0x0,0x7,0x1,0x0,0x1,0x0,0x2,0x0,0x0},
639 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0}
641 {/* level 17 (Alien) by ts-x */
642 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
643 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
644 {0x1,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x1},
645 {0x2,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x2},
646 {0x1,0x0,0x1,0x2,0x2,0x2,0x2,0x1,0x0,0x1},
647 {0x2,0x0,0x0,0x1,0x2,0x2,0x1,0x0,0x0,0x2},
648 {0x2,0x1,0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x2},
649 {0x2,0x2,0x1,0x0,0x1,0x1,0x0,0x1,0x2,0x2}
651 {/* level 18 (Tetris) by ts-x */
652 {0x0,0x2,0x0,0x0,0x3,0x4,0x0,0x2,0x2,0x0},
653 {0x0,0x2,0x7,0x0,0x3,0x4,0x0,0x2,0x2,0x0},
654 {0x2,0x2,0x7,0x0,0x3,0x4,0x0,0x6,0x2,0x2},
655 {0x2,0x2,0x7,0x7,0x3,0x4,0x0,0x6,0x2,0x2},
656 {0x2,0x1,0x7,0x7,0x3,0x4,0x4,0x6,0x5,0x5},
657 {0x2,0x1,0x0,0x7,0x3,0x4,0x4,0x6,0x5,0x5},
658 {0x1,0x1,0x1,0x7,0x3,0x0,0x6,0x6,0x5,0x5},
659 {0x1,0x1,0x1,0x0,0x3,0x0,0x6,0x6,0x5,0x5}
661 { /* level 19 (Stalactites) by ts-x */
662 {0x5,0x2,0x6,0x3,0x4,0x7,0x5,0x3,0x1,0x2},
663 {0x5,0x2,0x6,0x3,0x4,0x7,0x5,0x3,0x1,0x2},
664 {0x5,0x0,0x6,0x3,0x4,0x7,0x5,0x0,0x1,0x2},
665 {0x5,0x2,0x6,0x3,0x4,0x0,0x5,0x3,0x1,0x2},
666 {0x5,0x0,0x6,0x0,0x4,0x7,0x5,0x0,0x1,0x0},
667 {0x5,0x0,0x0,0x3,0x4,0x0,0x0,0x0,0x1,0x2},
668 {0x0,0x0,0x6,0x0,0x0,0x0,0x5,0x0,0x0,0x0},
669 {0x5,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x1,0x0}
671 { /* level 20 (Maze) by ts-x */
672 {0x1,0x1,0x21,0x1,0x1,0x1,0x1,0x1,0x1,0x21},
673 {0x1,0x0,0x0,0x3,0x0,0x0,0x3,0x1,0x31,0x1},
674 {0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x31,0x0,0x1},
675 {0x21,0x0,0x21,0x3,0x0,0x3,0x0,0x3,0x0,0x2},
676 {0x1,0x0,0x1,0x21,0x0,0x12,0x0,0x0,0x0,0x0},
677 {0x31,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x3,0x0},
678 {0x1,0x0,0x1,0x0,0x1,0x1,0x31,0x1,0x1,0x2},
679 {0x22,0x0,0x2,0x1,0x1,0x1,0x1,0x1,0x1,0x21}
681 { /* level 21 (Dentist) by ts-x */
682 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0},
683 {0x2,0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x2,0x2},
684 {0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x2},
685 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x6,0x0,0x2},
686 {0x2,0x0,0x6,0x0,0x6,0x0,0x0,0x0,0x0,0x2},
687 {0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x2},
688 {0x2,0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x2,0x2},
689 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0}
691 { /* level 22 (Spider) by ts-x */
692 {0x31,0x3,0x1,0x1,0x0,0x0,0x1,0x1,0x3,0x31},
693 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
694 {0x33,0x1,0x1,0x36,0x1,0x1,0x36,0x1,0x1,0x33},
695 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
696 {0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x1,0x0,0x0},
697 {0x21,0x3,0x1,0x21,0x2,0x2,0x21,0x1,0x3,0x21},
698 {0x0,0x0,0x0,0x1,0x21,0x1,0x1,0x0,0x0,0x0},
699 {0x3,0x1,0x3,0x1,0x0,0x0,0x1,0x3,0x1,0x3}
701 { /* level 23 (Pool) by ts-x */
702 {0x0,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x7,0x0},
703 {0x0,0x0,0x5,0x0,0x2,0x0,0x0,0x0,0x2,0x0},
704 {0x7,0x3,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x7},
705 {0x7,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x0,0x7},
706 {0x7,0x0,0x4,0x0,0x0,0x3,0x0,0x0,0x0,0x7},
707 {0x7,0x0,0x0,0x6,0x0,0x0,0x0,0x0,0x4,0x7},
708 {0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
709 {0x0,0x7,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x0}
711 { /* level 24 (Vorbis Fish) by ts-x */
712 {0x0,0x0,0x4,0x4,0x5,0x5,0x5,0x0,0x0,0x5},
713 {0x0,0x4,0x6,0x4,0x4,0x5,0x5,0x5,0x0,0x5},
714 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x5,0x5,0x5},
715 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x4,0x5,0x5},
716 {0x0,0x5,0x6,0x4,0x4,0x5,0x5,0x4,0x5,0x0},
717 {0x5,0x5,0x4,0x4,0x5,0x5,0x5,0x4,0x5,0x5},
718 {0x5,0x4,0x4,0x4,0x5,0x5,0x4,0x4,0x5,0x5},
719 {0x0,0x0,0x4,0x4,0x4,0x4,0x4,0x5,0x0,0x5}
721 {/* level 25 (Rainbow) by ts-x */
722 {0x0,0x4,0x1,0x0,0x0,0x0,0x0,0x1,0x4,0x0},
723 {0x24,0x1,0x3,0x1,0x0,0x0,0x21,0x3,0x1,0x24},
724 {0x1,0x23,0x5,0x3,0x1,0x21,0x3,0x5,0x3,0x21},
725 {0x3,0x5,0x6,0x5,0x3,0x3,0x5,0x6,0x5,0x3},
726 {0x5,0x6,0x7,0x6,0x5,0x5,0x6,0x7,0x6,0x5},
727 {0x6,0x7,0x2,0x27,0x6,0x6,0x27,0x2,0x7,0x6},
728 {0x7,0x2,0x0,0x2,0x27,0x27,0x2,0x0,0x2,0x7},
729 {0x32,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x32}
731 { /* level 26 (Bowtie) by ts-x */
732 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5},
733 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
734 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
735 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
736 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
737 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
738 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
739 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5}
741 { /* level 27 (Frog) by ts-x */
742 {0x0,0x5,0x25,0x0,0x0,0x0,0x0,0x25,0x5,0x0},
743 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5},
744 {0x25,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x25},
745 {0x5,0x0,0x3,0x0,0x6,0x6,0x0,0x3,0x0,0x5},
746 {0x5,0x0,0x31,0x0,0x6,0x6,0x0,0x31,0x0,0x5},
747 {0x5,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x5},
748 {0x5,0x5,0x5,0x35,0x0,0x0,0x35,0x5,0x5,0x5},
749 {0x0,0x25,0x5,0x0,0x4,0x4,0x0,0x5,0x25,0x0}
751 { /* level 28 (DigDug) by ts-x */
752 {0x35,0x5,0x5,0x25,0x0,0x25,0x25,0x5,0x5,0x35},
753 {0x6,0x0,0x0,0x6,0x0,0x6,0x6,0x0,0x0,0x6},
754 {0x7,0x0,0x37,0x37,0x0,0x37,0x37,0x7,0x0,0x7},
755 {0x7,0x0,0x7,0x0,0x0,0x0,0x7,0x7,0x7,0x7},
756 {0x4,0x4,0x4,0x24,0x0,0x24,0x4,0x0,0x0,0x4},
757 {0x4,0x4,0x0,0x0,0x0,0x4,0x4,0x0,0x4,0x4},
758 {0x24,0x24,0x4,0x4,0x4,0x4,0x0,0x0,0x24,0x4},
759 {0x1,0x1,0x1,0x1,0x1,0x1,0x21,0x21,0x1,0x1}
761 { /* TheEnd */
762 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
763 {0x22,0x22,0x26,0x0,0x0,0x26,0x24,0x24,0x0,0x0},
764 {0x22,0x0,0x26,0x26,0x0,0x26,0x24,0x0,0x24,0x0},
765 {0x22,0x22,0x26,0x26,0x0,0x26,0x24,0x0,0x24,0x0},
766 {0x22,0x22,0x26,0x0,0x26,0x26,0x24,0x0,0x24,0x0},
767 {0x22,0x0,0x26,0x0,0x26,0x26,0x24,0x0,0x24,0x0},
768 {0x22,0x22,0x26,0x0,0x0,0x26,0x24,0x24,0x0,0x0},
769 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
773 #define MAX_BALLS 10
774 int pad_pos_x;
775 int x[MAX_BALLS],y[MAX_BALLS];
776 int life;
777 int start_game,con_game;
778 int pad_type;
779 int score=0,vscore=0;
780 bool flip_sides=false;
781 int cur_level=0;
782 int brick_on_board=0;
783 int used_balls=1;
785 typedef struct cube {
786 int powertop;
787 int power;
788 char poweruse;
789 char used;
790 int color;
791 int hits;
792 int hiteffect;
793 } cube;
794 cube brick[80];
796 typedef struct balls {
797 int pos_x;
798 int pos_y;
799 int y;
800 int tempy;
801 int x;
802 int tempx;
803 bool glue;
804 } balls;
806 balls ball[MAX_BALLS];
808 typedef struct sfire {
809 int top;
810 int left;
811 } sfire;
812 sfire fire[30];
815 int highscore;
816 #define MAX_POINTS 200000 /* i dont think it needs to be more */
817 static struct configdata config[] =
819 {TYPE_INT, 0, MAX_POINTS, &highscore, "highscore", NULL, NULL}
822 void int_game(int new_game)
824 int i,j;
826 pad_pos_x=LCD_WIDTH/2-PAD_WIDTH/2;
828 for(i=0;i<MAX_BALLS;i++) {
829 ball[i].x=0;
830 ball[i].y=0;
831 ball[i].tempy=0;
832 ball[i].tempx=0;
833 ball[i].pos_y=PAD_POS_Y-BALL;
834 ball[i].pos_x=pad_pos_x+(PAD_WIDTH/2)-2;
835 ball[i].glue=false;
838 used_balls=1;
839 start_game =1;
840 con_game =0;
841 pad_type=0;
843 flip_sides=false;
845 if (new_game==1)
846 brick_on_board=0;
848 for(i=0;i<=7;i++) {
849 for(j=0;j<=9;j++) {
850 brick[i*10+j].poweruse=(levels[cur_level][i][j]==0?0:1);
851 if (i*10+j<=30)
852 fire[i*10+j].top=-8;
853 if (new_game==1) {
854 brick[i*10+j].power=rb->rand()%25;
855 /* +8 make the game with less powerups */
857 brick[i*10+j].hits=levels[cur_level][i][j]>=10?
858 levels[cur_level][i][j]/16-1:0;
859 brick[i*10+j].hiteffect=0;
860 brick[i*10+j].powertop=TOPMARGIN+i*BRICK_HEIGHT+BRICK_HEIGHT;
861 brick[i*10+j].used=(levels[cur_level][i][j]==0?0:1);
862 brick[i*10+j].color=(levels[cur_level][i][j]>=10?
863 levels[cur_level][i][j]%16:
864 levels[cur_level][i][j])-1;
865 if (levels[cur_level][i][j]!=0)
866 brick_on_board++;
872 int sw,i,w;
874 /* sleep timer counting the score */
875 void sleep (int secs)
877 bool done=false;
878 char s[20];
879 int count=0;
881 while (!done) {
883 if (vscore<score) {
884 vscore++;
885 rb->snprintf(s, sizeof(s), "%d", vscore);
886 rb->lcd_getstringsize(s, &sw, &w);
887 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
888 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
889 #else
890 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s);
891 #endif
892 rb->lcd_update_rect(0,0,LCD_WIDTH,w+2);
893 } else {
894 if (count==0)
895 count=*rb->current_tick+HZ*secs;
896 if (*rb->current_tick>=count)
897 done=true;
899 rb->yield();
904 #define HIGH_SCORE "brickmania.score"
905 #define MENU_LENGTH 4
906 int game_menu(int when)
908 int button,cur=0;
909 char str[10];
910 rb->lcd_clear_display();
911 #if (LCD_WIDTH != 112) && (LCD_HEIGHT != 64)
912 rb->lcd_bitmap(brickmania_menu_bg, 0, 0, BMPWIDTH_menu, BMPHEIGHT_menu);
913 #endif
914 while (true) {
915 for(i=0;i<MENU_LENGTH;i++) {
916 #ifdef HAVE_LCD_COLOR
917 if (cur==0)
918 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
919 MENU_BMPHEIGHT * BM_SEL_START, MENU_BMPWIDTH,
920 BMPXOFS_start, BMPYOFS_start, MENU_BMPWIDTH,
921 MENU_BMPHEIGHT);
922 else
923 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
924 MENU_BMPHEIGHT * BM_START, MENU_BMPWIDTH,
925 BMPXOFS_start, BMPYOFS_start, MENU_BMPWIDTH,
926 MENU_BMPHEIGHT);
928 if (when==1) {
929 if (cur==1)
930 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
931 MENU_BMPHEIGHT * BM_SEL_RESUME, MENU_BMPWIDTH,
932 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
933 MENU_BMPHEIGHT);
934 else
935 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
936 MENU_BMPHEIGHT * BM_RESUME, MENU_BMPWIDTH,
937 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
938 MENU_BMPHEIGHT);
940 } else {
941 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
942 MENU_BMPHEIGHT * BM_NO_RESUME, MENU_BMPWIDTH,
943 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
944 MENU_BMPHEIGHT);
948 if (cur==2)
949 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
950 MENU_BMPHEIGHT * BM_SEL_HELP, MENU_BMPWIDTH,
951 BMPXOFS_help, BMPYOFS_help, MENU_BMPWIDTH,
952 MENU_BMPHEIGHT);
953 else
954 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
955 MENU_BMPHEIGHT * BM_HELP, MENU_BMPWIDTH,
956 BMPXOFS_help, BMPYOFS_help, MENU_BMPWIDTH,
957 MENU_BMPHEIGHT);
959 if (cur==3)
960 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
961 MENU_BMPHEIGHT * BM_SEL_QUIT, MENU_BMPWIDTH,
962 BMPXOFS_quit, BMPYOFS_quit, MENU_BMPWIDTH,
963 MENU_BMPHEIGHT);
964 else
965 rb->lcd_bitmap_transparent_part(brickmania_menu_items, 0,
966 MENU_BMPHEIGHT * BM_QUIT, MENU_BMPWIDTH,
967 BMPXOFS_quit, BMPYOFS_quit, MENU_BMPWIDTH,
968 MENU_BMPHEIGHT);
969 #else
970 if (cur==0)
971 rb->lcd_bitmap_part(brickmania_menu_items, 0,
972 MENU_BMPHEIGHT * BM_SEL_START, MENU_BMPWIDTH,
973 BMPXOFS_start, BMPYOFS_start, MENU_BMPWIDTH,
974 MENU_BMPHEIGHT);
975 else
976 rb->lcd_bitmap_part(brickmania_menu_items, 0,
977 MENU_BMPHEIGHT * BM_START, MENU_BMPWIDTH,
978 BMPXOFS_start, BMPYOFS_start, MENU_BMPWIDTH,
979 MENU_BMPHEIGHT);
981 if (when==1) {
982 if (cur==1)
983 rb->lcd_bitmap_part(brickmania_menu_items, 0,
984 MENU_BMPHEIGHT * BM_SEL_RESUME, MENU_BMPWIDTH,
985 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
986 MENU_BMPHEIGHT);
987 else
988 rb->lcd_bitmap_part(brickmania_menu_items, 0,
989 MENU_BMPHEIGHT * BM_RESUME, MENU_BMPWIDTH,
990 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
991 MENU_BMPHEIGHT);
993 } else {
994 rb->lcd_bitmap_part(brickmania_menu_items, 0,
995 MENU_BMPHEIGHT * BM_NO_RESUME, MENU_BMPWIDTH,
996 BMPXOFS_resume, BMPYOFS_resume, MENU_BMPWIDTH,
997 MENU_BMPHEIGHT);
1001 if (cur==2)
1002 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1003 MENU_BMPHEIGHT * BM_SEL_HELP, MENU_BMPWIDTH,
1004 BMPXOFS_help, BMPYOFS_help, MENU_BMPWIDTH,
1005 MENU_BMPHEIGHT);
1006 else
1007 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1008 MENU_BMPHEIGHT * BM_HELP, MENU_BMPWIDTH,
1009 BMPXOFS_help, BMPYOFS_help, MENU_BMPWIDTH,
1010 MENU_BMPHEIGHT);
1012 if (cur==3)
1013 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1014 MENU_BMPHEIGHT * BM_SEL_QUIT, MENU_BMPWIDTH,
1015 BMPXOFS_quit, BMPYOFS_quit, MENU_BMPWIDTH,
1016 MENU_BMPHEIGHT);
1017 else
1018 rb->lcd_bitmap_part(brickmania_menu_items, 0,
1019 MENU_BMPHEIGHT * BM_QUIT, MENU_BMPWIDTH,
1020 BMPXOFS_quit, BMPYOFS_quit, MENU_BMPWIDTH,
1021 MENU_BMPHEIGHT);
1022 #endif
1024 rb->lcd_set_drawmode(DRMODE_FG);
1025 /* high score */
1026 #ifdef HAVE_LCD_COLOR
1027 rb->lcd_set_background(LCD_RGBPACK(0,0,140));
1028 rb->lcd_set_foreground(LCD_WHITE);
1029 #endif
1030 rb->lcd_putsxy(HIGHSCORE_XPOS, HIGHSCORE_YPOS, "High Score");
1031 rb->snprintf(str, sizeof(str), "%d", highscore);
1032 rb->lcd_getstringsize("High Score", &sw, NULL);
1033 rb->lcd_getstringsize(str, &w, NULL);
1034 rb->lcd_putsxy(HIGHSCORE_XPOS+sw/2-w/2, HIGHSCORE_YPOS+9, str);
1035 rb->lcd_set_drawmode(DRMODE_SOLID);
1037 rb->lcd_update();
1039 button = rb->button_get(true);
1040 switch(button) {
1041 case UP:
1042 case UP | BUTTON_REPEAT:
1043 if (cur==0)
1044 cur = MENU_LENGTH-1;
1045 else
1046 cur--;
1047 if (when==0 && cur==1) {
1048 cur = 0;
1050 break;
1052 case DOWN:
1053 case DOWN | BUTTON_REPEAT:
1054 if (cur==MENU_LENGTH-1)
1055 cur = 0;
1056 else
1057 cur++;
1058 if (when==0 && cur==1) {
1059 cur=2;
1061 break;
1063 case RIGHT:
1064 case SELECT:
1065 if (cur==0) {
1066 score=0;
1067 vscore=0;
1068 return 0;
1069 } else if (cur==1 && when==1) {
1070 return 1;
1071 } else if (cur==2) {
1072 return 2;
1073 } else if (cur==3) {
1074 return 3;
1076 break;
1077 #ifdef RC_QUIT
1078 case RC_QUIT:
1079 #endif
1080 case QUIT:
1081 return 3;
1082 break;
1084 default:
1085 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1086 return 3;
1087 break;
1092 int help(int when)
1094 int w,h;
1095 int button;
1096 int xoffset=0;
1097 int yoffset=0;
1098 /* set the maximum x and y in the helpscreen
1099 dont forget to update, if you change text */
1100 int maxY=180;
1101 int maxX=215;
1103 while(true) {
1104 #ifdef HAVE_LCD_COLOR
1105 rb->lcd_set_background(LCD_BLACK);
1106 rb->lcd_clear_display();
1107 rb->lcd_set_background(LCD_BLACK);
1108 rb->lcd_set_foreground(LCD_WHITE);
1109 #else
1110 rb->lcd_clear_display();
1111 #endif
1113 rb->lcd_getstringsize("BrickMania", &w, &h);
1114 rb->lcd_putsxy(LCD_WIDTH/2-w/2+xoffset, 1+yoffset, "BrickMania");
1116 #ifdef HAVE_LCD_COLOR
1117 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1118 rb->lcd_putsxy(1+xoffset, 1*(h+2)+yoffset,"Aim");
1119 rb->lcd_set_foreground(LCD_WHITE);
1120 #else
1121 rb->lcd_putsxy(1+xoffset, 1*(h+2)+yoffset,"Aim");
1122 #endif
1123 rb->lcd_putsxy(1+xoffset, 2*(h+2)+yoffset,
1124 "destroy all the bricks by bouncing");
1125 rb->lcd_putsxy(1+xoffset, 3*(h+2)+yoffset,
1126 "the ball of them using the paddle.");
1127 #ifdef HAVE_LCD_COLOR
1128 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1129 rb->lcd_putsxy(1+xoffset, 5*(h+2)+yoffset,"Controls");
1130 rb->lcd_set_foreground(LCD_WHITE);
1131 #else
1132 rb->lcd_putsxy(1+xoffset, 5*(h+2)+yoffset,"Controls");
1133 #endif
1134 rb->lcd_putsxy(1+xoffset, 6*(h+2)+yoffset,"< & > Move the paddle");
1135 #if CONFIG_KEYPAD == ONDIO_PAD
1136 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1137 "MENU Releases the ball/Fire!");
1138 #elif CONFIG_KEYPAD == RECORDER_PAD
1139 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1140 "PLAY Releases the ball/Fire!");
1141 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
1142 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1143 "NAVI Releases the ball/Fire!");
1144 #else
1145 rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset,
1146 "SELECT Releases the ball/Fire!");
1147 #endif
1148 rb->lcd_putsxy(1+xoffset, 8*(h+2)+yoffset, "STOP Opens menu/Quit");
1149 #ifdef HAVE_LCD_COLOR
1150 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1151 rb->lcd_putsxy(1+xoffset, 10*(h+2)+yoffset, "Specials");
1152 rb->lcd_set_foreground(LCD_WHITE);
1153 #else
1154 rb->lcd_putsxy(1+xoffset, 10*(h+2)+yoffset, "Specials");
1155 #endif
1156 rb->lcd_putsxy(1+xoffset, 11*(h+2)+yoffset,
1157 "N Normal:returns paddle to normal");
1158 rb->lcd_putsxy(1+xoffset, 12*(h+2)+yoffset, "D DIE!:loses a life");
1159 rb->lcd_putsxy(1+xoffset, 13*(h+2)+yoffset,
1160 "L Life:gains a life/power up");
1161 rb->lcd_putsxy(1+xoffset, 14*(h+2)+yoffset,
1162 "F Fire:allows you to shoot bricks");
1163 rb->lcd_putsxy(1+xoffset, 15*(h+2)+yoffset,
1164 "G Glue:ball sticks to paddle");
1165 rb->lcd_putsxy(1+xoffset, 16*(h+2)+yoffset,
1166 "B Ball:generates another ball");
1167 rb->lcd_putsxy(1+xoffset, 17*(h+2)+yoffset,
1168 "FL Flip:flips left / right movement");
1169 rb->lcd_update();
1171 button=rb->button_get(true);
1172 switch (button) {
1173 #ifdef RC_QUIT
1174 case RC_QUIT:
1175 #endif
1176 case QUIT:
1177 switch (game_menu(when)) {
1178 case 0:
1179 cur_level=0;
1180 life=2;
1181 int_game(1);
1182 break;
1183 case 1:
1184 con_game=1;
1185 break;
1186 case 2:
1187 if (help(when)==1)
1188 return 1;
1189 break;
1190 case 3:
1191 return 1;
1192 break;
1194 return 0;
1195 break;
1196 case LEFT:
1197 case LEFT | BUTTON_REPEAT:
1198 if( xoffset<0)
1199 xoffset+=2;
1200 break;
1201 case RIGHT:
1202 case RIGHT | BUTTON_REPEAT:
1203 if(xoffset+maxX > LCD_WIDTH)
1204 xoffset-=2;
1205 break;
1206 case UP:
1207 case UP | BUTTON_REPEAT:
1208 if(yoffset <0)
1209 yoffset+=2;
1210 break;
1211 case DOWN:
1212 case DOWN | BUTTON_REPEAT:
1213 if(yoffset+maxY > LCD_HEIGHT)
1214 yoffset-=2;
1215 break;
1217 default:
1218 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1219 return 1;
1220 break;
1223 return 0;
1226 int pad_check(int ballxc, int mode, int pon ,int ballnum)
1228 /* pon: positive(1) or negative(0) */
1230 if (mode==0) {
1231 if (pon == 0)
1232 return -ballxc;
1233 else
1234 return ballxc;
1235 } else {
1236 if (ball[ballnum].x > 0)
1237 return ballxc;
1238 else
1239 return ballxc*-1;
1243 int fire_space(void)
1245 int t;
1246 for(t=0;t<=30;t++)
1247 if (fire[t].top+7 < 0)
1248 return t;
1250 return 0;
1253 int game_loop(void)
1255 int j,i,k,bricky,brickx;
1256 char s[30];
1257 int sec_count=0,num_count=10;
1258 int end;
1260 rb->srand( *rb->current_tick );
1262 configfile_init(rb);
1263 configfile_load(HIGH_SCORE,config,1,0);
1265 switch(game_menu(0)) {
1266 case 0:
1267 cur_level = 0;
1268 life = 2;
1269 int_game(1);
1270 break;
1271 case 1:
1272 con_game = 1;
1273 break;
1274 case 2:
1275 if (help(0) == 1) return 1;
1276 break;
1277 case 3:
1278 return 1;
1279 break;
1282 while(true) {
1283 /* Convert CYCLETIME (in ms) to HZ */
1284 end = *rb->current_tick + (CYCLETIME * HZ) / 1000;
1286 if (life >= 0) {
1287 #ifdef HAVE_LCD_COLOR
1288 rb->lcd_set_background(LCD_BLACK);
1289 rb->lcd_set_drawmode(DRMODE_SOLID);
1290 rb->lcd_clear_display();
1291 rb->lcd_set_background(LCD_BLACK);
1292 #if LCD_HEIGHT > GAMESCREEN_HEIGHT
1293 rb->lcd_set_foreground(rb->global_settings->bg_color);
1294 rb->lcd_fillrect(0, GAMESCREEN_HEIGHT, LCD_WIDTH,
1295 LCD_HEIGHT - GAMESCREEN_HEIGHT);
1296 #endif
1297 rb->lcd_set_foreground(LCD_WHITE);
1298 #else
1299 rb->lcd_clear_display();
1300 #endif
1302 if (flip_sides) {
1303 if (*rb->current_tick>=sec_count) {
1304 sec_count=*rb->current_tick+HZ;
1305 if (num_count!=0)
1306 num_count--;
1307 else
1308 flip_sides=false;
1310 rb->snprintf(s, sizeof(s), "%d", num_count);
1311 rb->lcd_getstringsize(s, &sw, NULL);
1312 rb->lcd_putsxy(LCD_WIDTH/2-2, STRINGPOS_flipsides, s);
1315 /* write life num */
1316 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1317 rb->snprintf(s, sizeof(s), "L:%d", life);
1318 rb->lcd_putsxy(0, 0, s);
1319 #else
1320 rb->snprintf(s, sizeof(s), "Life: %d", life);
1321 rb->lcd_putsxy(2, 2, s);
1322 #endif
1324 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1325 rb->snprintf(s, sizeof(s), "L%d", cur_level+1);
1326 rb->lcd_getstringsize(s, &sw, NULL);
1327 rb->lcd_putsxy(LCD_WIDTH-sw, 0, s);
1328 #else
1329 rb->snprintf(s, sizeof(s), "Level %d", cur_level+1);
1330 rb->lcd_getstringsize(s, &sw, NULL);
1331 rb->lcd_putsxy(LCD_WIDTH-sw-2, 2, s);
1332 #endif
1334 if (vscore<score) vscore++;
1335 rb->snprintf(s, sizeof(s), "%d", vscore);
1336 rb->lcd_getstringsize(s, &sw, NULL);
1337 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1338 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
1339 #else
1340 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s);
1341 #endif
1343 /* continue game */
1344 if (con_game== 1 && start_game!=1) {
1345 #if CONFIG_KEYPAD == ONDIO_PAD
1346 rb->snprintf(s, sizeof(s), "MENU To Continue");
1347 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
1348 rb->snprintf(s, sizeof(s), "Press NAVI To Continue");
1349 #else
1350 rb->snprintf(s, sizeof(s), "Press SELECT To Continue");
1351 #endif
1352 rb->lcd_getstringsize(s, &sw, NULL);
1353 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_navi, s);
1355 sec_count=*rb->current_tick+HZ;
1358 /* draw the ball */
1359 for(i=0;i<used_balls;i++)
1360 rb->lcd_bitmap(brickmania_ball,ball[i].pos_x, ball[i].pos_y,
1361 BALL, BALL);
1363 if (brick_on_board==0)
1364 brick_on_board--;
1366 /* if the pad is fire */
1367 for(i=0;i<=30;i++) {
1368 if (fire[i].top+7>0) {
1369 if (con_game!=1)
1370 fire[i].top-=4;
1371 rb->lcd_vline(fire[i].left, fire[i].top, fire[i].top+7);
1375 /* the bricks */
1376 for (i=0;i<=7;i++) {
1377 for (j=0;j<=9;j++) {
1378 if (brick[i*10+j].power<7) {
1379 if (brick[i*10+j].poweruse==2) {
1380 if (con_game!=1)
1381 brick[i*10+j].powertop+=2;
1382 rb->lcd_bitmap_part(brickmania_powerups,0,
1383 BMPHEIGHT_powerup*brick[i*10+j
1384 ].power,
1385 BMPWIDTH_powerup,
1386 LEFTMARGIN+j*BRICK_WIDTH+
1387 (BRICK_WIDTH/2-
1388 BMPWIDTH_powerup/2),
1389 brick[i*10+j].powertop,
1390 BMPWIDTH_powerup,
1391 BMPHEIGHT_powerup);
1395 if ((pad_pos_x<LEFTMARGIN+j*BRICK_WIDTH+5 &&
1396 pad_pos_x+PAD_WIDTH>LEFTMARGIN+j*BRICK_WIDTH+5) &&
1397 brick[i*10+j].powertop+6>=PAD_POS_Y &&
1398 brick[i*10+j].poweruse==2) {
1399 switch(brick[i*10+j].power) {
1400 case 0:
1401 life++;
1402 score+=50;
1403 break;
1404 case 1:
1405 life--;
1406 if (life>=0) {
1407 int_game(0);
1408 sleep(2);
1410 break;
1411 case 2:
1412 score+=34;
1413 pad_type=1;
1414 break;
1415 case 3:
1416 score+=47;
1417 pad_type=2;
1418 for(k=0;k<used_balls;k++)
1419 ball[k].glue=false;
1420 break;
1421 case 4:
1422 score+=23;
1423 pad_type=0;
1424 for(k=0;k<used_balls;k++)
1425 ball[k].glue=false;
1426 flip_sides=false;
1427 break;
1428 case 5:
1429 score+=23;
1430 sec_count=*rb->current_tick+HZ;
1431 num_count=10;
1432 flip_sides=!flip_sides;
1433 break;
1434 case 6:
1435 score+=23;
1436 used_balls++;
1437 ball[used_balls-1].x= rb->rand()%1 == 0 ?
1438 -1 : 1;
1439 ball[used_balls-1].y= -4;
1440 break;
1442 brick[i*10+j].poweruse=1;
1445 if (brick[i*10+j].powertop>PAD_POS_Y)
1446 brick[i*10+j].poweruse=1;
1448 brickx=LEFTMARGIN+j*BRICK_WIDTH;
1449 bricky=TOPMARGIN+i*BRICK_HEIGHT;
1450 if (pad_type==2) {
1451 for (k=0;k<=30;k++) {
1452 if (fire[k].top+7>0) {
1453 if (brick[i*10+j].used==1 &&
1454 (fire[k].left+1 >= brickx &&
1455 fire[k].left+1 <= brickx+BRICK_WIDTH) &&
1456 (bricky+BRICK_HEIGHT>fire[k].top)) {
1457 score+=13;
1458 fire[k].top=-16;
1459 if (brick[i*10+j].hits > 0) {
1460 brick[i*10+j].hits--;
1461 brick[i*10+j].hiteffect++;
1462 score+=3;
1464 else {
1465 brick[i*10+j].used=0;
1466 if (brick[i*10+j].power!=10)
1467 brick[i*10+j].poweruse=2;
1468 brick_on_board--;
1475 if (brick[i*10+j].used==1) {
1476 rb->lcd_bitmap_part(brickmania_bricks,0,
1477 BRICK_HEIGHT*brick[i*10+j].color,
1478 BRICK_WIDTH,
1479 LEFTMARGIN+j*BRICK_WIDTH,
1480 TOPMARGIN+i*BRICK_HEIGHT,
1481 BRICK_WIDTH, BRICK_HEIGHT);
1482 #ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */
1483 if (brick[i*10+j].hiteffect>0)
1484 rb->lcd_bitmap_transparent_part(brickmania_break,
1486 BRICK_HEIGHT*brick[i*10+j].hiteffect,
1487 BRICK_WIDTH,
1488 LEFTMARGIN+j*BRICK_WIDTH,
1489 TOPMARGIN+i*BRICK_HEIGHT,
1490 BRICK_WIDTH,
1491 BRICK_HEIGHT);
1492 #endif
1495 for(k=0;k<used_balls;k++) {
1496 if (ball[k].pos_y <160) {
1497 if (brick[i*10+j].used==1) {
1498 if ((ball[k].pos_x+ball[k].x+HALFBALL >=
1499 brickx &&
1500 ball[k].pos_x+ball[k].x+HALFBALL <=
1501 brickx+BRICK_WIDTH) &&
1502 ((bricky-4<ball[k].pos_y+BALL &&
1503 bricky>ball[k].pos_y+BALL) ||
1504 (bricky+4>ball[k].pos_y+BALL+BALL &&
1505 bricky<ball[k].pos_y+BALL+BALL)) &&
1506 (ball[k].y >0)) {
1507 ball[k].tempy=bricky-ball[k].pos_y-BALL;
1509 else if ((ball[k].pos_x+ball[k].x+HALFBALL >=
1510 brickx &&
1511 ball[k].pos_x+ball[k].x+HALFBALL <=
1512 brickx+BRICK_WIDTH) &&
1513 ((bricky+BRICK_HEIGHT+4>ball[k].pos_y &&
1514 bricky+BRICK_HEIGHT<ball[k].pos_y) ||
1515 (bricky+BRICK_HEIGHT-4<ball[k].pos_y-BALL &&
1516 bricky+BRICK_HEIGHT>ball[k].pos_y-BALL)) &&
1517 (ball[k].y <0)) {
1518 ball[k].tempy=
1519 -(ball[k].pos_y-(bricky+BRICK_HEIGHT));
1522 if ((ball[k].pos_y+HALFBALL >=
1523 bricky &&
1524 ball[k].pos_y+HALFBALL <=
1525 bricky+BRICK_HEIGHT) &&
1526 ((brickx-4<ball[k].pos_x+BALL &&
1527 brickx>ball[k].pos_x+BALL) ||
1528 (brickx+4>ball[k].pos_x+BALL+BALL &&
1529 brickx<ball[k].pos_x+BALL+BALL)) &&
1530 (ball[k].x >0)) {
1531 ball[k].tempx=brickx-ball[k].pos_x-BALL;
1533 else if ((ball[k].pos_y+ball[k].y+HALFBALL >=
1534 bricky &&
1535 ball[k].pos_y+ball[k].y+HALFBALL <=
1536 bricky+BRICK_HEIGHT) &&
1537 ((brickx+BRICK_WIDTH+4>ball[k].pos_x &&
1538 brickx+BRICK_WIDTH<ball[k].pos_x) ||
1539 (brickx+BRICK_WIDTH-4<ball[k].pos_x-
1540 BALL &&
1541 brickx+BRICK_WIDTH>ball[k].pos_x-
1542 BALL)) && (ball[k].x <0)) {
1543 ball[k].tempx=
1544 -(ball[k].pos_x-(brickx+BRICK_WIDTH));
1547 if ((ball[k].pos_x+HALFBALL >= brickx &&
1548 ball[k].pos_x+HALFBALL <=
1549 brickx+BRICK_WIDTH) &&
1550 ((bricky+BRICK_HEIGHT==ball[k].pos_y) ||
1551 (bricky+BRICK_HEIGHT-6<=ball[k].pos_y &&
1552 bricky+BRICK_HEIGHT>ball[k].pos_y)) &&
1553 (ball[k].y <0)) { /* bottom line */
1554 if (brick[i*10+j].hits > 0) {
1555 brick[i*10+j].hits--;
1556 brick[i*10+j].hiteffect++;
1557 score+=2;
1559 else {
1560 brick[i*10+j].used=0;
1561 if (brick[i*10+j].power!=10)
1562 brick[i*10+j].poweruse=2;
1565 ball[k].y = ball[k].y*-1;
1567 else if ((ball[k].pos_x+HALFBALL >= brickx &&
1568 ball[k].pos_x+HALFBALL <=
1569 brickx+BRICK_WIDTH) &&
1570 ((bricky==ball[k].pos_y+BALL) ||
1571 (bricky+6>=ball[k].pos_y+BALL &&
1572 bricky<ball[k].pos_y+BALL)) &&
1573 (ball[k].y >0)) { /* top line */
1574 if (brick[i*10+j].hits > 0) {
1575 brick[i*10+j].hits--;
1576 brick[i*10+j].hiteffect++;
1577 score+=2;
1579 else {
1580 brick[i*10+j].used=0;
1581 if (brick[i*10+j].power!=10)
1582 brick[i*10+j].poweruse=2;
1585 ball[k].y = ball[k].y*-1;
1588 if ((ball[k].pos_y+HALFBALL >= bricky &&
1589 ball[k].pos_y+HALFBALL <=
1590 bricky+BRICK_HEIGHT) &&
1591 ((brickx==ball[k].pos_x+BALL) ||
1592 (brickx+6>=ball[k].pos_x+BALL &&
1593 brickx<ball[k].pos_x+BALL)) &&
1594 (ball[k].x > 0)) { /* left line */
1595 if (brick[i*10+j].hits > 0) {
1596 brick[i*10+j].hits--;
1597 brick[i*10+j].hiteffect++;
1598 score+=2;
1600 else {
1601 brick[i*10+j].used=0;
1602 if (brick[i*10+j].power!=10)
1603 brick[i*10+j].poweruse=2;
1605 ball[k].x = ball[k].x*-1;
1608 else if ((ball[k].pos_y+HALFBALL >= bricky &&
1609 ball[k].pos_y+HALFBALL <=
1610 bricky+BRICK_HEIGHT) &&
1611 ((brickx+BRICK_WIDTH==
1612 ball[k].pos_x) ||
1613 (brickx+BRICK_WIDTH-6<=
1614 ball[k].pos_x &&
1615 brickx+BRICK_WIDTH>
1616 ball[k].pos_x)) &&
1617 (ball[k].x < 0)) { /* Right line */
1618 if (brick[i*10+j].hits > 0) {
1619 brick[i*10+j].hits--;
1620 brick[i*10+j].hiteffect++;
1621 score+=2;
1623 else {
1624 brick[i*10+j].used=0;
1625 if (brick[i*10+j].power!=10)
1626 brick[i*10+j].poweruse=2;
1629 ball[k].x = ball[k].x*-1;
1632 if (brick[i*10+j].used==0) {
1633 brick_on_board--;
1634 score+=8;
1638 } /* for k */
1639 } /* for j */
1640 } /* for i */
1642 /* draw the pad */
1643 rb->lcd_bitmap_part(brickmania_pads,0,pad_type*PAD_HEIGHT,
1644 PAD_WIDTH,pad_pos_x, PAD_POS_Y, PAD_WIDTH,
1645 PAD_HEIGHT);
1647 for(k=0;k<used_balls;k++) {
1649 if ((ball[k].pos_x >= pad_pos_x &&
1650 ball[k].pos_x <= pad_pos_x+PAD_WIDTH) &&
1651 (PAD_POS_Y-4<ball[k].pos_y+BALL &&
1652 PAD_POS_Y>ball[k].pos_y+BALL) && (ball[k].y >0))
1653 ball[k].tempy=PAD_POS_Y-ball[k].pos_y-BALL;
1654 else if ((4>ball[k].pos_y && 0<ball[k].pos_y) &&
1655 (ball[k].y <0))
1656 ball[k].tempy=-ball[k].pos_y;
1657 if ((LCD_WIDTH-4<ball[k].pos_x+BALL &&
1658 LCD_WIDTH>ball[k].pos_x+BALL) && (ball[k].x >0))
1659 ball[k].tempx=LCD_WIDTH-ball[k].pos_x-BALL;
1660 else if ((4>ball[k].pos_x && 0<ball[k].pos_x) &&
1661 (ball[k].x <0))
1662 ball[k].tempx=-ball[k].pos_x;
1664 /* top line */
1665 if (ball[k].pos_y<= 0)
1666 ball[k].y = ball[k].y*-1;
1667 /* bottom line */
1668 else if (ball[k].pos_y+BALL >= GAMESCREEN_HEIGHT) {
1669 if (used_balls>1) {
1670 used_balls--;
1671 ball[k].pos_x = ball[used_balls].pos_x;
1672 ball[k].pos_y = ball[used_balls].pos_y;
1673 ball[k].y = ball[used_balls].y;
1674 ball[k].tempy = ball[used_balls].tempy;
1675 ball[k].x = ball[used_balls].x;
1676 ball[k].tempx = ball[used_balls].tempx;
1677 ball[k].glue = ball[used_balls].glue;
1679 ball[used_balls].x=0;
1680 ball[used_balls].y=0;
1681 ball[used_balls].tempy=0;
1682 ball[used_balls].tempx=0;
1683 ball[used_balls].pos_y=PAD_POS_Y-BALL;
1684 ball[used_balls].pos_x=pad_pos_x+(PAD_WIDTH/2)-2;
1686 k--;
1687 continue;
1688 } else {
1689 life--;
1690 if (life>=0) {
1691 int_game(0);
1692 sleep(2);
1697 /* left line ,right line */
1698 if ((ball[k].pos_x <= 0) ||
1699 (ball[k].pos_x+BALL >= LCD_WIDTH)) {
1700 ball[k].x = ball[k].x*-1;
1701 ball[k].pos_x = ball[k].pos_x <= 0 ? 0 : LCD_WIDTH-BALL;
1704 if ((ball[k].pos_y+BALL >= PAD_POS_Y &&
1705 (ball[k].pos_x >= pad_pos_x &&
1706 ball[k].pos_x <= pad_pos_x+PAD_WIDTH)) &&
1707 start_game != 1 && !ball[k].glue) {
1709 if ((ball[k].pos_x+HALFBALL >= pad_pos_x &&
1710 ball[k].pos_x+HALFBALL <=
1711 pad_pos_x+(PAD_WIDTH/2/4)) ||
1712 (ball[k].pos_x +HALFBALL>=
1713 pad_pos_x+(PAD_WIDTH-(PAD_WIDTH/2/4)) &&
1714 ball[k].pos_x+HALFBALL <= pad_pos_x+PAD_WIDTH)) {
1716 ball[k].y = -2;
1717 if (ball[k].pos_x != 0 &&
1718 ball[k].pos_x+BALL!=LCD_WIDTH)
1719 ball[k].x = pad_check(6,0,ball[k].pos_x+2<=
1720 pad_pos_x+(PAD_WIDTH/2)?
1721 0:1,k);
1724 else if ((ball[k].pos_x+HALFBALL >=
1725 pad_pos_x+(PAD_WIDTH/2/4) &&
1726 ball[k].pos_x+HALFBALL <=
1727 pad_pos_x+2*(PAD_WIDTH/2/4)) ||
1728 (ball[k].pos_x+HALFBALL >=
1729 pad_pos_x+(PAD_WIDTH-2*(PAD_WIDTH/2/4)) &&
1730 ball[k].pos_x+HALFBALL <=
1731 pad_pos_x+(PAD_WIDTH-(PAD_WIDTH/2/4)) )) {
1733 ball[k].y = -3;
1734 if (ball[k].pos_x != 0 &&
1735 ball[k].pos_x+BALL!=LCD_WIDTH)
1736 ball[k].x = pad_check(4,0,ball[k].pos_x+2<=
1737 pad_pos_x+(PAD_WIDTH/2)?
1738 0:1,k);
1741 else if ((ball[k].pos_x+HALFBALL >=
1742 pad_pos_x+2*(PAD_WIDTH/2/4) &&
1743 ball[k].pos_x+HALFBALL <=
1744 pad_pos_x+3*(PAD_WIDTH/2/4)) ||
1745 (ball[k].pos_x+2 >=
1746 pad_pos_x+(PAD_WIDTH-3*(PAD_WIDTH/2/4)) &&
1747 ball[k].pos_x+2 <=
1748 pad_pos_x+ ((PAD_WIDTH/2)-2*(PAD_WIDTH/2/4)) )) {
1750 ball[k].y = -4;
1751 if (ball[k].pos_x != 0 &&
1752 ball[k].pos_x+BALL!=LCD_WIDTH)
1753 ball[k].x = pad_check(3,0,ball[k].pos_x+2<=
1754 pad_pos_x+(PAD_WIDTH/2)?
1755 0:1,k);
1758 else if ((ball[k].pos_x+HALFBALL >=
1759 pad_pos_x+3*(PAD_WIDTH/2/4) &&
1760 ball[k].pos_x+HALFBALL <=
1761 pad_pos_x+4*(PAD_WIDTH/2/4)-2) ||
1762 (ball[k].pos_x+2 >= pad_pos_x+(PAD_WIDTH/2+2) &&
1763 ball[k].pos_x+2 <=
1764 pad_pos_x+(PAD_WIDTH-3*(PAD_WIDTH/2/4)) )) {
1766 ball[k].y = -4;
1767 if (ball[k].pos_x != 0 &&
1768 ball[k].pos_x+BALL!=LCD_WIDTH)
1769 ball[k].x = pad_check(2,1,0,k);
1772 else {
1773 ball[k].y = -4;
1777 if (!ball[k].glue) {
1778 ball[k].pos_x+=ball[k].tempx!=0?ball[k].tempx:ball[k].x;
1779 ball[k].pos_y+=ball[k].tempy!=0?ball[k].tempy:ball[k].y;
1781 ball[k].tempy=0;
1782 ball[k].tempx=0;
1785 if (ball[k].pos_y+5 >= PAD_POS_Y &&
1786 (pad_type==1 && !ball[k].glue) &&
1787 (ball[k].pos_x >= pad_pos_x &&
1788 ball[k].pos_x <= pad_pos_x+PAD_WIDTH)) {
1789 ball[k].y=0;
1790 ball[k].pos_y=PAD_POS_Y-BALL;
1791 ball[k].glue=true;
1793 } /* for k */
1795 rb->lcd_update();
1797 if (brick_on_board < 0) {
1798 if (cur_level+1<levels_num) {
1799 cur_level++;
1800 score+=100;
1801 int_game(1);
1802 sleep(2);
1804 else {
1805 rb->lcd_getstringsize("Congratulations!", &sw, NULL);
1806 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_congrats,
1807 "Congratulations!");
1808 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1809 rb->lcd_getstringsize("No more levels", &sw, NULL);
1810 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_finsh,
1811 "No more levels");
1812 #else
1813 rb->lcd_getstringsize("You have finished the game!",
1814 &sw, NULL);
1815 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, STRINGPOS_finsh,
1816 "You have finished the game!");
1817 #endif
1818 vscore=score;
1819 rb->lcd_update();
1820 if (score>highscore) {
1821 sleep(2);
1822 highscore=score;
1823 rb->splash(HZ*2, "New High Score");
1825 else {
1826 sleep(3);
1829 switch(game_menu(0)) {
1830 case 0:
1831 life=2;
1832 cur_level=0;
1833 int_game(1);
1834 break;
1835 case 1:
1836 con_game=1;
1837 break;
1838 case 2:
1839 if (help(0)==1) return 1;
1840 break;
1841 case 3:
1842 return 1;
1843 break;
1848 int move_button,button;
1849 int button_right,button_left;
1850 button=rb->button_get(false);
1852 #ifdef HAS_BUTTON_HOLD
1853 if (rb->button_hold())
1854 button = QUIT;
1855 #endif
1857 move_button=rb->button_status();
1859 button_right=((move_button & RIGHT) || (SCROLL_FWD(button)));
1860 button_left=((move_button & LEFT) || (SCROLL_BACK(button)));
1861 if ((con_game== 1 && start_game!=1) && (button_right || button_left))
1862 continue;
1863 if ((button_right && flip_sides==false) ||
1864 (button_left && flip_sides==true)) {
1865 if (pad_pos_x+8+PAD_WIDTH > LCD_WIDTH) {
1866 for(k=0;k<used_balls;k++)
1867 if (start_game==1 || ball[k].glue)
1868 ball[k].pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
1869 pad_pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
1871 else {
1872 for(k=0;k<used_balls;k++)
1873 if ((start_game==1 || ball[k].glue))
1874 ball[k].pos_x+=8;
1875 pad_pos_x+=8;
1878 else if ((button_left && flip_sides==false) ||
1879 (button_right && flip_sides==true)) {
1880 if (pad_pos_x-8 < 0) {
1881 for(k=0;k<used_balls;k++)
1882 if (start_game==1 || ball[k].glue)
1883 ball[k].pos_x-=pad_pos_x;
1884 pad_pos_x-=pad_pos_x;
1886 else {
1887 for(k=0;k<used_balls;k++)
1888 if (start_game==1 || ball[k].glue)
1889 ball[k].pos_x-=8;
1890 pad_pos_x-=8;
1895 switch(button) {
1896 case UP:
1897 case SELECT:
1898 if (start_game==1 && con_game!=1 && pad_type!=1) {
1899 for(k=0;k<used_balls;k++) {
1900 ball[k].y=-4;
1901 ball[k].x=pad_pos_x+(PAD_WIDTH/2)-2>=
1902 LCD_WIDTH/2?2:-2;
1904 start_game =0;
1906 else if (pad_type==1) {
1907 for(k=0;k<used_balls;k++) {
1908 if (ball[k].glue)
1909 ball[k].glue=false;
1910 else if (start_game==1) {
1911 ball[k].x = x[k];
1912 ball[k].y = y[k];
1916 if (start_game!=1 && con_game==1) {
1917 start_game =0;
1918 con_game=0;
1920 } else if (pad_type==2 && con_game!=1) {
1921 int tfire;
1922 tfire=fire_space();
1923 fire[tfire].top=PAD_POS_Y-7;
1924 fire[tfire].left=pad_pos_x+1;
1925 tfire=fire_space();
1926 fire[tfire].top=PAD_POS_Y-7;
1927 fire[tfire].left=pad_pos_x+PAD_WIDTH-1;
1928 } else if (con_game==1 && start_game!=1) {
1929 for(k=0;k<used_balls;k++) {
1930 ball[k].x=x[k];
1931 ball[k].y=y[k];
1933 con_game=0;
1935 break;
1936 #ifdef RC_QUIT
1937 case RC_QUIT:
1938 #endif
1939 case QUIT:
1940 switch(game_menu(1)) {
1941 case 0:
1942 life=2;
1943 cur_level=0;
1944 int_game(1);
1945 break;
1946 case 1:
1947 for(k=0;k<used_balls;k++)
1948 if (ball[k].x!=0 && ball[k].y !=0)
1949 con_game=1;
1950 break;
1951 case 2:
1952 if (help(1)==1)
1953 return 1;
1954 break;
1955 case 3:
1956 return 1;
1957 break;
1960 for(k=0;k<used_balls;k++) {
1961 if (ball[k].x!=0)
1962 x[k]=ball[k].x;
1963 ball[k].x=0;
1964 if (ball[k].y!=0)
1965 y[k]=ball[k].y;
1966 ball[k].y=0;
1969 break;
1971 default:
1972 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
1973 return 1;
1974 break;
1977 else {
1978 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1979 rb->splash(HZ*2, "Game Over");
1980 #else
1981 rb->lcd_bitmap(brickmania_gameover,LCD_WIDTH/2-55,LCD_HEIGHT-87,
1982 110,52);
1983 rb->lcd_update();
1984 #endif
1985 if (score>highscore) {
1986 sleep(2);
1987 highscore=score;
1988 rb->splash(HZ*2, "New High Score");
1989 } else {
1990 sleep(3);
1993 for(k=0;k<used_balls;k++) {
1994 ball[k].x=0;
1995 ball[k].y=0;
1998 switch(game_menu(0)) {
1999 case 0:
2000 cur_level=0;
2001 life=2;
2002 int_game(1);
2003 break;
2004 case 1:
2005 con_game=1;
2006 break;
2007 case 2:
2008 if (help(0)==1)
2009 return 1;
2010 break;
2011 case 3:
2012 return 1;
2013 break;
2016 if (end > *rb->current_tick)
2017 rb->sleep(end-*rb->current_tick);
2018 else
2019 rb->yield();
2023 /* this is the plugin entry point */
2024 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
2026 (void)parameter;
2027 rb = api;
2029 rb->lcd_setfont(FONT_SYSFIXED);
2030 #if LCD_DEPTH > 1
2031 rb->lcd_set_backdrop(NULL);
2032 #endif
2033 /* Turn off backlight timeout */
2034 backlight_force_on(rb); /* backlight control in lib/helper.c */
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 /* Turn on backlight timeout (revert to settings) */
2044 backlight_use_settings(rb); /* backlight control in lib/helper.c */
2046 return PLUGIN_OK;