Bubbles: Change the saving message slightly to include saving scores.
[kugel-rb/myfork.git] / apps / plugins / bubbles.c
blobfe9e693a6166b2ff8635d0a3b963b61ad581efb2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Adam Boot
12 * Color graphics from Frozen Bubble (http://www.frozen-bubble.org/)
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
24 #include "plugin.h"
26 #ifdef HAVE_LCD_BITMAP
28 #include "lib/xlcd.h"
29 #include "lib/pluginlib_actions.h"
30 #include "lib/fixedpoint.h"
31 #include "lib/playback_control.h"
32 #include "lib/highscore.h"
34 PLUGIN_HEADER
36 /* files */
37 #define SCORE_FILE PLUGIN_GAMES_DIR "/bubbles.score"
38 #define SAVE_FILE PLUGIN_GAMES_DIR "/bubbles.save"
39 #define DATA_FILE PLUGIN_GAMES_DIR "/bubbles.data"
41 /* final game return status */
42 enum {
43 BB_LOSE,
44 BB_QUIT_WITHOUT_SAVING,
45 BB_QUIT,
46 BB_USB,
47 BB_END,
48 BB_WIN,
49 BB_NONE,
52 /* play board dimension */
53 #define BB_HEIGHT 12
54 #define BB_WIDTH 8
55 #define BB_LEVEL_HEIGHT 10
57 /* various amounts */
58 #define NUM_SCORES 5
59 #define NUM_LEVELS 100
60 #define NUM_QUEUE 2
61 #define NUM_BUBBLES 8
62 #define MIN_ANGLE -76
63 #define MAX_ANGLE 76
64 #define NUM_COMPRESS 9
65 #define MAX_SHOTTIME 1000
67 /* keyboard layouts */
69 #if (CONFIG_KEYPAD != SANSA_E200_PAD) && \
70 (CONFIG_KEYPAD != SANSA_FUZE_PAD)
71 /* sansas use the wheel instead of left/right if available */
72 #define BUBBLES_LEFT PLA_LEFT
73 #define BUBBLES_LEFT_REP PLA_LEFT_REPEAT
74 #define BUBBLES_RIGHT PLA_RIGHT
75 #define BUBBLES_RIGHT_REP PLA_RIGHT_REPEAT
76 #define ANGLE_STEP 4
77 #define ANGLE_STEP_REP 4
78 #else
79 #define BUBBLES_LEFT PLA_UP
80 #define BUBBLES_LEFT_REP PLA_UP_REPEAT
81 #define BUBBLES_RIGHT PLA_DOWN
82 #define BUBBLES_RIGHT_REP PLA_DOWN_REPEAT
83 #define ANGLE_STEP 2
84 #define ANGLE_STEP_REP 4
85 #endif
87 #define BUBBLES_QUIT PLA_QUIT
88 #define BUBBLES_START PLA_START
89 #define BUBBLES_SELECT PLA_FIRE
90 #define BUBBLES_RESUME PLA_MENU
92 #if CONFIG_KEYPAD != ONDIO_PAD
94 #define BUBBLES_LVLINC PLA_UP
95 #define BUBBLES_LVLINC_REP PLA_UP_REPEAT
96 #define BUBBLES_LVLDEC PLA_DOWN
97 #define BUBBLES_LVLDEC_REP PLA_DOWN_REPEAT
99 #else /* ondio keys */
101 #define BUBBLES_LVLINC PLA_RIGHT
102 #define BUBBLES_LVLINC_REP PLA_RIGHT_REPEAT
103 #define BUBBLES_LVLDEC PLA_LEFT
104 #define BUBBLES_LVLDEC_REP PLA_LEFT_REPEAT
106 #endif
108 /* external bitmaps */
109 #ifdef HAVE_LCD_COLOR
110 #include "pluginbitmaps/bubbles_background.h"
111 #endif
112 #include "pluginbitmaps/bubbles_bubble.h"
113 #include "pluginbitmaps/bubbles_emblem.h"
115 #define BUBBLE_WIDTH BMPWIDTH_bubbles_bubble
116 #define BUBBLE_HEIGHT BMPHEIGHT_bubbles_bubble
117 #define EMBLEM_WIDTH BMPWIDTH_bubbles_emblem
118 #define EMBLEM_HEIGHT (BMPHEIGHT_bubbles_emblem/8)
120 /* bubbles will consume height of ROW_HEIGHT*(BB_HEIGHT-1)+BUBBLE_HEIGHT*3/2 */
121 /* 44x44 bubbles (m:robe 500) */
122 #if (LCD_WIDTH == 640) && (LCD_HEIGHT == 480)
123 #define XOFS 144
124 #define MAX_FPS 40
126 #elif (LCD_WIDTH == 480) && (LCD_HEIGHT == 640)
127 #define XOFS 128
128 #define MAX_FPS 40
130 /* 22x22 bubbles (iPod Video) */
131 #elif (LCD_HEIGHT == 240) && (LCD_WIDTH == 320)
132 #define XOFS 72
133 #define MAX_FPS 40
135 /* 22x22 bubbles (Gigabeat, Onda VX747) */
136 #elif ((LCD_HEIGHT == 320) || (LCD_HEIGHT == 400)) && (LCD_WIDTH == 240)
137 #define XOFS 64
138 #define MAX_FPS 30
140 /* 16x16 bubbles (H300, iPod Color) */
141 #elif (LCD_HEIGHT == 176) && (LCD_WIDTH == 220)
142 #define XOFS 46
143 #define MAX_FPS 30
145 /* 16x16 bubbles (Sansa E200) */
146 #elif (LCD_HEIGHT == 220) && (LCD_WIDTH == 176)
147 #define XOFS 24
148 #define MAX_FPS 30
149 #define YOFS 45
151 /* custom text positioning */
152 #define LEVEL_TXT_X 24
153 #define LEVEL_TXT_WIDTH 31
154 #define LEVEL_TXT_Y 5
155 #define SCORE_TXT_X 58
156 #define SCORE_TXT_WIDTH 31
157 #define SCORE_TXT_Y 5
158 #define NEXT_BB_X 112
159 #define NEXT_BB_WIDTH 31
160 #define NEXT_BB_Y 3
162 /* 12x12 bubbles (iPod Nano) */
163 #elif (LCD_HEIGHT == 132) && (LCD_WIDTH == 176)
164 #define XOFS 40
165 #define MAX_FPS 40
167 /* 12x12 bubbles (H100, H10, iAudio X5, iPod 3G, iPod 4G grayscale) */
168 #elif (LCD_HEIGHT == 128) && ((LCD_WIDTH == 160) || (LCD_WIDTH == 128))
169 #define XOFS 33
170 #define MAX_FPS 30
172 /* 10x10 bubbles (iPod Mini) */
173 #elif (LCD_HEIGHT == 110) && (LCD_WIDTH == 138)
174 #define XOFS 33
175 #define MAX_FPS 30
177 /* 9x9 bubbles (iAudio M3) */
178 #elif (LCD_HEIGHT == 96) && (LCD_WIDTH == 128)
179 #define XOFS 45
180 #define MAX_FPS 30
182 /* 8x8 bubbles (Sansa C200) */
183 #elif ((LCD_HEIGHT == 80) && (LCD_WIDTH == 132))
184 #define XOFS 45
185 #define MAX_FPS 30
187 /* 7x7 bubbles (Sansa Clip/m200) */
188 #elif (LCD_HEIGHT == 64 && LCD_WIDTH == 128)
189 #define XOFS 33
190 #define ROW_HEIGHT 5
191 #define MAX_FPS 30
193 /* 8x7 bubbles (Archos recorder, Ondio) */
194 #elif (LCD_HEIGHT == 64) && (LCD_WIDTH == 112)
195 #define XOFS 33
196 #define ROW_HEIGHT 5
197 #define MAX_FPS 20
199 #else
200 #error BUBBLES: Unsupported LCD type
201 #endif
203 #if !defined(ROW_HEIGHT)
204 #define ROW_HEIGHT (BUBBLE_WIDTH-(BUBBLE_WIDTH-EMBLEM_WIDTH)/2)
205 #endif
207 #define ROW_INDENT (BUBBLE_WIDTH/2)
209 #define TEXT_LINES (LCD_HEIGHT/8)
211 #ifndef YOFS
212 #define YOFS 0
213 #endif
215 /* shot position */
216 #define SHOTX XOFS+ROW_INDENT+BUBBLE_WIDTH*3
217 #define SHOTY (YOFS+ROW_HEIGHT*(BB_HEIGHT-1)+BUBBLE_HEIGHT/2)
219 /* collision distance squared */
220 #define MIN_DISTANCE ((BUBBLE_WIDTH*8)/10)*((BUBBLE_HEIGHT*8)/10)
222 /* levels */
223 char level[NUM_LEVELS][BB_LEVEL_HEIGHT][BB_WIDTH] = {
224 {{ 6, 6, 4, 4, 2, 2, 3, 3},
225 { 6, 6, 4, 4, 2, 2, 3, -1},
226 { 2, 2, 3, 3, 6, 6, 4, 4},
227 { 2, 3, 3, 6, 6, 4, 4, -1},
228 {-1, -1, -1, -1, -1, -1, -1, -1},
229 {-1, -1, -1, -1, -1, -1, -1, -1},
230 {-1, -1, -1, -1, -1, -1, -1, -1},
231 {-1, -1, -1, -1, -1, -1, -1, -1},
232 {-1, -1, -1, -1, -1, -1, -1, -1},
233 {-1, -1, -1, -1, -1, -1, -1, -1}},
234 {{-1, 7, 7, 7, 7, 7, 7, -1},
235 {-1, 1, 1, 1, 1, 1, -1, -1},
236 {-1, -1, 2, 2, 2, 2, -1, -1},
237 {-1, -1, -1, 2, -1, -1, -1, -1},
238 {-1, -1, -1, 2, 2, -1, -1, -1},
239 {-1, -1, -1, 5, -1, -1, -1, -1},
240 {-1, -1, -1, 5, 5, -1, -1, -1},
241 {-1, -1, -1, -1, -1, -1, -1, -1},
242 {-1, -1, -1, -1, -1, -1, -1, -1},
243 {-1, -1, -1, -1, -1, -1, -1, -1}},
244 {{-1, -1, 7, -1, -1, 7, -1, -1},
245 {-1, -1, 7, 1, 7, -1, -1, -1},
246 {-1, -1, -1, 1, 2, -1, -1, -1},
247 {-1, -1, 1, 2, 1, -1, -1, -1},
248 {-1, -1, -1, 2, 5, -1, -1, -1},
249 {-1, -1, 3, 5, 3, -1, -1, -1},
250 {-1, -1, -1, 5, 3, -1, -1, -1},
251 {-1, -1, -1, 3, -1, -1, -1, -1},
252 {-1, -1, -1, -1, -1, -1, -1, -1},
253 {-1, -1, -1, -1, -1, -1, -1, -1}},
254 {{-1, -1, -1, 0, 0, -1, -1, -1},
255 {-1, -1, 5, 0, 1, -1, -1, -1},
256 {-1, -1, 3, 5, 1, 6, -1, -1},
257 {-1, 4, 3, -1, 6, 7, -1, -1},
258 {-1, 7, 4, -1, -1, 7, 4, -1},
259 { 6, 7, -1, -1, -1, 4, 3, -1},
260 { 1, 6, -1, -1, -1, -1, 3, 5},
261 { 1, -1, -1, -1, -1, -1, 5, -1},
262 {-1, -1, -1, -1, -1, -1, -1, -1},
263 {-1, -1, -1, -1, -1, -1, -1, -1}},
264 {{-1, -1, 0, 0, 0, 0, -1, -1},
265 {-1, 0, 1, 1, 1, 0, -1, -1},
266 {-1, 0, 1, 0, 0, 1, 0, -1},
267 {-1, 0, 1, 1, 1, 0, -1, -1},
268 {-1, -1, 0, 0, 0, 0, -1, -1},
269 {-1, -1, 7, -1, 7, -1, -1, -1},
270 {-1, -1, 7, 7, 7, 7, -1, -1},
271 {-1, -1, -1, -1, -1, -1, -1, -1},
272 {-1, -1, -1, -1, -1, -1, -1, -1},
273 {-1, -1, -1, -1, -1, -1, -1, -1}},
274 {{-1, 4, 4, 4, 6, 6, 6, -1},
275 { 4, -1, -1, -1, -1, -1, 6, -1},
276 {-1, 4, -1, -1, -1, -1, 6, -1},
277 { 4, 2, 3, 1, 2, 3, 6, -1},
278 {-1, 3, 1, 2, 3, 1, 2, -1},
279 {-1, -1, -1, -1, -1, -1, -1, -1},
280 {-1, -1, -1, -1, -1, -1, -1, -1},
281 {-1, -1, -1, -1, -1, -1, -1, -1},
282 {-1, -1, -1, -1, -1, -1, -1, -1},
283 {-1, -1, -1, -1, -1, -1, -1, -1}},
284 {{-1, 4, 4, 4, 6, 6, 6, -1},
285 { 4, -1, -1, -1, -1, -1, 6, -1},
286 {-1, 4, -1, -1, -1, -1, 6, -1},
287 { 4, 2, 3, 1, 2, 3, 6, -1},
288 {-1, 3, 1, 2, 3, 1, 2, -1},
289 {-1, 2, 3, 1, 2, 3, -1, -1},
290 {-1, -1, -1, -1, -1, -1, -1, -1},
291 {-1, -1, -1, -1, -1, -1, -1, -1},
292 {-1, -1, -1, -1, -1, -1, -1, -1},
293 {-1, -1, -1, -1, -1, -1, -1, -1}},
294 {{-1, 0, 0, -1, -1, 2, 2, -1},
295 {-1, 5, -1, -1, -1, 3, -1, -1},
296 {-1, 0, -1, -1, -1, 6, -1, -1},
297 {-1, 3, -1, -1, -1, 0, -1, -1},
298 {-1, 4, -1, -1, -1, 5, -1, -1},
299 {-1, 2, -1, -1, -1, 3, -1, -1},
300 {-1, 2, -1, -1, -1, 1, -1, -1},
301 {-1, 3, -1, -1, -1, 4, -1, -1},
302 {-1, -1, -1, -1, -1, -1, -1, -1},
303 {-1, -1, -1, -1, -1, -1, -1, -1}},
304 {{ 3, -1, -1, -1, -1, -1, -1, 3},
305 { 6, 3, 2, 4, 6, 3, 2, -1},
306 { 4, -1, -1, -1, -1, -1, -1, 4},
307 { 2, 4, 6, 3, 2, 4, 6, -1},
308 {-1, -1, -1, 6, -1, -1, -1, -1},
309 {-1, -1, -1, 3, -1, -1, -1, -1},
310 {-1, -1, -1, -1, -1, -1, -1, -1},
311 {-1, -1, -1, -1, -1, -1, -1, -1},
312 {-1, -1, -1, -1, -1, -1, -1, -1},
313 {-1, -1, -1, -1, -1, -1, -1, -1}},
314 {{-1, 2, -1, 1, -1, 1, -1, 2},
315 { 1, 2, -1, 2, 1, -1, 1, -1},
316 { 1, -1, 1, -1, 2, -1, 2, -1},
317 { 2, 1, -1, 1, 2, -1, 2, -1},
318 {-1, 2, -1, 2, -1, 2, -1, 2},
319 { 1, 2, -1, 2, 1, -1, 1, -1},
320 { 1, -1, 1, -1, 2, -1, 1, -1},
321 { 2, 2, -1, 1, 1, -1, 2, -1},
322 {-1, 2, -1, 1, -1, 1, -1, 1},
323 {-1, -1, -1, -1, -1, -1, -1, -1}},
324 {{-1, 7, 7, -1, -1, 5, 5, -1},
325 { 1, -1, -1, -1, -1, -1, 4, -1},
326 { 2, 1, -1, -1, -1, -1, 4, 3},
327 { 2, -1, -1, -1, -1, -1, 3, -1},
328 { 1, 2, -1, -1, -1, -1, 3, 4},
329 { 1, -1, -1, -1, -1, -1, 4, -1},
330 { 7, 1, -1, -1, -1, -1, 4, 5},
331 { 7, 7, -1, -1, -1, 5, 5, -1},
332 {-1, -1, -1, -1, -1, -1, -1, -1},
333 {-1, -1, -1, -1, -1, -1, -1, -1}},
334 {{ 7, 7, -1, -1, -1, -1, 5, 5},
335 { 1, 5, -1, -1, -1, 7, 4, -1},
336 { 2, 1, -1, -1, -1, -1, 4, 3},
337 { 2, -1, -1, -1, -1, -1, 3, -1},
338 { 1, 5, -1, -1, -1, -1, 7, 4},
339 { 1, -1, -1, -1, -1, -1, 4, -1},
340 { 7, 1, -1, -1, -1, -1, 4, 5},
341 { 7, 5, -1, -1, -1, 7, 5, -1},
342 {-1, -1, -1, -1, -1, -1, -1, -1},
343 {-1, -1, -1, -1, -1, -1, -1, -1}},
344 {{-1, -1, -1, 0, 0, -1, -1, -1},
345 {-1, -1, 5, 0, 1, -1, -1, -1},
346 {-1, -1, 3, 5, 1, 6, -1, -1},
347 {-1, 4, 3, 2, 6, 2, -1, -1},
348 {-1, 7, 4, 7, 2, 2, 4, -1},
349 { 6, 7, 7, 3, 3, 4, 3, -1},
350 { 1, 6, 1, 1, 1, 3, 3, 5},
351 { 1, 1, -1, -1, -1, -1, 5, -1},
352 {-1, -1, -1, -1, -1, -1, -1, -1},
353 {-1, -1, -1, -1, -1, -1, -1, -1}},
354 {{-1, -1, 0, -1, -1, 0, -1, -1},
355 {-1, 3, 3, -1, 3, 3, -1, -1},
356 {-1, 0, 2, 0, 0, 2, 0, -1},
357 {-1, 3, 3, -1, 3, 3, -1, -1},
358 {-1, -1, 0, -1, -1, 0, -1, -1},
359 {-1, -1, -1, -1, -1, -1, -1, -1},
360 {-1, -1, -1, -1, -1, -1, -1, -1},
361 {-1, -1, -1, -1, -1, -1, -1, -1},
362 {-1, -1, -1, -1, -1, -1, -1, -1},
363 {-1, -1, -1, -1, -1, -1, -1, -1}},
364 {{-1, -1, -1, 1, 1, -1, -1, -1},
365 {-1, -1, 2, 2, 2, -1, -1, -1},
366 {-1, -1, 3, 3, 3, 3, -1, -1},
367 {-1, 4, 4, 4, 4, 4, -1, -1},
368 {-1, 5, 5, 5, 5, 5, 5, -1},
369 {-1, -1, -1, 6, -1, -1, -1, -1},
370 {-1, -1, -1, 7, 7, -1, -1, -1},
371 {-1, -1, -1, 0, -1, -1, -1, -1},
372 {-1, -1, -1, -1, -1, -1, -1, -1},
373 {-1, -1, -1, -1, -1, -1, -1, -1}},
374 {{-1, -1, -1, 2, 5, -1, -1, -1},
375 {-1, 4, 3, -1, -1, -1, -1, -1},
376 { 6, 7, -1, 5, 2, -1, -1, -1},
377 {-1, -1, -1, -1, 3, 4, -1, -1},
378 {-1, -1, -1, 2, 5, -1, 7, 6},
379 {-1, 4, 3, -1, -1, -1, -1, -1},
380 { 6, 7, -1, 5, 2, -1, -1, -1},
381 {-1, -1, -1, -1, 3, 4, -1, -1},
382 {-1, -1, -1, -1, -1, -1, 7, 6},
383 {-1, -1, -1, -1, -1, -1, -1, -1}},
384 {{-1, -1, -1, 5, 5, -1, -1, -1},
385 {-1, -1, -1, 3, -1, -1, -1, -1},
386 {-1, -1, -1, 1, -1, -1, -1, -1},
387 {-1, -1, -1, 7, -1, -1, -1, -1},
388 {-1, -1, -1, 2, -1, -1, -1, -1},
389 {-1, -1, -1, 4, -1, -1, -1, -1},
390 {-1, -1, -1, 5, -1, -1, -1, -1},
391 {-1, -1, -1, 3, -1, -1, -1, -1},
392 {-1, -1, -1, -1, -1, -1, -1, -1},
393 {-1, -1, -1, -1, -1, -1, -1, -1}},
394 {{-1, -1, -1, 0, 1, -1, -1, -1},
395 {-1, -1, 0, 2, 7, 7, -1, -1},
396 {-1, -1, -1, 0, 1, 7, -1, -1},
397 {-1, 0, 0, 0, 0, -1, -1, -1},
398 {-1, 0, 0, 0, 1, 1, -1, -1},
399 { 0, 0, 0, 1, 1, 1, -1, -1},
400 {-1, 0, 0, 1, 1, 1, -1, -1},
401 {-1, 0, 0, 0, 7, 7, -1, -1},
402 {-1, -1, 7, 7, -1, -1, -1, -1},
403 {-1, -1, -1, -1, -1, -1, -1, -1}},
404 {{-1, 1, -1, -1, -1, -1, -1, -1},
405 { 1, -1, -1, -1, -1, -1, -1, -1},
406 {-1, 2, 3, 4, 7, 6, 5, -1},
407 {-1, -1, -1, -1, -1, -1, 1, -1},
408 {-1, -1, -1, -1, -1, -1, 1, -1},
409 {-1, 2, 3, 4, 7, 6, -1, -1},
410 {-1, 1, -1, -1, -1, -1, -1, -1},
411 { 1, -1, -1, -1, -1, -1, -1, -1},
412 {-1, 2, 3, 4, 7, 6, 5, -1},
413 {-1, -1, -1, -1, -1, -1, -1, -1}},
414 {{-1, 6, -1, -1, -1, -1, -1, -1},
415 { 5, -1, -1, -1, -1, -1, -1, -1},
416 { 2, 3, 4, 7, 6, 5, 2, 3},
417 {-1, -1, -1, -1, -1, -1, 4, -1},
418 {-1, -1, -1, -1, -1, -1, 7, -1},
419 {-1, 4, 3, 2, 5, 6, -1, -1},
420 {-1, 7, -1, -1, -1, -1, -1, -1},
421 { 6, -1, -1, -1, -1, -1, -1, -1},
422 { 5, 2, 3, 4, 7, 6, 5, -1},
423 {-1, -1, -1, -1, -1, -1, -1, -1}},
424 {{ 3, 2, 1, 0, 0, 1, 2, 3},
425 { 3, 2, 1, 0, 1, 2, 3, -1},
426 { 4, 3, 2, 1, 1, 2, 3, 4},
427 { 4, 3, 2, 1, 2, 3, 4, -1},
428 { 5, 4, 3, 2, 2, 3, 4, 5},
429 { 5, 4, 3, 2, 3, 4, 5, -1},
430 { 6, 5, 4, 3, 3, 4, 5, 6},
431 { 6, 5, 4, 3, 4, 5, 6, -1},
432 { 7, 6, 5, 4, 4, 5, 6, 7},
433 {-1, -1, -1, -1, -1, -1, -1, -1}},
434 {{-1, -1, -1, 5, 5, -1, -1, -1},
435 {-1, -1, -1, 3, -1, -1, -1, -1},
436 {-1, -1, -1, 2, 4, -1, -1, -1},
437 {-1, -1, -1, 6, -1, -1, -1, -1},
438 {-1, -1, -1, 2, 4, -1, -1, -1},
439 {-1, 2, -1, 5, -1, 4, -1, -1},
440 { 1, 0, 1, 0, 1, 0, 1, 0},
441 { 3, -1, 3, -1, 2, -1, 6, -1},
442 {-1, -1, -1, -1, -1, -1, -1, -1},
443 {-1, -1, -1, -1, -1, -1, -1, -1}},
444 {{-1, -1, -1, -1, 1, -1, -1, -1},
445 { 7, 4, 3, 5, -1, -1, -1, -1},
446 { 6, -1, -1, 1, -1, -1, -1, -1},
447 {-1, -1, -1, 5, 3, 4, 7, -1},
448 { 6, -1, -1, -1, 1, -1, -1, 6},
449 { 7, 4, 3, 5, -1, -1, -1, -1},
450 {-1, -1, -1, 1, -1, -1, -1, 6},
451 {-1, -1, -1, 5, 3, 4, 7, -1},
452 {-1, -1, -1, -1, -1, -1, -1, -1},
453 {-1, -1, -1, -1, -1, -1, -1, -1}},
454 {{-1, -1, -1, -1, 7, 3, 6, -1},
455 {-1, -1, 3, 7, 3, 6, 3, -1},
456 {-1, -1, 5, 7, 3, 6, 3, -1},
457 {-1, 6, 7, 3, 6, 7, -1, -1},
458 {-1, 7, 7, 3, 6, 1, -1, -1},
459 { 3, 7, 3, 6, 3, -1, -1, -1},
460 { 5, 6, 2, 7, 1, -1, -1, -1},
461 {-1, -1, -1, -1, -1, -1, -1, -1},
462 {-1, -1, -1, -1, -1, -1, -1, -1},
463 {-1, -1, -1, -1, -1, -1, -1, -1}},
464 {{ 5, -1, -1, -1, -1, -1, -1, 5},
465 { 5, -1, 6, 6, 6, -1, 5, -1},
466 {-1, 5, 4, -1, -1, 4, 5, -1},
467 {-1, 3, -1, -1, -1, 3, -1, -1},
468 {-1, 6, 0, -1, -1, 0, 6, -1},
469 {-1, 3, -1, -1, -1, 3, -1, -1},
470 {-1, -1, 4, -1, -1, 4, -1, -1},
471 {-1, -1, 6, 6, 6, -1, -1, -1},
472 {-1, -1, -1, -1, -1, -1, -1, -1},
473 {-1, -1, -1, -1, -1, -1, -1, -1}},
474 {{-1, 7, 0, -1, -1, 0, 7, -1},
475 { 7, -1, 0, -1, 0, -1, 7, -1},
476 { 7, 1, -1, 0, 0, -1, 1, 7},
477 { 7, 1, 2, 0, 2, 1, 7, -1},
478 { 7, 6, 3, 2, 2, 3, 6, 7},
479 { 7, -1, 3, 2, 3, -1, 7, -1},
480 {-1, 7, 7, 3, 3, 7, 7, -1},
481 {-1, -1, -1, 3, -1, -1, -1, -1},
482 {-1, -1, -1, -1, -1, -1, -1, -1},
483 {-1, -1, -1, -1, -1, -1, -1, -1}},
484 {{-1, 3, -1, 1, -1, 7, -1, 6},
485 { 5, -1, 7, -1, 7, -1, 6, -1},
486 { 6, -1, 0, -1, 5, -1, 3, -1},
487 {-1, 2, -1, 1, -1, 5, -1, -1},
488 {-1, 4, -1, 3, -1, 4, -1, -1},
489 { 2, -1, 3, -1, 2, -1, -1, -1},
490 {-1, -1, 4, -1, 6, -1, -1, -1},
491 {-1, -1, -1, 5, -1, -1, -1, -1},
492 {-1, -1, -1, -1, -1, -1, -1, -1},
493 {-1, -1, -1, -1, -1, -1, -1, -1}},
494 {{-1, -1, -1, -1, 1, -1, -1, -1},
495 {-1, -1, -1, -1, 3, -1, -1, -1},
496 { 6, 1, 3, 1, 2, 1, 4, 1},
497 {-1, -1, -1, -1, 6, -1, -1, -1},
498 {-1, -1, -1, 4, 1, -1, -1, -1},
499 {-1, -1, 1, -1, 3, -1, -1, -1},
500 {-1, -1, -1, 2, 1, -1, -1, -1},
501 {-1, -1, -1, -1, 4, -1, -1, -1},
502 {-1, -1, -1, 6, 1, -1, -1, -1},
503 {-1, -1, -1, 6, -1, -1, -1, -1}},
504 {{-1, -1, -1, 5, 4, -1, -1, -1},
505 {-1, -1, 4, 1, 0, -1, -1, -1},
506 {-1, -1, -1, 2, 3, -1, -1, -1},
507 {-1, 1, 4, -1, 2, 2, -1, -1},
508 {-1, 3, 1, 2, 5, 1, 4, -1},
509 {-1, 4, 2, -1, 0, 4, -1, -1},
510 {-1, -1, -1, -1, -1, -1, -1, -1},
511 {-1, -1, -1, -1, -1, -1, -1, -1},
512 {-1, -1, -1, -1, -1, -1, -1, -1},
513 {-1, -1, -1, -1, -1, -1, -1, -1}},
514 {{-1, -1, -1, -1, 1, -1, -1, -1},
515 {-1, -1, -1, 1, -1, -1, -1, -1},
516 {-1, 2, -1, -1, 1, -1, 5, -1},
517 { 5, -1, -1, 1, -1, -1, 0, -1},
518 {-1, 6, -1, -1, 1, -1, 4, -1},
519 {-1, 0, -1, 1, -1, 5, -1, -1},
520 {-1, -1, 5, 5, 0, 1, -1, -1},
521 {-1, -1, -1, -1, -1, -1, -1, -1},
522 {-1, -1, -1, -1, -1, -1, -1, -1},
523 {-1, -1, -1, -1, -1, -1, -1, -1}},
524 {{-1, -1, -1, 6, 3, -1, -1, -1},
525 {-1, -1, 3, 2, 6, -1, -1, -1},
526 {-1, -1, 2, 6, 3, 2, -1, -1},
527 {-1, 6, 3, 2, 6, 3, -1, -1},
528 {-1, 3, 2, 6, 3, 2, 6, -1},
529 { 2, 6, 3, 2, 6, 3, 2, -1},
530 { 6, 3, 2, 6, 3, 2, 6, 3},
531 {-1, -1, -1, -1, -1, -1, -1, -1},
532 {-1, -1, -1, -1, -1, -1, -1, -1},
533 {-1, -1, -1, -1, -1, -1, -1, -1}},
534 {{ 6, 6, 6, 6, 6, 6, 6, 6},
535 { 4, -1, -1, -1, -1, -1, -1, -1},
536 {-1, 3, 2, 5, 7, 6, 4, 3},
537 {-1, 5, -1, -1, -1, -1, -1, -1},
538 {-1, -1, 7, 6, 4, 3, 2, 5},
539 {-1, -1, 4, -1, -1, -1, -1, -1},
540 {-1, -1, -1, 3, 2, 5, 7, 6},
541 {-1, -1, -1, -1, -1, -1, -1, -1},
542 {-1, -1, -1, -1, -1, -1, -1, -1},
543 {-1, -1, -1, -1, -1, -1, -1, -1}},
544 {{ 1, -1, 7, -1, -1, 6, -1, 2},
545 { 6, -1, 1, -1, 6, 1, 3, -1},
546 {-1, 4, -1, 7, 2, -1, 7, -1},
547 { 2, 7, -1, -1, -1, 4, -1, -1},
548 { 6, -1, 3, 5, 0, 2, -1, 7},
549 { 1, -1, -1, -1, -1, -1, 1, -1},
550 {-1, 1, 4, 5, 7, 5, 1, -1},
551 {-1, -1, -1, -1, -1, -1, -1, -1},
552 {-1, -1, -1, -1, -1, -1, -1, -1},
553 {-1, -1, -1, -1, -1, -1, -1, -1}},
554 {{ 6, 6, 6, -1, -1, 6, 6, 6},
555 {-1, -1, 6, -1, 6, -1, -1, -1},
556 {-1, -1, 2, 3, 3, 2, -1, -1},
557 {-1, 3, -1, 5, -1, 3, -1, -1},
558 {-1, -1, 5, 3, 3, 5, -1, -1},
559 {-1, -1, 6, 1, 6, -1, -1, -1},
560 {-1, 4, 2, -1, -1, 2, 4, -1},
561 {-1, -1, -1, -1, -1, -1, -1, -1},
562 {-1, -1, -1, -1, -1, -1, -1, -1},
563 {-1, -1, -1, -1, -1, -1, -1, -1}},
564 {{-1, -1, -1, 5, 5, -1, -1, -1},
565 {-1, -1, 5, -1, -1, -1, -1, -1},
566 {-1, 3, 4, 6, 6, -1, -1, 5},
567 { 3, 3, 4, 6, 5, -1, 5, -1},
568 { 3, 2, 3, 6, 6, 5, 5, -1},
569 { 3, 3, 4, 6, 5, -1, 5, -1},
570 {-1, 3, 4, 6, 6, -1, -1, 5},
571 {-1, -1, 5, -1, -1, -1, -1, -1},
572 {-1, -1, -1, 5, 5, -1, -1, -1},
573 {-1, -1, -1, -1, -1, -1, -1, -1}},
574 {{ 1, -1, -1, -1, -1, -1, -1, 1},
575 { 1, -1, 2, 2, 2, -1, 1, -1},
576 {-1, 1, 2, 3, 3, 2, 1, -1},
577 { 6, 2, 3, -1, 3, 2, 6, -1},
578 { 6, 2, 3, -1, -1, 3, 2, 6},
579 { 6, 2, 3, -1, 3, 2, 6, -1},
580 { 3, 3, 3, 7, 7, 3, 3, 3},
581 { 0, 5, 0, 2, 0, 5, 0, -1},
582 {-1, -1, -1, -1, -1, -1, -1, -1},
583 {-1, -1, -1, -1, -1, -1, -1, -1}},
584 {{-1, -1, 7, 7, 7, -1, -1, -1},
585 {-1, 7, 2, 2, 7, -1, -1, -1},
586 {-1, 7, 5, 5, 5, 7, -1, -1},
587 { 7, 7, 7, 7, 7, 7, -1, -1},
588 {-1, -1, 6, -1, 6, -1, -1, -1},
589 {-1, 6, -1, -1, 6, -1, -1, -1},
590 {-1, 6, 4, 4, -1, 6, 4, 4},
591 {-1, -1, -1, -1, -1, -1, -1, -1},
592 {-1, -1, -1, -1, -1, -1, -1, -1},
593 {-1, -1, -1, -1, -1, -1, -1, -1}},
594 {{-1, 3, 3, -1, 3, 3, 3, -1},
595 { 3, 7, 5, 4, 6, 5, 3, -1},
596 { 1, 3, 3, 3, -1, 3, 3, 1},
597 { 2, 1, 2, 1, 2, 1, 2, -1},
598 { 1, 3, 3, -1, 3, 3, 3, 1},
599 { 3, 5, 6, 4, 5, 7, 3, -1},
600 { 2, 3, 3, 3, -1, 3, 3, 2},
601 { 1, 1, 2, 2, 2, 1, 1, -1},
602 {-1, -1, -1, -1, -1, -1, -1, -1},
603 {-1, -1, -1, -1, -1, -1, -1, -1}},
604 {{-1, 6, 5, -1, -1, -1, -1, -1},
605 { 3, 1, 3, -1, -1, -1, -1, -1},
606 {-1, 5, 6, -1, -1, -1, -1, -1},
607 {-1, -1, 5, 3, -1, -1, -1, -1},
608 {-1, -1, 6, 1, 6, -1, -1, -1},
609 {-1, -1, 3, 5, -1, -1, -1, -1},
610 {-1, -1, -1, -1, 3, 6, -1, -1},
611 {-1, -1, -1, 5, 6, 5, -1, -1},
612 {-1, -1, -1, -1, 6, 3, -1, -1},
613 {-1, -1, -1, -1, -1, -1, -1, -1}},
614 {{ 6, 3, 7, 4, 5, 1, 6, 3},
615 { 5, 1, 6, 3, 7, 4, 5, -1},
616 { 6, 3, 7, 4, 5, 1, 6, 3},
617 {-1, -1, -1, -1, -1, -1, -1, -1},
618 {-1, -1, -1, -1, -1, -1, -1, -1},
619 {-1, -1, -1, -1, -1, -1, -1, -1},
620 {-1, -1, -1, -1, -1, -1, -1, -1},
621 {-1, -1, -1, -1, -1, -1, -1, -1},
622 {-1, -1, -1, -1, -1, -1, -1, -1},
623 {-1, -1, -1, -1, -1, -1, -1, -1}},
624 {{-1, -1, -1, -1, -1, -1, 4, 4},
625 {-1, -1, 7, 7, 7, 4, 4, -1},
626 {-1, -1, -1, -1, -1, -1, 4, 4},
627 {-1, 1, -1, -1, -1, 7, -1, -1},
628 {-1, 1, 1, -1, -1, 7, -1, -1},
629 { 3, 3, 3, -1, 7, -1, -1, -1},
630 { 3, -1, 2, 3, 3, 3, -1, 3},
631 {-1, 2, -1, 3, -1, 3, 3, -1},
632 {-1, 2, -1, -1, -1, -1, -1, -1},
633 {-1, -1, -1, -1, -1, -1, -1, -1}},
634 {{-1, -1, 4, -1, -1, -1, -1, -1},
635 {-1, 7, 4, -1, -1, -1, -1, -1},
636 {-1, -1, 7, 4, -1, -1, -1, -1},
637 {-1, 4, 7, 4, -1, -1, -1, -1},
638 { 1, 1, 1, 1, 1, 1, 1, -1},
639 { 1, 2, 1, 2, 1, 1, -1, -1},
640 { 2, 2, 2, 2, 2, 2, 2, 2},
641 {-1, -1, -1, -1, -1, -1, -1, -1},
642 {-1, -1, -1, -1, -1, -1, -1, -1},
643 {-1, -1, -1, -1, -1, -1, -1, -1}},
644 {{ 0, -1, -1, -1, -1, -1, -1, 6},
645 { 6, 1, 4, 3, 7, 5, 0, -1},
646 { 0, -1, -1, -1, -1, -1, -1, 6},
647 { 6, 1, 4, 3, 7, 5, 0, -1},
648 { 0, -1, -1, -1, -1, -1, -1, 6},
649 { 6, 1, 4, 3, 7, 5, 0, -1},
650 {-1, -1, -1, -1, -1, -1, -1, -1},
651 {-1, -1, -1, -1, -1, -1, -1, -1},
652 {-1, -1, -1, -1, -1, -1, -1, -1},
653 {-1, -1, -1, -1, -1, -1, -1, -1}},
654 {{ 3, 3, 4, 6, 6, 4, 3, 3},
655 { 0, 3, 4, 6, 4, 3, 1, -1},
656 { 5, 1, 3, 4, 4, 3, 0, 1},
657 { 0, 1, 3, 4, 3, 1, 0, -1},
658 { 2, 1, 6, 3, 3, 0, 0, 1},
659 { 0, 3, 4, 3, 6, 1, 5, -1},
660 { 6, 1, 2, 6, 4, 0, 0, 2},
661 {-1, -1, -1, -1, -1, -1, -1, -1},
662 {-1, -1, -1, -1, -1, -1, -1, -1},
663 {-1, -1, -1, -1, -1, -1, -1, -1}},
664 {{ 6, 6, -1, -1, -1, -1, 4, 4},
665 { 4, 0, -1, -1, -1, 3, 6, -1},
666 { 0, 6, -1, -1, -1, -1, 4, 2},
667 { 7, -1, -1, -1, -1, -1, 7, -1},
668 { 4, 4, -1, -1, -1, -1, 5, 6},
669 { 6, 4, 7, 7, 5, 6, 4, -1},
670 {-1, 7, 6, 4, 6, 4, 7, -1},
671 {-1, 0, -1, 7, -1, 7, -1, -1},
672 {-1, -1, -1, -1, -1, -1, -1, -1},
673 {-1, -1, -1, -1, -1, -1, -1, -1}},
674 {{-1, 5, -1, -1, -1, -1, 4, -1},
675 {-1, 5, -1, -1, -1, 4, -1, -1},
676 {-1, -1, 5, 6, 6, 4, -1, -1},
677 {-1, -1, 2, -1, 2, -1, -1, -1},
678 { 0, 0, 6, -1, -1, 6, 1, 1},
679 {-1, -1, 2, -1, 2, -1, -1, -1},
680 {-1, -1, 7, 6, 6, 3, -1, -1},
681 {-1, 7, -1, -1, -1, 3, -1, -1},
682 {-1, 7, -1, -1, -1, -1, 3, -1},
683 {-1, -1, -1, -1, -1, -1, -1, -1}},
684 {{-1, 6, -1, -1, -1, -1, 2, -1},
685 { 1, 7, 1, 1, 1, 3, 1, -1},
686 {-1, -1, 4, 1, 1, 4, -1, -1},
687 {-1, 1, 3, 1, 7, 1, -1, -1},
688 {-1, -1, -1, 2, 6, -1, -1, -1},
689 {-1, -1, 1, 5, 1, -1, -1, -1},
690 {-1, -1, -1, -1, -1, -1, -1, -1},
691 {-1, -1, -1, -1, -1, -1, -1, -1},
692 {-1, -1, -1, -1, -1, -1, -1, -1},
693 {-1, -1, -1, -1, -1, -1, -1, -1}},
694 {{ 7, 7, 7, 7, 7, 7, 7, 7},
695 { 7, -1, -1, -1, -1, -1, 7, -1},
696 { 7, -1, -1, 2, 0, 5, 2, 2},
697 { 7, -1, -1, -1, 0, 3, 6, -1},
698 { 7, -1, -1, -1, -1, -1, 4, 0},
699 { 5, 5, -1, -1, -1, -1, -1, -1},
700 { 4, 3, 6, 2, -1, -1, -1, -1},
701 { 0, 2, 0, 4, -1, -1, -1, -1},
702 {-1, -1, -1, -1, -1, -1, -1, -1},
703 {-1, -1, -1, -1, -1, -1, -1, -1}},
704 {{-1, -1, 1, -1, -1, 1, -1, -1},
705 {-1, 4, -1, -1, 5, -1, -1, -1},
706 {-1, 7, -1, -1, 1, 1, 1, -1},
707 { 6, -1, -1, -1, -1, 7, -1, -1},
708 { 1, 1, 1, 1, -1, 4, -1, -1},
709 {-1, -1, 5, -1, -1, -1, -1, -1},
710 {-1, -1, 0, -1, -1, -1, -1, -1},
711 {-1, 3, -1, -1, -1, -1, -1, -1},
712 {-1, 1, -1, -1, -1, -1, -1, -1},
713 {-1, -1, -1, -1, -1, -1, -1, -1}},
714 {{-1, 7, 7, -1, -1, 7, 7, -1},
715 { 6, -1, 4, -1, 4, -1, 6, -1},
716 { 5, -1, -1, 3, 3, -1, -1, 5},
717 { 6, -1, -1, -1, -1, -1, 6, -1},
718 {-1, 7, -1, -1, -1, -1, 7, -1},
719 {-1, 4, -1, -1, -1, 4, -1, -1},
720 {-1, -1, 3, -1, -1, 3, -1, -1},
721 {-1, -1, 2, -1, 2, -1, -1, -1},
722 {-1, -1, -1, 5, 5, -1, -1, -1},
723 {-1, -1, -1, -1, -1, -1, -1, -1}},
724 {{-1, 0, 0, -1, -1, 0, 0, -1},
725 { 7, 4, 6, 6, 6, 4, 3, -1},
726 { 5, 6, 6, 6, 2, 6, 6, 3},
727 { 7, 4, 6, 6, 6, 4, 3, -1},
728 {-1, 0, 0, -1, -1, 0, 0, -1},
729 {-1, -1, -1, -1, -1, -1, -1, -1},
730 {-1, -1, -1, -1, -1, -1, -1, -1},
731 {-1, -1, -1, -1, -1, -1, -1, -1},
732 {-1, -1, -1, -1, -1, -1, -1, -1},
733 {-1, -1, -1, -1, -1, -1, -1, -1}},
734 {{-1, -1, -1, -1, -1, 7, 7, 7},
735 {-1, -1, -1, -1, 2, 7, 7, -1},
736 {-1, 0, 7, 7, 7, -1, 7, 7},
737 { 6, 7, 7, 7, -1, -1, -1, -1},
738 { 6, -1, -1, -1, 7, 7, 7, 7},
739 { 6, -1, -1, -1, -1, -1, -1, -1},
740 { 4, 2, 2, 2, 4, -1, 3, -1},
741 { 4, 4, 4, 4, 3, 3, 3, -1},
742 {-1, -1, -1, -1, -1, -1, -1, -1},
743 {-1, -1, -1, -1, -1, -1, -1, -1}},
744 {{ 4, -1, -1, 7, -1, 6, -1, 7},
745 { 7, 6, 7, -1, -1, 7, 4, -1},
746 {-1, -1, 7, -1, -1, 7, -1, -1},
747 {-1, 0, 0, 0, 0, 0, 3, -1},
748 {-1, -1, 0, 2, 2, 0, 6, 4},
749 {-1, -1, 0, 0, 0, 1, 3, -1},
750 {-1, -1, -1, 0, 0, -1, 3, 4},
751 {-1, -1, -1, 6, -1, 5, 6, -1},
752 {-1, -1, -1, -1, -1, -1, 1, 0},
753 {-1, -1, -1, -1, -1, -1, -1, -1}},
754 {{-1, 5, -1, -1, -1, -1, 5, -1},
755 { 0, -1, -1, 0, -1, -1, 0, -1},
756 { 0, 0, 0, 2, 2, 0, 0, 0},
757 { 0, -1, -1, 0, -1, -1, 0, -1},
758 {-1, 7, -1, 3, -1, -1, 7, -1},
759 {-1, -1, 3, 6, -1, -1, -1, -1},
760 {-1, -1, -1, 6, -1, -1, -1, -1},
761 {-1, 3, 6, -1, -1, -1, -1, -1},
762 {-1, 3, -1, -1, -1, -1, -1, -1},
763 {-1, -1, -1, -1, -1, -1, -1, -1}},
764 {{-1, -1, -1, 6, 5, -1, -1, -1},
765 {-1, -1, 2, 6, 3, -1, -1, -1},
766 {-1, -1, 5, 4, 7, 1, -1, -1},
767 {-1, 6, 2, 2, 3, 4, -1, -1},
768 {-1, -1, 3, 7, 3, 6, -1, -1},
769 {-1, -1, 1, 3, 2, -1, -1, -1},
770 {-1, -1, -1, 4, 5, -1, -1, -1},
771 {-1, -1, -1, 4, -1, -1, -1, -1},
772 {-1, -1, -1, -1, -1, -1, -1, -1},
773 {-1, -1, -1, -1, -1, -1, -1, -1}},
774 {{ 7, 7, -1, 2, 2, -1, 6, 6},
775 { 6, -1, -1, 6, -1, -1, 3, -1},
776 { 2, -1, -1, 1, -1, -1, 2, -1},
777 { 5, -1, -1, 3, -1, -1, 2, -1},
778 { 1, -1, -1, 2, -1, -1, 1, -1},
779 { 5, -1, -1, 2, -1, -1, 2, -1},
780 { 6, -1, -1, 1, -1, -1, 7, -1},
781 { 5, -1, -1, 5, -1, -1, 4, -1},
782 {-1, -1, -1, -1, -1, -1, -1, -1},
783 {-1, -1, -1, -1, -1, -1, -1, -1}},
784 {{-1, -1, -1, 6, 6, -1, -1, -1},
785 {-1, 0, 4, 4, 4, 0, -1, -1},
786 {-1, -1, -1, 6, 6, -1, -1, -1},
787 {-1, -1, 2, 7, 2, -1, -1, -1},
788 {-1, -1, -1, 6, 6, -1, -1, -1},
789 {-1, 0, 5, 5, 5, 0, -1, -1},
790 {-1, -1, -1, 3, 3, -1, -1, -1},
791 {-1, -1, -1, -1, -1, -1, -1, -1},
792 {-1, -1, -1, -1, -1, -1, -1, -1},
793 {-1, -1, -1, -1, -1, -1, -1, -1}},
794 {{-1, -1, 4, 1, 3, -1, -1, -1},
795 {-1, 1, -1, -1, 1, -1, -1, -1},
796 {-1, -1, 4, 1, 3, 4, 1, -1},
797 {-1, 1, 3, 4, -1, -1, 4, -1},
798 {-1, 3, -1, -1, 3, 4, 1, -1},
799 {-1, 1, 3, 4, 1, 3, -1, -1},
800 {-1, -1, 4, 1, -1, -1, -1, -1},
801 {-1, -1, -1, -1, -1, -1, -1, -1},
802 {-1, -1, -1, -1, -1, -1, -1, -1},
803 {-1, -1, -1, -1, -1, -1, -1, -1}},
804 {{-1, 6, 4, -1, 3, 2, 5, -1},
805 { 0, -1, -1, -1, -1, -1, 1, -1},
806 {-1, 2, 3, 5, -1, 4, 6, -1},
807 { 0, -1, -1, -1, -1, -1, 1, -1},
808 {-1, 4, 6, -1, 2, 5, 3, -1},
809 { 0, -1, -1, -1, -1, -1, 1, -1},
810 {-1, 5, 2, 3, -1, 4, 6, -1},
811 {-1, -1, -1, -1, -1, -1, -1, -1},
812 {-1, -1, -1, -1, -1, -1, -1, -1},
813 {-1, -1, -1, -1, -1, -1, -1, -1}},
814 {{-1, -1, -1, 6, 6, -1, -1, -1},
815 {-1, -1, 7, 6, 4, -1, -1, -1},
816 {-1, 2, 1, 7, 4, 1, 3, -1},
817 { 2, 1, 1, 1, 1, 1, 3, -1},
818 {-1, 2, 2, 2, 3, 3, 3, -1},
819 {-1, -1, -1, 5, -1, -1, -1, -1},
820 {-1, -1, -1, 2, 3, -1, -1, -1},
821 {-1, -1, -1, 5, -1, -1, -1, -1},
822 {-1, -1, 2, 2, 3, 3, -1, -1},
823 {-1, -1, -1, -1, -1, -1, -1, -1}},
824 {{ 4, -1, 5, -1, -1, 3, -1, 6},
825 { 2, -1, 3, -1, 2, -1, 4, -1},
826 { 4, -1, -1, 1, 0, -1, -1, 6},
827 { 6, -1, 2, 3, 5, -1, 4, -1},
828 { 4, -1, -1, 0, 1, -1, -1, 6},
829 { 2, -1, 5, -1, 3, -1, 4, -1},
830 { 4, -1, 3, -1, -1, 2, -1, 6},
831 { 6, -1, -1, -1, -1, -1, 4, -1},
832 {-1, -1, -1, -1, -1, -1, -1, -1},
833 {-1, -1, -1, -1, -1, -1, -1, -1}},
834 {{ 2, 6, 0, 5, 5, 1, 3, 4},
835 { 1, -1, -1, 2, -1, -1, 0, -1},
836 { 4, -1, -1, 3, 6, -1, -1, 2},
837 {-1, -1, -1, 0, -1, -1, -1, -1},
838 {-1, -1, -1, 1, 4, -1, -1, -1},
839 {-1, -1, -1, 2, -1, -1, -1, -1},
840 {-1, -1, -1, 6, 3, -1, -1, -1},
841 {-1, -1, -1, 5, -1, -1, -1, -1},
842 {-1, -1, -1, 4, 1, -1, -1, -1},
843 {-1, -1, -1, -1, -1, -1, -1, -1}},
844 {{-1, -1, -1, -1, 5, 1, 1, 3},
845 { 0, 5, 1, 0, 5, 3, 3, -1},
846 { 5, 1, 0, 5, 1, 0, 5, 1},
847 { 0, 5, 1, 0, 5, 1, 6, -1},
848 {-1, -1, -1, -1, 1, 6, 5, 1},
849 {-1, -1, -1, -1, 5, 1, 6, -1},
850 {-1, -1, -1, -1, 1, 0, 5, 1},
851 {-1, -1, -1, -1, 5, 1, 0, -1},
852 {-1, -1, -1, -1, -1, -1, -1, -1},
853 {-1, -1, -1, -1, -1, -1, -1, -1}},
854 {{-1, 0, 7, 3, -1, -1, 2, 2},
855 {-1, 0, 7, 3, -1, -1, 2, -1},
856 {-1, 0, 7, 3, -1, -1, 2, 2},
857 {-1, 0, 7, 3, -1, 3, 1, -1},
858 {-1, 0, 7, 3, -1, 6, 4, 5},
859 {-1, 0, 7, 3, -1, 7, 0, -1},
860 {-1, 0, 7, 3, -1, 2, 3, 4},
861 {-1, 0, 7, 3, -1, 5, 6, -1},
862 {-1, -1, -1, -1, -1, 7, 0, 1},
863 {-1, -1, -1, -1, -1, -1, -1, -1}},
864 {{-1, -1, -1, 7, 7, 7, 7, -1},
865 { 3, 4, 5, -1, -1, -1, 7, -1},
866 { 2, -1, -1, -1, -1, -1, -1, 3},
867 { 7, -1, -1, -1, -1, -1, 4, -1},
868 { 7, -1, -1, -1, 3, 4, 5, 6},
869 { 7, -1, -1, 2, 0, 1, 2, -1},
870 { 6, -1, -1, -1, 3, 4, 5, 6},
871 { 0, 1, -1, -1, -1, -1, -1, -1},
872 { 2, 3, 4, -1, -1, -1, -1, -1},
873 { 5, 6, 0, -1, -1, -1, -1, -1}},
874 {{-1, 7, -1, -1, -1, -1, 2, -1},
875 { 1, 1, -1, -1, -1, 3, 3, -1},
876 {-1, 2, -1, -1, -1, -1, 4, -1},
877 { 3, 3, -1, -1, -1, 5, 5, -1},
878 {-1, 4, -1, -1, -1, -1, 6, -1},
879 { 5, 5, -1, -1, -1, 1, 1, -1},
880 {-1, 6, -1, -1, -1, -1, 7, -1},
881 {-1, -1, -1, -1, -1, -1, -1, -1},
882 {-1, -1, -1, -1, -1, -1, -1, -1},
883 {-1, -1, -1, -1, -1, -1, -1, -1}},
884 {{-1, 4, -1, -1, -1, -1, 4, -1},
885 { 2, -1, -1, 1, -1, -1, 2, -1},
886 { 5, -1, -1, 0, 0, -1, -1, 5},
887 { 5, -1, -1, 1, -1, -1, 6, -1},
888 {-1, 4, 2, 7, 7, 5, 4, -1},
889 {-1, -1, -1, 6, -1, -1, -1, -1},
890 {-1, -1, -1, 3, 3, -1, -1, -1},
891 {-1, -1, -1, 7, -1, -1, -1, -1},
892 {-1, -1, -1, -1, -1, -1, -1, -1},
893 {-1, -1, -1, -1, -1, -1, -1, -1}},
894 {{-1, 1, -1, -1, 2, 3, 4, -1},
895 { 2, -1, -1, 3, 0, 4, -1, -1},
896 { 4, -1, -1, 2, 3, 1, -1, -1},
897 { 3, -1, 4, 3, 0, -1, -1, -1},
898 { 4, -1, -1, 2, 5, 1, -1, -1},
899 { 3, -1, 4, 5, 0, 4, -1, -1},
900 {-1, -1, -1, -1, -1, -1, -1, -1},
901 {-1, -1, -1, -1, -1, -1, -1, -1},
902 {-1, -1, -1, -1, -1, -1, -1, -1},
903 {-1, -1, -1, -1, -1, -1, -1, -1}},
904 {{ 2, -1, -1, 1, 1, -1, -1, 2},
905 { 2, -1, 3, 3, 3, -1, 2, -1},
906 {-1, 2, -1, 4, 4, -1, 2, -1},
907 {-1, 7, 7, 0, 7, 7, -1, -1},
908 {-1, -1, -1, 4, 4, -1, -1, -1},
909 {-1, -1, 5, 7, 5, -1, -1, -1},
910 { 6, 3, 2, 6, 4, 2, 3, 6},
911 { 5, -1, -1, -1, -1, -1, 1, -1},
912 {-1, -1, -1, -1, -1, -1, -1, -1},
913 {-1, -1, -1, -1, -1, -1, -1, -1}},
914 {{ 4, 2, 3, 5, 7, 1, 3, 6},
915 { 1, -1, -1, 1, -1, -1, 1, -1},
916 { 3, 0, 1, 3, 2, 4, 3, 5},
917 { 4, -1, -1, 4, -1, -1, 4, -1},
918 {-1, 5, -1, -1, 5, -1, -1, 5},
919 { 0, 3, 2, 0, 4, 5, 0, -1},
920 {-1, 6, -1, -1, 6, -1, -1, 6},
921 { 7, -1, -1, 7, -1, -1, 7, -1},
922 {-1, -1, -1, -1, -1, -1, -1, -1},
923 {-1, -1, -1, -1, -1, -1, -1, -1}},
924 {{-1, 5, 4, -1, 1, 1, -1, -1},
925 { 5, -1, 4, 1, -1, 1, -1, -1},
926 { 0, -1, -1, -1, -1, -1, 0, -1},
927 { 0, 6, 4, -1, -1, 4, 2, -1},
928 {-1, 4, 3, 5, 2, 6, 3, 6},
929 {-1, 2, 6, -1, -1, 5, 4, -1},
930 {-1, -1, -1, -1, -1, -1, -1, -1},
931 {-1, -1, -1, -1, -1, -1, -1, -1},
932 {-1, -1, -1, -1, -1, -1, -1, -1},
933 {-1, -1, -1, -1, -1, -1, -1, -1}},
934 {{-1, -1, -1, 6, 6, -1, -1, -1},
935 {-1, -1, 5, 5, 4, -1, -1, -1},
936 {-1, -1, 1, 6, 6, 4, -1, -1},
937 {-1, 1, 7, 2, 5, 3, -1, -1},
938 {-1, 2, 7, 2, 1, 5, 3, -1},
939 { 2, 1, 3, 1, 4, 2, 7, -1},
940 {-1, 3, 1, 3, 4, 2, 7, -1},
941 {-1, 3, 5, 5, 6, 6, -1, -1},
942 {-1, -1, -1, -1, -1, -1, -1, -1},
943 {-1, -1, -1, -1, -1, -1, -1, -1}},
944 {{-1, -1, 7, 3, -1, -1, -1, -1},
945 {-1, 1, 7, 6, -1, -1, -1, -1},
946 {-1, 3, 7, 5, 1, 5, -1, -1},
947 { 7, 7, 0, 2, 4, 0, 4, -1},
948 { 7, 1, 4, 6, 5, 6, 5, 7},
949 { 1, 7, 7, 1, 7, 7, 1, -1},
950 {-1, -1, -1, -1, -1, -1, -1, -1},
951 {-1, -1, -1, -1, -1, -1, -1, -1},
952 {-1, -1, -1, -1, -1, -1, -1, -1},
953 {-1, -1, -1, -1, -1, -1, -1, -1}},
954 {{-1, -1, 1, -1, -1, 1, -1, -1},
955 {-1, 5, 6, 1, 5, 6, -1, -1},
956 {-1, 1, 1, 2, 2, 1, 1, -1},
957 { 4, 7, 1, 0, 1, 7, 4, -1},
958 {-1, 3, 7, 5, 7, 5, 3, -1},
959 {-1, 1, 1, 1, 1, 1, -1, -1},
960 {-1, -1, -1, -1, -1, -1, -1, -1},
961 {-1, -1, -1, -1, -1, -1, -1, -1},
962 {-1, -1, -1, -1, -1, -1, -1, -1},
963 {-1, -1, -1, -1, -1, -1, -1, -1}},
964 {{ 4, -1, -1, -1, 5, -1, -1, 4},
965 { 6, 6, 7, 6, -1, 4, 5, -1},
966 { 4, 2, 7, 5, 2, 2, 6, 4},
967 {-1, -1, 4, 1, -1, 5, 2, -1},
968 {-1, 5, 2, 7, 7, -1, 7, 4},
969 { 4, 6, 5, 4, -1, 4, 2, -1},
970 {-1, -1, -1, 4, -1, 4, 1, -1},
971 { 0, 0, 0, 5, -1, -1, -1, -1},
972 {-1, -1, -1, -1, 0, 0, 0, 0},
973 {-1, -1, -1, -1, -1, -1, -1, -1}},
974 {{ 1, -1, -1, -1, 0, 0, -1, -1},
975 { 2, -1, -1, 0, 1, 0, -1, -1},
976 { 3, -1, -1, 0, 2, 2, 0, -1},
977 { 4, -1, 0, 1, 1, 1, 0, -1},
978 { 5, -1, -1, 0, 4, 4, 0, -1},
979 { 6, -1, -1, 4, 4, 4, -1, -1},
980 { 7, -1, -1, -1, 4, 4, -1, -1},
981 {-1, -1, -1, 0, 1, 0, -1, -1},
982 {-1, -1, -1, 0, 1, 1, 0, -1},
983 {-1, -1, -1, -1, -1, -1, -1, -1}},
984 {{-1, -1, 3, -1, -1, 1, 7, -1},
985 {-1, 7, 4, -1, -1, 4, 3, -1},
986 { 1, -1, -1, 0, 2, 0, -1, -1},
987 { 5, 4, -1, 3, -1, -1, -1, -1},
988 { 4, -1, 3, 6, 1, 1, 6, -1},
989 {-1, 1, -1, -1, 4, -1, 1, -1},
990 {-1, 7, 5, -1, -1, -1, 3, -1},
991 {-1, -1, 3, -1, -1, -1, -1, -1},
992 {-1, -1, -1, -1, -1, -1, -1, -1},
993 {-1, -1, -1, -1, -1, -1, -1, -1}},
994 {{ 1, -1, -1, -1, 1, -1, -1, -1},
995 { 2, -1, -1, -1, 2, -1, -1, -1},
996 {-1, 3, -1, -1, 3, 3, -1, -1},
997 {-1, 4, -1, 4, -1, 4, -1, -1},
998 {-1, 5, -1, -1, 5, 5, -1, -1},
999 { 6, -1, -1, 7, 1, 7, -1, -1},
1000 { 7, -1, -1, -1, 6, 6, -1, -1},
1001 {-1, -1, -1, -1, -1, -1, -1, -1},
1002 {-1, -1, -1, -1, -1, -1, -1, -1},
1003 {-1, -1, -1, -1, -1, -1, -1, -1}},
1004 {{ 2, -1, -1, 6, -1, 2, 5, 1},
1005 { 5, -1, 4, -1, 4, -1, 4, -1},
1006 { 6, -1, -1, 3, -1, -1, -1, 3},
1007 { 4, 2, 0, -1, -1, -1, 5, -1},
1008 {-1, -1, -1, 6, -1, 3, 6, -1},
1009 {-1, -1, 5, -1, 5, -1, -1, -1},
1010 {-1, -1, -1, 3, -1, 4, 2, 5},
1011 {-1, -1, -1, -1, -1, -1, -1, -1},
1012 {-1, -1, -1, -1, -1, -1, -1, -1},
1013 {-1, -1, -1, -1, -1, -1, -1, -1}},
1014 {{ 6, -1, -1, -1, 4, -1, -1, 3},
1015 { 0, 3, -1, -1, 6, -1, 0, -1},
1016 {-1, -1, 7, -1, 1, -1, 3, -1},
1017 { 7, -1, 4, 7, -1, 2, -1, -1},
1018 { 5, 2, 3, 2, 1, 6, -1, 3},
1019 {-1, -1, 0, 4, 3, 5, 4, -1},
1020 {-1, 7, 6, -1, -1, 0, -1, -1},
1021 { 4, 3, -1, -1, -1, 4, 2, -1},
1022 { 0, -1, -1, -1, -1, -1, 6, -1},
1023 {-1, -1, -1, -1, -1, -1, -1, -1}},
1024 {{ 6, 1, 2, 5, 1, 6, 3, 0},
1025 {-1, -1, -1, -1, -1, -1, 4, -1},
1026 { 0, 5, 2, 7, 1, 6, 2, -1},
1027 { 3, -1, -1, -1, -1, -1, -1, -1},
1028 { 6, 7, 6, 4, 0, 5, 2, 6},
1029 {-1, -1, -1, -1, -1, -1, 1, -1},
1030 { 6, 1, 4, 0, 6, 2, 3, -1},
1031 { 0, -1, -1, -1, -1, -1, -1, -1},
1032 {-1, 0, 4, 5, 3, 7, 6, 0},
1033 {-1, -1, -1, -1, -1, -1, -1, -1}},
1034 {{-1, -1, -1, 0, 1, -1, -1, -1},
1035 {-1, -1, 0, 7, 0, -1, -1, -1},
1036 {-1, -1, 1, 2, 2, 0, -1, -1},
1037 {-1, 0, 7, 0, 7, 0, -1, -1},
1038 {-1, 6, -1, 7, 7, -1, 6, -1},
1039 { 4, 1, 6, 6, 6, 4, 1, -1},
1040 {-1, 5, -1, 7, 7, -1, 5, -1},
1041 {-1, -1, -1, -1, -1, -1, -1, -1},
1042 {-1, -1, -1, -1, -1, -1, -1, -1},
1043 {-1, -1, -1, -1, -1, -1, -1, -1}},
1044 {{-1, -1, -1, 5, 6, -1, -1, -1},
1045 {-1, -1, 3, 3, 3, -1, -1, -1},
1046 {-1, -1, 7, 5, 3, 7, -1, -1},
1047 {-1, 3, -1, 6, -1, 3, -1, -1},
1048 { 2, -1, -1, 3, 7, -1, -1, 1},
1049 { 2, 2, -1, 3, -1, 1, 1, -1},
1050 {-1, 0, 2, 5, 6, 1, 0, -1},
1051 {-1, -1, -1, 3, -1, -1, -1, -1},
1052 {-1, -1, -1, 3, 7, -1, -1, -1},
1053 {-1, -1, -1, -1, -1, -1, -1, -1}},
1054 {{-1, 6, -1, -1, -1, -1, 2, -1},
1055 {-1, 2, 6, 0, 6, 0, -1, -1},
1056 {-1, 0, -1, -1, -1, -1, -1, -1},
1057 { 6, -1, -1, -1, -1, -1, -1, -1},
1058 {-1, 3, 3, 2, 0, 6, 0, 0},
1059 {-1, 6, -1, -1, -1, -1, 0, -1},
1060 {-1, -1, -1, 6, 0, 2, 6, -1},
1061 {-1, 2, 0, -1, -1, -1, -1, -1},
1062 {-1, -1, -1, -1, -1, -1, -1, -1},
1063 {-1, -1, -1, -1, -1, -1, -1, -1}},
1064 {{ 0, 7, -1, -1, -1, -1, -1, -1},
1065 { 1, 5, -1, -1, -1, -1, -1, -1},
1066 { 7, 2, 5, -1, -1, -1, -1, -1},
1067 { 6, 3, 4, -1, -1, -1, -1, -1},
1068 { 5, 5, 4, 4, -1, -1, -1, -1},
1069 { 3, 3, 5, 3, -1, -1, -1, -1},
1070 { 1, 2, 2, 5, 3, -1, -1, -1},
1071 { 1, 0, 0, 7, 6, -1, -1, -1},
1072 { 3, 3, 5, 5, 7, 6, -1, -1},
1073 {-1, -1, -1, -1, -1, -1, -1, -1}},
1074 {{-1, -1, 2, 6, 6, 2, -1, -1},
1075 {-1, 2, 1, 1, 0, 2, -1, -1},
1076 {-1, 2, 3, 2, 2, 0, 2, -1},
1077 { 2, 3, 2, 5, 2, 7, 2, -1},
1078 { 2, 4, 2, 5, 2, 7, 2, 0},
1079 { 2, 4, 2, 6, 6, 2, 0, -1},
1080 {-1, 2, 5, 2, 2, 2, 7, 2},
1081 {-1, 2, 5, 6, 6, 7, 2, -1},
1082 {-1, -1, 2, 2, 2, 2, 2, -1},
1083 {-1, -1, -1, -1, -1, -1, -1, -1}},
1084 {{-1, -1, 0, -1, -1, 0, -1, -1},
1085 { 1, 0, 0, 1, 0, 0, 1, -1},
1086 { 1, 7, 7, 5, 5, 7, 7, 1},
1087 { 3, 2, -1, 2, -1, 2, 3, -1},
1088 { 3, 7, -1, 6, 6, -1, 7, 3},
1089 { 7, -1, -1, 6, -1, -1, 7, -1},
1090 { 4, 4, 5, -1, -1, 5, 4, 4},
1091 {-1, -1, -1, -1, -1, -1, -1, -1},
1092 {-1, -1, -1, -1, -1, -1, -1, -1},
1093 {-1, -1, -1, -1, -1, -1, -1, -1}},
1094 {{-1, 6, 3, -1, -1, 3, 6, -1},
1095 { 6, -1, 2, -1, 2, -1, 6, -1},
1096 { 2, -1, 0, 1, 1, 0, -1, 2},
1097 { 5, 0, -1, 7, -1, 0, 5, -1},
1098 {-1, 5, -1, 6, 6, -1, 5, -1},
1099 { 7, 1, 4, -1, 4, 1, 7, -1},
1100 { 7, -1, 4, -1, -1, 4, -1, 7},
1101 { 2, 0, -1, -1, -1, 0, 2, -1},
1102 {-1, 2, -1, -1, -1, -1, 2, -1},
1103 {-1, -1, -1, -1, -1, -1, -1, -1}},
1104 {{ 6, 1, -1, -1, -1, -1, 4, 0},
1105 { 2, 7, 5, 5, 5, 7, 3, -1},
1106 { 6, 1, -1, -1, -1, -1, 4, 0},
1107 { 2, 5, 7, 7, 7, 5, 3, -1},
1108 { 6, 1, -1, -1, -1, -1, 4, 0},
1109 { 2, 0, 6, 6, 6, 0, 3, -1},
1110 { 6, 1, -1, -1, -1, -1, 4, 0},
1111 {-1, -1, -1, -1, -1, -1, -1, -1},
1112 {-1, -1, -1, -1, -1, -1, -1, -1},
1113 {-1, -1, -1, -1, -1, -1, -1, -1}},
1114 {{ 5, -1, -1, 1, 1, -1, -1, 5},
1115 { 5, -1, 4, -1, 4, -1, 5, -1},
1116 {-1, 2, 4, -1, -1, 4, 2, -1},
1117 { 7, 2, -1, -1, -1, 2, 7, -1},
1118 { 0, -1, 0, 4, 4, 0, -1, 0},
1119 { 7, 2, -1, -1, -1, 2, 7, -1},
1120 {-1, 2, 3, -1, -1, 3, 2, -1},
1121 { 5, -1, 3, -1, 3, -1, 5, -1},
1122 { 5, -1, -1, 6, 6, -1, -1, 5},
1123 {-1, -1, -1, -1, -1, -1, -1, -1}},
1124 {{ 2, 2, -1, -1, -1, -1, 5, 5},
1125 { 5, -1, -1, -1, -1, -1, 2, -1},
1126 { 5, -1, -1, -1, -1, -1, -1, 2},
1127 { 1, -1, 1, 5, 1, -1, 3, -1},
1128 { 5, 2, 5, 3, 1, 2, 5, 2},
1129 { 2, 0, 5, -1, 2, 0, 5, -1},
1130 {-1, 3, 7, -1, -1, 3, 7, -1},
1131 {-1, -1, 2, 0, 5, -1, -1, -1},
1132 {-1, -1, -1, -1, -1, -1, -1, -1},
1133 {-1, -1, -1, -1, -1, -1, -1, -1}},
1134 {{ 0, 6, 5, 2, 3, 4, 1, 7},
1135 {-1, -1, -1, -1, 1, -1, -1, -1},
1136 {-1, -1, -1, 1, 1, -1, -1, -1},
1137 {-1, -1, 1, -1, -1, -1, -1, -1},
1138 { 7, 1, 4, 3, 2, 5, 6, 0},
1139 {-1, -1, -1, -1, 1, -1, -1, -1},
1140 {-1, -1, -1, 1, 1, -1, -1, -1},
1141 {-1, -1, 1, -1, -1, -1, -1, -1},
1142 { 0, 6, 5, 2, 3, 4, 1, 7},
1143 {-1, -1, -1, -1, -1, -1, -1, -1}},
1144 {{-1, -1, 1, -1, -1, 1, -1, -1},
1145 {-1, 2, 4, -1, 2, 4, -1, -1},
1146 {-1, 2, 3, 6, 5, 3, 2, -1},
1147 {-1, 6, 5, -1, 6, 5, -1, -1},
1148 {-1, -1, -1, 7, 7, -1, -1, -1},
1149 {-1, -1, -1, 7, -1, -1, -1, -1},
1150 { 1, -1, -1, 7, 7, -1, -1, 3},
1151 { 2, -1, -1, 7, -1, -1, 2, -1},
1152 {-1, 3, 4, 5, 6, 4, 1, -1},
1153 {-1, -1, -1, -1, -1, -1, -1, -1}},
1154 {{ 1, -1, -1, 2, 2, -1, -1, 2},
1155 { 1, 3, 7, 3, 7, 4, 2, -1},
1156 {-1, 1, 6, -1, -1, 6, 2, -1},
1157 { 6, -1, 7, 3, 7, -1, 6, -1},
1158 {-1, 4, 2, -1, -1, 1, 3, -1},
1159 {-1, -1, 2, 6, 1, -1, -1, -1},
1160 {-1, 4, 3, 3, 4, 4, 3, -1},
1161 {-1, -1, -1, -1, -1, -1, -1, -1},
1162 {-1, -1, -1, -1, -1, -1, -1, -1},
1163 {-1, -1, -1, -1, -1, -1, -1, -1}},
1164 {{-1, -1, -1, 5, 6, -1, -1, -1},
1165 {-1, -1, -1, 3, -1, -1, -1, -1},
1166 {-1, -1, -1, 1, 2, -1, -1, -1},
1167 {-1, -1, -1, 4, -1, -1, -1, -1},
1168 {-1, -1, -1, 5, 7, -1, -1, -1},
1169 {-1, -1, -1, 2, -1, -1, -1, -1},
1170 { 6, 5, 4, 3, 2, 1, 7, 5},
1171 {-1, -1, -1, -1, -1, -1, -1, -1},
1172 {-1, -1, -1, -1, -1, -1, -1, -1},
1173 {-1, -1, -1, -1, -1, -1, -1, -1}},
1174 {{-1, 0, -1, 1, -1, 2, -1, -1},
1175 {-1, 4, -1, 5, -1, 6, -1, -1},
1176 {-1, 7, -1, 0, -1, 2, -1, -1},
1177 {-1, 6, -1, 3, -1, 6, -1, -1},
1178 {-1, 1, -1, 1, -1, 2, -1, -1},
1179 {-1, 3, -1, 5, -1, 0, -1, -1},
1180 {-1, 2, -1, 4, -1, 6, -1, -1},
1181 {-1, 3, -1, 6, -1, 7, -1, -1},
1182 {-1, -1, -1, -1, -1, -1, -1, -1},
1183 {-1, -1, -1, -1, -1, -1, -1, -1}},
1184 {{ 1, 1, 2, 2, 3, 3, 4, 4},
1185 { 5, 5, 6, 7, 6, 5, 5, -1},
1186 { 6, 4, 3, 3, 2, 2, 1, 6},
1187 { 4, 6, 5, 7, 6, 3, 1, -1},
1188 {-1, -1, -1, -1, -1, -1, -1, -1},
1189 {-1, -1, -1, -1, -1, -1, -1, -1},
1190 {-1, -1, -1, -1, -1, -1, -1, -1},
1191 {-1, -1, -1, -1, -1, -1, -1, -1},
1192 {-1, -1, -1, -1, -1, -1, -1, -1},
1193 {-1, -1, -1, -1, -1, -1, -1, -1}},
1194 {{ 7, 4, -1, 1, 2, -1, 4, 7},
1195 { 5, 5, -1, 2, -1, 4, 4, -1},
1196 {-1, 5, -1, 7, 7, -1, 4, -1},
1197 { 1, 0, 6, 7, 6, 0, 2, -1},
1198 {-1, 2, -1, 5, 3, -1, 1, -1},
1199 { 1, 1, -1, -1, -1, 2, 2, -1},
1200 { 6, 1, 4, -1, -1, 4, 2, 6},
1201 { 5, 3, -1, -1, -1, 3, 5, -1},
1202 {-1, -1, -1, -1, -1, -1, -1, -1},
1203 {-1, -1, -1, -1, -1, -1, -1, -1}},
1204 {{ 1, 5, 1, 0, 0, 1, 5, 1},
1205 { 1, 2, 5, -1, 5, 2, 1, -1},
1206 { 3, 6, 1, 2, 2, 1, 6, 3},
1207 { 4, 3, 4, -1, 4, 3, 4, -1},
1208 { 3, 4, 6, 5, 5, 6, 4, 3},
1209 { 0, 2, 3, -1, 3, 2, 0, -1},
1210 { 2, 3, 1, 5, 5, 1, 3, 2},
1211 {-1, -1, -1, -1, -1, -1, -1, -1},
1212 {-1, -1, -1, -1, -1, -1, -1, -1},
1213 {-1, -1, -1, -1, -1, -1, -1, -1}},
1214 {{ 3, 0, 2, 7, 5, 7, 6, 5},
1215 { 6, -1, 1, -1, 2, -1, 1, -1},
1216 {-1, 6, 4, 0, 3, 4, 5, -1},
1217 {-1, 5, -1, 1, -1, 4, -1, -1},
1218 {-1, 7, 3, 5, 6, 5, 3, -1},
1219 { 1, -1, 2, -1, 4, -1, 2, -1},
1220 { 6, 4, 4, 6, 6, 5, 5, 1},
1221 {-1, -1, -1, -1, -1, -1, -1, -1},
1222 {-1, -1, -1, -1, -1, -1, -1, -1},
1223 {-1, -1, -1, -1, -1, -1, -1, -1}}
1226 /* the tile struct
1227 * type is the bubble number 0-7
1228 * fallx is the x axis movement for the falling bubble
1229 * fallvel is the initial upward velocity for the falling bubble
1230 * ingroup denotes a bubble that is part of a group to be removed
1231 * anchored denotes a bubble that is anchored to the ceiling
1233 struct tile {
1234 int type;
1235 int fallx;
1236 int fallvel;
1237 bool ingroup;
1238 bool anchored;
1239 bool delete;
1242 /* the game context struct
1243 * score is the current score
1244 * level is the current level
1245 * angle is the current cannon direction
1246 * shots is the number of shots fired since last compression
1247 * compress is the height of the compressor
1248 * onboardcnt is the number of unique bubbles on the playing board
1249 * onboard is the unique bubbles on the playing board
1250 * nextinq is the pointer to the next bubble in the firing queue
1251 * queue is the circular buffer of bubbles to be fired
1252 * elapsedlvl is level elapsed time in 1/100s of seconds
1253 * elapsedshot is the shot elapsed time in 1/100s of seconds
1254 * startedshot is when the current shot began
1255 * playboard is the game playing board
1257 struct game_context {
1258 unsigned int score;
1259 unsigned int level;
1260 int angle;
1261 int shots;
1262 int compress;
1263 int onboardcnt;
1264 int onboard[NUM_BUBBLES];
1265 int nextinq;
1266 int queue[NUM_QUEUE];
1267 long elapsedlvl;
1268 long elapsedshot;
1269 long startedshot;
1270 struct tile playboard[BB_HEIGHT][BB_WIDTH];
1273 struct highscore highscores[NUM_SCORES];
1275 /* used to denote available resume info */
1276 static bool resume = false;
1277 static unsigned int highlevel = 0; /* the highest level beaten */
1278 static unsigned int last_highlevel = 0;
1280 static void bubbles_init(struct game_context* bb);
1281 static bool bubbles_nextlevel(struct game_context* bb);
1282 static void bubbles_getonboard(struct game_context* bb);
1283 static void bubbles_drawboard(struct game_context* bb);
1284 static int bubbles_fire(struct game_context* bb);
1285 static bool bubbles_collision(struct game_context* bb, int y, int x,
1286 int nearrow, int nearcol);
1287 static bool bubbles_ingroup(struct game_context* bb, int row, int col);
1288 static int bubbles_searchgroup(struct game_context* bb, int row, int col);
1289 static int bubbles_remove(struct game_context* bb);
1290 static void bubbles_anchored(struct game_context* bb, int row, int col);
1291 static int bubbles_fall(struct game_context* bb);
1292 static int bubbles_checklevel(struct game_context* bb);
1293 static void bubbles_recordscore(struct game_context* bb);
1294 static bool bubbles_loadgame(struct game_context* bb);
1295 static void bubbles_savegame(struct game_context* bb);
1296 static inline void bubbles_setcolors(void);
1297 static void bubbles_callback(void* param);
1298 static int bubbles_handlebuttons(struct game_context* bb, bool animblock,
1299 int timeout);
1300 static int bubbles(struct game_context* bb);
1302 /*****************************************************************************
1303 * bubbles_init() initializes bubbles data structures.
1304 ******************************************************************************/
1305 static void bubbles_init(struct game_context* bb) {
1306 bubbles_setcolors();
1307 /* seed the rand generator */
1308 rb->srand(*rb->current_tick);
1310 /* check for resumed game */
1311 if (resume)
1313 resume = false;
1314 return;
1317 bb->score = 0;
1318 bubbles_nextlevel(bb);
1321 /*****************************************************************************
1322 * bubbles_nextlevel() sets up the game for the next level, returns false if
1323 * there are no more levels.
1324 ******************************************************************************/
1325 static bool bubbles_nextlevel(struct game_context* bb) {
1326 int i, j, pos;
1328 bb->level++;
1330 /* check if there are no more levels */
1331 if(bb->level > NUM_LEVELS) return false;
1333 /* save highest level */
1334 if (bb->level-1 > highlevel)
1335 highlevel = bb->level-1;
1337 /* set up the play board */
1338 rb->memset(bb->playboard, 0, sizeof(bb->playboard));
1339 for(i=0; i<BB_LEVEL_HEIGHT; i++) {
1340 for(j=0; j<BB_WIDTH; j++) {
1341 pos = (int)level[bb->level-1][i][j];
1342 if(pos >=0 && pos < NUM_BUBBLES) {
1343 bb->playboard[i][j].type = pos;
1344 } else {
1345 bb->playboard[i][j].type = -1;
1349 for(i=BB_LEVEL_HEIGHT; i<BB_HEIGHT; i++) {
1350 for(j=0; j<BB_WIDTH; j++) {
1351 bb->playboard[i][j].type = -1;
1355 /* fill first bubbles in shot queue */
1356 bubbles_getonboard(bb);
1357 for(i=0; i<NUM_QUEUE; i++) {
1358 bb->queue[i] = bb->onboard[rb->rand()%bb->onboardcnt];
1361 bb->angle = 0;
1362 bb->shots = 0;
1363 bb->compress = 0;
1364 bb->nextinq = 0;
1365 bb->elapsedlvl = 0;
1366 bb->elapsedshot = 0;
1368 return true;
1371 /*****************************************************************************
1372 * bubbles_getonboard() determines which bubble types are on the play board.
1373 ******************************************************************************/
1374 static void bubbles_getonboard(struct game_context* bb) {
1375 int i, j, k;
1376 bool found;
1378 bb->onboardcnt = 0;
1379 rb->memset(bb->onboard, -1, sizeof(bb->onboard));
1381 for(i=0; i<BB_HEIGHT; i++) {
1382 for(j=0; j<BB_WIDTH; j++) {
1383 if(bb->playboard[i][j].type >= 0) {
1384 found = false;
1386 for(k=0; k<bb->onboardcnt; k++) {
1387 if(bb->playboard[i][j].type == bb->onboard[k]) {
1388 found = true;
1389 break;
1393 if(!found) {
1394 bb->onboard[bb->onboardcnt] = bb->playboard[i][j].type;
1395 bb->onboardcnt++;
1398 if(bb->onboardcnt == NUM_BUBBLES) return;
1404 /*****************************************************************************
1405 * bubbles_drawboard() draws the game board to the buffer but does not update
1406 * the lcd.
1407 ******************************************************************************/
1408 static void bubbles_drawboard(struct game_context* bb) {
1409 int i, j;
1410 int w1, w2, h;
1411 int colmax, indent;
1412 int tipx, tipy;
1413 bool evenline = false;
1414 char *level = "Level";
1415 char *score = "Score";
1416 char *next = "Next";
1417 char *hurry = "HURRY!";
1418 char str[11];
1420 /* clear screen */
1421 rb->lcd_clear_display();
1422 int font = rb->screens[SCREEN_MAIN]->getfont();
1423 h = rb->font_get(font)->height + 1;
1424 /* draw background */
1425 #ifdef HAVE_LCD_COLOR
1426 rb->lcd_bitmap(bubbles_background, 0, 0, LCD_WIDTH, LCD_HEIGHT);
1427 #endif
1429 /* display play board */
1430 for(i=0; i<BB_HEIGHT; i++) {
1431 colmax = BB_WIDTH;
1432 if(evenline) {
1433 colmax--;
1434 indent = ROW_INDENT;
1435 } else {
1436 indent = 0;
1438 evenline = !evenline;
1440 for(j=0; j<colmax; j++) {
1441 if(bb->playboard[i][j].type >= 0 && !bb->playboard[i][j].delete) {
1442 rb->lcd_bitmap_part(bubbles_emblem,
1443 0, EMBLEM_HEIGHT*bb->playboard[i][j].type, EMBLEM_WIDTH,
1444 XOFS+indent+BUBBLE_WIDTH*j+(BUBBLE_WIDTH-EMBLEM_WIDTH)/2,
1445 YOFS+ROW_HEIGHT*i+(BUBBLE_HEIGHT-EMBLEM_HEIGHT)/2+bb->compress*ROW_HEIGHT,
1446 EMBLEM_WIDTH, EMBLEM_HEIGHT);
1447 rb->lcd_set_drawmode(DRMODE_FG);
1448 rb->lcd_mono_bitmap((const unsigned char *)bubbles_bubble,
1449 XOFS+indent+BUBBLE_WIDTH*j,
1450 YOFS+ROW_HEIGHT*i+bb->compress*ROW_HEIGHT,
1451 BUBBLE_WIDTH, BUBBLE_HEIGHT);
1452 rb->lcd_set_drawmode(DRMODE_SOLID);
1457 /* display bubble to be shot */
1458 rb->lcd_bitmap_part(bubbles_emblem,
1459 0, EMBLEM_HEIGHT*bb->queue[bb->nextinq], EMBLEM_WIDTH,
1460 SHOTX+(BUBBLE_WIDTH-EMBLEM_WIDTH)/2,
1461 SHOTY+(BUBBLE_HEIGHT-EMBLEM_HEIGHT)/2,
1462 EMBLEM_WIDTH, EMBLEM_HEIGHT);
1463 rb->lcd_set_drawmode(DRMODE_FG);
1464 rb->lcd_mono_bitmap((const unsigned char *)bubbles_bubble,
1465 SHOTX, SHOTY,
1466 BUBBLE_WIDTH, BUBBLE_HEIGHT);
1467 rb->lcd_set_drawmode(DRMODE_SOLID);
1469 /* display next bubble to be shot */
1470 #ifndef NEXT_BB_X
1471 rb->lcd_bitmap_part(bubbles_emblem,
1472 0, EMBLEM_HEIGHT*bb->queue[(bb->nextinq+1)%NUM_QUEUE], EMBLEM_WIDTH,
1473 XOFS/2-BUBBLE_WIDTH/2+(BUBBLE_WIDTH-EMBLEM_WIDTH)/2,
1474 SHOTY+(BUBBLE_HEIGHT-EMBLEM_HEIGHT)/2,
1475 EMBLEM_WIDTH, EMBLEM_HEIGHT);
1476 rb->lcd_set_drawmode(DRMODE_FG);
1477 rb->lcd_mono_bitmap((const unsigned char *)bubbles_bubble,
1478 XOFS/2-BUBBLE_WIDTH/2, SHOTY,
1479 BUBBLE_WIDTH, BUBBLE_HEIGHT);
1480 rb->lcd_set_drawmode(DRMODE_SOLID);
1481 #else
1482 rb->lcd_bitmap_part(bubbles_emblem,
1483 0, EMBLEM_HEIGHT*bb->queue[(bb->nextinq+1)%NUM_QUEUE], EMBLEM_WIDTH,
1484 NEXT_BB_X + NEXT_BB_WIDTH/2-BUBBLE_WIDTH/2+(BUBBLE_WIDTH-EMBLEM_WIDTH)/2,
1485 NEXT_BB_Y + (BUBBLE_HEIGHT-EMBLEM_HEIGHT)/2 + h,
1486 EMBLEM_WIDTH, EMBLEM_HEIGHT);
1487 rb->lcd_set_drawmode(DRMODE_FG);
1488 rb->lcd_mono_bitmap((const unsigned char *)bubbles_bubble,
1489 NEXT_BB_X + NEXT_BB_WIDTH/2-BUBBLE_WIDTH/2, NEXT_BB_Y + h,
1490 BUBBLE_WIDTH, BUBBLE_HEIGHT);
1491 rb->lcd_set_drawmode(DRMODE_SOLID);
1492 #endif
1494 /* draw bounding lines */
1495 #ifndef HAVE_LCD_COLOR
1496 rb->lcd_vline(XOFS-1, 0, LCD_HEIGHT);
1497 rb->lcd_vline(XOFS+BUBBLE_WIDTH*BB_WIDTH, 0, LCD_HEIGHT);
1498 #endif
1499 rb->lcd_hline(XOFS, XOFS+BUBBLE_WIDTH*BB_WIDTH-1, YOFS+bb->compress*ROW_HEIGHT-1);
1500 rb->lcd_hline(XOFS, XOFS+BUBBLE_WIDTH*BB_WIDTH-1,
1501 YOFS+ROW_HEIGHT*(BB_HEIGHT-2)+BUBBLE_HEIGHT);
1503 /* draw arrow */
1504 tipx = SHOTX+BUBBLE_WIDTH/2+(((fp14_sin(bb->angle)>>4)*BUBBLE_WIDTH*3/2)>>10);
1505 tipy = SHOTY+BUBBLE_HEIGHT/2-(((fp14_cos(bb->angle)>>4)*BUBBLE_HEIGHT*3/2)>>10);
1507 rb->lcd_drawline(SHOTX+BUBBLE_WIDTH/2+(((fp14_sin(bb->angle)>>4)*BUBBLE_WIDTH/2)>>10),
1508 SHOTY+BUBBLE_HEIGHT/2-(((fp14_cos(bb->angle)>>4)*BUBBLE_HEIGHT/2)>>10),
1509 tipx, tipy);
1510 xlcd_filltriangle(tipx, tipy,
1511 tipx+(((fp14_sin(bb->angle-135)>>4)*BUBBLE_WIDTH/3)>>10),
1512 tipy-(((fp14_cos(bb->angle-135)>>4)*BUBBLE_HEIGHT/3)>>10),
1513 tipx+(((fp14_sin(bb->angle+135)>>4)*BUBBLE_WIDTH/3)>>10),
1514 tipy-(((fp14_cos(bb->angle+135)>>4)*BUBBLE_HEIGHT/3)>>10));
1516 /* draw text */
1517 rb->snprintf(str, 4, "%d", bb->level);
1518 rb->lcd_getstringsize(level, &w1, NULL);
1519 rb->lcd_getstringsize(str, &w2, NULL);
1520 #ifndef LEVEL_TXT_X
1521 rb->lcd_putsxy(XOFS/2-w1/2, 2, level);
1522 rb->lcd_putsxy(XOFS/2-w2/2, 2+h, str);
1523 #else
1524 rb->lcd_putsxy(LEVEL_TXT_X+(LEVEL_TXT_WIDTH/2-w1/2), LEVEL_TXT_Y, level);
1525 rb->lcd_putsxy(LEVEL_TXT_X+(LEVEL_TXT_WIDTH/2-w2/2), LEVEL_TXT_Y+h, str);
1526 #endif
1528 rb->snprintf(str, 10, "%d", bb->score);
1529 rb->lcd_getstringsize(score, &w1,NULL);
1530 rb->lcd_getstringsize(str, &w2, NULL);
1531 #ifndef SCORE_TXT_X
1532 rb->lcd_putsxy(XOFS/2-w1/2, 29, score);
1533 rb->lcd_putsxy(XOFS/2-w2/2, 29+h, str);
1534 #else
1535 rb->lcd_putsxy(SCORE_TXT_X+(SCORE_TXT_WIDTH/2-w1/2), SCORE_TXT_Y, score);
1536 rb->lcd_putsxy(SCORE_TXT_X+(SCORE_TXT_WIDTH/2-w2/2), SCORE_TXT_Y+h, str);
1537 #endif
1539 rb->lcd_getstringsize(next, &w1, NULL);
1540 #ifndef NEXT_BB_X
1541 rb->lcd_putsxy(XOFS/2-w1/2, SHOTY-h, next);
1542 #else
1543 rb->lcd_putsxy(NEXT_BB_X+(NEXT_BB_WIDTH/2-w1/2), NEXT_BB_Y, next);
1544 #endif
1547 if(bb->elapsedshot >= (MAX_SHOTTIME*7)/10) {
1548 rb->lcd_getstringsize(hurry, &w1, &h);
1549 rb->lcd_putsxy(LCD_WIDTH/2-w1/2, LCD_HEIGHT/2-h/2, hurry);
1553 /*****************************************************************************
1554 * bubbles_fire() fires the current bubble, reloads the cannon, attaches
1555 * bubble to playboard, removes appropriate bubbles, and advances the
1556 * the compressor.
1557 ******************************************************************************/
1558 static int bubbles_fire(struct game_context* bb) {
1559 int bubblecur;
1560 long shotxinc, shotyinc;
1561 long shotxofs, shotyofs;
1562 int shotxdirec = 1;
1563 long tempxofs, tempyofs;
1564 int nearrow, nearcol;
1565 int lastrow = BB_HEIGHT-1;
1566 int lastcol = (BB_WIDTH-1)/2;
1567 int buttonres;
1568 long lasttick, currenttick;
1570 /* get current bubble */
1571 bubblecur = bb->queue[bb->nextinq];
1572 shotxinc = ((fp14_sin(bb->angle)>>4)*BUBBLE_WIDTH)/3;
1573 shotyinc = ((-1*(fp14_cos(bb->angle)>>4))*BUBBLE_HEIGHT)/3;
1574 shotxofs = shotyofs = 0;
1576 /* advance the queue */
1577 bb->queue[bb->nextinq] = bb->onboard[rb->rand()%bb->onboardcnt];
1578 bb->nextinq = (bb->nextinq+1)%NUM_QUEUE;
1579 bubbles_drawboard(bb);
1580 rb->lcd_update_rect(0, 0, XOFS, LCD_HEIGHT);
1582 /* move the bubble across the play board */
1583 lasttick = *rb->current_tick;
1585 while(true) {
1586 /* move the bubble one step */
1587 shotyofs += shotyinc;
1588 shotxofs += shotxinc*shotxdirec;
1590 /* check for bounce off sides */
1591 if(SHOTX+(shotxofs>>10) < XOFS) {
1592 shotxofs += 2*((XOFS<<10)-(((SHOTX)<<10)+shotxofs));
1593 shotxdirec *= -1;
1594 } else if(SHOTX+(shotxofs>>10) > XOFS+(BB_WIDTH-1)*BUBBLE_WIDTH) {
1595 shotxofs -= 2*((((SHOTX)<<10)+shotxofs)-
1596 ((XOFS<<10)+(((BB_WIDTH-1)*BUBBLE_WIDTH)<<10)));
1597 shotxdirec *= -1;
1600 tempxofs = shotxofs>>10;
1601 tempyofs = shotyofs>>10;
1603 /* display shot */
1604 bubbles_drawboard(bb);
1605 rb->lcd_bitmap_part(bubbles_emblem, 0, EMBLEM_HEIGHT*bubblecur, EMBLEM_WIDTH,
1606 SHOTX+tempxofs+(BUBBLE_WIDTH-EMBLEM_WIDTH)/2,
1607 SHOTY+tempyofs+(BUBBLE_HEIGHT-EMBLEM_HEIGHT)/2,
1608 EMBLEM_WIDTH, EMBLEM_HEIGHT);
1609 rb->lcd_set_drawmode(DRMODE_FG);
1610 rb->lcd_mono_bitmap((const unsigned char *)bubbles_bubble,
1611 SHOTX+tempxofs, SHOTY+tempyofs,
1612 BUBBLE_WIDTH, BUBBLE_HEIGHT);
1613 rb->lcd_set_drawmode(DRMODE_SOLID);
1614 rb->lcd_update_rect(XOFS, 0, BB_WIDTH*BUBBLE_WIDTH, LCD_HEIGHT);
1616 /* find nearest position */
1617 nearrow = ((SHOTY+tempyofs)-
1618 (YOFS+bb->compress*ROW_HEIGHT)+
1619 (ROW_HEIGHT/2))/ROW_HEIGHT;
1620 if(nearrow >= BB_HEIGHT) nearrow = BB_HEIGHT-1;
1622 if(nearrow%2) { /* odd row */
1623 nearcol = ((SHOTX+tempxofs)-
1624 (XOFS+ROW_INDENT)+
1625 (BUBBLE_WIDTH/2))/BUBBLE_WIDTH;
1626 if(nearcol >= BB_WIDTH-1) nearcol = BB_WIDTH-2;
1627 } else { /* even row */
1628 nearcol = ((SHOTX+tempxofs)-XOFS+(BUBBLE_WIDTH/2))/BUBBLE_WIDTH;
1629 if(nearcol >= BB_WIDTH) nearcol = BB_WIDTH-1;
1631 if(nearcol < 0) nearcol = 0;
1633 /* if nearest position is occupied attach to last position */
1634 if(bb->playboard[nearrow][nearcol].type >= 0) {
1635 bb->playboard[lastrow][lastcol].type = bubblecur;
1636 break;
1639 /* save last position */
1640 lastrow = nearrow;
1641 lastcol = nearcol;
1643 /* if collision with neighbor then attach shot */
1644 if(bubbles_collision(bb, YOFS+SHOTY+tempyofs, SHOTX+tempxofs,
1645 nearrow, nearcol)) {
1646 bb->playboard[nearrow][nearcol].type = bubblecur;
1647 break;
1650 /* if at top then attach shot to the ceiling */
1651 if(nearrow == 0 && SHOTY+tempyofs <= YOFS+bb->compress*ROW_HEIGHT) {
1652 bb->playboard[nearrow][nearcol].type = bubblecur;
1653 break;
1656 /* handle button events */
1657 buttonres = bubbles_handlebuttons(bb, true, 0);
1658 if(buttonres != BB_NONE) return buttonres;
1660 /* framerate limiting */
1661 currenttick = *rb->current_tick;
1662 if(currenttick-lasttick < HZ/MAX_FPS) {
1663 rb->sleep((HZ/MAX_FPS)-(currenttick-lasttick));
1664 } else {
1665 rb->yield();
1667 lasttick = currenttick;
1670 bubbles_drawboard(bb);
1671 rb->lcd_update();
1673 /* clear appropriate bubbles from playing board */
1674 if(bubbles_ingroup(bb, lastrow, lastcol)) {
1675 buttonres = bubbles_remove(bb);
1676 if(buttonres != BB_NONE) return buttonres;
1679 /* update shots and compress amount */
1680 bb->shots++;
1681 if(bb->shots >= NUM_COMPRESS) {
1682 bb->shots = 0;
1683 bb->compress++;
1686 return BB_NONE;
1689 /*****************************************************************************
1690 * bubbles_collision() determines if a fired bubble has collided with another
1691 * bubble.
1692 ******************************************************************************/
1693 static bool bubbles_collision(struct game_context* bb, int y, int x,
1694 int nearrow, int nearcol) {
1695 int nx, ny;
1696 int adj = nearrow%2;
1698 /* check neighbors */
1699 if(nearcol-1 >= 0) {
1700 if(bb->playboard[nearrow][nearcol-1].type >= 0) {
1701 nx = XOFS+(nearrow%2 ? ROW_INDENT : 0)+BUBBLE_WIDTH*(nearcol-1);
1702 ny = YOFS+ROW_HEIGHT*nearrow+bb->compress*ROW_HEIGHT;
1703 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1707 if(nearcol-1+adj >= 0) {
1708 if(nearrow-1 >= 0) {
1709 if(bb->playboard[nearrow-1][nearcol-1+adj].type >= 0) {
1710 nx = XOFS+((nearrow-1)%2 ? ROW_INDENT : 0)+
1711 BUBBLE_WIDTH*(nearcol-1+adj);
1712 ny = YOFS+ROW_HEIGHT*(nearrow-1)+bb->compress*ROW_HEIGHT;
1713 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1717 if(nearrow+1 < BB_HEIGHT) {
1718 if(bb->playboard[nearrow+1][nearcol-1+adj].type >= 0) {
1719 nx = XOFS+((nearrow+1)%2 ? ROW_INDENT : 0)+
1720 BUBBLE_WIDTH*(nearcol-1+adj);
1721 ny = YOFS+ROW_HEIGHT*(nearrow+1)+bb->compress*ROW_HEIGHT;
1722 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1727 if(nearcol+adj >= 0) {
1728 if(nearrow-1 >= 0) {
1729 if(bb->playboard[nearrow-1][nearcol+adj].type >= 0) {
1730 nx = XOFS+((nearrow-1)%2 ? ROW_INDENT : 0)+
1731 BUBBLE_WIDTH*(nearcol+adj);
1732 ny = YOFS+ROW_HEIGHT*(nearrow-1)+bb->compress*ROW_HEIGHT;
1733 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1737 if(nearrow+1 < BB_HEIGHT) {
1738 if(bb->playboard[nearrow+1][nearcol+adj].type >= 0) {
1739 nx = XOFS+((nearrow+1)%2 ? ROW_INDENT : 0)+
1740 BUBBLE_WIDTH*(nearcol+adj);
1741 ny = YOFS+ROW_HEIGHT*(nearrow+1)+bb->compress*ROW_HEIGHT;
1742 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1747 if(nearcol+1 < BB_WIDTH-adj) {
1748 if(bb->playboard[nearrow][nearcol+1].type >= 0) {
1749 nx = XOFS+(nearrow%2 ? ROW_INDENT : 0)+BUBBLE_WIDTH*(nearcol+1);
1750 ny = YOFS+ROW_HEIGHT*nearrow+bb->compress*ROW_HEIGHT;
1751 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1755 return false;
1758 /*****************************************************************************
1759 * bubbles_ingroup() marks all bubbles that form the current group.
1760 ******************************************************************************/
1761 static bool bubbles_ingroup(struct game_context* bb, int row, int col) {
1762 int i, j;
1763 int count;
1765 count = bubbles_searchgroup(bb, row, col);
1767 /* unmark group if too small */
1768 if(count < 3) {
1769 for(i=0; i<BB_HEIGHT; i++) {
1770 for(j=0; j<BB_WIDTH; j++) {
1771 bb->playboard[i][j].ingroup = false;
1775 return false;
1778 return true;
1781 /*****************************************************************************
1782 * bubbles_searchgroup() return the size of the group of bubbles of the same
1783 * type that the current bubble belongs to.
1784 ******************************************************************************/
1785 static int bubbles_searchgroup(struct game_context* bb, int row, int col) {
1786 int i, adj;
1787 int myrow, mycol, mytype;
1788 int count = 0;
1790 struct coord {
1791 int row;
1792 int col;
1793 } search[(2*BB_WIDTH-1)*(BB_HEIGHT/2)];
1795 /* search initial bubble */
1796 bb->playboard[row][col].ingroup = true;
1797 search[count].row = row;
1798 search[count].col = col;
1799 count++;
1801 /* breadth-first search neighbors */
1802 for(i=0; i<count; i++) {
1803 myrow = search[i].row;
1804 mycol = search[i].col;
1805 mytype = bb->playboard[myrow][mycol].type;
1806 adj = myrow%2;
1808 if(mycol-1 >= 0) {
1809 if(bb->playboard[myrow][mycol-1].type == mytype &&
1810 !bb->playboard[myrow][mycol-1].ingroup) {
1811 bb->playboard[myrow][mycol-1].ingroup = true;
1812 search[count].row = myrow;
1813 search[count].col = mycol-1;
1814 count++;
1818 if(mycol-1+adj >= 0) {
1819 if(myrow-1 >= 0) {
1820 if(bb->playboard[myrow-1][mycol-1+adj].type == mytype &&
1821 !bb->playboard[myrow-1][mycol-1+adj].ingroup) {
1822 bb->playboard[myrow-1][mycol-1+adj].ingroup = true;
1823 search[count].row = myrow-1;
1824 search[count].col = mycol-1+adj;
1825 count++;
1829 if(myrow+1 < BB_HEIGHT) {
1830 if(bb->playboard[myrow+1][mycol-1+adj].type == mytype &&
1831 !bb->playboard[myrow+1][mycol-1+adj].ingroup) {
1832 bb->playboard[myrow+1][mycol-1+adj].ingroup = true;
1833 search[count].row = myrow+1;
1834 search[count].col = mycol-1+adj;
1835 count++;
1840 if(mycol+adj >= 0) {
1841 if(myrow-1 >= 0) {
1842 if(bb->playboard[myrow-1][mycol+adj].type == mytype &&
1843 !bb->playboard[myrow-1][mycol+adj].ingroup) {
1844 bb->playboard[myrow-1][mycol+adj].ingroup = true;
1845 search[count].row = myrow-1;
1846 search[count].col = mycol+adj;
1847 count++;
1851 if(myrow+1 < BB_HEIGHT) {
1852 if(bb->playboard[myrow+1][mycol+adj].type == mytype &&
1853 !bb->playboard[myrow+1][mycol+adj].ingroup) {
1854 bb->playboard[myrow+1][mycol+adj].ingroup = true;
1855 search[count].row = myrow+1;
1856 search[count].col = mycol+adj;
1857 count++;
1862 if(mycol+1 < BB_WIDTH-adj) {
1863 if(bb->playboard[myrow][mycol+1].type == mytype &&
1864 !bb->playboard[myrow][mycol+1].ingroup) {
1865 bb->playboard[myrow][mycol+1].ingroup = true;
1866 search[count].row = myrow;
1867 search[count].col = mycol+1;
1868 count++;
1873 return count;
1876 /*****************************************************************************
1877 * bubbles_remove() removes all bubbles in the current group and all
1878 * unanchored bubbles from the play board.
1879 ******************************************************************************/
1880 static int bubbles_remove(struct game_context* bb) {
1881 int i, j;
1882 int buttonres;
1884 /* determine all anchored bubbles */
1885 for(j=0; j<BB_WIDTH; j++) {
1886 if(bb->playboard[0][j].type >= 0 && !bb->playboard[0][j].ingroup) {
1887 bubbles_anchored(bb, 0, j);
1891 /* mark bubbles to be deleted */
1892 for(i=0; i<BB_HEIGHT; i++) {
1893 for(j=0; j<BB_WIDTH; j++) {
1894 if(bb->playboard[i][j].type >= 0 &&
1895 (!bb->playboard[i][j].anchored || bb->playboard[i][j].ingroup)) {
1896 bb->playboard[i][j].delete = true;
1901 /* animate falling bubbles */
1902 buttonres = bubbles_fall(bb);
1903 if(buttonres != BB_NONE) return buttonres;
1905 /* remove bubbles */
1906 for(i=0; i<BB_HEIGHT; i++) {
1907 for(j=0; j<BB_WIDTH; j++) {
1908 if(bb->playboard[i][j].delete) {
1909 bb->playboard[i][j].ingroup = false;
1910 bb->playboard[i][j].type = -1;
1911 bb->playboard[i][j].delete = false;
1912 } else {
1913 bb->playboard[i][j].anchored = false;
1918 bubbles_getonboard(bb);
1920 return BB_NONE;
1923 /*****************************************************************************
1924 * bubbles_anchored() marks all bubbles that are anchored in some way to the
1925 * current bubble.
1926 ******************************************************************************/
1927 static void bubbles_anchored(struct game_context* bb, int row, int col) {
1928 int i, adj;
1929 int myrow, mycol, mytype;
1930 int count = 0;
1932 struct coord {
1933 int row;
1934 int col;
1935 } search[(2*BB_WIDTH-1)*(BB_HEIGHT/2)];
1937 /* search initial bubble */
1938 bb->playboard[row][col].anchored = true;
1939 search[count].row = row;
1940 search[count].col = col;
1941 count++;
1943 /* breadth-first search neighbors */
1944 for(i=0; i<count; i++) {
1945 myrow = search[i].row;
1946 mycol = search[i].col;
1947 mytype = bb->playboard[myrow][mycol].type;
1948 adj = myrow%2;
1950 if(mycol-1 >= 0) {
1951 if(bb->playboard[myrow][mycol-1].type >= 0 &&
1952 !bb->playboard[myrow][mycol-1].ingroup &&
1953 !bb->playboard[myrow][mycol-1].anchored) {
1954 bb->playboard[myrow][mycol-1].anchored = true;
1955 search[count].row = myrow;
1956 search[count].col = mycol-1;
1957 count++;
1961 if(mycol-1+adj >= 0) {
1962 if(myrow-1 >= 0) {
1963 if(bb->playboard[myrow-1][mycol-1+adj].type >= 0 &&
1964 !bb->playboard[myrow-1][mycol-1+adj].ingroup &&
1965 !bb->playboard[myrow-1][mycol-1+adj].anchored) {
1966 bb->playboard[myrow-1][mycol-1+adj].anchored = true;
1967 search[count].row = myrow-1;
1968 search[count].col = mycol-1+adj;
1969 count++;
1973 if(myrow+1 < BB_HEIGHT) {
1974 if(bb->playboard[myrow+1][mycol-1+adj].type >= 0 &&
1975 !bb->playboard[myrow+1][mycol-1+adj].ingroup &&
1976 !bb->playboard[myrow+1][mycol-1+adj].anchored) {
1977 bb->playboard[myrow+1][mycol-1+adj].anchored = true;
1978 search[count].row = myrow+1;
1979 search[count].col = mycol-1+adj;
1980 count++;
1985 if(mycol+adj >= 0) {
1986 if(myrow-1 >= 0) {
1987 if(bb->playboard[myrow-1][mycol+adj].type >= 0 &&
1988 !bb->playboard[myrow-1][mycol+adj].ingroup &&
1989 !bb->playboard[myrow-1][mycol+adj].anchored) {
1990 bb->playboard[myrow-1][mycol+adj].anchored = true;
1991 search[count].row = myrow-1;
1992 search[count].col = mycol+adj;
1993 count++;
1997 if(myrow+1 < BB_HEIGHT) {
1998 if(bb->playboard[myrow+1][mycol+adj].type >= 0 &&
1999 !bb->playboard[myrow+1][mycol+adj].ingroup &&
2000 !bb->playboard[myrow+1][mycol+adj].anchored) {
2001 bb->playboard[myrow+1][mycol+adj].anchored = true;
2002 search[count].row = myrow+1;
2003 search[count].col = mycol+adj;
2004 count++;
2009 if(mycol+1 < BB_WIDTH-adj) {
2010 if(bb->playboard[myrow][mycol+1].type >= 0 &&
2011 !bb->playboard[myrow][mycol+1].ingroup &&
2012 !bb->playboard[myrow][mycol+1].anchored) {
2013 bb->playboard[myrow][mycol+1].anchored = true;
2014 search[count].row = myrow;
2015 search[count].col = mycol+1;
2016 count++;
2022 /*****************************************************************************
2023 * bubbles_fall() makes removed bubbles fall from the screen.
2024 ******************************************************************************/
2025 static int bubbles_fall(struct game_context* bb) {
2026 int i, j;
2027 int count;
2028 int indent;
2029 int xofs, yofs;
2030 int buttonres;
2031 bool onscreen;
2032 long lasttick, currenttick;
2034 /* give all falling bubbles an x axis movement */
2035 for(i=0; i<BB_HEIGHT; i++) {
2036 for(j=0; j<BB_WIDTH; j++) {
2037 if(bb->playboard[i][j].delete) {
2038 bb->playboard[i][j].fallx = rb->rand()%25 - 12;
2039 bb->playboard[i][j].fallvel = rb->rand()%5 + 6;
2044 /* draw bubbles falling off the screen
2045 * follows y=x^2-8x scaled to bubble size
2047 lasttick = *rb->current_tick;
2049 for(count=1; ;count++) {
2050 onscreen = false;
2051 bubbles_drawboard(bb);
2053 for(i=0; i<BB_HEIGHT; i++) {
2054 for(j=0; j<BB_WIDTH; j++) {
2055 if(bb->playboard[i][j].delete) {
2056 indent = (i%2 ? ROW_INDENT : 0);
2057 xofs = ((bb->playboard[i][j].fallx*count)*BUBBLE_WIDTH)/48;
2058 yofs = ((count*count - bb->playboard[i][j].fallvel*count)*
2059 BUBBLE_HEIGHT)/20;
2061 /* draw bubble if it is still on the screen */
2062 if(YOFS+ROW_HEIGHT*i+bb->compress*ROW_HEIGHT+yofs
2063 <= LCD_HEIGHT) {
2064 onscreen = true;
2066 rb->lcd_bitmap_part(bubbles_emblem, 0,
2067 EMBLEM_HEIGHT*bb->playboard[i][j].type, EMBLEM_WIDTH,
2068 XOFS+indent+BUBBLE_WIDTH*j+
2069 (BUBBLE_WIDTH-EMBLEM_WIDTH)/2+xofs,
2070 YOFS+ROW_HEIGHT*i+(BUBBLE_HEIGHT-EMBLEM_HEIGHT)/2+
2071 bb->compress*ROW_HEIGHT+yofs,
2072 EMBLEM_WIDTH, EMBLEM_HEIGHT);
2073 rb->lcd_set_drawmode(DRMODE_FG);
2074 rb->lcd_mono_bitmap(
2075 (const unsigned char *)bubbles_bubble,
2076 XOFS+indent+BUBBLE_WIDTH*j+xofs,
2077 YOFS+ROW_HEIGHT*i+bb->compress*ROW_HEIGHT+yofs,
2078 BUBBLE_WIDTH, BUBBLE_HEIGHT);
2079 rb->lcd_set_drawmode(DRMODE_SOLID);
2085 rb->lcd_update();
2087 /* break out if all bubbles are off the screen */
2088 if(!onscreen) break;
2090 /* handle button events */
2091 buttonres = bubbles_handlebuttons(bb, true, 0);
2092 if(buttonres != BB_NONE) return buttonres;
2094 /* framerate limiting */
2095 currenttick = *rb->current_tick;
2096 if(currenttick-lasttick < HZ/MAX_FPS) {
2097 rb->sleep((HZ/MAX_FPS)-(currenttick-lasttick));
2098 } else {
2099 rb->yield();
2101 lasttick = currenttick;
2104 return BB_NONE;
2107 /*****************************************************************************
2108 * bubbles_checklevel() checks the state of the playboard for a win or loss.
2109 ******************************************************************************/
2110 static int bubbles_checklevel(struct game_context* bb) {
2111 int i, j;
2112 int points;
2113 char str[13];
2115 bubbles_drawboard(bb);
2116 rb->lcd_update();
2118 /* check for bubbles below cut off point */
2119 for(i=0; i<=bb->compress; i++) {
2120 for(j=0; j<BB_WIDTH; j++) {
2121 if(bb->playboard[BB_HEIGHT-1-i][j].type >= 0) return BB_LOSE;
2125 /* check for bubbles above cut off point */
2126 for(i=0; i<BB_HEIGHT-1-bb->compress; i++) {
2127 for(j=0; j<BB_WIDTH; j++) {
2128 if(bb->playboard[i][j].type >= 0) return BB_NONE;
2132 /* level complete, record score */
2133 points = 100 - bb->elapsedlvl/100;
2134 if(points > 0) {
2135 bb->score += points;
2136 } else {
2137 points = 0;
2140 rb->snprintf(str, 12, "%d points", points);
2141 rb->splash(HZ, str);
2143 /* advance to the next level */
2144 if(!bubbles_nextlevel(bb)) {
2145 return BB_WIN;
2148 bubbles_drawboard(bb);
2149 rb->lcd_update();
2150 rb->snprintf(str, 12, "Level %d", bb->level);
2151 rb->splash(HZ, str);
2152 bubbles_drawboard(bb);
2153 rb->lcd_update();
2155 return BB_NONE;
2158 /*****************************************************************************
2159 * bubbles_recordscore() inserts a high score into the high scores list and
2160 * returns the high score position.
2161 ******************************************************************************/
2162 static void bubbles_recordscore(struct game_context* bb) {
2164 int position;
2166 position = highscore_update(bb->score, bb->level-1, "",
2167 highscores, NUM_SCORES);
2168 if (position==0)
2169 rb->splash(HZ*2, "New High Score");
2170 if (position != -1)
2171 highscore_show(position, highscores, NUM_SCORES, true);
2174 /*****************************************************************************
2175 * bubbles_loaddata() loads highest level beaten.
2176 ******************************************************************************/
2177 static void bubbles_loaddata(void) {
2178 int fd;
2180 last_highlevel = highlevel = 0;
2181 /* open data file */
2182 fd = rb->open(DATA_FILE, O_RDONLY);
2183 if (fd < 0) return;
2185 /* read in saved game */
2186 if (rb->read(fd, &highlevel, sizeof(highlevel)) < (long)sizeof(highlevel))
2188 highlevel = 0;
2190 if (highlevel >= NUM_LEVELS)
2191 highlevel = NUM_LEVELS-1;
2192 last_highlevel = highlevel;
2194 rb->close(fd);
2197 /*****************************************************************************
2198 * bubbles_savedata() saves the current game state.
2199 ******************************************************************************/
2200 static void bubbles_savedata(void) {
2201 int fd;
2203 if (last_highlevel >= highlevel) /* no need to save */
2204 return;
2206 fd = rb->open(DATA_FILE, O_WRONLY|O_CREAT);
2207 if (fd < 0) return;
2209 rb->write(fd, &highlevel, sizeof(highlevel));
2211 rb->close(fd);
2214 /*****************************************************************************
2215 * bubbles_loadgame() loads the saved game and returns load success.
2216 ******************************************************************************/
2217 static bool bubbles_loadgame(struct game_context* bb) {
2218 int fd;
2220 bool ret = true;
2221 /* open game file */
2222 fd = rb->open(SAVE_FILE, O_RDONLY);
2223 if(fd < 0) return false;
2225 /* read in saved game */
2226 if(rb->read(fd, bb, sizeof(struct game_context))
2227 < (long)sizeof(struct game_context))
2229 ret = false;
2232 rb->close(fd);
2234 return ret;
2237 /*****************************************************************************
2238 * bubbles_savegame() saves the current game state.
2239 ******************************************************************************/
2240 static void bubbles_savegame(struct game_context* bb) {
2241 int fd;
2243 if (!resume) /* nothing to save */
2244 return;
2245 /* write out the game state to the save file */
2246 fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
2247 if (fd < 0)
2249 rb->splash(HZ/2, "Failed to save game");
2250 return;
2252 if (rb->write(fd, bb, sizeof(struct game_context)) <= 0)
2254 rb->splash(HZ/2, "Failed to save game");
2257 rb->close(fd);
2260 /*****************************************************************************
2261 * bubbles_setcolors() set the foreground and background colors.
2262 ******************************************************************************/
2263 static inline void bubbles_setcolors(void) {
2264 #ifdef HAVE_LCD_COLOR
2265 rb->lcd_set_background(LCD_RGBPACK(181,181,222));
2266 rb->lcd_set_foreground(LCD_BLACK);
2267 #endif
2270 /*****************************************************************************
2271 * bubbles_callback() is the default event handler callback which is called
2272 * on usb connect and shutdown.
2273 ******************************************************************************/
2274 static void bubbles_callback(void* param) {
2275 (void) param;
2276 highscore_save(SCORE_FILE, highscores, NUM_SCORES);
2279 /*****************************************************************************
2280 * bubbles_handlebuttons() handles button events during a game.
2281 ******************************************************************************/
2282 static int bubbles_handlebuttons(struct game_context* bb, bool animblock,
2283 int timeout) {
2284 int button;
2285 int buttonres;
2286 long start;
2287 const struct button_mapping *plugin_contexts[]
2288 #if (CONFIG_KEYPAD != SANSA_E200_PAD) && \
2289 (CONFIG_KEYPAD != SANSA_FUZE_PAD)
2290 = {generic_left_right_fire,generic_actions};
2291 #else
2292 = {generic_directions,generic_actions};
2293 #endif
2295 if (timeout < 0)
2296 timeout = 0;
2297 button = pluginlib_getaction(timeout,plugin_contexts,2);
2298 #if defined(HAS_BUTTON_HOLD) && !defined(HAVE_REMOTE_LCD_AS_MAIN)
2299 /* FIXME: Should probably check remote hold here */
2300 if (rb->button_hold())
2301 button = BUBBLES_START;
2302 #endif
2304 switch(button){
2305 case BUBBLES_LEFT_REP:
2306 if(bb->angle > MIN_ANGLE) bb->angle -= ANGLE_STEP_REP;
2307 case BUBBLES_LEFT: /* change angle to the left */
2308 if(bb->angle > MIN_ANGLE) bb->angle -= ANGLE_STEP;
2309 break;
2311 case BUBBLES_RIGHT_REP:
2312 if(bb->angle < MAX_ANGLE) bb->angle += ANGLE_STEP_REP;
2313 case BUBBLES_RIGHT: /* change angle to the right */
2314 if(bb->angle < MAX_ANGLE) bb->angle += ANGLE_STEP;
2315 break;
2317 case BUBBLES_SELECT: /* fire the shot */
2318 if(!animblock) {
2319 bb->elapsedlvl += bb->elapsedshot;
2320 bb->elapsedshot = 0;
2321 buttonres = bubbles_fire(bb);
2322 if(buttonres != BB_NONE) return buttonres;
2323 buttonres = bubbles_checklevel(bb);
2324 if(buttonres != BB_NONE) return buttonres;
2325 bb->startedshot = *rb->current_tick;
2327 break;
2329 case BUBBLES_START: /* pause the game */
2330 start = *rb->current_tick;
2331 rb->splash(0, "Paused");
2332 while(pluginlib_getaction(TIMEOUT_BLOCK,plugin_contexts,2)
2333 != (BUBBLES_START));
2334 bb->startedshot += *rb->current_tick-start;
2335 bubbles_drawboard(bb);
2336 rb->lcd_update();
2337 break;
2339 case BUBBLES_RESUME: /* save and end the game */
2340 case BUBBLES_QUIT: /* end the game */
2341 if(!animblock) {
2342 resume = true;
2343 return BB_END;
2345 break;
2347 case ACTION_UNKNOWN:
2348 case ACTION_NONE: /* no button pressed */
2349 break;
2351 default:
2352 if(rb->default_event_handler_ex(button, bubbles_callback,
2353 (void*) bb) == SYS_USB_CONNECTED)
2354 return BB_USB;
2355 break;
2358 return BB_NONE;
2361 /*****************************************************************************
2362 * bubbles_menu() is the initial menu at the start of the game.
2363 ******************************************************************************/
2364 static int bubbles_menu(struct game_context* bb) {
2365 static unsigned int startlevel = 0;
2366 int selected = resume?0:1;
2367 bool startgame = false;
2369 MENUITEM_STRINGLIST(menu,"Bubbles Menu",NULL,
2370 "Resume Game", "Start New Game",
2371 "Level", "High Scores", "Playback Control",
2372 "Quit without Saving", "Quit");
2374 while(!startgame){
2375 switch (rb->do_menu(&menu, &selected, NULL, false))
2377 case 0: /* resume game */
2378 if (!resume)
2379 rb->splash(HZ/2, "Nothing to resume");
2380 else
2381 startgame = true;
2383 if(rb->file_exists(SAVE_FILE))
2384 rb->remove(SAVE_FILE);
2385 break;
2386 case 1: /* new game */
2387 bb->level = startlevel;
2388 startgame = true;
2389 resume = false;
2390 break;
2391 case 2: /* choose level */
2392 startlevel++;
2393 rb->set_int("Choose start level", "", UNIT_INT, &startlevel,
2394 NULL, 1, 1, highlevel+1, NULL);
2395 startlevel--;
2396 break;
2397 case 3: /* High scores */
2398 highscore_show(NUM_SCORES, highscores, NUM_SCORES, true);
2399 break;
2400 case 4: /* Playback Control */
2401 playback_control(NULL);
2402 break;
2403 case 5: /* quit but don't save */
2404 return BB_QUIT_WITHOUT_SAVING;
2405 case 6: /* save and quit */
2406 return BB_QUIT;
2407 case MENU_ATTACHED_USB:
2408 bubbles_callback(bb);
2409 return BB_USB;
2412 return 0;
2415 /*****************************************************************************
2416 * bubbles() is the main game subroutine, it returns the final game status.
2417 ******************************************************************************/
2418 static int bubbles(struct game_context* bb) {
2419 int buttonres;
2420 long timeout;
2422 /********************
2423 * menu *
2424 ********************/
2425 buttonres = bubbles_menu(bb);
2426 if(buttonres != 0)
2427 return buttonres;
2429 /********************
2430 * init *
2431 ********************/
2432 bubbles_init(bb);
2433 bubbles_drawboard(bb);
2434 rb->lcd_update();
2436 /**********************
2437 * play *
2438 **********************/
2439 bb->startedshot = *rb->current_tick;
2441 while(true) {
2442 /* refresh the board */
2443 bubbles_drawboard(bb);
2444 rb->lcd_update();
2446 /* manange idle framerate */
2447 bb->elapsedshot = *rb->current_tick-bb->startedshot;
2449 if(MAX_SHOTTIME-bb->elapsedshot < HZ/2) {
2450 timeout = MAX_SHOTTIME-bb->elapsedshot;
2451 } else {
2452 timeout = HZ/2;
2455 /* handle button events */
2456 buttonres = bubbles_handlebuttons(bb, false, timeout);
2457 if(buttonres != BB_NONE) return buttonres;
2459 /* handle timing */
2460 bb->elapsedshot = *rb->current_tick-bb->startedshot;
2462 if(bb->elapsedshot > MAX_SHOTTIME) {
2463 bb->elapsedlvl += bb->elapsedshot;
2464 bb->elapsedshot = 0;
2465 buttonres = bubbles_fire(bb);
2466 if(buttonres != BB_NONE) return buttonres;
2467 buttonres = bubbles_checklevel(bb);
2468 if(buttonres != BB_NONE) return buttonres;
2469 bb->startedshot = *rb->current_tick;
2474 /*****************************************************************************
2475 * plugin entry point.
2476 ******************************************************************************/
2477 enum plugin_status plugin_start(const void* parameter) {
2478 static struct game_context bb;
2479 bool exit = false;
2480 enum plugin_status ret = PLUGIN_OK;
2482 (void)parameter;
2484 /* load files */
2485 resume = bubbles_loadgame(&bb);
2486 bubbles_loaddata();
2487 highscore_load(SCORE_FILE, highscores, NUM_SCORES);
2488 rb->lcd_clear_display();
2490 /* start app */
2491 #if LCD_DEPTH > 1
2492 rb->lcd_set_backdrop(NULL);
2493 #endif
2494 rb->lcd_setfont(FONT_SYSFIXED);
2496 while(!exit) {
2497 switch(bubbles(&bb)){
2498 case BB_WIN:
2499 rb->splash(HZ*2, "You Win!");
2500 /* record high level */
2501 highlevel = NUM_LEVELS-1;
2502 /* record high score */
2503 bubbles_recordscore(&bb);
2504 break;
2506 case BB_LOSE:
2507 resume = false;
2508 rb->splash(HZ*2, "Game Over");
2509 /* record high score */
2510 bubbles_recordscore(&bb);
2511 /* fall through to BB_END */
2513 case BB_END:
2514 break;
2516 case BB_USB:
2517 ret = PLUGIN_USB_CONNECTED;
2518 exit = true;
2519 break;
2521 case BB_QUIT:
2522 #define SAVE_MESSAGE "Saving Game and Scores..."
2523 /* the first splash is to make sure it's read, but don't make it
2524 * too long to not delay the saving further */
2525 rb->splash(HZ/5, SAVE_MESSAGE);
2526 rb->splash(0, SAVE_MESSAGE);
2527 bubbles_savegame(&bb);
2528 bubbles_savedata();
2529 highscore_save(SCORE_FILE, highscores, NUM_SCORES);
2530 /* fall through */
2532 case BB_QUIT_WITHOUT_SAVING:
2533 exit = true;
2534 break;
2536 default:
2537 break;
2541 rb->lcd_setfont(FONT_UI);
2542 return ret;
2545 #endif