Use a more natural guard for the callback definition
[kugel-rb.git] / apps / plugins / brickmania.c
blobae52babdaab932b9cec5dca9e48d35710fd103d8
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005, 2006 Ben Basha (Paprica)
11 * Copyright (C) 2009 Karl Kurbjun
12 * check_lines is based off an explanation and expanded math presented by Paul
13 * Bourke: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
25 #include "plugin.h"
26 #include "lib/configfile.h"
27 #include "lib/display_text.h"
28 #include "lib/helper.h"
29 #include "lib/highscore.h"
30 #include "lib/playback_control.h"
32 #include "pluginbitmaps/brickmania_pads.h"
33 #include "pluginbitmaps/brickmania_short_pads.h"
34 #include "pluginbitmaps/brickmania_long_pads.h"
35 #include "pluginbitmaps/brickmania_bricks.h"
36 #include "pluginbitmaps/brickmania_powerups.h"
37 #include "pluginbitmaps/brickmania_ball.h"
38 #include "pluginbitmaps/brickmania_gameover.h"
40 #ifdef HAVE_LCD_COLOR /* currently no transparency for non-colour */
41 #include "pluginbitmaps/brickmania_break.h"
42 #endif
44 PLUGIN_HEADER
49 * Keymaps
53 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
54 (CONFIG_KEYPAD == IRIVER_H300_PAD)
55 #define CONTINUE_TEXT "Press NAVI To Continue"
56 #define QUIT BUTTON_OFF
57 #define LEFT BUTTON_LEFT
58 #define RIGHT BUTTON_RIGHT
59 #define SELECT BUTTON_SELECT
60 #define UP BUTTON_UP
61 #define DOWN BUTTON_DOWN
62 #define RC_QUIT BUTTON_RC_STOP
64 #elif CONFIG_KEYPAD == ONDIO_PAD
65 #define CONTINUE_TEXT "MENU To Continue"
66 #define QUIT BUTTON_OFF
67 #define LEFT BUTTON_LEFT
68 #define RIGHT BUTTON_RIGHT
69 #define SELECT BUTTON_MENU
70 #define UP BUTTON_UP
71 #define DOWN BUTTON_DOWN
73 #elif CONFIG_KEYPAD == RECORDER_PAD
74 #define QUIT BUTTON_OFF
75 #define LEFT BUTTON_LEFT
76 #define RIGHT BUTTON_RIGHT
77 #define SELECT BUTTON_PLAY
78 #define UP BUTTON_UP
79 #define DOWN BUTTON_DOWN
81 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
82 #define QUIT BUTTON_OFF
83 #define LEFT BUTTON_LEFT
84 #define RIGHT BUTTON_RIGHT
85 #define SELECT BUTTON_SELECT
86 #define UP BUTTON_UP
87 #define DOWN BUTTON_DOWN
89 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
90 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
91 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
92 #define QUIT BUTTON_MENU
93 #define LEFT BUTTON_LEFT
94 #define RIGHT BUTTON_RIGHT
95 #define SELECT BUTTON_SELECT
96 #define UP BUTTON_SCROLL_BACK
97 #define DOWN BUTTON_SCROLL_FWD
98 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD)
99 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK)
101 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
102 #define QUIT BUTTON_POWER
103 #define LEFT BUTTON_LEFT
104 #define RIGHT BUTTON_RIGHT
105 #define SELECT BUTTON_SELECT
106 #define UP BUTTON_UP
107 #define DOWN BUTTON_DOWN
109 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
110 #define QUIT BUTTON_POWER
111 #define LEFT BUTTON_LEFT
112 #define RIGHT BUTTON_RIGHT
113 #define SELECT BUTTON_PLAY
114 #define UP BUTTON_UP
115 #define DOWN BUTTON_DOWN
117 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
118 #define QUIT BUTTON_POWER
119 #define LEFT BUTTON_LEFT
120 #define RIGHT BUTTON_RIGHT
121 #define SELECT BUTTON_SELECT
122 #define UP BUTTON_UP
123 #define DOWN BUTTON_DOWN
124 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD)
125 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK)
128 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
129 #define QUIT (BUTTON_HOME|BUTTON_REPEAT)
130 #define LEFT BUTTON_LEFT
131 #define RIGHT BUTTON_RIGHT
132 #define SELECT BUTTON_SELECT
133 #define UP BUTTON_UP
134 #define DOWN BUTTON_DOWN
136 #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD)
137 #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK)
140 #elif CONFIG_KEYPAD == SANSA_C200_PAD || \
141 CONFIG_KEYPAD == SANSA_CLIP_PAD || \
142 CONFIG_KEYPAD == SANSA_M200_PAD
143 #define QUIT BUTTON_POWER
144 #define LEFT BUTTON_LEFT
145 #define RIGHT BUTTON_RIGHT
146 #define ALTLEFT BUTTON_VOL_DOWN
147 #define ALTRIGHT BUTTON_VOL_UP
148 #define SELECT BUTTON_SELECT
149 #define UP BUTTON_UP
150 #define DOWN BUTTON_DOWN
152 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
153 #define QUIT BUTTON_POWER
154 #define LEFT BUTTON_LEFT
155 #define RIGHT BUTTON_RIGHT
156 #define SELECT BUTTON_PLAY
157 #define UP BUTTON_SCROLL_UP
158 #define DOWN BUTTON_SCROLL_DOWN
160 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
161 #define QUIT BUTTON_BACK
162 #define LEFT BUTTON_LEFT
163 #define RIGHT BUTTON_RIGHT
164 #define SELECT BUTTON_SELECT
165 #define UP BUTTON_UP
166 #define DOWN BUTTON_DOWN
168 #elif (CONFIG_KEYPAD == MROBE100_PAD)
169 #define QUIT BUTTON_POWER
170 #define LEFT BUTTON_LEFT
171 #define RIGHT BUTTON_RIGHT
172 #define SELECT BUTTON_SELECT
173 #define UP BUTTON_UP
174 #define DOWN BUTTON_DOWN
176 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
177 #define CONTINUE_TEXT "PLAY To Continue"
178 #define QUIT BUTTON_RC_REC
179 #define LEFT BUTTON_RC_REW
180 #define RIGHT BUTTON_RC_FF
181 #define SELECT BUTTON_RC_PLAY
182 #define UP BUTTON_RC_VOL_UP
183 #define DOWN BUTTON_RC_VOL_DOWN
184 #define RC_QUIT BUTTON_REC
186 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
187 #define QUIT BUTTON_BACK
188 #define LEFT BUTTON_LEFT
189 #define RIGHT BUTTON_RIGHT
190 #define SELECT BUTTON_SELECT
191 #define UP BUTTON_UP
192 #define DOWN BUTTON_DOWN
194 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
195 #define QUIT BUTTON_POWER
196 #define LEFT BUTTON_LEFT
197 #define RIGHT BUTTON_RIGHT
198 #define SELECT BUTTON_SELECT
199 #define UP BUTTON_UP
200 #define DOWN BUTTON_DOWN
202 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
203 #define QUIT BUTTON_POWER
204 #define LEFT BUTTON_PREV
205 #define RIGHT BUTTON_NEXT
206 #define SELECT BUTTON_PLAY
207 #define UP BUTTON_UP
208 #define DOWN BUTTON_DOWN
210 #elif CONFIG_KEYPAD == COWON_D2_PAD
211 #define CONTINUE_TEXT "MENU To Continue"
212 #define QUIT BUTTON_POWER
213 #define LEFT BUTTON_MINUS
214 #define RIGHT BUTTON_PLUS
215 #define SELECT BUTTON_MENU
217 #elif CONFIG_KEYPAD == ONDAVX747_PAD
218 #define QUIT BUTTON_POWER
219 #define LEFT BUTTON_VOL_DOWN
220 #define RIGHT BUTTON_VOL_UP
221 #define SELECT BUTTON_MENU
222 #elif CONFIG_KEYPAD == ONDAVX777_PAD
223 #define QUIT BUTTON_POWER
225 #elif CONFIG_KEYPAD == MROBE500_PAD
226 #define QUIT BUTTON_POWER
228 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
229 #define QUIT BUTTON_FFWD
230 #define SELECT BUTTON_PLAY
231 #define LEFT BUTTON_LEFT
232 #define RIGHT BUTTON_RIGHT
233 #define UP BUTTON_UP
234 #define DOWN BUTTON_DOWN
236 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
237 #define QUIT BUTTON_REC
238 #define LEFT BUTTON_PREV
239 #define RIGHT BUTTON_NEXT
240 #define ALTLEFT BUTTON_MENU
241 #define ALTRIGHT BUTTON_PLAY
242 #define SELECT BUTTON_OK
243 #define UP BUTTON_UP
244 #define DOWN BUTTON_DOWN
246 #else
247 #error No keymap defined!
248 #endif
250 #ifdef HAVE_TOUCHSCREEN
251 #ifdef LEFT
252 #define ALTLEFT BUTTON_BOTTOMLEFT
253 #else
254 #define LEFT BUTTON_BOTTOMLEFT
255 #endif
256 #ifdef RIGHT
257 #define ALTRIGHT BUTTON_BOTTOMRIGHT
258 #else
259 #define RIGHT BUTTON_BOTTOMRIGHT
260 #endif
261 #ifdef SELECT
262 #define ALTSELECT BUTTON_CENTER
263 #else
264 #define SELECT BUTTON_CENTER
265 #endif
266 #ifndef UP
267 #define UP BUTTON_TOPMIDDLE
268 #endif
269 #ifndef DOWN
270 #define DOWN BUTTON_BOTTOMMIDDLE
271 #endif
272 #endif
274 /* Continue text is used as a string later when the game is paused. This allows
275 * targets to specify their own text if needed.
277 #if !defined(CONTINUE_TEXT)
278 #define CONTINUE_TEXT "Press SELECT To Continue"
279 #endif
281 #ifndef SCROLL_FWD /* targets without scroll wheel*/
282 #define SCROLL_FWD(x) (0)
283 #define SCROLL_BACK(x) (0)
284 #endif
289 * Geometric dimensions
293 /* If there are three fractional bits, the smallest screen size that will scale
294 * properly is 28x22. If you have a smaller screen increase the fractional
295 * precision. If you have a precision of 4 the smallest screen size would be
296 * 14x11. Note though that this will decrease the maximum resolution due to
297 * the line intersection tests. These defines are used for all of the fixed
298 * point calculations/conversions.
300 #define FIXED3(x) ((x)<<3)
301 #define FIXED3_MUL(x, y) ((long long)((x)*(y))>>3)
302 #define FIXED3_DIV(x, y) (((x)<<3)/(y))
303 #define INT3(x) ((x)>>3)
305 #define GAMESCREEN_WIDTH FIXED3(LCD_WIDTH)
306 #define GAMESCREEN_HEIGHT FIXED3(LCD_HEIGHT)
308 #define PAD_WIDTH FIXED3(BMPWIDTH_brickmania_pads)
309 #define PAD_HEIGHT FIXED3(BMPHEIGHT_brickmania_pads/3)
310 #define SHORT_PAD_WIDTH FIXED3(BMPWIDTH_brickmania_short_pads)
311 #define LONG_PAD_WIDTH FIXED3(BMPWIDTH_brickmania_long_pads)
312 #define BRICK_HEIGHT FIXED3(BMPHEIGHT_brickmania_bricks/7)
313 #define BRICK_WIDTH FIXED3(BMPWIDTH_brickmania_bricks)
314 #define LEFTMARGIN ((GAMESCREEN_WIDTH-10*BRICK_WIDTH)/2)
315 #define POWERUP_WIDTH FIXED3(BMPWIDTH_brickmania_powerups)
316 #define BALL FIXED3(BMPHEIGHT_brickmania_ball)
317 #define HALFBALL (BALL / 2)
318 #define PAD_POS_Y (GAMESCREEN_HEIGHT - PAD_HEIGHT - 1)
319 #define ON_PAD_POS_Y (PAD_POS_Y - HALFBALL)
321 #define GAMEOVER_WIDTH FIXED3(BMPWIDTH_brickmania_gameover)
322 #define GAMEOVER_HEIGHT FIXED3(BMPHEIGHT_brickmania_gameover)
324 #define TOPMARGIN MAX(BRICK_HEIGHT, FIXED3(8))
326 #define STRINGPOS_FINISH (GAMESCREEN_HEIGHT - (GAMESCREEN_HEIGHT / 6))
327 #define STRINGPOS_CONGRATS (STRINGPOS_FINISH - 20)
328 #define STRINGPOS_NAVI (STRINGPOS_FINISH - 10)
329 #define STRINGPOS_FLIP (STRINGPOS_FINISH - 10)
334 * Speeds
338 /* Brickmania was originally designed for the H300, other targets should scale
339 * the speed up/down as needed based on the screen height.
341 #define SPEED_SCALE_H(y) FIXED3_DIV(GAMESCREEN_HEIGHT, FIXED3(176)/(y) )
342 #define SPEED_SCALE_W(x) FIXED3_DIV(GAMESCREEN_WIDTH, FIXED3(220)/(x) )
344 /* These are all used as ball speeds depending on where the ball hit the
345 * paddle.
347 * Note that all of these speeds (including pad, power, and fire)
348 * could be made variable and could be raised to be much higher to add
349 * additional difficulty to the game. The line intersection tests allow this
350 * to be drastically increased without the collision detection failing
351 * (ideally).
353 #define SPEED_1Q_X SPEED_SCALE_W( 6)
354 #define SPEED_1Q_Y SPEED_SCALE_H(-2)
356 #define SPEED_2Q_X SPEED_SCALE_W( 4)
357 #define SPEED_2Q_Y SPEED_SCALE_H(-3)
359 #define SPEED_3Q_X SPEED_SCALE_W( 3)
360 #define SPEED_3Q_Y SPEED_SCALE_H(-4)
362 #define SPEED_4Q_X SPEED_SCALE_W( 2)
363 #define SPEED_4Q_Y SPEED_SCALE_H(-4)
365 /* This is used to determine the speed of the paddle */
366 #define SPEED_PAD SPEED_SCALE_W( 8)
368 /* This defines the speed that the powerups drop */
369 #define SPEED_POWER SPEED_SCALE_H( 2)
371 /* This defines the speed that the shot moves */
372 #define SPEED_FIRE SPEED_SCALE_H( 4)
373 #define FIRE_LENGTH SPEED_SCALE_H( 7)
378 * Timings
382 /* The time ms for one iteration through the game loop - decrease this to speed
383 * up the game - note that current_tick is (currently) only accurate to 10ms.
385 #define CYCLETIME 30 /* ms */
387 #define FLIP_SIDES_DELAY 10 /* seconds */
392 * Scores
396 #define SCORE_BALL_HIT_BRICK 2
397 #define SCORE_BALL_DEMOLISHED_BRICK 8
398 #define SCORE_FIRE_HIT_BRICK 13
399 #define SCORE_LEVEL_COMPLETED 100
400 #define SCORE_POWER_LIFE_GAIN 50
401 #define SCORE_POWER_PADDLE_STICKY 34
402 #define SCORE_POWER_PADDLE_SHOOTER 47
403 #define SCORE_POWER_PADDLE_NORMAL 23
404 #define SCORE_POWER_FLIP 23
405 #define SCORE_POWER_EXTRA_BALL 23
406 #define SCORE_POWER_LONG_PADDLE 23
411 * Limits
415 #define MAX_BALLS 10
416 #define MAX_FIRES 30
417 #define MAX_POWERS 10
422 * Files
426 #define CONFIG_FILE_NAME "brickmania.cfg"
427 #define SAVE_FILE PLUGIN_GAMES_DIR "/brickmania.save"
428 #define SCORE_FILE PLUGIN_GAMES_DIR "/brickmania.score"
429 #define NUM_SCORES 5
434 * Game levels
438 #define NUM_BRICKS_ROWS 8
439 #define NUM_BRICKS_COLS 10
441 /* change to however many levels there are, i.e. how many arrays there are total */
442 #define NUM_LEVELS 40
444 /* change the first number in [ ] to however many levels there are */
445 static unsigned char levels[NUM_LEVELS][NUM_BRICKS_ROWS][NUM_BRICKS_COLS] =
446 /* You can set up new levels with the level editor
447 ( http://plugbox.rockbox-lounge.com/brickmania.htm ).
448 With 0x1, it refers to the first brick in the bitmap, 0x2 would refer to the
449 second, ect., 0x0 leaves a empty space. If you add a 2 before the 2nd number,
450 it will take two hits to break, and 3 hits if you add a 3. That is 0x24, will
451 result with the fourth brick being displayed and having take 2 hits to break.
452 You could do the same with the 3, just replace the 2 with a 3 for it to take
453 three hits to break it apart. */
455 { /* level 1 */
456 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
457 {0x2,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x2},
458 {0x0,0x2,0x1,0x0,0x0,0x0,0x0,0x1,0x2,0x0},
459 {0x0,0x0,0x2,0x1,0x0,0x0,0x1,0x2,0x0,0x0},
460 {0x0,0x0,0x0,0x2,0x1,0x1,0x2,0x0,0x0,0x0},
461 {0x7,0x0,0x0,0x7,0x2,0x2,0x7,0x0,0x0,0x7},
462 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
463 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
465 { /* level 2 */
466 {0x0,0x0,0x7,0x7,0x1,0x1,0x7,0x7,0x0,0x0},
467 {0x0,0x1,0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x0},
468 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
469 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1},
470 {0x1,0x1,0x2,0x1,0x0,0x0,0x1,0x2,0x1,0x1},
471 {0x1,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x2,0x1},
472 {0x0,0x1,0x2,0x0,0x0,0x0,0x0,0x2,0x1,0x0},
473 {0x0,0x0,0x1,0x2,0x2,0x2,0x2,0x1,0x0,0x0}
475 { /* level 3 */
476 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
477 {0x3,0x23,0x23,0x3,0x0,0x0,0x2,0x22,0x22,0x2},
478 {0x3,0x3,0x3,0x3,0x0,0x0,0x2,0x2,0x2,0x2},
479 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
480 {0x0,0x0,0x0,0x0,0x37,0x37,0x0,0x0,0x0,0x0},
481 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6},
482 {0x5,0x25,0x25,0x5,0x0,0x0,0x6,0x26,0x26,0x6},
483 {0x5,0x5,0x5,0x5,0x0,0x0,0x6,0x6,0x6,0x6}
485 { /* level 4 */
486 {0x0,0x0,0x0,0x27,0x27,0x27,0x27,0x0,0x0,0x0},
487 {0x0,0x0,0x0,0x27,0x7,0x7,0x27,0x0,0x0,0x0},
488 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
489 {0x22,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x22},
490 {0x26,0x6,0x0,0x2,0x2,0x2,0x2,0x0,0x6,0x26},
491 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
492 {0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0},
493 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1}
495 { /* level 5 */
496 {0x1,0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4},
497 {0x0,0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0},
498 {0x2,0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5},
499 {0x2,0x0,0x3,0x3,0x0,0x4,0x4,0x0,0x5,0x5},
500 {0x0,0x33,0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0},
501 {0x3,0x33,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x36},
502 {0x3,0x0,0x4,0x4,0x0,0x5,0x5,0x0,0x6,0x36},
503 {0x0,0x24,0x24,0x0,0x25,0x25,0x0,0x26,0x26,0x0}
505 { /* level 6 */
506 {0x0,0x1,0x3,0x7,0x7,0x7,0x7,0x3,0x1,0x0},
507 {0x3,0x1,0x3,0x7,0x0,0x0,0x7,0x3,0x1,0x3},
508 {0x3,0x1,0x3,0x7,0x7,0x7,0x7,0x3,0x1,0x3},
509 {0x0,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x0},
510 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5},
511 {0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5},
512 {0x0,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x0},
513 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
515 { /* level 7 */
516 {0x0,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x0},
517 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
518 {0x6,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x6},
519 {0x6,0x0,0x0,0x2,0x2,0x2,0x2,0x0,0x0,0x6},
520 {0x6,0x6,0x6,0x0,0x0,0x0,0x0,0x6,0x6,0x6},
521 {0x0,0x0,0x0,0x1,0x1,0x1,0x1,0x0,0x0,0x0},
522 {0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0},
523 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
525 { /* level 8 */
526 {0x0,0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x0},
527 {0x0,0x0,0x0,0x4,0x0,0x0,0x4,0x0,0x0,0x0},
528 {0x6,0x6,0x0,0x2,0x32,0x32,0x2,0x0,0x6,0x6},
529 {0x0,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x0,0x0},
530 {0x0,0x6,0x6,0x0,0x0,0x0,0x0,0x6,0x6,0x0},
531 {0x0,0x0,0x0,0x5,0x25,0x25,0x5,0x0,0x0,0x0},
532 {0x0,0x5,0x5,0x25,0x5,0x5,0x25,0x5,0x5,0x0},
533 {0x5,0x5,0x25,0x5,0x5,0x5,0x5,0x25,0x5,0x5}
535 { /* level 9 */
536 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
537 {0x2,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x2},
538 {0x2,0x0,0x3,0x0,0x1,0x1,0x0,0x3,0x0,0x2},
539 {0x2,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x2},
540 {0x2,0x0,0x1,0x0,0x3,0x3,0x0,0x1,0x0,0x2},
541 {0x2,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x2},
542 {0x2,0x2,0x0,0x0,0x1,0x1,0x0,0x0,0x2,0x2},
543 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
545 { /* level 10 */
546 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
547 {0x0,0x5,0x0,0x5,0x0,0x5,0x0,0x5,0x0,0x5},
548 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
549 {0x0,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x0},
550 {0x0,0x0,0x0,0x4,0x1,0x1,0x4,0x0,0x0,0x0},
551 {0x0,0x0,0x3,0x4,0x1,0x1,0x4,0x3,0x0,0x0},
552 {0x0,0x2,0x3,0x4,0x1,0x1,0x4,0x3,0x2,0x0},
553 {0x1,0x2,0x3,0x4,0x1,0x1,0x4,0x3,0x2,0x1}
555 { /* level 11 */
556 {0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3},
557 {0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x2},
558 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
559 {0x2,0x0,0x0,0x0,0x7,0x7,0x0,0x0,0x0,0x2},
560 {0x2,0x0,0x0,0x7,0x7,0x7,0x7,0x0,0x0,0x2},
561 {0x0,0x0,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x0},
562 {0x0,0x2,0x0,0x1,0x0,0x0,0x1,0x0,0x2,0x0},
563 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5}
565 { /* level 12 */
566 {0x2,0x1,0x3,0x1,0x0,0x0,0x1,0x3,0x1,0x2},
567 {0x1,0x1,0x1,0x1,0x0,0x0,0x1,0x1,0x1,0x1},
568 {0x1,0x1,0x1,0x0,0x1,0x1,0x0,0x1,0x1,0x1},
569 {0x0,0x1,0x0,0x1,0x6,0x6,0x1,0x0,0x1,0x0},
570 {0x0,0x0,0x1,0x1,0x6,0x6,0x1,0x1,0x0,0x0},
571 {0x1,0x1,0x1,0x7,0x0,0x0,0x7,0x1,0x1,0x1},
572 {0x1,0x1,0x7,0x1,0x0,0x0,0x1,0x7,0x1,0x1},
573 {0x2,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x2,0x2}
575 {/* levell13 */
576 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
577 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
578 {0x2,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x0,0x2},
579 {0x2,0x0,0x2,0x3,0x3,0x3,0x3,0x3,0x0,0x2},
580 {0x2,0x0,0x2,0x4,0x4,0x4,0x4,0x4,0x0,0x2},
581 {0x2,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2},
582 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
583 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
585 {/* level 14 */
586 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
587 {0x4,0x4,0x4,0x4,0x2,0x2,0x4,0x4,0x4,0x4},
588 {0x4,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x4},
589 {0x4,0x0,0x0,0x2,0x3,0x3,0x2,0x0,0x0,0x4},
590 {0x4,0x0,0x2,0x23,0x3,0x3,0x23,0x2,0x0,0x4},
591 {0x4,0x0,0x2,0x22,0x2,0x2,0x22,0x2,0x0,0x4},
592 {0x4,0x0,0x6,0x21,0x5,0x5,0x21,0x6,0x0,0x4},
593 {0x4,0x6,0x1,0x1,0x5,0x5,0x1,0x1,0x6,0x4}
595 {/* level 15 */
596 {0x4,0x4,0x4,0x4,0x4,0x3,0x3,0x3,0x3,0x3},
597 {0x2,0x2,0x1,0x1,0x1,0x1,0x1,0x5,0x0,0x0},
598 {0x2,0x2,0x1,0x1,0x1,0x0,0x1,0x6,0x0,0x0},
599 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x5,0x0,0x0},
600 {0x2,0x1,0x2,0x2,0x2,0x1,0x1,0x6,0x0,0x0},
601 {0x2,0x1,0x2,0x2,0x2,0x1,0x3,0x5,0x3,0x0},
602 {0x2,0x1,0x1,0x2,0x1,0x1,0x1,0x6,0x0,0x0},
603 {0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2}
605 {/* level 16 (Rockbox) by ts-x */
606 {0x2,0x2,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
607 {0x2,0x0,0x3,0x0,0x3,0x4,0x0,0x5,0x5,0x0},
608 {0x2,0x0,0x3,0x3,0x3,0x4,0x4,0x5,0x0,0x5},
609 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
610 {0x6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
611 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0},
612 {0x7,0x0,0x7,0x1,0x0,0x1,0x0,0x2,0x0,0x0},
613 {0x7,0x7,0x7,0x1,0x1,0x1,0x2,0x0,0x2,0x0}
615 {/* level 17 (Alien) by ts-x */
616 {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1},
617 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2},
618 {0x1,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x1},
619 {0x2,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x2},
620 {0x1,0x0,0x1,0x2,0x2,0x2,0x2,0x1,0x0,0x1},
621 {0x2,0x0,0x0,0x1,0x2,0x2,0x1,0x0,0x0,0x2},
622 {0x2,0x1,0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x2},
623 {0x2,0x2,0x1,0x0,0x1,0x1,0x0,0x1,0x2,0x2}
625 {/* level 18 (Tetris) by ts-x */
626 {0x0,0x2,0x0,0x0,0x3,0x4,0x0,0x2,0x2,0x0},
627 {0x0,0x2,0x7,0x0,0x3,0x4,0x0,0x2,0x2,0x0},
628 {0x2,0x2,0x7,0x0,0x3,0x4,0x0,0x6,0x2,0x2},
629 {0x2,0x2,0x7,0x7,0x3,0x4,0x0,0x6,0x2,0x2},
630 {0x2,0x1,0x7,0x7,0x3,0x4,0x4,0x6,0x5,0x5},
631 {0x2,0x1,0x0,0x7,0x3,0x4,0x4,0x6,0x5,0x5},
632 {0x1,0x1,0x1,0x7,0x3,0x0,0x6,0x6,0x5,0x5},
633 {0x1,0x1,0x1,0x0,0x3,0x0,0x6,0x6,0x5,0x5}
635 { /* level 19 (Stalactites) by ts-x */
636 {0x5,0x2,0x6,0x3,0x4,0x7,0x5,0x3,0x1,0x2},
637 {0x5,0x2,0x6,0x3,0x4,0x7,0x5,0x3,0x1,0x2},
638 {0x5,0x0,0x6,0x3,0x4,0x7,0x5,0x0,0x1,0x2},
639 {0x5,0x2,0x6,0x3,0x4,0x0,0x5,0x3,0x1,0x2},
640 {0x5,0x0,0x6,0x0,0x4,0x7,0x5,0x0,0x1,0x0},
641 {0x5,0x0,0x0,0x3,0x4,0x0,0x0,0x0,0x1,0x2},
642 {0x0,0x0,0x6,0x0,0x0,0x0,0x5,0x0,0x0,0x0},
643 {0x5,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x1,0x0}
645 { /* level 20 (Maze) by ts-x */
646 {0x1,0x1,0x21,0x1,0x1,0x1,0x1,0x1,0x1,0x21},
647 {0x1,0x0,0x0,0x3,0x0,0x0,0x3,0x1,0x31,0x1},
648 {0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x31,0x0,0x1},
649 {0x21,0x0,0x21,0x3,0x0,0x3,0x0,0x3,0x0,0x2},
650 {0x1,0x0,0x1,0x21,0x0,0x12,0x0,0x0,0x0,0x0},
651 {0x31,0x0,0x1,0x0,0x0,0x1,0x0,0x0,0x3,0x0},
652 {0x1,0x0,0x1,0x0,0x1,0x1,0x31,0x1,0x1,0x2},
653 {0x22,0x0,0x2,0x1,0x1,0x1,0x1,0x1,0x1,0x21}
655 { /* level 21 (Dentist) by ts-x */
656 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0},
657 {0x2,0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x2,0x2},
658 {0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x2},
659 {0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x6,0x0,0x2},
660 {0x2,0x0,0x6,0x0,0x6,0x0,0x0,0x0,0x0,0x2},
661 {0x2,0x0,0x6,0x0,0x6,0x0,0x6,0x0,0x6,0x2},
662 {0x2,0x2,0x6,0x0,0x6,0x0,0x6,0x0,0x2,0x2},
663 {0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0}
665 { /* level 22 (Spider) by ts-x */
666 {0x31,0x3,0x1,0x1,0x0,0x0,0x1,0x1,0x3,0x31},
667 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
668 {0x33,0x1,0x1,0x36,0x1,0x1,0x36,0x1,0x1,0x33},
669 {0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x0},
670 {0x0,0x0,0x1,0x1,0x0,0x0,0x1,0x1,0x0,0x0},
671 {0x21,0x3,0x1,0x21,0x2,0x2,0x21,0x1,0x3,0x21},
672 {0x0,0x0,0x0,0x1,0x21,0x1,0x1,0x0,0x0,0x0},
673 {0x3,0x1,0x3,0x1,0x0,0x0,0x1,0x3,0x1,0x3}
675 { /* level 23 (Pool) by ts-x */
676 {0x0,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x7,0x0},
677 {0x0,0x0,0x5,0x0,0x2,0x0,0x0,0x0,0x2,0x0},
678 {0x7,0x3,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x7},
679 {0x7,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x0,0x7},
680 {0x7,0x0,0x4,0x0,0x0,0x3,0x0,0x0,0x0,0x7},
681 {0x7,0x0,0x0,0x6,0x0,0x0,0x0,0x0,0x4,0x7},
682 {0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
683 {0x0,0x7,0x7,0x7,0x7,0x0,0x7,0x7,0x7,0x0}
685 { /* level 24 (Vorbis Fish) by ts-x */
686 {0x0,0x0,0x4,0x4,0x5,0x5,0x5,0x0,0x0,0x5},
687 {0x0,0x4,0x6,0x4,0x4,0x5,0x5,0x5,0x0,0x5},
688 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x5,0x5,0x5},
689 {0x5,0x6,0x0,0x6,0x4,0x4,0x4,0x4,0x5,0x5},
690 {0x0,0x5,0x6,0x4,0x4,0x5,0x5,0x4,0x5,0x0},
691 {0x5,0x5,0x4,0x4,0x5,0x5,0x5,0x4,0x5,0x5},
692 {0x5,0x4,0x4,0x4,0x5,0x5,0x4,0x4,0x5,0x5},
693 {0x0,0x0,0x4,0x4,0x4,0x4,0x4,0x5,0x0,0x5}
695 {/* level 25 (Rainbow) by ts-x */
696 {0x0,0x4,0x1,0x0,0x0,0x0,0x0,0x1,0x4,0x0},
697 {0x24,0x1,0x3,0x1,0x0,0x0,0x21,0x3,0x1,0x24},
698 {0x1,0x23,0x5,0x3,0x1,0x21,0x3,0x5,0x3,0x21},
699 {0x3,0x5,0x6,0x5,0x3,0x3,0x5,0x6,0x5,0x3},
700 {0x5,0x6,0x7,0x6,0x5,0x5,0x6,0x7,0x6,0x5},
701 {0x6,0x7,0x2,0x27,0x6,0x6,0x27,0x2,0x7,0x6},
702 {0x7,0x2,0x0,0x2,0x27,0x27,0x2,0x0,0x2,0x7},
703 {0x32,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x32}
705 { /* level 26 (Bowtie) by ts-x */
706 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5},
707 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
708 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
709 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
710 {0x1,0x0,0x6,0x6,0x0,0x0,0x6,0x6,0x0,0x1},
711 {0x5,0x0,0x6,0x0,0x1,0x1,0x0,0x6,0x0,0x5},
712 {0x1,0x0,0x0,0x1,0x5,0x5,0x1,0x0,0x0,0x1},
713 {0x5,0x1,0x5,0x1,0x0,0x0,0x1,0x5,0x1,0x5}
715 { /* level 27 (Frog) by ts-x */
716 {0x0,0x5,0x25,0x0,0x0,0x0,0x0,0x25,0x5,0x0},
717 {0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5},
718 {0x25,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x25},
719 {0x5,0x0,0x3,0x0,0x6,0x6,0x0,0x3,0x0,0x5},
720 {0x5,0x0,0x31,0x0,0x6,0x6,0x0,0x31,0x0,0x5},
721 {0x5,0x0,0x0,0x5,0x6,0x6,0x5,0x0,0x0,0x5},
722 {0x5,0x5,0x5,0x35,0x0,0x0,0x35,0x5,0x5,0x5},
723 {0x0,0x25,0x5,0x0,0x4,0x4,0x0,0x5,0x25,0x0}
725 { /* level 28 (DigDug) by ts-x */
726 {0x35,0x5,0x5,0x25,0x0,0x25,0x25,0x5,0x5,0x35},
727 {0x6,0x0,0x0,0x6,0x0,0x6,0x6,0x0,0x0,0x6},
728 {0x7,0x0,0x37,0x37,0x0,0x37,0x37,0x7,0x0,0x7},
729 {0x7,0x0,0x7,0x0,0x0,0x0,0x7,0x7,0x7,0x7},
730 {0x4,0x4,0x4,0x24,0x0,0x24,0x4,0x0,0x0,0x4},
731 {0x4,0x4,0x0,0x0,0x0,0x4,0x4,0x0,0x4,0x4},
732 {0x24,0x24,0x4,0x4,0x4,0x4,0x0,0x0,0x24,0x4},
733 {0x1,0x1,0x1,0x1,0x1,0x1,0x21,0x21,0x1,0x1}
735 { /* level 29 UK Flag by Seth Opgenorth */
736 {0x32,0x0,0x3,0x3,0x2,0x2,0x3,0x3,0x0,0x32},
737 {0x0,0x2,0x0,0x3,0x32,0x22,0x33,0x0,0x32,0x0},
738 {0x33,0x0,0x22,0x0,0x2,0x2,0x0,0x2,0x0,0x33},
739 {0x22,0x32,0x2,0x2,0x2,0x2,0x2,0x2,0x22,0x2},
740 {0x3,0x0,0x0,0x32,0x22,0x2,0x2,0x0,0x0,0x3},
741 {0x23,0x0,0x32,0x0,0x32,0x2,0x0,0x2,0x0,0x3},
742 {0x0,0x2,0x0,0x3,0x2,0x2,0x3,0x0,0x22,0x0},
743 {0x32,0x0,0x3,0x23,0x2,0x2,0x23,0x33,0x0,0x32}
745 { /* level 30 Win-Logo by Seth Opgenorth */
746 {0x0,0x0,0x0,0x22,0x0,0x0,0x0,0x0,0x0,0x0},
747 {0x0,0x0,0x32,0x2,0x2,0x25,0x0,0x5,0x0,0x0},
748 {0x0,0x0,0x2,0x22,0x2,0x5,0x5,0x35,0x0,0x0},
749 {0x0,0x0,0x2,0x1,0x2,0x5,0x5,0x25,0x0,0x0},
750 {0x0,0x0,0x21,0x1,0x1,0x36,0x7,0x26,0x0,0x0},
751 {0x0,0x0,0x1,0x1,0x1,0x6,0x6,0x6,0x0,0x0},
752 {0x0,0x0,0x21,0x0,0x21,0x6,0x6,0x26,0x0,0x0},
753 {0x0,0x0,0x0,0x0,0x0,0x0,0x6,0x0,0x0,0x0}
755 { /* level 31 Color wave/V by Seth Opgenorth */
756 {0x25,0x34,0x2,0x31,0x33,0x23,0x1,0x2,0x34,0x5},
757 {0x3,0x5,0x24,0x2,0x1,0x1,0x2,0x4,0x5,0x3},
758 {0x1,0x3,0x5,0x4,0x2,0x2,0x4,0x5,0x3,0x1},
759 {0x2,0x1,0x33,0x35,0x4,0x4,0x5,0x33,0x1,0x22},
760 {0x31,0x22,0x1,0x3,0x5,0x25,0x3,0x1,0x2,0x31},
761 {0x3,0x1,0x2,0x1,0x3,0x3,0x1,0x2,0x21,0x3},
762 {0x5,0x23,0x1,0x32,0x1,0x1,0x2,0x1,0x3,0x5},
763 {0x4,0x35,0x3,0x1,0x2,0x22,0x31,0x3,0x5,0x4}
765 { /* level 32 Sweedish Flag by Seth Opgenorth */
766 {0x3,0x3,0x3,0x36,0x3,0x3,0x3,0x3,0x3,0x3},
767 {0x3,0x3,0x3,0x36,0x3,0x3,0x3,0x3,0x3,0x3},
768 {0x3,0x3,0x3,0x36,0x3,0x3,0x3,0x3,0x3,0x3},
769 {0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36},
770 {0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36},
771 {0x3,0x3,0x3,0x36,0x3,0x3,0x3,0x3,0x3,0x3},
772 {0x3,0x3,0x3,0x36,0x3,0x3,0x3,0x3,0x3,0x3},
773 {0x3,0x3,0x3,0x36,0x3,0x3,0x3,0x3,0x3,0x3}
775 { /* level 33 Color Pyramid by Seth Opgenorth */
776 {0x0,0x0,0x0,0x0,0x2,0x2,0x0,0x0,0x0,0x0},
777 {0x0,0x0,0x0,0x4,0x24,0x4,0x24,0x0,0x0,0x0},
778 {0x0,0x0,0x23,0x3,0x3,0x3,0x23,0x3,0x0,0x0},
779 {0x0,0x0,0x25,0x5,0x25,0x35,0x5,0x35,0x0,0x0},
780 {0x0,0x36,0x6,0x6,0x6,0x6,0x26,0x6,0x6,0x0},
781 {0x0,0x7,0x7,0x7,0x7,0x25,0x27,0x7,0x27,0x0},
782 {0x2,0x2,0x22,0x2,0x2,0x2,0x22,0x2,0x2,0x2},
783 {0x21,0x1,0x1,0x31,0x1,0x21,0x1,0x1,0x31,0x1}
785 { /* level 34 Rhombus by Seth Opgenorth */
786 {0x0,0x0,0x0,0x0,0x3,0x33,0x0,0x0,0x0,0x0},
787 {0x0,0x0,0x0,0x3,0x32,0x22,0x23,0x0,0x0,0x0},
788 {0x0,0x0,0x3,0x2,0x24,0x4,0x2,0x23,0x0,0x0},
789 {0x26,0x3,0x2,0x4,0x5,0x5,0x4,0x22,0x3,0x6},
790 {0x36,0x3,0x2,0x34,0x5,0x5,0x4,0x2,0x3,0x36},
791 {0x0,0x0,0x3,0x2,0x4,0x34,0x2,0x23,0x0,0x0},
792 {0x0,0x0,0x0,0x23,0x2,0x2,0x3,0x0,0x0,0x0},
793 {0x0,0x0,0x0,0x0,0x3,0x33,0x0,0x0,0x0,0x0}
795 { /* level 35 PacMan Ghost by Seth Opgenorth */
796 {0x0,0x0,0x0,0x0,0x2,0x32,0x2,0x0,0x0,0x0},
797 {0x0,0x0,0x0,0x2,0x2,0x2,0x2,0x2,0x0,0x0},
798 {0x0,0x0,0x2,0x24,0x4,0x2,0x4,0x4,0x32,0x0},
799 {0x0,0x0,0x2,0x24,0x0,0x22,0x24,0x0,0x22,0x0},
800 {0x0,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0},
801 {0x0,0x0,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0},
802 {0x0,0x0,0x2,0x32,0x2,0x2,0x22,0x2,0x32,0x0},
803 {0x0,0x0,0x0,0x22,0x0,0x32,0x0,0x22,0x0,0x0}
805 { /* level 36 Star by Seth Opgenorth */
806 {0x3,0x4,0x3,0x4,0x6,0x24,0x3,0x24,0x3,0x0},
807 {0x24,0x0,0x0,0x6,0x6,0x6,0x0,0x0,0x4,0x0},
808 {0x3,0x26,0x6,0x2,0x6,0x2,0x6,0x26,0x23,0x0},
809 {0x4,0x0,0x6,0x6,0x36,0x6,0x6,0x0,0x4,0x0},
810 {0x3,0x0,0x0,0x26,0x6,0x26,0x0,0x0,0x33,0x0},
811 {0x34,0x0,0x6,0x6,0x0,0x6,0x6,0x0,0x4,0x0},
812 {0x3,0x26,0x6,0x0,0x0,0x0,0x6,0x6,0x3,0x0},
813 {0x4,0x3,0x4,0x23,0x24,0x3,0x4,0x33,0x4,0x0}
815 { /* level 37 It's 8-Bit by Seth Opgenorth */
816 {0x26,0x26,0x6,0x6,0x5,0x6,0x26,0x6,0x26,0x6},
817 {0x2,0x2,0x22,0x3,0x3,0x0,0x0,0x0,0x4,0x0},
818 {0x2,0x0,0x2,0x33,0x3,0x3,0x5,0x0,0x24,0x0},
819 {0x32,0x2,0x2,0x33,0x0,0x23,0x0,0x4,0x4,0x4},
820 {0x2,0x22,0x2,0x3,0x3,0x0,0x5,0x4,0x4,0x24},
821 {0x2,0x0,0x2,0x23,0x0,0x3,0x25,0x0,0x4,0x0},
822 {0x22,0x2,0x2,0x3,0x23,0x0,0x5,0x0,0x4,0x0},
823 {0x6,0x26,0x6,0x36,0x6,0x36,0x6,0x6,0x6,0x6}
825 { /* level 38 Linux by Seth Opgenorth */
826 {0x27,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
827 {0x7,0x0,0x0,0x0,0x33,0x0,0x23,0x0,0x0,0x0},
828 {0x7,0x32,0x0,0x0,0x3,0x0,0x23,0x6,0x0,0x6},
829 {0x37,0x0,0x0,0x0,0x23,0x0,0x3,0x6,0x0,0x26},
830 {0x7,0x22,0x24,0x0,0x3,0x33,0x3,0x0,0x26,0x0},
831 {0x37,0x22,0x24,0x24,0x4,0x0,0x0,0x0,0x26,0x0},
832 {0x7,0x2,0x4,0x0,0x4,0x0,0x0,0x6,0x0,0x26},
833 {0x7,0x27,0x4,0x0,0x34,0x0,0x0,0x6,0x0,0x26}
835 { /* level 39 Colorful Squares by Seth Opgenorth*/
836 {0x0,0x4,0x4,0x4,0x4,0x4,0x4,0x4,0x4,0x0},
837 {0x0,0x4,0x5,0x5,0x5,0x5,0x5,0x5,0x4,0x0},
838 {0x0,0x4,0x5,0x3,0x3,0x3,0x3,0x5,0x4,0x0},
839 {0x0,0x4,0x5,0x3,0x4,0x4,0x3,0x5,0x4,0x0},
840 {0x0,0x4,0x5,0x3,0x4,0x4,0x3,0x5,0x4,0x0},
841 {0x0,0x4,0x5,0x3,0x3,0x3,0x3,0x5,0x4,0x0},
842 {0x0,0x4,0x5,0x5,0x5,0x5,0x5,0x5,0x4,0x0},
843 {0x0,0x4,0x4,0x4,0x4,0x4,0x4,0x4,0x4,0x0}
845 { /* TheEnd */
846 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
847 {0x32,0x32,0x36,0x0,0x0,0x36,0x34,0x34,0x0,0x0},
848 {0x32,0x0,0x36,0x36,0x0,0x36,0x34,0x0,0x34,0x0},
849 {0x32,0x32,0x36,0x36,0x0,0x36,0x34,0x0,0x34,0x0},
850 {0x32,0x32,0x36,0x0,0x36,0x36,0x34,0x0,0x34,0x0},
851 {0x32,0x0,0x36,0x0,0x36,0x36,0x34,0x0,0x34,0x0},
852 {0x32,0x32,0x36,0x0,0x0,0x36,0x34,0x34,0x0,0x0},
853 {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
860 * Enums and structs
864 enum power_types
866 POWER_TYPE_LIFE_GAIN = 0,
867 POWER_TYPE_LIFE_LOSS,
868 POWER_TYPE_PADDLE_STICKY,
869 POWER_TYPE_PADDLE_SHOOTER,
870 POWER_TYPE_PADDLE_NORMAL,
871 POWER_TYPE_PADDLE_FLIP,
872 POWER_TYPE_EXTRA_BALL,
873 POWER_TYPE_PADDLE_LONG,
874 POWER_TYPE_PADDLE_SHORT,
875 NUMBER_OF_POWERUPS,
878 #define POWERUP_HEIGHT FIXED3(BMPHEIGHT_brickmania_powerups/NUMBER_OF_POWERUPS)
879 /* Increasing this value makes the game with less powerups */
880 #define POWER_RAND (NUMBER_OF_POWERUPS + 15)
882 enum difficulty_options
884 EASY,
885 NORMAL
888 enum game_state
890 ST_READY,
891 ST_START,
892 ST_PAUSE
895 enum paddle_type
897 PADDLE_TYPE_NORMAL = 0,
898 PADDLE_TYPE_STICKY,
899 PADDLE_TYPE_SHOOTER,
902 enum intersection
904 INTERSECTION_TOP,
905 INTERSECTION_BOTTOM,
906 INTERSECTION_LEFT,
907 INTERSECTION_RIGHT,
908 INTERSECTION_ALL,
911 struct brick
913 bool used; /* Is the brick still in play? */
914 int color;
915 int hits; /* How many hits can this brick take? */
916 int hiteffect;
919 struct ball
921 /* pos_x and y store the current center position of the ball */
922 int pos_x;
923 int pos_y;
924 /* tempx and tempy store an absolute position the ball should be in. If
925 * they are equal to 0, they are not used when positioning the ball.
927 int tempx;
928 int tempy;
929 /* speedx and speedy store the current speed of the ball */
930 int speedx;
931 int speedy;
932 bool glue; /* Is the ball stuck to the paddle? */
935 struct fire
937 int top; /* This stores the fire y position, it is a fixed point num */
938 int x_pos; /* This stores the fire x position, it is a whole number */
941 struct power
943 int top; /* This stores the powerup y position, it is a fixed point num */
944 int x_pos; /* This stores the (middle of) powerup x position, it is a whole number */
945 enum power_types type; /* This stores the powerup type */
948 struct point
950 int x;
951 int y;
954 struct line
956 struct point p1;
957 struct point p2;
960 struct rect
962 struct point top_left;
963 struct point bottom_right;
968 * Globals
972 static enum game_state game_state = ST_READY;
973 static int pad_pos_x;
974 static int life;
975 static int score=0,vscore=0;
976 static bool flip_sides=false;
977 static int level=0;
978 static int brick_on_board=0;
979 static int used_balls=1;
980 static int used_fires=0;
981 static int used_powers=0;
982 static int difficulty = NORMAL;
983 static int pad_width;
984 static int flip_sides_delay;
985 static bool resume = false;
986 static bool resume_file = false;
987 static struct brick brick[NUM_BRICKS_ROWS][NUM_BRICKS_COLS];
988 static struct ball ball[MAX_BALLS];
989 static struct fire fire[MAX_FIRES];
990 static struct power power[MAX_POWERS];
991 static enum paddle_type paddle_type;
993 static struct configdata config[] =
995 {TYPE_INT, 0, 1, { .int_p = &difficulty }, "difficulty", NULL},
998 static struct highscore highscores[NUM_SCORES];
1003 * Functions
1008 * check_lines:
1009 * This is based off an explanation and expanded math presented by Paul Bourke:
1010 * http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
1012 * It takes two lines as inputs and returns 1 if they intersect, 0 if they do
1013 * not. hitp returns the point where the two lines intersected.
1015 * This function expects fixed point inputs with a precision of 3. When a
1016 * collision occurs hitp is updated with a fixed point location (precision 3)
1017 * where the collision happened. The internal calculations are fixed
1018 * point with a 7 bit fractional precision.
1020 * If you choose 10 bits of precision a screen size of about 640x480 is the
1021 * largest this can go. 7 bits allows for an accurate intersection calculation
1022 * with a line length of about 64 and a rougher line lenght of 128 which is
1023 * larger than any target currently needs (the pad is the longest line and it
1024 * only needs an accuracy of 2^4 at most to figure out which section of the pad
1025 * the ball hit). A precision of 7 gives breathing room for larger screens.
1026 * Longer line sizes that need accurate intersection points will need more
1027 * precision, but will decrease the maximum screen resolution.
1030 #define LINE_PREC 7
1031 static int check_lines(struct line *line1, struct line *line2,
1032 struct point *hitp)
1034 /* Introduction:
1035 * This code is based on the solution of these two input equations:
1036 * Pa = P1 + ua (P2-P1)
1037 * Pb = P3 + ub (P4-P3)
1039 * Where line one is composed of points P1 and P2 and line two is composed
1040 * of points P3 and P4.
1042 * ua/b is the fractional value you can multiply the x and y legs of the
1043 * triangle formed by each line to find a point on the line.
1045 * The two equations can be expanded to their x/y components:
1046 * Pa.x = p1.x + ua(p2.x - p1.x)
1047 * Pa.y = p1.y + ua(p2.y - p1.y)
1049 * Pb.x = p3.x + ub(p4.x - p3.x)
1050 * Pb.y = p3.y + ub(p4.y - p3.y)
1052 * When Pa.x == Pb.x and Pa.y == Pb.y the lines intersect so you can come
1053 * up with two equations (one for x and one for y):
1055 * p1.x + ua(p2.x - p1.x) = p3.x + ub(p4.x - p3.x)
1056 * p1.y + ua(p2.y - p1.y) = p3.y + ub(p4.y - p3.y)
1058 * ua and ub can then be individually solved for. This results in the
1059 * equations used in the following code.
1062 /* Denominator for ua and ub are the same so store this calculation */
1063 int d = FIXED3_MUL((line2->p2.y - line2->p1.y),(line1->p2.x-line1->p1.x))
1064 -FIXED3_MUL((line2->p2.x - line2->p1.x),(line1->p2.y-line1->p1.y));
1066 /* n_a and n_b are calculated as seperate values for readability */
1067 int n_a = FIXED3_MUL((line2->p2.x - line2->p1.x),(line1->p1.y-line2->p1.y))
1068 -FIXED3_MUL((line2->p2.y - line2->p1.y),(line1->p1.x-line2->p1.x));
1070 int n_b = FIXED3_MUL((line1->p2.x - line1->p1.x),(line1->p1.y-line2->p1.y))
1071 -FIXED3_MUL((line1->p2.y - line1->p1.y),(line1->p1.x-line2->p1.x));
1073 /* Make sure there is not a division by zero - this also indicates that
1074 * the lines are parallel.
1076 * If n_a and n_b were both equal to zero the lines would be on top of each
1077 * other (coincidental). This check is not done because it is not
1078 * necessary for this implementation (the parallel check accounts for this).
1080 if(d == 0)
1081 return 0;
1083 /* Calculate the intermediate fractional point that the lines potentially
1084 * intersect.
1086 int ua = (n_a << LINE_PREC)/d;
1087 int ub = (n_b << LINE_PREC)/d;
1089 /* The fractional point will be between 0 and 1 inclusive if the lines
1090 * intersect. If the fractional calculation is larger than 1 or smaller
1091 * than 0 the lines would need to be longer to intersect.
1093 if(ua >=0 && ua <= (1<<LINE_PREC) && ub >= 0 && ub <= (1<<LINE_PREC))
1095 hitp->x = line1->p1.x + ((ua * (line1->p2.x - line1->p1.x))>>LINE_PREC);
1096 hitp->y = line1->p1.y + ((ua * (line1->p2.y - line1->p1.y))>>LINE_PREC);
1097 return 1;
1099 return 0;
1103 static int check_rect(struct line *line, struct rect *rect,
1104 enum intersection intersection, struct point *hitp)
1106 struct line edge;
1108 switch (intersection)
1110 case INTERSECTION_TOP:
1112 edge.p1.x = rect->top_left.x;
1113 edge.p1.y = rect->top_left.y;
1115 edge.p2.x = rect->bottom_right.x;
1116 edge.p2.y = rect->top_left.y;
1118 break;
1120 case INTERSECTION_BOTTOM:
1122 edge.p1.x = rect->top_left.x;
1123 edge.p1.y = rect->bottom_right.y;
1125 edge.p2.x = rect->bottom_right.x;
1126 edge.p2.y = rect->bottom_right.y;
1128 break;
1130 case INTERSECTION_LEFT:
1132 edge.p1.x = rect->top_left.x;
1133 edge.p1.y = rect->top_left.y;
1135 edge.p2.x = rect->top_left.x;
1136 edge.p2.y = rect->bottom_right.y;
1138 break;
1140 case INTERSECTION_RIGHT:
1142 edge.p1.x = rect->bottom_right.x;
1143 edge.p1.y = rect->top_left.y;
1145 edge.p2.x = rect->bottom_right.x;
1146 edge.p2.y = rect->bottom_right.y;
1148 break;
1150 case INTERSECTION_ALL: /* Test hit on all edges */
1152 return (check_rect(line, rect, INTERSECTION_TOP, hitp) ||
1153 check_rect(line, rect, INTERSECTION_BOTTOM, hitp) ||
1154 check_rect(line, rect, INTERSECTION_LEFT, hitp) ||
1155 check_rect(line, rect, INTERSECTION_RIGHT, hitp));
1159 return check_lines(line, &edge, hitp);
1162 static void brickmania_init_game(bool new_game)
1164 int i,j;
1166 pad_pos_x = GAMESCREEN_WIDTH/2 - PAD_WIDTH/2;
1168 for(i=0;i<MAX_BALLS;i++)
1170 ball[i].speedx = 0;
1171 ball[i].speedy = 0;
1172 ball[i].tempy = 0;
1173 ball[i].tempx = 0;
1174 ball[i].pos_y = ON_PAD_POS_Y;
1175 ball[i].pos_x = GAMESCREEN_WIDTH/2;
1176 ball[i].glue = false;
1179 used_balls = 1;
1180 used_fires = 0;
1181 used_powers = 0;
1182 game_state = ST_READY;
1183 paddle_type = PADDLE_TYPE_NORMAL;
1184 pad_width = PAD_WIDTH;
1185 flip_sides = false;
1186 flip_sides_delay = FLIP_SIDES_DELAY;
1188 if (new_game) {
1189 brick_on_board=0;
1190 /* add one life per achieved level */
1191 if (difficulty==EASY && life<2) {
1192 score+=SCORE_LEVEL_COMPLETED;
1193 life++;
1197 for(i=0;i<NUM_BRICKS_ROWS;i++) {
1198 for(j=0;j<NUM_BRICKS_COLS;j++) {
1199 if (new_game) {
1200 brick[i][j].hits=levels[level][i][j]>=10?
1201 levels[level][i][j]/16-1:0;
1202 brick[i][j].hiteffect=0;
1203 brick[i][j].used=!(levels[level][i][j]==0);
1204 brick[i][j].color=(levels[level][i][j]>=10?
1205 levels[level][i][j]%16:
1206 levels[level][i][j])-1;
1207 if (levels[level][i][j]!=0)
1208 brick_on_board++;
1214 static void brickmania_loadgame(void)
1216 int fd;
1218 resume = false;
1220 /* open game file */
1221 fd = rb->open(SAVE_FILE, O_RDONLY);
1222 if(fd < 0) return;
1224 /* read in saved game */
1225 if((rb->read(fd, &pad_pos_x, sizeof(pad_pos_x)) <= 0) ||
1226 (rb->read(fd, &life, sizeof(life)) <= 0) ||
1227 (rb->read(fd, &game_state, sizeof(game_state)) <= 0) ||
1228 (rb->read(fd, &paddle_type, sizeof(paddle_type)) <= 0) ||
1229 (rb->read(fd, &score, sizeof(score)) <= 0) ||
1230 (rb->read(fd, &flip_sides, sizeof(flip_sides)) <= 0) ||
1231 (rb->read(fd, &level, sizeof(level)) <= 0) ||
1232 (rb->read(fd, &brick_on_board, sizeof(brick_on_board)) <= 0) ||
1233 (rb->read(fd, &used_balls, sizeof(used_balls)) <= 0) ||
1234 (rb->read(fd, &used_fires, sizeof(used_fires)) <= 0) ||
1235 (rb->read(fd, &used_powers, sizeof(used_powers)) <= 0) ||
1236 (rb->read(fd, &pad_width, sizeof(pad_width)) <= 0) ||
1237 (rb->read(fd, &flip_sides_delay, sizeof(flip_sides_delay)) <= 0) ||
1238 (rb->read(fd, &brick, sizeof(brick)) <= 0) ||
1239 (rb->read(fd, &ball, sizeof(ball)) <= 0) ||
1240 (rb->read(fd, &fire, sizeof(fire)) <= 0) ||
1241 (rb->read(fd, &power, sizeof(power)) <= 0))
1243 rb->splash(HZ/2, "Failed to load game");
1245 else
1247 vscore = score;
1248 resume = true;
1251 rb->close(fd);
1253 return;
1256 static void brickmania_savegame(void)
1258 int fd;
1260 /* write out the game state to the save file */
1261 fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
1262 if(fd < 0) return;
1264 if ((rb->write(fd, &pad_pos_x, sizeof(pad_pos_x)) <= 0) ||
1265 (rb->write(fd, &life, sizeof(life)) <= 0) ||
1266 (rb->write(fd, &game_state, sizeof(game_state)) <= 0) ||
1267 (rb->write(fd, &paddle_type, sizeof(paddle_type)) <= 0) ||
1268 (rb->write(fd, &score, sizeof(score)) <= 0) ||
1269 (rb->write(fd, &flip_sides, sizeof(flip_sides)) <= 0) ||
1270 (rb->write(fd, &level, sizeof(level)) <= 0) ||
1271 (rb->write(fd, &brick_on_board, sizeof(brick_on_board)) <= 0) ||
1272 (rb->write(fd, &used_balls, sizeof(used_balls)) <= 0) ||
1273 (rb->write(fd, &used_fires, sizeof(used_fires)) <= 0) ||
1274 (rb->write(fd, &used_powers, sizeof(used_powers)) <= 0) ||
1275 (rb->write(fd, &pad_width, sizeof(pad_width)) <= 0) ||
1276 (rb->write(fd, &flip_sides_delay, sizeof(flip_sides_delay)) <= 0) ||
1277 (rb->write(fd, &brick, sizeof(brick)) <= 0) ||
1278 (rb->write(fd, &ball, sizeof(ball)) <= 0) ||
1279 (rb->write(fd, &fire, sizeof(fire)) <= 0) ||
1280 (rb->write(fd, &power, sizeof(power)) <= 0))
1282 rb->close(fd);
1283 rb->remove(SAVE_FILE);
1284 rb->splash(HZ/2, "Failed to save game");
1285 return;
1288 rb->close(fd);
1291 /* brickmania_sleep timer counting the score */
1292 static void brickmania_sleep(int secs)
1294 bool done=false;
1295 char s[20];
1296 int count=0;
1297 int sw, w;
1299 while (!done)
1301 if (count == 0)
1302 count = *rb->current_tick + HZ*secs;
1303 if ( (TIME_AFTER(*rb->current_tick, count)) && (vscore == score) )
1304 done = true;
1306 if(vscore != score)
1308 if (vscore<score)
1309 vscore++;
1310 if (vscore>score)
1311 vscore--;
1312 rb->snprintf(s, sizeof(s), "%d", vscore);
1313 rb->lcd_getstringsize(s, &sw, &w);
1314 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
1315 rb->lcd_update_rect(0,0,LCD_WIDTH,w+2);
1317 rb->yield();
1321 static int brickmania_help(void)
1323 static char *help_text[] = {
1324 "Brickmania", "", "Aim", "",
1325 "Destroy", "all", "the", "bricks", "by", "bouncing",
1326 "the", "ball", "of", "them", "using", "the", "paddle.", "", "",
1327 "Controls", "",
1328 #if CONFIG_KEYPAD == COWON_D2_PAD
1329 "- & +:",
1330 #else
1331 "< & >:",
1332 #endif
1333 "Moves", "the", "paddle", "",
1334 #if CONFIG_KEYPAD == ONDIO_PAD
1335 "MENU:",
1336 #elif (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1337 "PLAY:",
1338 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
1339 "NAVI:",
1340 #elif CONFIG_KEYPAD == COWON_D2_PAD
1341 "MENU:",
1342 #else
1343 "SELECT:",
1344 #endif
1345 "Releases", "the", "ball/Fire!", "",
1346 #if CONFIG_KEYPAD == IAUDIO_M3_PAD
1347 "REC:",
1348 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
1349 (CONFIG_KEYPAD == CREATIVEZVM_PAD)
1350 "BACK:",
1351 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
1352 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1353 (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
1354 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
1355 "MENU:",
1356 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
1357 (CONFIG_KEYPAD == IRIVER_H300_PAD) || \
1358 (CONFIG_KEYPAD == ONDIO_PAD) || \
1359 (CONFIG_KEYPAD == RECORDER_PAD) || \
1360 (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
1361 "STOP:",
1362 #else
1363 "POWER:",
1364 #endif
1365 "Returns", "to", "menu", "", "",
1366 "Specials", "",
1367 "N", "Normal:", "returns", "paddle", "to", "normal", "",
1368 "D", "DIE!:", "loses", "a", "life", "",
1369 "L", "Life:", "gains", "a", "life/power", "up", "",
1370 "F", "Fire:", "allows", "you", "to", "shoot", "bricks", "",
1371 "G", "Glue:", "ball", "sticks", "to", "paddle", "",
1372 "B", "Ball:", "generates", "another", "ball", "",
1373 "FL", "Flip:", "flips", "left / right", "movement", "",
1374 "<->", "or", "<E>:", "enlarges", "the", "paddle", "",
1375 ">-<", "or", ">S<:", "shrinks", "the", "paddle", "",
1377 static struct style_text formation[]={
1378 { 0, TEXT_CENTER|TEXT_UNDERLINE },
1379 { 2, C_RED },
1380 { 19, C_RED },
1381 { 37, C_RED },
1382 { 39, C_BLUE },
1383 { 46, C_RED },
1384 { 52, C_GREEN },
1385 { 59, C_ORANGE },
1386 { 67, C_GREEN },
1387 { 74, C_YELLOW },
1388 { 80, C_RED },
1389 LAST_STYLE_ITEM
1392 rb->lcd_setfont(FONT_UI);
1393 #ifdef HAVE_LCD_COLOR
1394 rb->lcd_set_background(LCD_BLACK);
1395 rb->lcd_set_foreground(LCD_WHITE);
1396 #endif
1397 if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
1398 return 1;
1399 rb->lcd_setfont(FONT_SYSFIXED);
1401 return 0;
1404 static int brickmania_menu_cb(int action, const struct menu_item_ex *this_item)
1406 int i = ((intptr_t)this_item);
1407 if(action == ACTION_REQUEST_MENUITEM
1408 && !resume && (i==0 || i==6))
1409 return ACTION_EXIT_MENUITEM;
1410 return action;
1413 static int brickmania_menu(void)
1415 int selected = 0;
1417 static struct opt_items options[] = {
1418 { "Easy", -1 },
1419 { "Normal", -1 },
1422 #ifdef HAVE_TOUCHSCREEN
1423 /* Entering Menu, set the touchscreen to the global setting */
1424 rb->touchscreen_set_mode(rb->global_settings->touch_mode);
1425 #endif
1427 MENUITEM_STRINGLIST(main_menu, "Brickmania Menu", brickmania_menu_cb,
1428 "Resume Game", "Start New Game",
1429 "Difficulty", "Help", "High Scores",
1430 "Playback Control",
1431 "Quit without Saving", "Quit");
1433 rb->button_clear_queue();
1434 while (true) {
1435 switch (rb->do_menu(&main_menu, &selected, NULL, false)) {
1436 case 0:
1437 if(game_state!=ST_READY)
1438 game_state = ST_PAUSE;
1439 if(resume_file)
1440 rb->remove(SAVE_FILE);
1441 return 0;
1442 case 1:
1443 score=0;
1444 vscore=0;
1445 life=2;
1446 level=0;
1447 brickmania_init_game(true);
1448 return 0;
1449 case 2:
1450 rb->set_option("Difficulty", &difficulty, INT,
1451 options, 2, NULL);
1452 break;
1453 case 3:
1454 if (brickmania_help())
1455 return 1;
1456 break;
1457 case 4:
1458 highscore_show(-1, highscores, NUM_SCORES, true);
1459 break;
1460 case 5:
1461 if (playback_control(NULL))
1462 return 1;
1463 break;
1464 case 6:
1465 return 1;
1466 case 7:
1467 if (resume) {
1468 rb->splash(HZ*1, "Saving game ...");
1469 brickmania_savegame();
1471 return 1;
1472 case MENU_ATTACHED_USB:
1473 return 1;
1474 default:
1475 break;
1478 #ifdef HAVE_TOUCHSCREEN
1479 rb->touchscreen_set_mode(TOUCHSCREEN_POINT);
1480 #endif
1483 static void brick_hit(int i, int j)
1485 if(!brick[i][j].used)
1486 return;
1488 /* if this is a crackable brick hits starts as
1489 * greater than 0.
1491 if (brick[i][j].hits > 0) {
1492 brick[i][j].hits--;
1493 brick[i][j].hiteffect++;
1494 score+=SCORE_BALL_HIT_BRICK;
1496 else {
1497 brick[i][j].used=false;
1498 if (used_powers<MAX_POWERS)
1500 int ran = rb->rand()%POWER_RAND;
1502 if (ran<NUMBER_OF_POWERUPS)
1504 power[used_powers].top = TOPMARGIN + i*BRICK_HEIGHT;
1505 power[used_powers].x_pos = LEFTMARGIN + j*BRICK_WIDTH +
1506 (BRICK_WIDTH >> 1);
1507 power[used_powers].type = ran;
1508 used_powers++;
1511 brick_on_board--;
1512 score+=SCORE_BALL_DEMOLISHED_BRICK;
1516 static int brickmania_game_loop(void)
1518 int j,i,k;
1519 int sw;
1520 char s[30];
1521 int sec_count=0;
1522 int end;
1524 /* pad_rect used for powerup/ball checks */
1525 struct rect pad_rect;
1526 /* This is used for various lines that are checked (ball and powerup) */
1527 struct line misc_line;
1529 /* This stores the point that the two lines intersected in a test */
1530 struct point pt_hit;
1532 if (brickmania_menu()) {
1533 return 1;
1535 resume = false;
1536 resume_file = false;
1538 #ifdef HAVE_LCD_COLOR
1539 rb->lcd_set_background(LCD_BLACK);
1540 rb->lcd_set_foreground(LCD_WHITE);
1541 rb->lcd_set_drawmode(DRMODE_SOLID);
1542 rb->lcd_clear_display();
1543 #endif
1545 while(true) {
1546 /* Convert CYCLETIME (in ms) to HZ */
1547 end = *rb->current_tick + (CYCLETIME * HZ) / 1000;
1549 if (life >= 0) {
1550 rb->lcd_clear_display();
1552 if (flip_sides)
1554 if (TIME_AFTER(*rb->current_tick, sec_count))
1556 sec_count=*rb->current_tick+HZ;
1557 if (flip_sides_delay!=0)
1558 flip_sides_delay--;
1559 else
1560 flip_sides=false;
1562 rb->snprintf(s, sizeof(s), "%d", flip_sides_delay);
1563 rb->lcd_getstringsize(s, &sw, NULL);
1564 rb->lcd_putsxy(LCD_WIDTH/2-2, INT3(STRINGPOS_FLIP), s);
1567 /* write life num */
1568 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1569 rb->snprintf(s, sizeof(s), "L:%d", life);
1570 #else
1571 rb->snprintf(s, sizeof(s), "Life: %d", life);
1572 #endif
1573 rb->lcd_putsxy(0, 0, s);
1575 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
1576 rb->snprintf(s, sizeof(s), "L%d", level+1);
1577 #else
1578 rb->snprintf(s, sizeof(s), "Level %d", level+1);
1579 #endif
1581 rb->lcd_getstringsize(s, &sw, NULL);
1582 rb->lcd_putsxy(LCD_WIDTH-sw, 0, s);
1584 if (vscore<score) vscore++;
1585 rb->snprintf(s, sizeof(s), "%d", vscore);
1586 rb->lcd_getstringsize(s, &sw, NULL);
1587 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
1589 /* continue game */
1590 if (game_state == ST_PAUSE)
1592 rb->snprintf(s, sizeof(s), CONTINUE_TEXT);
1593 rb->lcd_getstringsize(s, &sw, NULL);
1594 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, INT3(STRINGPOS_NAVI), s);
1596 sec_count=*rb->current_tick+HZ;
1599 /* draw the ball */
1600 for(i=0;i<used_balls;i++)
1601 rb->lcd_bitmap(brickmania_ball,
1602 INT3(ball[i].pos_x - HALFBALL),
1603 INT3(ball[i].pos_y - HALFBALL),
1604 INT3(BALL), INT3(BALL));
1606 if (brick_on_board==0)
1607 brick_on_board--;
1609 /* Setup the pad line-later used in intersection test */
1610 pad_rect.top_left.x = pad_pos_x;
1611 pad_rect.top_left.y = PAD_POS_Y;
1613 pad_rect.bottom_right.x = pad_pos_x + pad_width;
1614 pad_rect.bottom_right.y = PAD_POS_Y + PAD_HEIGHT;
1616 if (game_state!=ST_PAUSE)
1618 /* move the fires */
1619 for(k=0;k<used_fires;k++)
1621 fire[k].top -= SPEED_FIRE;
1622 if (fire[k].top < 0)
1624 used_fires--;
1625 fire[k].top = fire[used_fires].top;
1626 fire[k].x_pos = fire[used_fires].x_pos;
1627 k--;
1629 else if (fire[k].x_pos >= LEFTMARGIN &&
1630 fire[k].x_pos < LEFTMARGIN + NUM_BRICKS_COLS * BRICK_WIDTH)
1632 j = (fire[k].x_pos - LEFTMARGIN) / BRICK_WIDTH;
1633 for (i=NUM_BRICKS_ROWS-1;i>=0;i--)
1636 if (brick[i][j].used)
1638 score += SCORE_FIRE_HIT_BRICK;
1639 brick_hit(i, j);
1640 used_fires--;
1641 fire[k].top = fire[used_fires].top;
1642 fire[k].x_pos = fire[used_fires].x_pos;
1643 k--;
1644 break;
1646 if (TOPMARGIN + i*BRICK_HEIGHT<=fire[k].top)
1647 break;
1652 /* move and handle the powerups */
1653 for (k=0;k<used_powers;k++)
1655 int remove_power = 0;
1657 power[k].top += SPEED_POWER;
1659 if (power[k].top > PAD_POS_Y)
1661 /* power hit bottom */
1662 remove_power = 1;
1664 else
1666 /* Use misc_line to check if the center of the powerup
1667 * hit the paddle.
1669 misc_line.p1.x = power[k].x_pos;
1670 misc_line.p1.y = power[k].top;
1672 misc_line.p2 = misc_line.p1;
1673 misc_line.p2.y += SPEED_POWER;
1675 /* Check if the powerup will hit the paddle */
1676 if (check_rect(&misc_line, &pad_rect, INTERSECTION_ALL,
1677 &pt_hit))
1680 /* power hit paddle */
1681 remove_power = 1;
1682 switch(power[k].type)
1684 case POWER_TYPE_LIFE_GAIN:
1685 life++;
1686 score += SCORE_POWER_LIFE_GAIN;
1687 break;
1688 case POWER_TYPE_LIFE_LOSS:
1689 life--;
1690 if (life>=0)
1692 brickmania_init_game(false);
1693 brickmania_sleep(2);
1695 break;
1696 case POWER_TYPE_PADDLE_STICKY:
1697 score += SCORE_POWER_PADDLE_STICKY;
1698 paddle_type = PADDLE_TYPE_STICKY;
1699 break;
1700 case POWER_TYPE_PADDLE_SHOOTER:
1701 score += SCORE_POWER_PADDLE_SHOOTER;
1702 paddle_type = PADDLE_TYPE_SHOOTER;
1703 for(i=0;i<used_balls;i++)
1704 ball[i].glue=false;
1705 break;
1706 case POWER_TYPE_PADDLE_NORMAL:
1707 score += SCORE_POWER_PADDLE_NORMAL;
1708 paddle_type = PADDLE_TYPE_NORMAL;
1709 for(i=0;i<used_balls;i++)
1710 ball[i].glue=false;
1711 flip_sides=false;
1712 pad_pos_x += (pad_width-PAD_WIDTH)/2;
1713 pad_width = PAD_WIDTH;
1714 break;
1715 case POWER_TYPE_PADDLE_FLIP:
1716 score += SCORE_POWER_FLIP;
1717 sec_count = *rb->current_tick+HZ;
1718 flip_sides_delay = FLIP_SIDES_DELAY;
1719 flip_sides = true;
1720 break;
1721 case POWER_TYPE_EXTRA_BALL:
1722 score += SCORE_POWER_EXTRA_BALL;
1723 if(used_balls<MAX_BALLS)
1725 /* Set the speed */
1726 if(rb->rand()%2 == 0)
1727 ball[used_balls].speedx=-SPEED_4Q_X;
1728 else
1729 ball[used_balls].speedx= SPEED_4Q_X;
1730 ball[used_balls].speedy= SPEED_4Q_Y;
1731 /* Ball is not glued */
1732 ball[used_balls].glue= false;
1733 used_balls++;
1735 break;
1736 case POWER_TYPE_PADDLE_LONG:
1737 score+=SCORE_POWER_LONG_PADDLE;
1738 if (pad_width==PAD_WIDTH)
1740 pad_width = LONG_PAD_WIDTH;
1741 pad_pos_x -= (LONG_PAD_WIDTH -
1742 PAD_WIDTH)/2;
1744 else if (pad_width==SHORT_PAD_WIDTH)
1746 pad_width = PAD_WIDTH;
1747 pad_pos_x-=(PAD_WIDTH-
1748 SHORT_PAD_WIDTH)/2;
1750 if (pad_pos_x < 0)
1751 pad_pos_x = 0;
1752 else if(pad_pos_x + pad_width >
1753 GAMESCREEN_WIDTH)
1754 pad_pos_x = GAMESCREEN_WIDTH-pad_width;
1755 break;
1756 case POWER_TYPE_PADDLE_SHORT:
1757 if (pad_width==PAD_WIDTH)
1759 pad_width=SHORT_PAD_WIDTH;
1760 pad_pos_x+=(PAD_WIDTH-
1761 SHORT_PAD_WIDTH)/2;
1763 else if (pad_width==LONG_PAD_WIDTH)
1765 pad_width=PAD_WIDTH;
1766 pad_pos_x+=(LONG_PAD_WIDTH-PAD_WIDTH)/2;
1768 break;
1769 default:
1770 break;
1774 if (remove_power)
1776 used_powers--;
1777 if (k != used_powers)
1779 power[k].top = power[used_powers].top;
1780 power[k].x_pos = power[used_powers].x_pos;
1781 power[k].type = power[used_powers].type;
1783 k--;
1789 /* draw the fires */
1790 for(k=0;k<used_fires;k++)
1792 rb->lcd_vline(INT3(fire[k].x_pos), INT3(fire[k].top),
1793 INT3(fire[k].top + FIRE_LENGTH));
1796 /* draw the powerups */
1797 for(k=0;k<used_powers;k++)
1799 rb->lcd_bitmap_part(brickmania_powerups,0,
1800 INT3(POWERUP_HEIGHT)*power[k].type,
1801 STRIDE(SCREEN_MAIN, BMPWIDTH_brickmania_powerups,
1802 BMPHEIGHT_brickmania_powerups),
1803 INT3(power[k].x_pos - (POWERUP_WIDTH >> 1)),
1804 INT3(power[k].top), INT3(POWERUP_WIDTH),
1805 INT3(POWERUP_HEIGHT));
1808 /* handle all of the bricks */
1809 for (i=0; i<NUM_BRICKS_ROWS; i++)
1811 for (j=0; j<NUM_BRICKS_COLS ;j++)
1813 int brickx,bricky;
1815 /* The brick is a brick, but it may or may not be in use */
1816 if(brick[i][j].used)
1818 struct rect brick_rect;
1820 brickx = LEFTMARGIN + j*BRICK_WIDTH;
1821 bricky = TOPMARGIN + i*BRICK_HEIGHT;
1823 brick_rect.top_left.x = brickx;
1824 brick_rect.top_left.y = bricky;
1826 brick_rect.bottom_right.x = brickx + BRICK_WIDTH;
1827 brick_rect.bottom_right.y = bricky + BRICK_HEIGHT;
1829 /* Draw the brick */
1830 rb->lcd_bitmap_part(brickmania_bricks,0,
1831 INT3(BRICK_HEIGHT)*brick[i][j].color,
1832 STRIDE( SCREEN_MAIN,
1833 BMPWIDTH_brickmania_bricks,
1834 BMPHEIGHT_brickmania_bricks),
1835 INT3(brickx),
1836 INT3(bricky),
1837 INT3(BRICK_WIDTH), INT3(BRICK_HEIGHT) );
1839 #ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */
1840 if (brick[i][j].hiteffect > 0)
1841 rb->lcd_bitmap_transparent_part(brickmania_break,0,
1842 INT3(BRICK_HEIGHT)*brick[i][j].hiteffect,
1843 STRIDE( SCREEN_MAIN,
1844 BMPWIDTH_brickmania_break,
1845 BMPHEIGHT_brickmania_break),
1846 INT3(brickx),
1847 INT3(bricky),
1848 INT3(BRICK_WIDTH), INT3(BRICK_HEIGHT) );
1849 #endif
1851 /* Check if any balls collided with the brick */
1852 for(k=0; k<used_balls; k++)
1854 int hit = 0;
1856 /* Setup the ball path to describe the current ball
1857 * position and the line it makes to its next
1858 * position.
1860 misc_line.p1.x = ball[k].pos_x;
1861 misc_line.p1.y = ball[k].pos_y;
1863 misc_line.p2.x = ball[k].pos_x + ball[k].speedx;
1864 misc_line.p2.y = ball[k].pos_y + ball[k].speedy;
1866 /* Check to see if the ball and the bottom hit. If
1867 * the ball is moving down we don't want to
1868 * include the bottom line intersection.
1870 * The order that the sides are checked matters.
1872 * Note that tempx/tempy store the next position
1873 * that the ball should be drawn.
1875 if (ball[k].speedy <= 0 && check_rect(&misc_line,
1876 &brick_rect, INTERSECTION_BOTTOM, &pt_hit))
1878 ball[k].speedy = -ball[k].speedy;
1879 hit = 1;
1881 /* Check the top, if the ball is moving up dont
1882 * count it as a hit.
1884 else if (ball[k].speedy > 0 && check_rect(&misc_line,
1885 &brick_rect, INTERSECTION_TOP, &pt_hit))
1887 ball[k].speedy = -ball[k].speedy;
1888 hit = 1;
1890 /* Check the left side of the brick */
1891 else if (check_rect(&misc_line, &brick_rect,
1892 INTERSECTION_LEFT, &pt_hit))
1894 ball[k].speedx = -ball[k].speedx;
1895 hit = 1;
1897 /* Check the right side of the brick */
1898 else if (check_rect(&misc_line, &brick_rect,
1899 INTERSECTION_RIGHT, &pt_hit))
1901 ball[k].speedx = -ball[k].speedx;
1902 hit = 1;
1905 if (hit)
1907 ball[k].tempy = pt_hit.y;
1908 ball[k].tempx = pt_hit.x;
1909 brick_hit(i, j);
1910 break;
1912 } /* for k */
1913 } /* if(used) */
1915 } /* for j */
1916 } /* for i */
1918 /* draw the paddle according to the PAD_WIDTH */
1919 if( pad_width == PAD_WIDTH ) /* Normal width */
1921 rb->lcd_bitmap_part(
1922 brickmania_pads,
1923 0, paddle_type*INT3(PAD_HEIGHT),
1924 STRIDE( SCREEN_MAIN, BMPWIDTH_brickmania_pads,
1925 BMPHEIGHT_brickmania_pads),
1926 INT3(pad_pos_x), INT3(PAD_POS_Y),
1927 INT3(pad_width), INT3(PAD_HEIGHT) );
1929 else if( pad_width == LONG_PAD_WIDTH ) /* Long Pad */
1931 rb->lcd_bitmap_part(
1932 brickmania_long_pads,
1933 0,paddle_type*INT3(PAD_HEIGHT),
1934 STRIDE( SCREEN_MAIN, BMPWIDTH_brickmania_long_pads,
1935 BMPHEIGHT_brickmania_long_pads),
1936 INT3(pad_pos_x), INT3(PAD_POS_Y),
1937 INT3(pad_width), INT3(PAD_HEIGHT) );
1939 else /* Short pad */
1941 rb->lcd_bitmap_part(
1942 brickmania_short_pads,
1943 0,paddle_type*INT3(PAD_HEIGHT),
1944 STRIDE( SCREEN_MAIN, BMPWIDTH_brickmania_short_pads,
1945 BMPHEIGHT_brickmania_short_pads),
1946 INT3(pad_pos_x), INT3(PAD_POS_Y),
1947 INT3(pad_width), INT3(PAD_HEIGHT) );
1950 /* If the game is not paused continue */
1951 if (game_state!=ST_PAUSE)
1953 /* Loop through all of the balls in play */
1954 for(k=0;k<used_balls;k++)
1956 struct line screen_edge;
1958 /* Describe the ball movement for the edge collision detection */
1959 misc_line.p1.x = ball[k].pos_x;
1960 misc_line.p1.y = ball[k].pos_y;
1962 misc_line.p2.x = ball[k].pos_x + ball[k].speedx;
1963 misc_line.p2.y = ball[k].pos_y + ball[k].speedy;
1965 /* Did the Ball hit the top of the screen? */
1966 screen_edge.p1.x = 0;
1967 screen_edge.p1.y = 0;
1969 screen_edge.p2.x = GAMESCREEN_WIDTH;
1970 screen_edge.p2.y = 0;
1971 /* the test for pos_y prevents the ball from bouncing back
1972 * from _over_ the top to infinity on some rare cases */
1973 if (ball[k].pos_y > 0 &&
1974 check_lines(&misc_line, &screen_edge, &pt_hit))
1976 ball[k].tempy = pt_hit.y + 1;
1977 ball[k].tempx = pt_hit.x;
1978 /* Reverse the direction */
1979 ball[k].speedy = -ball[k].speedy;
1982 /* Player missed the ball and hit bottom of screen */
1983 if (ball[k].pos_y >= GAMESCREEN_HEIGHT)
1985 /* Player had balls to spare, so handle the removal */
1986 if (used_balls>1)
1988 /* decrease number of balls in play */
1989 used_balls--;
1990 /* Replace removed ball with the last ball */
1991 ball[k].pos_x = ball[used_balls].pos_x;
1992 ball[k].pos_y = ball[used_balls].pos_y;
1993 ball[k].speedy = ball[used_balls].speedy;
1994 ball[k].tempy = ball[used_balls].tempy;
1995 ball[k].speedx = ball[used_balls].speedx;
1996 ball[k].tempx = ball[used_balls].tempx;
1997 ball[k].glue = ball[used_balls].glue;
1999 /* Reset the last ball that was removed */
2000 ball[used_balls].speedx=0;
2001 ball[used_balls].speedy=0;
2002 ball[used_balls].tempy=0;
2003 ball[used_balls].tempx=0;
2004 ball[used_balls].pos_y=ON_PAD_POS_Y;
2005 ball[used_balls].pos_x=pad_pos_x+(pad_width/2)-HALFBALL;
2007 k--;
2008 continue;
2010 else
2012 /* Player lost a life */
2013 life--;
2014 if (life>=0)
2016 /* No lives left reset game */
2017 brickmania_init_game(false);
2018 brickmania_sleep(2);
2019 rb->button_clear_queue();
2024 if (game_state != ST_READY && !ball[k].glue)
2026 /* Check if the ball hit the left side */
2027 screen_edge.p1.x = 0;
2028 screen_edge.p1.y = 0;
2030 screen_edge.p2.x = 0;
2031 screen_edge.p2.y = GAMESCREEN_HEIGHT;
2032 if (check_lines(&misc_line, &screen_edge, &pt_hit))
2034 /* Reverse direction */
2035 ball[k].speedx = -ball[k].speedx;
2037 /* Re-position ball in gameboard */
2038 ball[k].tempy = pt_hit.y;
2039 ball[k].tempx = 0;
2042 /* Check if the ball hit the right side */
2043 screen_edge.p1.x = GAMESCREEN_WIDTH;
2044 screen_edge.p1.y = 0;
2046 screen_edge.p2.x = GAMESCREEN_WIDTH;
2047 screen_edge.p2.y = GAMESCREEN_HEIGHT;
2048 if (check_lines(&misc_line, &screen_edge, &pt_hit))
2050 /* Reverse direction */
2051 ball[k].speedx = -ball[k].speedx;
2053 /* Re-position ball in gameboard */
2054 ball[k].tempy = pt_hit.y;
2055 ball[k].tempx = GAMESCREEN_WIDTH - FIXED3(1);
2058 /* Did the ball hit the paddle? Depending on where the ball
2059 * Hit set the x/y speed appropriately.
2061 if(check_rect(&misc_line, &pad_rect, INTERSECTION_TOP,
2062 &pt_hit) )
2064 /* Re-position ball based on collision */
2065 ball[k].tempy = ON_PAD_POS_Y;
2066 ball[k].tempx = pt_hit.x;
2068 /* Calculate the ball position relative to the paddle width */
2069 int ball_repos = pt_hit.x - pad_pos_x;
2070 /* If the ball hits the right half of paddle, x speed
2071 * should be positive, if it hits the left half it
2072 * should be negative.
2074 int x_direction = -1;
2076 /* Comparisons are done with respect to 1/2 pad_width */
2077 if(ball_repos > pad_width/2)
2079 /* flip the relative position */
2080 ball_repos -= ((ball_repos - pad_width/2) << 1);
2081 /* Ball hit the right half so X speed calculations
2082 * should be positive.
2084 x_direction = 1;
2087 /* Figure out where the ball hit relative to 1/2 pad
2088 * and in divisions of 4.
2090 ball_repos = ball_repos / (pad_width/2/4);
2092 switch(ball_repos)
2094 /* Ball hit the outer edge of the paddle */
2095 case 0:
2096 ball[k].speedy = SPEED_1Q_Y;
2097 ball[k].speedx = SPEED_1Q_X * x_direction;
2098 break;
2099 /* Ball hit the next fourth of the paddle */
2100 case 1:
2101 ball[k].speedy = SPEED_2Q_Y;
2102 ball[k].speedx = SPEED_2Q_X * x_direction;
2103 break;
2104 /* Ball hit the third fourth of the paddle */
2105 case 2:
2106 ball[k].speedy = SPEED_3Q_Y;
2107 ball[k].speedx = SPEED_3Q_X * x_direction;
2108 break;
2109 /* Ball hit the fourth fourth of the paddle or dead
2110 * center.
2112 case 3:
2113 case 4:
2114 ball[k].speedy = SPEED_4Q_Y;
2115 /* Since this is the middle we don't want to
2116 * force the ball in a different direction.
2117 * Just keep it going in the same direction
2118 * with a specific speed.
2120 if(ball[k].speedx > 0)
2122 ball[k].speedx = SPEED_4Q_X;
2124 else
2126 ball[k].speedx = -SPEED_4Q_X;
2128 break;
2130 default:
2131 ball[k].speedy = SPEED_4Q_Y;
2132 break;
2135 if(paddle_type == PADDLE_TYPE_STICKY)
2137 ball[k].speedy = -ball[k].speedy;
2138 ball[k].glue=true;
2140 /* X location should not be forced since that is moved with the paddle. The Y
2141 * position should be forced to keep the ball at the paddle.
2143 ball[k].tempx = 0;
2144 ball[k].tempy = ON_PAD_POS_Y;
2149 /* Update the ball position */
2150 if (!ball[k].glue)
2152 if(ball[k].tempx)
2153 ball[k].pos_x = ball[k].tempx;
2154 else
2155 ball[k].pos_x += ball[k].speedx;
2157 if(ball[k].tempy)
2158 ball[k].pos_y = ball[k].tempy;
2159 else
2160 ball[k].pos_y += ball[k].speedy;
2162 ball[k].tempy=0;
2163 ball[k].tempx=0;
2165 } /* for k */
2168 rb->lcd_update();
2170 if (brick_on_board < 0)
2172 if (level+1<NUM_LEVELS)
2174 level++;
2175 if (difficulty==NORMAL)
2176 score+=SCORE_LEVEL_COMPLETED;
2177 brickmania_init_game(true);
2178 brickmania_sleep(2);
2179 rb->button_clear_queue();
2181 else
2183 rb->lcd_getstringsize("Congratulations!", &sw, NULL);
2184 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, INT3(STRINGPOS_CONGRATS),
2185 "Congratulations!");
2186 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
2187 rb->lcd_getstringsize("No more levels", &sw, NULL);
2188 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, INT3(STRINGPOS_FINISH),
2189 "No more levels");
2190 #else
2191 rb->lcd_getstringsize("You have finished the game!",
2192 &sw, NULL);
2193 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, INT3(STRINGPOS_FINISH),
2194 "You have finished the game!");
2195 #endif
2196 vscore=score;
2197 rb->lcd_update();
2198 brickmania_sleep(2);
2199 return 0;
2203 int button=rb->button_get(false);
2204 int move_button = rb->button_status();
2206 #if defined(HAS_BUTTON_HOLD) && !defined(HAVE_REMOTE_LCD_AS_MAIN)
2207 /* FIXME: Should probably check remote hold here */
2208 if (rb->button_hold())
2209 button = QUIT;
2210 #endif
2212 #ifdef HAVE_TOUCHSCREEN
2213 if( move_button & BUTTON_TOUCHSCREEN)
2215 int data;
2216 short touch_x, touch_y;
2217 rb->button_status_wdata(&data);
2218 touch_x = FIXED3(data >> 16);
2219 touch_y = FIXED3(data & 0xffff);
2221 if(flip_sides)
2223 pad_pos_x = GAMESCREEN_WIDTH - (touch_x + pad_width/2);
2225 else
2227 pad_pos_x = (touch_x - pad_width/2);
2230 if(pad_pos_x < 0)
2231 pad_pos_x = 0;
2232 else if(pad_pos_x + pad_width > GAMESCREEN_WIDTH)
2233 pad_pos_x = GAMESCREEN_WIDTH-pad_width;
2234 for(k=0; k<used_balls; k++)
2235 if (game_state==ST_READY || ball[k].glue)
2236 ball[k].pos_x = pad_pos_x + pad_width/2;
2238 else
2239 #endif
2241 int button_right, button_left;
2242 #ifdef ALTRIGHT
2243 button_right = move_button & (RIGHT | ALTRIGHT);
2244 button_left = move_button & (LEFT | ALTLEFT);
2245 #else
2246 button_right =((move_button & RIGHT)|| SCROLL_FWD(button));
2247 button_left =((move_button & LEFT) ||SCROLL_BACK(button));
2248 #endif
2249 if ((game_state==ST_PAUSE) && (button_right || button_left))
2250 continue;
2252 if (button_left || button_right)
2254 int dx = 0;
2256 if ((button_right && !flip_sides) ||
2257 (button_left && flip_sides))
2259 if (pad_pos_x+SPEED_PAD+pad_width > GAMESCREEN_WIDTH)
2260 dx = GAMESCREEN_WIDTH - pad_pos_x - pad_width;
2261 else
2262 dx = SPEED_PAD;
2264 else if ((button_left && !flip_sides) ||
2265 (button_right && flip_sides))
2267 if (pad_pos_x-SPEED_PAD < 0)
2268 dx = -pad_pos_x;
2269 else
2270 dx = -SPEED_PAD;
2273 pad_pos_x+=dx;
2274 for(k=0;k<used_balls;k++)
2276 if (game_state==ST_READY || ball[k].glue)
2278 ball[k].pos_x+=dx;
2280 if (ball[k].pos_x < HALFBALL)
2281 ball[k].pos_x = HALFBALL;
2282 else if (ball[k].pos_x > GAMESCREEN_WIDTH - HALFBALL)
2283 ball[k].pos_x = GAMESCREEN_WIDTH - HALFBALL;
2289 switch(button)
2291 #if defined(HAVE_TOUCHSCREEN)
2292 case (BUTTON_REL | BUTTON_TOUCHSCREEN):
2293 #endif
2294 case UP:
2295 case SELECT:
2296 #ifdef ALTSELECT
2297 case ALTSELECT:
2298 #endif
2299 if (game_state==ST_READY)
2301 /* Initialize used balls starting speed */
2302 for(k=0 ; k < used_balls ; k++)
2304 ball[k].speedy = SPEED_4Q_Y;
2305 if(pad_pos_x + (pad_width/2) >= GAMESCREEN_WIDTH/2)
2307 ball[k].speedx = SPEED_4Q_X;
2309 else
2311 ball[k].speedx = -SPEED_4Q_X;
2314 game_state=ST_START;
2316 else if (game_state==ST_PAUSE)
2318 game_state=ST_START;
2320 else if (paddle_type == PADDLE_TYPE_STICKY)
2322 for(k=0;k<used_balls;k++)
2324 if (ball[k].glue)
2326 ball[k].glue=false;
2327 ball[k].speedy = -ball[k].speedy;
2331 else if (paddle_type == PADDLE_TYPE_SHOOTER)
2333 if (used_fires < MAX_FIRES)
2335 fire[used_fires].top = PAD_POS_Y - FIRE_LENGTH;
2336 fire[used_fires].x_pos = pad_pos_x + 1; /* Add 1 for edge */
2337 used_fires++;
2339 if (used_fires < MAX_FIRES)
2341 fire[used_fires].top = PAD_POS_Y - FIRE_LENGTH;
2342 fire[used_fires].x_pos = pad_pos_x + pad_width - 1; /* Sub1 edge*/
2343 used_fires++;
2346 break;
2347 #ifdef RC_QUIT
2348 case RC_QUIT:
2349 #endif
2350 case QUIT:
2351 resume = true;
2352 return 0;
2353 break;
2355 default:
2356 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
2357 return 1;
2358 break;
2361 else
2363 #ifdef HAVE_LCD_COLOR
2364 rb->lcd_bitmap_transparent(brickmania_gameover,
2365 (LCD_WIDTH - INT3(GAMEOVER_WIDTH))/2,
2366 INT3(GAMESCREEN_HEIGHT - GAMEOVER_HEIGHT)/2,
2367 INT3(GAMEOVER_WIDTH),INT3(GAMEOVER_HEIGHT));
2368 #else /* greyscale and mono */
2369 rb->lcd_bitmap(brickmania_gameover,(LCD_WIDTH -
2370 INT3(GAMEOVER_WIDTH))/2,
2371 INT3(GAMESCREEN_HEIGHT - GAMEOVER_HEIGHT)/2,
2372 INT3(GAMEOVER_WIDTH),INT3(GAMEOVER_HEIGHT) );
2373 #endif
2374 rb->lcd_update();
2375 brickmania_sleep(2);
2376 return 0;
2379 /* Game always needs to yield for other threads */
2380 rb->yield();
2382 /* Sleep for a bit if there is time to spare */
2383 if (TIME_BEFORE(*rb->current_tick, end))
2384 rb->sleep(end-*rb->current_tick);
2386 return 0;
2389 /* this is the plugin entry point */
2390 enum plugin_status plugin_start(const void* parameter)
2392 (void)parameter;
2393 int last_difficulty;
2395 highscore_load(SCORE_FILE, highscores, NUM_SCORES);
2396 configfile_load(CONFIG_FILE_NAME,config,1,0);
2397 last_difficulty = difficulty;
2399 #ifdef HAVE_TOUCHSCREEN
2400 rb->touchscreen_set_mode(TOUCHSCREEN_POINT);
2401 #endif
2403 rb->lcd_setfont(FONT_SYSFIXED);
2404 #if LCD_DEPTH > 1
2405 rb->lcd_set_backdrop(NULL);
2406 #endif
2407 /* Turn off backlight timeout */
2408 backlight_force_on(); /* backlight control in lib/helper.c */
2410 /* now go ahead and have fun! */
2411 rb->srand( *rb->current_tick );
2412 brickmania_loadgame();
2413 resume_file = resume;
2414 while(!brickmania_game_loop())
2416 if(!resume)
2418 int position = highscore_update(score, level+1, "",
2419 highscores, NUM_SCORES);
2420 if (position != -1)
2422 if (position == 0)
2423 rb->splash(HZ*2, "New High Score");
2424 highscore_show(position, highscores, NUM_SCORES, true);
2426 else
2428 brickmania_sleep(3);
2433 highscore_save(SCORE_FILE, highscores, NUM_SCORES);
2434 if(last_difficulty != difficulty)
2435 configfile_save(CONFIG_FILE_NAME,config,1,0);
2436 /* Restore user's original backlight setting */
2437 rb->lcd_setfont(FONT_UI);
2438 /* Turn on backlight timeout (revert to settings) */
2439 backlight_use_settings(); /* backlight control in lib/helper.c */
2441 return PLUGIN_OK;