Remove two left-over DEBUGFs
[kugel-rb/myfork.git] / apps / plugins / bubbles.c
blob9454fd14a342e518b7b40043ce2b4cb5e7b479ca
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"
40 /* final game return status */
41 enum {
42 BB_LOSE,
43 BB_QUIT,
44 BB_QUIT_AND_SAVE,
45 BB_USB,
46 BB_END,
47 BB_WIN,
48 BB_NONE,
51 /* play board dimension */
52 #define BB_HEIGHT 12
53 #define BB_WIDTH 8
54 #define BB_LEVEL_HEIGHT 10
56 /* various amounts */
57 #define NUM_SCORES 5
58 #define NUM_LEVELS 100
59 #define NUM_QUEUE 2
60 #define NUM_BUBBLES 8
61 #define MIN_ANGLE -76
62 #define MAX_ANGLE 76
63 #define NUM_COMPRESS 9
64 #define MAX_SHOTTIME 1000
66 /* keyboard layouts */
68 #if (CONFIG_KEYPAD != SANSA_E200_PAD) && \
69 (CONFIG_KEYPAD != SANSA_FUZE_PAD)
70 /* sansas use the wheel instead of left/right if available */
71 #define BUBBLES_LEFT PLA_LEFT
72 #define BUBBLES_LEFT_REP PLA_LEFT_REPEAT
73 #define BUBBLES_RIGHT PLA_RIGHT
74 #define BUBBLES_RIGHT_REP PLA_RIGHT_REPEAT
75 #define ANGLE_STEP 4
76 #define ANGLE_STEP_REP 4
77 #else
78 #define BUBBLES_LEFT PLA_UP
79 #define BUBBLES_LEFT_REP PLA_UP_REPEAT
80 #define BUBBLES_RIGHT PLA_DOWN
81 #define BUBBLES_RIGHT_REP PLA_DOWN_REPEAT
82 #define ANGLE_STEP 2
83 #define ANGLE_STEP_REP 4
84 #endif
86 #define BUBBLES_QUIT PLA_QUIT
87 #define BUBBLES_START PLA_START
88 #define BUBBLES_SELECT PLA_FIRE
89 #define BUBBLES_RESUME PLA_MENU
91 #if CONFIG_KEYPAD != ONDIO_PAD
93 #define BUBBLES_LVLINC PLA_UP
94 #define BUBBLES_LVLINC_REP PLA_UP_REPEAT
95 #define BUBBLES_LVLDEC PLA_DOWN
96 #define BUBBLES_LVLDEC_REP PLA_DOWN_REPEAT
98 #else /* ondio keys */
100 #define BUBBLES_LVLINC PLA_RIGHT
101 #define BUBBLES_LVLINC_REP PLA_RIGHT_REPEAT
102 #define BUBBLES_LVLDEC PLA_LEFT
103 #define BUBBLES_LVLDEC_REP PLA_LEFT_REPEAT
105 #endif
107 /* external bitmaps */
108 #ifdef HAVE_LCD_COLOR
109 #include "pluginbitmaps/bubbles_background.h"
110 #endif
111 #include "pluginbitmaps/bubbles_bubble.h"
112 #include "pluginbitmaps/bubbles_emblem.h"
114 #define BUBBLE_WIDTH BMPWIDTH_bubbles_bubble
115 #define BUBBLE_HEIGHT BMPHEIGHT_bubbles_bubble
116 #define EMBLEM_WIDTH BMPWIDTH_bubbles_emblem
117 #define EMBLEM_HEIGHT (BMPHEIGHT_bubbles_emblem/8)
119 /* bubbles will consume height of ROW_HEIGHT*(BB_HEIGHT-1)+BUBBLE_HEIGHT*3/2 */
120 /* 44x44 bubbles (m:robe 500) */
121 #if (LCD_WIDTH == 640) && (LCD_HEIGHT == 480)
122 #define XOFS 144
123 #define MAX_FPS 40
125 #elif (LCD_WIDTH == 480) && (LCD_HEIGHT == 640)
126 #define XOFS 128
127 #define MAX_FPS 40
129 /* 22x22 bubbles (iPod Video) */
130 #elif (LCD_HEIGHT == 240) && (LCD_WIDTH == 320)
131 #define XOFS 72
132 #define MAX_FPS 40
134 /* 22x22 bubbles (Gigabeat, Onda VX747) */
135 #elif ((LCD_HEIGHT == 320) || (LCD_HEIGHT == 400)) && (LCD_WIDTH == 240)
136 #define XOFS 64
137 #define MAX_FPS 30
139 /* 16x16 bubbles (H300, iPod Color) */
140 #elif (LCD_HEIGHT == 176) && (LCD_WIDTH == 220)
141 #define XOFS 46
142 #define MAX_FPS 30
144 /* 16x16 bubbles (Sansa E200) */
145 #elif (LCD_HEIGHT == 220) && (LCD_WIDTH == 176)
146 #define XOFS 48
147 #define MAX_FPS 30
149 /* 12x12 bubbles (iPod Nano) */
150 #elif (LCD_HEIGHT == 132) && (LCD_WIDTH == 176)
151 #define XOFS 40
152 #define MAX_FPS 40
154 /* 12x12 bubbles (H100, H10, iAudio X5, iPod 3G, iPod 4G grayscale) */
155 #elif (LCD_HEIGHT == 128) && ((LCD_WIDTH == 160) || (LCD_WIDTH == 128))
156 #define XOFS 33
157 #define MAX_FPS 30
159 /* 10x10 bubbles (iPod Mini) */
160 #elif (LCD_HEIGHT == 110) && (LCD_WIDTH == 138)
161 #define XOFS 33
162 #define MAX_FPS 30
164 /* 9x9 bubbles (iAudio M3) */
165 #elif (LCD_HEIGHT == 96) && (LCD_WIDTH == 128)
166 #define XOFS 45
167 #define MAX_FPS 30
169 /* 8x8 bubbles (Sansa C200) */
170 #elif ((LCD_HEIGHT == 80) && (LCD_WIDTH == 132))
171 #define XOFS 45
172 #define MAX_FPS 30
174 /* 7x7 bubbles (Sansa Clip/m200) */
175 #elif (LCD_HEIGHT == 64 && LCD_WIDTH == 128)
176 #define XOFS 33
177 #define ROW_HEIGHT 5
178 #define MAX_FPS 30
180 /* 8x7 bubbles (Archos recorder, Ondio) */
181 #elif (LCD_HEIGHT == 64) && (LCD_WIDTH == 112)
182 #define XOFS 33
183 #define ROW_HEIGHT 5
184 #define MAX_FPS 20
186 #else
187 #error BUBBLES: Unsupported LCD type
188 #endif
190 #if !defined(ROW_HEIGHT)
191 #define ROW_HEIGHT (BUBBLE_WIDTH-(BUBBLE_WIDTH-EMBLEM_WIDTH)/2)
192 #endif
194 #define ROW_INDENT (BUBBLE_WIDTH/2)
196 #define TEXT_LINES (LCD_HEIGHT/8)
198 /* shot position */
199 #define SHOTX XOFS+ROW_INDENT+BUBBLE_WIDTH*3
200 #define SHOTY ROW_HEIGHT*(BB_HEIGHT-1)+BUBBLE_HEIGHT/2
202 /* collision distance squared */
203 #define MIN_DISTANCE ((BUBBLE_WIDTH*8)/10)*((BUBBLE_HEIGHT*8)/10)
205 /* levels */
206 char level[NUM_LEVELS][BB_LEVEL_HEIGHT][BB_WIDTH] = {
207 {{ 6, 6, 4, 4, 2, 2, 3, 3},
208 { 6, 6, 4, 4, 2, 2, 3, -1},
209 { 2, 2, 3, 3, 6, 6, 4, 4},
210 { 2, 3, 3, 6, 6, 4, 4, -1},
211 {-1, -1, -1, -1, -1, -1, -1, -1},
212 {-1, -1, -1, -1, -1, -1, -1, -1},
213 {-1, -1, -1, -1, -1, -1, -1, -1},
214 {-1, -1, -1, -1, -1, -1, -1, -1},
215 {-1, -1, -1, -1, -1, -1, -1, -1},
216 {-1, -1, -1, -1, -1, -1, -1, -1}},
217 {{-1, 7, 7, 7, 7, 7, 7, -1},
218 {-1, 1, 1, 1, 1, 1, -1, -1},
219 {-1, -1, 2, 2, 2, 2, -1, -1},
220 {-1, -1, -1, 2, -1, -1, -1, -1},
221 {-1, -1, -1, 2, 2, -1, -1, -1},
222 {-1, -1, -1, 5, -1, -1, -1, -1},
223 {-1, -1, -1, 5, 5, -1, -1, -1},
224 {-1, -1, -1, -1, -1, -1, -1, -1},
225 {-1, -1, -1, -1, -1, -1, -1, -1},
226 {-1, -1, -1, -1, -1, -1, -1, -1}},
227 {{-1, -1, 7, -1, -1, 7, -1, -1},
228 {-1, -1, 7, 1, 7, -1, -1, -1},
229 {-1, -1, -1, 1, 2, -1, -1, -1},
230 {-1, -1, 1, 2, 1, -1, -1, -1},
231 {-1, -1, -1, 2, 5, -1, -1, -1},
232 {-1, -1, 3, 5, 3, -1, -1, -1},
233 {-1, -1, -1, 5, 3, -1, -1, -1},
234 {-1, -1, -1, 3, -1, -1, -1, -1},
235 {-1, -1, -1, -1, -1, -1, -1, -1},
236 {-1, -1, -1, -1, -1, -1, -1, -1}},
237 {{-1, -1, -1, 0, 0, -1, -1, -1},
238 {-1, -1, 5, 0, 1, -1, -1, -1},
239 {-1, -1, 3, 5, 1, 6, -1, -1},
240 {-1, 4, 3, -1, 6, 7, -1, -1},
241 {-1, 7, 4, -1, -1, 7, 4, -1},
242 { 6, 7, -1, -1, -1, 4, 3, -1},
243 { 1, 6, -1, -1, -1, -1, 3, 5},
244 { 1, -1, -1, -1, -1, -1, 5, -1},
245 {-1, -1, -1, -1, -1, -1, -1, -1},
246 {-1, -1, -1, -1, -1, -1, -1, -1}},
247 {{-1, -1, 0, 0, 0, 0, -1, -1},
248 {-1, 0, 1, 1, 1, 0, -1, -1},
249 {-1, 0, 1, 0, 0, 1, 0, -1},
250 {-1, 0, 1, 1, 1, 0, -1, -1},
251 {-1, -1, 0, 0, 0, 0, -1, -1},
252 {-1, -1, 7, -1, 7, -1, -1, -1},
253 {-1, -1, 7, 7, 7, 7, -1, -1},
254 {-1, -1, -1, -1, -1, -1, -1, -1},
255 {-1, -1, -1, -1, -1, -1, -1, -1},
256 {-1, -1, -1, -1, -1, -1, -1, -1}},
257 {{-1, 4, 4, 4, 6, 6, 6, -1},
258 { 4, -1, -1, -1, -1, -1, 6, -1},
259 {-1, 4, -1, -1, -1, -1, 6, -1},
260 { 4, 2, 3, 1, 2, 3, 6, -1},
261 {-1, 3, 1, 2, 3, 1, 2, -1},
262 {-1, -1, -1, -1, -1, -1, -1, -1},
263 {-1, -1, -1, -1, -1, -1, -1, -1},
264 {-1, -1, -1, -1, -1, -1, -1, -1},
265 {-1, -1, -1, -1, -1, -1, -1, -1},
266 {-1, -1, -1, -1, -1, -1, -1, -1}},
267 {{-1, 4, 4, 4, 6, 6, 6, -1},
268 { 4, -1, -1, -1, -1, -1, 6, -1},
269 {-1, 4, -1, -1, -1, -1, 6, -1},
270 { 4, 2, 3, 1, 2, 3, 6, -1},
271 {-1, 3, 1, 2, 3, 1, 2, -1},
272 {-1, 2, 3, 1, 2, 3, -1, -1},
273 {-1, -1, -1, -1, -1, -1, -1, -1},
274 {-1, -1, -1, -1, -1, -1, -1, -1},
275 {-1, -1, -1, -1, -1, -1, -1, -1},
276 {-1, -1, -1, -1, -1, -1, -1, -1}},
277 {{-1, 0, 0, -1, -1, 2, 2, -1},
278 {-1, 5, -1, -1, -1, 3, -1, -1},
279 {-1, 0, -1, -1, -1, 6, -1, -1},
280 {-1, 3, -1, -1, -1, 0, -1, -1},
281 {-1, 4, -1, -1, -1, 5, -1, -1},
282 {-1, 2, -1, -1, -1, 3, -1, -1},
283 {-1, 2, -1, -1, -1, 1, -1, -1},
284 {-1, 3, -1, -1, -1, 4, -1, -1},
285 {-1, -1, -1, -1, -1, -1, -1, -1},
286 {-1, -1, -1, -1, -1, -1, -1, -1}},
287 {{ 3, -1, -1, -1, -1, -1, -1, 3},
288 { 6, 3, 2, 4, 6, 3, 2, -1},
289 { 4, -1, -1, -1, -1, -1, -1, 4},
290 { 2, 4, 6, 3, 2, 4, 6, -1},
291 {-1, -1, -1, 6, -1, -1, -1, -1},
292 {-1, -1, -1, 3, -1, -1, -1, -1},
293 {-1, -1, -1, -1, -1, -1, -1, -1},
294 {-1, -1, -1, -1, -1, -1, -1, -1},
295 {-1, -1, -1, -1, -1, -1, -1, -1},
296 {-1, -1, -1, -1, -1, -1, -1, -1}},
297 {{-1, 2, -1, 1, -1, 1, -1, 2},
298 { 1, 2, -1, 2, 1, -1, 1, -1},
299 { 1, -1, 1, -1, 2, -1, 2, -1},
300 { 2, 1, -1, 1, 2, -1, 2, -1},
301 {-1, 2, -1, 2, -1, 2, -1, 2},
302 { 1, 2, -1, 2, 1, -1, 1, -1},
303 { 1, -1, 1, -1, 2, -1, 1, -1},
304 { 2, 2, -1, 1, 1, -1, 2, -1},
305 {-1, 2, -1, 1, -1, 1, -1, 1},
306 {-1, -1, -1, -1, -1, -1, -1, -1}},
307 {{-1, 7, 7, -1, -1, 5, 5, -1},
308 { 1, -1, -1, -1, -1, -1, 4, -1},
309 { 2, 1, -1, -1, -1, -1, 4, 3},
310 { 2, -1, -1, -1, -1, -1, 3, -1},
311 { 1, 2, -1, -1, -1, -1, 3, 4},
312 { 1, -1, -1, -1, -1, -1, 4, -1},
313 { 7, 1, -1, -1, -1, -1, 4, 5},
314 { 7, 7, -1, -1, -1, 5, 5, -1},
315 {-1, -1, -1, -1, -1, -1, -1, -1},
316 {-1, -1, -1, -1, -1, -1, -1, -1}},
317 {{ 7, 7, -1, -1, -1, -1, 5, 5},
318 { 1, 5, -1, -1, -1, 7, 4, -1},
319 { 2, 1, -1, -1, -1, -1, 4, 3},
320 { 2, -1, -1, -1, -1, -1, 3, -1},
321 { 1, 5, -1, -1, -1, -1, 7, 4},
322 { 1, -1, -1, -1, -1, -1, 4, -1},
323 { 7, 1, -1, -1, -1, -1, 4, 5},
324 { 7, 5, -1, -1, -1, 7, 5, -1},
325 {-1, -1, -1, -1, -1, -1, -1, -1},
326 {-1, -1, -1, -1, -1, -1, -1, -1}},
327 {{-1, -1, -1, 0, 0, -1, -1, -1},
328 {-1, -1, 5, 0, 1, -1, -1, -1},
329 {-1, -1, 3, 5, 1, 6, -1, -1},
330 {-1, 4, 3, 2, 6, 2, -1, -1},
331 {-1, 7, 4, 7, 2, 2, 4, -1},
332 { 6, 7, 7, 3, 3, 4, 3, -1},
333 { 1, 6, 1, 1, 1, 3, 3, 5},
334 { 1, 1, -1, -1, -1, -1, 5, -1},
335 {-1, -1, -1, -1, -1, -1, -1, -1},
336 {-1, -1, -1, -1, -1, -1, -1, -1}},
337 {{-1, -1, 0, -1, -1, 0, -1, -1},
338 {-1, 3, 3, -1, 3, 3, -1, -1},
339 {-1, 0, 2, 0, 0, 2, 0, -1},
340 {-1, 3, 3, -1, 3, 3, -1, -1},
341 {-1, -1, 0, -1, -1, 0, -1, -1},
342 {-1, -1, -1, -1, -1, -1, -1, -1},
343 {-1, -1, -1, -1, -1, -1, -1, -1},
344 {-1, -1, -1, -1, -1, -1, -1, -1},
345 {-1, -1, -1, -1, -1, -1, -1, -1},
346 {-1, -1, -1, -1, -1, -1, -1, -1}},
347 {{-1, -1, -1, 1, 1, -1, -1, -1},
348 {-1, -1, 2, 2, 2, -1, -1, -1},
349 {-1, -1, 3, 3, 3, 3, -1, -1},
350 {-1, 4, 4, 4, 4, 4, -1, -1},
351 {-1, 5, 5, 5, 5, 5, 5, -1},
352 {-1, -1, -1, 6, -1, -1, -1, -1},
353 {-1, -1, -1, 7, 7, -1, -1, -1},
354 {-1, -1, -1, 0, -1, -1, -1, -1},
355 {-1, -1, -1, -1, -1, -1, -1, -1},
356 {-1, -1, -1, -1, -1, -1, -1, -1}},
357 {{-1, -1, -1, 2, 5, -1, -1, -1},
358 {-1, 4, 3, -1, -1, -1, -1, -1},
359 { 6, 7, -1, 5, 2, -1, -1, -1},
360 {-1, -1, -1, -1, 3, 4, -1, -1},
361 {-1, -1, -1, 2, 5, -1, 7, 6},
362 {-1, 4, 3, -1, -1, -1, -1, -1},
363 { 6, 7, -1, 5, 2, -1, -1, -1},
364 {-1, -1, -1, -1, 3, 4, -1, -1},
365 {-1, -1, -1, -1, -1, -1, 7, 6},
366 {-1, -1, -1, -1, -1, -1, -1, -1}},
367 {{-1, -1, -1, 5, 5, -1, -1, -1},
368 {-1, -1, -1, 3, -1, -1, -1, -1},
369 {-1, -1, -1, 1, -1, -1, -1, -1},
370 {-1, -1, -1, 7, -1, -1, -1, -1},
371 {-1, -1, -1, 2, -1, -1, -1, -1},
372 {-1, -1, -1, 4, -1, -1, -1, -1},
373 {-1, -1, -1, 5, -1, -1, -1, -1},
374 {-1, -1, -1, 3, -1, -1, -1, -1},
375 {-1, -1, -1, -1, -1, -1, -1, -1},
376 {-1, -1, -1, -1, -1, -1, -1, -1}},
377 {{-1, -1, -1, 0, 1, -1, -1, -1},
378 {-1, -1, 0, 2, 7, 7, -1, -1},
379 {-1, -1, -1, 0, 1, 7, -1, -1},
380 {-1, 0, 0, 0, 0, -1, -1, -1},
381 {-1, 0, 0, 0, 1, 1, -1, -1},
382 { 0, 0, 0, 1, 1, 1, -1, -1},
383 {-1, 0, 0, 1, 1, 1, -1, -1},
384 {-1, 0, 0, 0, 7, 7, -1, -1},
385 {-1, -1, 7, 7, -1, -1, -1, -1},
386 {-1, -1, -1, -1, -1, -1, -1, -1}},
387 {{-1, 1, -1, -1, -1, -1, -1, -1},
388 { 1, -1, -1, -1, -1, -1, -1, -1},
389 {-1, 2, 3, 4, 7, 6, 5, -1},
390 {-1, -1, -1, -1, -1, -1, 1, -1},
391 {-1, -1, -1, -1, -1, -1, 1, -1},
392 {-1, 2, 3, 4, 7, 6, -1, -1},
393 {-1, 1, -1, -1, -1, -1, -1, -1},
394 { 1, -1, -1, -1, -1, -1, -1, -1},
395 {-1, 2, 3, 4, 7, 6, 5, -1},
396 {-1, -1, -1, -1, -1, -1, -1, -1}},
397 {{-1, 6, -1, -1, -1, -1, -1, -1},
398 { 5, -1, -1, -1, -1, -1, -1, -1},
399 { 2, 3, 4, 7, 6, 5, 2, 3},
400 {-1, -1, -1, -1, -1, -1, 4, -1},
401 {-1, -1, -1, -1, -1, -1, 7, -1},
402 {-1, 4, 3, 2, 5, 6, -1, -1},
403 {-1, 7, -1, -1, -1, -1, -1, -1},
404 { 6, -1, -1, -1, -1, -1, -1, -1},
405 { 5, 2, 3, 4, 7, 6, 5, -1},
406 {-1, -1, -1, -1, -1, -1, -1, -1}},
407 {{ 3, 2, 1, 0, 0, 1, 2, 3},
408 { 3, 2, 1, 0, 1, 2, 3, -1},
409 { 4, 3, 2, 1, 1, 2, 3, 4},
410 { 4, 3, 2, 1, 2, 3, 4, -1},
411 { 5, 4, 3, 2, 2, 3, 4, 5},
412 { 5, 4, 3, 2, 3, 4, 5, -1},
413 { 6, 5, 4, 3, 3, 4, 5, 6},
414 { 6, 5, 4, 3, 4, 5, 6, -1},
415 { 7, 6, 5, 4, 4, 5, 6, 7},
416 {-1, -1, -1, -1, -1, -1, -1, -1}},
417 {{-1, -1, -1, 5, 5, -1, -1, -1},
418 {-1, -1, -1, 3, -1, -1, -1, -1},
419 {-1, -1, -1, 2, 4, -1, -1, -1},
420 {-1, -1, -1, 6, -1, -1, -1, -1},
421 {-1, -1, -1, 2, 4, -1, -1, -1},
422 {-1, 2, -1, 5, -1, 4, -1, -1},
423 { 1, 0, 1, 0, 1, 0, 1, 0},
424 { 3, -1, 3, -1, 2, -1, 6, -1},
425 {-1, -1, -1, -1, -1, -1, -1, -1},
426 {-1, -1, -1, -1, -1, -1, -1, -1}},
427 {{-1, -1, -1, -1, 1, -1, -1, -1},
428 { 7, 4, 3, 5, -1, -1, -1, -1},
429 { 6, -1, -1, 1, -1, -1, -1, -1},
430 {-1, -1, -1, 5, 3, 4, 7, -1},
431 { 6, -1, -1, -1, 1, -1, -1, 6},
432 { 7, 4, 3, 5, -1, -1, -1, -1},
433 {-1, -1, -1, 1, -1, -1, -1, 6},
434 {-1, -1, -1, 5, 3, 4, 7, -1},
435 {-1, -1, -1, -1, -1, -1, -1, -1},
436 {-1, -1, -1, -1, -1, -1, -1, -1}},
437 {{-1, -1, -1, -1, 7, 3, 6, -1},
438 {-1, -1, 3, 7, 3, 6, 3, -1},
439 {-1, -1, 5, 7, 3, 6, 3, -1},
440 {-1, 6, 7, 3, 6, 7, -1, -1},
441 {-1, 7, 7, 3, 6, 1, -1, -1},
442 { 3, 7, 3, 6, 3, -1, -1, -1},
443 { 5, 6, 2, 7, 1, -1, -1, -1},
444 {-1, -1, -1, -1, -1, -1, -1, -1},
445 {-1, -1, -1, -1, -1, -1, -1, -1},
446 {-1, -1, -1, -1, -1, -1, -1, -1}},
447 {{ 5, -1, -1, -1, -1, -1, -1, 5},
448 { 5, -1, 6, 6, 6, -1, 5, -1},
449 {-1, 5, 4, -1, -1, 4, 5, -1},
450 {-1, 3, -1, -1, -1, 3, -1, -1},
451 {-1, 6, 0, -1, -1, 0, 6, -1},
452 {-1, 3, -1, -1, -1, 3, -1, -1},
453 {-1, -1, 4, -1, -1, 4, -1, -1},
454 {-1, -1, 6, 6, 6, -1, -1, -1},
455 {-1, -1, -1, -1, -1, -1, -1, -1},
456 {-1, -1, -1, -1, -1, -1, -1, -1}},
457 {{-1, 7, 0, -1, -1, 0, 7, -1},
458 { 7, -1, 0, -1, 0, -1, 7, -1},
459 { 7, 1, -1, 0, 0, -1, 1, 7},
460 { 7, 1, 2, 0, 2, 1, 7, -1},
461 { 7, 6, 3, 2, 2, 3, 6, 7},
462 { 7, -1, 3, 2, 3, -1, 7, -1},
463 {-1, 7, 7, 3, 3, 7, 7, -1},
464 {-1, -1, -1, 3, -1, -1, -1, -1},
465 {-1, -1, -1, -1, -1, -1, -1, -1},
466 {-1, -1, -1, -1, -1, -1, -1, -1}},
467 {{-1, 3, -1, 1, -1, 7, -1, 6},
468 { 5, -1, 7, -1, 7, -1, 6, -1},
469 { 6, -1, 0, -1, 5, -1, 3, -1},
470 {-1, 2, -1, 1, -1, 5, -1, -1},
471 {-1, 4, -1, 3, -1, 4, -1, -1},
472 { 2, -1, 3, -1, 2, -1, -1, -1},
473 {-1, -1, 4, -1, 6, -1, -1, -1},
474 {-1, -1, -1, 5, -1, -1, -1, -1},
475 {-1, -1, -1, -1, -1, -1, -1, -1},
476 {-1, -1, -1, -1, -1, -1, -1, -1}},
477 {{-1, -1, -1, -1, 1, -1, -1, -1},
478 {-1, -1, -1, -1, 3, -1, -1, -1},
479 { 6, 1, 3, 1, 2, 1, 4, 1},
480 {-1, -1, -1, -1, 6, -1, -1, -1},
481 {-1, -1, -1, 4, 1, -1, -1, -1},
482 {-1, -1, 1, -1, 3, -1, -1, -1},
483 {-1, -1, -1, 2, 1, -1, -1, -1},
484 {-1, -1, -1, -1, 4, -1, -1, -1},
485 {-1, -1, -1, 6, 1, -1, -1, -1},
486 {-1, -1, -1, 6, -1, -1, -1, -1}},
487 {{-1, -1, -1, 5, 4, -1, -1, -1},
488 {-1, -1, 4, 1, 0, -1, -1, -1},
489 {-1, -1, -1, 2, 3, -1, -1, -1},
490 {-1, 1, 4, -1, 2, 2, -1, -1},
491 {-1, 3, 1, 2, 5, 1, 4, -1},
492 {-1, 4, 2, -1, 0, 4, -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, -1, -1, -1, -1},
496 {-1, -1, -1, -1, -1, -1, -1, -1}},
497 {{-1, -1, -1, -1, 1, -1, -1, -1},
498 {-1, -1, -1, 1, -1, -1, -1, -1},
499 {-1, 2, -1, -1, 1, -1, 5, -1},
500 { 5, -1, -1, 1, -1, -1, 0, -1},
501 {-1, 6, -1, -1, 1, -1, 4, -1},
502 {-1, 0, -1, 1, -1, 5, -1, -1},
503 {-1, -1, 5, 5, 0, 1, -1, -1},
504 {-1, -1, -1, -1, -1, -1, -1, -1},
505 {-1, -1, -1, -1, -1, -1, -1, -1},
506 {-1, -1, -1, -1, -1, -1, -1, -1}},
507 {{-1, -1, -1, 6, 3, -1, -1, -1},
508 {-1, -1, 3, 2, 6, -1, -1, -1},
509 {-1, -1, 2, 6, 3, 2, -1, -1},
510 {-1, 6, 3, 2, 6, 3, -1, -1},
511 {-1, 3, 2, 6, 3, 2, 6, -1},
512 { 2, 6, 3, 2, 6, 3, 2, -1},
513 { 6, 3, 2, 6, 3, 2, 6, 3},
514 {-1, -1, -1, -1, -1, -1, -1, -1},
515 {-1, -1, -1, -1, -1, -1, -1, -1},
516 {-1, -1, -1, -1, -1, -1, -1, -1}},
517 {{ 6, 6, 6, 6, 6, 6, 6, 6},
518 { 4, -1, -1, -1, -1, -1, -1, -1},
519 {-1, 3, 2, 5, 7, 6, 4, 3},
520 {-1, 5, -1, -1, -1, -1, -1, -1},
521 {-1, -1, 7, 6, 4, 3, 2, 5},
522 {-1, -1, 4, -1, -1, -1, -1, -1},
523 {-1, -1, -1, 3, 2, 5, 7, 6},
524 {-1, -1, -1, -1, -1, -1, -1, -1},
525 {-1, -1, -1, -1, -1, -1, -1, -1},
526 {-1, -1, -1, -1, -1, -1, -1, -1}},
527 {{ 1, -1, 7, -1, -1, 6, -1, 2},
528 { 6, -1, 1, -1, 6, 1, 3, -1},
529 {-1, 4, -1, 7, 2, -1, 7, -1},
530 { 2, 7, -1, -1, -1, 4, -1, -1},
531 { 6, -1, 3, 5, 0, 2, -1, 7},
532 { 1, -1, -1, -1, -1, -1, 1, -1},
533 {-1, 1, 4, 5, 7, 5, 1, -1},
534 {-1, -1, -1, -1, -1, -1, -1, -1},
535 {-1, -1, -1, -1, -1, -1, -1, -1},
536 {-1, -1, -1, -1, -1, -1, -1, -1}},
537 {{ 6, 6, 6, -1, -1, 6, 6, 6},
538 {-1, -1, 6, -1, 6, -1, -1, -1},
539 {-1, -1, 2, 3, 3, 2, -1, -1},
540 {-1, 3, -1, 5, -1, 3, -1, -1},
541 {-1, -1, 5, 3, 3, 5, -1, -1},
542 {-1, -1, 6, 1, 6, -1, -1, -1},
543 {-1, 4, 2, -1, -1, 2, 4, -1},
544 {-1, -1, -1, -1, -1, -1, -1, -1},
545 {-1, -1, -1, -1, -1, -1, -1, -1},
546 {-1, -1, -1, -1, -1, -1, -1, -1}},
547 {{-1, -1, -1, 5, 5, -1, -1, -1},
548 {-1, -1, 5, -1, -1, -1, -1, -1},
549 {-1, 3, 4, 6, 6, -1, -1, 5},
550 { 3, 3, 4, 6, 5, -1, 5, -1},
551 { 3, 2, 3, 6, 6, 5, 5, -1},
552 { 3, 3, 4, 6, 5, -1, 5, -1},
553 {-1, 3, 4, 6, 6, -1, -1, 5},
554 {-1, -1, 5, -1, -1, -1, -1, -1},
555 {-1, -1, -1, 5, 5, -1, -1, -1},
556 {-1, -1, -1, -1, -1, -1, -1, -1}},
557 {{ 1, -1, -1, -1, -1, -1, -1, 1},
558 { 1, -1, 2, 2, 2, -1, 1, -1},
559 {-1, 1, 2, 3, 3, 2, 1, -1},
560 { 6, 2, 3, -1, 3, 2, 6, -1},
561 { 6, 2, 3, -1, -1, 3, 2, 6},
562 { 6, 2, 3, -1, 3, 2, 6, -1},
563 { 3, 3, 3, 7, 7, 3, 3, 3},
564 { 0, 5, 0, 2, 0, 5, 0, -1},
565 {-1, -1, -1, -1, -1, -1, -1, -1},
566 {-1, -1, -1, -1, -1, -1, -1, -1}},
567 {{-1, -1, 7, 7, 7, -1, -1, -1},
568 {-1, 7, 2, 2, 7, -1, -1, -1},
569 {-1, 7, 5, 5, 5, 7, -1, -1},
570 { 7, 7, 7, 7, 7, 7, -1, -1},
571 {-1, -1, 6, -1, 6, -1, -1, -1},
572 {-1, 6, -1, -1, 6, -1, -1, -1},
573 {-1, 6, 4, 4, -1, 6, 4, 4},
574 {-1, -1, -1, -1, -1, -1, -1, -1},
575 {-1, -1, -1, -1, -1, -1, -1, -1},
576 {-1, -1, -1, -1, -1, -1, -1, -1}},
577 {{-1, 3, 3, -1, 3, 3, 3, -1},
578 { 3, 7, 5, 4, 6, 5, 3, -1},
579 { 1, 3, 3, 3, -1, 3, 3, 1},
580 { 2, 1, 2, 1, 2, 1, 2, -1},
581 { 1, 3, 3, -1, 3, 3, 3, 1},
582 { 3, 5, 6, 4, 5, 7, 3, -1},
583 { 2, 3, 3, 3, -1, 3, 3, 2},
584 { 1, 1, 2, 2, 2, 1, 1, -1},
585 {-1, -1, -1, -1, -1, -1, -1, -1},
586 {-1, -1, -1, -1, -1, -1, -1, -1}},
587 {{-1, 6, 5, -1, -1, -1, -1, -1},
588 { 3, 1, 3, -1, -1, -1, -1, -1},
589 {-1, 5, 6, -1, -1, -1, -1, -1},
590 {-1, -1, 5, 3, -1, -1, -1, -1},
591 {-1, -1, 6, 1, 6, -1, -1, -1},
592 {-1, -1, 3, 5, -1, -1, -1, -1},
593 {-1, -1, -1, -1, 3, 6, -1, -1},
594 {-1, -1, -1, 5, 6, 5, -1, -1},
595 {-1, -1, -1, -1, 6, 3, -1, -1},
596 {-1, -1, -1, -1, -1, -1, -1, -1}},
597 {{ 6, 3, 7, 4, 5, 1, 6, 3},
598 { 5, 1, 6, 3, 7, 4, 5, -1},
599 { 6, 3, 7, 4, 5, 1, 6, 3},
600 {-1, -1, -1, -1, -1, -1, -1, -1},
601 {-1, -1, -1, -1, -1, -1, -1, -1},
602 {-1, -1, -1, -1, -1, -1, -1, -1},
603 {-1, -1, -1, -1, -1, -1, -1, -1},
604 {-1, -1, -1, -1, -1, -1, -1, -1},
605 {-1, -1, -1, -1, -1, -1, -1, -1},
606 {-1, -1, -1, -1, -1, -1, -1, -1}},
607 {{-1, -1, -1, -1, -1, -1, 4, 4},
608 {-1, -1, 7, 7, 7, 4, 4, -1},
609 {-1, -1, -1, -1, -1, -1, 4, 4},
610 {-1, 1, -1, -1, -1, 7, -1, -1},
611 {-1, 1, 1, -1, -1, 7, -1, -1},
612 { 3, 3, 3, -1, 7, -1, -1, -1},
613 { 3, -1, 2, 3, 3, 3, -1, 3},
614 {-1, 2, -1, 3, -1, 3, 3, -1},
615 {-1, 2, -1, -1, -1, -1, -1, -1},
616 {-1, -1, -1, -1, -1, -1, -1, -1}},
617 {{-1, -1, 4, -1, -1, -1, -1, -1},
618 {-1, 7, 4, -1, -1, -1, -1, -1},
619 {-1, -1, 7, 4, -1, -1, -1, -1},
620 {-1, 4, 7, 4, -1, -1, -1, -1},
621 { 1, 1, 1, 1, 1, 1, 1, -1},
622 { 1, 2, 1, 2, 1, 1, -1, -1},
623 { 2, 2, 2, 2, 2, 2, 2, 2},
624 {-1, -1, -1, -1, -1, -1, -1, -1},
625 {-1, -1, -1, -1, -1, -1, -1, -1},
626 {-1, -1, -1, -1, -1, -1, -1, -1}},
627 {{ 0, -1, -1, -1, -1, -1, -1, 6},
628 { 6, 1, 4, 3, 7, 5, 0, -1},
629 { 0, -1, -1, -1, -1, -1, -1, 6},
630 { 6, 1, 4, 3, 7, 5, 0, -1},
631 { 0, -1, -1, -1, -1, -1, -1, 6},
632 { 6, 1, 4, 3, 7, 5, 0, -1},
633 {-1, -1, -1, -1, -1, -1, -1, -1},
634 {-1, -1, -1, -1, -1, -1, -1, -1},
635 {-1, -1, -1, -1, -1, -1, -1, -1},
636 {-1, -1, -1, -1, -1, -1, -1, -1}},
637 {{ 3, 3, 4, 6, 6, 4, 3, 3},
638 { 0, 3, 4, 6, 4, 3, 1, -1},
639 { 5, 1, 3, 4, 4, 3, 0, 1},
640 { 0, 1, 3, 4, 3, 1, 0, -1},
641 { 2, 1, 6, 3, 3, 0, 0, 1},
642 { 0, 3, 4, 3, 6, 1, 5, -1},
643 { 6, 1, 2, 6, 4, 0, 0, 2},
644 {-1, -1, -1, -1, -1, -1, -1, -1},
645 {-1, -1, -1, -1, -1, -1, -1, -1},
646 {-1, -1, -1, -1, -1, -1, -1, -1}},
647 {{ 6, 6, -1, -1, -1, -1, 4, 4},
648 { 4, 0, -1, -1, -1, 3, 6, -1},
649 { 0, 6, -1, -1, -1, -1, 4, 2},
650 { 7, -1, -1, -1, -1, -1, 7, -1},
651 { 4, 4, -1, -1, -1, -1, 5, 6},
652 { 6, 4, 7, 7, 5, 6, 4, -1},
653 {-1, 7, 6, 4, 6, 4, 7, -1},
654 {-1, 0, -1, 7, -1, 7, -1, -1},
655 {-1, -1, -1, -1, -1, -1, -1, -1},
656 {-1, -1, -1, -1, -1, -1, -1, -1}},
657 {{-1, 5, -1, -1, -1, -1, 4, -1},
658 {-1, 5, -1, -1, -1, 4, -1, -1},
659 {-1, -1, 5, 6, 6, 4, -1, -1},
660 {-1, -1, 2, -1, 2, -1, -1, -1},
661 { 0, 0, 6, -1, -1, 6, 1, 1},
662 {-1, -1, 2, -1, 2, -1, -1, -1},
663 {-1, -1, 7, 6, 6, 3, -1, -1},
664 {-1, 7, -1, -1, -1, 3, -1, -1},
665 {-1, 7, -1, -1, -1, -1, 3, -1},
666 {-1, -1, -1, -1, -1, -1, -1, -1}},
667 {{-1, 6, -1, -1, -1, -1, 2, -1},
668 { 1, 7, 1, 1, 1, 3, 1, -1},
669 {-1, -1, 4, 1, 1, 4, -1, -1},
670 {-1, 1, 3, 1, 7, 1, -1, -1},
671 {-1, -1, -1, 2, 6, -1, -1, -1},
672 {-1, -1, 1, 5, 1, -1, -1, -1},
673 {-1, -1, -1, -1, -1, -1, -1, -1},
674 {-1, -1, -1, -1, -1, -1, -1, -1},
675 {-1, -1, -1, -1, -1, -1, -1, -1},
676 {-1, -1, -1, -1, -1, -1, -1, -1}},
677 {{ 7, 7, 7, 7, 7, 7, 7, 7},
678 { 7, -1, -1, -1, -1, -1, 7, -1},
679 { 7, -1, -1, 2, 0, 5, 2, 2},
680 { 7, -1, -1, -1, 0, 3, 6, -1},
681 { 7, -1, -1, -1, -1, -1, 4, 0},
682 { 5, 5, -1, -1, -1, -1, -1, -1},
683 { 4, 3, 6, 2, -1, -1, -1, -1},
684 { 0, 2, 0, 4, -1, -1, -1, -1},
685 {-1, -1, -1, -1, -1, -1, -1, -1},
686 {-1, -1, -1, -1, -1, -1, -1, -1}},
687 {{-1, -1, 1, -1, -1, 1, -1, -1},
688 {-1, 4, -1, -1, 5, -1, -1, -1},
689 {-1, 7, -1, -1, 1, 1, 1, -1},
690 { 6, -1, -1, -1, -1, 7, -1, -1},
691 { 1, 1, 1, 1, -1, 4, -1, -1},
692 {-1, -1, 5, -1, -1, -1, -1, -1},
693 {-1, -1, 0, -1, -1, -1, -1, -1},
694 {-1, 3, -1, -1, -1, -1, -1, -1},
695 {-1, 1, -1, -1, -1, -1, -1, -1},
696 {-1, -1, -1, -1, -1, -1, -1, -1}},
697 {{-1, 7, 7, -1, -1, 7, 7, -1},
698 { 6, -1, 4, -1, 4, -1, 6, -1},
699 { 5, -1, -1, 3, 3, -1, -1, 5},
700 { 6, -1, -1, -1, -1, -1, 6, -1},
701 {-1, 7, -1, -1, -1, -1, 7, -1},
702 {-1, 4, -1, -1, -1, 4, -1, -1},
703 {-1, -1, 3, -1, -1, 3, -1, -1},
704 {-1, -1, 2, -1, 2, -1, -1, -1},
705 {-1, -1, -1, 5, 5, -1, -1, -1},
706 {-1, -1, -1, -1, -1, -1, -1, -1}},
707 {{-1, 0, 0, -1, -1, 0, 0, -1},
708 { 7, 4, 6, 6, 6, 4, 3, -1},
709 { 5, 6, 6, 6, 2, 6, 6, 3},
710 { 7, 4, 6, 6, 6, 4, 3, -1},
711 {-1, 0, 0, -1, -1, 0, 0, -1},
712 {-1, -1, -1, -1, -1, -1, -1, -1},
713 {-1, -1, -1, -1, -1, -1, -1, -1},
714 {-1, -1, -1, -1, -1, -1, -1, -1},
715 {-1, -1, -1, -1, -1, -1, -1, -1},
716 {-1, -1, -1, -1, -1, -1, -1, -1}},
717 {{-1, -1, -1, -1, -1, 7, 7, 7},
718 {-1, -1, -1, -1, 2, 7, 7, -1},
719 {-1, 0, 7, 7, 7, -1, 7, 7},
720 { 6, 7, 7, 7, -1, -1, -1, -1},
721 { 6, -1, -1, -1, 7, 7, 7, 7},
722 { 6, -1, -1, -1, -1, -1, -1, -1},
723 { 4, 2, 2, 2, 4, -1, 3, -1},
724 { 4, 4, 4, 4, 3, 3, 3, -1},
725 {-1, -1, -1, -1, -1, -1, -1, -1},
726 {-1, -1, -1, -1, -1, -1, -1, -1}},
727 {{ 4, -1, -1, 7, -1, 6, -1, 7},
728 { 7, 6, 7, -1, -1, 7, 4, -1},
729 {-1, -1, 7, -1, -1, 7, -1, -1},
730 {-1, 0, 0, 0, 0, 0, 3, -1},
731 {-1, -1, 0, 2, 2, 0, 6, 4},
732 {-1, -1, 0, 0, 0, 1, 3, -1},
733 {-1, -1, -1, 0, 0, -1, 3, 4},
734 {-1, -1, -1, 6, -1, 5, 6, -1},
735 {-1, -1, -1, -1, -1, -1, 1, 0},
736 {-1, -1, -1, -1, -1, -1, -1, -1}},
737 {{-1, 5, -1, -1, -1, -1, 5, -1},
738 { 0, -1, -1, 0, -1, -1, 0, -1},
739 { 0, 0, 0, 2, 2, 0, 0, 0},
740 { 0, -1, -1, 0, -1, -1, 0, -1},
741 {-1, 7, -1, 3, -1, -1, 7, -1},
742 {-1, -1, 3, 6, -1, -1, -1, -1},
743 {-1, -1, -1, 6, -1, -1, -1, -1},
744 {-1, 3, 6, -1, -1, -1, -1, -1},
745 {-1, 3, -1, -1, -1, -1, -1, -1},
746 {-1, -1, -1, -1, -1, -1, -1, -1}},
747 {{-1, -1, -1, 6, 5, -1, -1, -1},
748 {-1, -1, 2, 6, 3, -1, -1, -1},
749 {-1, -1, 5, 4, 7, 1, -1, -1},
750 {-1, 6, 2, 2, 3, 4, -1, -1},
751 {-1, -1, 3, 7, 3, 6, -1, -1},
752 {-1, -1, 1, 3, 2, -1, -1, -1},
753 {-1, -1, -1, 4, 5, -1, -1, -1},
754 {-1, -1, -1, 4, -1, -1, -1, -1},
755 {-1, -1, -1, -1, -1, -1, -1, -1},
756 {-1, -1, -1, -1, -1, -1, -1, -1}},
757 {{ 7, 7, -1, 2, 2, -1, 6, 6},
758 { 6, -1, -1, 6, -1, -1, 3, -1},
759 { 2, -1, -1, 1, -1, -1, 2, -1},
760 { 5, -1, -1, 3, -1, -1, 2, -1},
761 { 1, -1, -1, 2, -1, -1, 1, -1},
762 { 5, -1, -1, 2, -1, -1, 2, -1},
763 { 6, -1, -1, 1, -1, -1, 7, -1},
764 { 5, -1, -1, 5, -1, -1, 4, -1},
765 {-1, -1, -1, -1, -1, -1, -1, -1},
766 {-1, -1, -1, -1, -1, -1, -1, -1}},
767 {{-1, -1, -1, 6, 6, -1, -1, -1},
768 {-1, 0, 4, 4, 4, 0, -1, -1},
769 {-1, -1, -1, 6, 6, -1, -1, -1},
770 {-1, -1, 2, 7, 2, -1, -1, -1},
771 {-1, -1, -1, 6, 6, -1, -1, -1},
772 {-1, 0, 5, 5, 5, 0, -1, -1},
773 {-1, -1, -1, 3, 3, -1, -1, -1},
774 {-1, -1, -1, -1, -1, -1, -1, -1},
775 {-1, -1, -1, -1, -1, -1, -1, -1},
776 {-1, -1, -1, -1, -1, -1, -1, -1}},
777 {{-1, -1, 4, 1, 3, -1, -1, -1},
778 {-1, 1, -1, -1, 1, -1, -1, -1},
779 {-1, -1, 4, 1, 3, 4, 1, -1},
780 {-1, 1, 3, 4, -1, -1, 4, -1},
781 {-1, 3, -1, -1, 3, 4, 1, -1},
782 {-1, 1, 3, 4, 1, 3, -1, -1},
783 {-1, -1, 4, 1, -1, -1, -1, -1},
784 {-1, -1, -1, -1, -1, -1, -1, -1},
785 {-1, -1, -1, -1, -1, -1, -1, -1},
786 {-1, -1, -1, -1, -1, -1, -1, -1}},
787 {{-1, 6, 4, -1, 3, 2, 5, -1},
788 { 0, -1, -1, -1, -1, -1, 1, -1},
789 {-1, 2, 3, 5, -1, 4, 6, -1},
790 { 0, -1, -1, -1, -1, -1, 1, -1},
791 {-1, 4, 6, -1, 2, 5, 3, -1},
792 { 0, -1, -1, -1, -1, -1, 1, -1},
793 {-1, 5, 2, 3, -1, 4, 6, -1},
794 {-1, -1, -1, -1, -1, -1, -1, -1},
795 {-1, -1, -1, -1, -1, -1, -1, -1},
796 {-1, -1, -1, -1, -1, -1, -1, -1}},
797 {{-1, -1, -1, 6, 6, -1, -1, -1},
798 {-1, -1, 7, 6, 4, -1, -1, -1},
799 {-1, 2, 1, 7, 4, 1, 3, -1},
800 { 2, 1, 1, 1, 1, 1, 3, -1},
801 {-1, 2, 2, 2, 3, 3, 3, -1},
802 {-1, -1, -1, 5, -1, -1, -1, -1},
803 {-1, -1, -1, 2, 3, -1, -1, -1},
804 {-1, -1, -1, 5, -1, -1, -1, -1},
805 {-1, -1, 2, 2, 3, 3, -1, -1},
806 {-1, -1, -1, -1, -1, -1, -1, -1}},
807 {{ 4, -1, 5, -1, -1, 3, -1, 6},
808 { 2, -1, 3, -1, 2, -1, 4, -1},
809 { 4, -1, -1, 1, 0, -1, -1, 6},
810 { 6, -1, 2, 3, 5, -1, 4, -1},
811 { 4, -1, -1, 0, 1, -1, -1, 6},
812 { 2, -1, 5, -1, 3, -1, 4, -1},
813 { 4, -1, 3, -1, -1, 2, -1, 6},
814 { 6, -1, -1, -1, -1, -1, 4, -1},
815 {-1, -1, -1, -1, -1, -1, -1, -1},
816 {-1, -1, -1, -1, -1, -1, -1, -1}},
817 {{ 2, 6, 0, 5, 5, 1, 3, 4},
818 { 1, -1, -1, 2, -1, -1, 0, -1},
819 { 4, -1, -1, 3, 6, -1, -1, 2},
820 {-1, -1, -1, 0, -1, -1, -1, -1},
821 {-1, -1, -1, 1, 4, -1, -1, -1},
822 {-1, -1, -1, 2, -1, -1, -1, -1},
823 {-1, -1, -1, 6, 3, -1, -1, -1},
824 {-1, -1, -1, 5, -1, -1, -1, -1},
825 {-1, -1, -1, 4, 1, -1, -1, -1},
826 {-1, -1, -1, -1, -1, -1, -1, -1}},
827 {{-1, -1, -1, -1, 5, 1, 1, 3},
828 { 0, 5, 1, 0, 5, 3, 3, -1},
829 { 5, 1, 0, 5, 1, 0, 5, 1},
830 { 0, 5, 1, 0, 5, 1, 6, -1},
831 {-1, -1, -1, -1, 1, 6, 5, 1},
832 {-1, -1, -1, -1, 5, 1, 6, -1},
833 {-1, -1, -1, -1, 1, 0, 5, 1},
834 {-1, -1, -1, -1, 5, 1, 0, -1},
835 {-1, -1, -1, -1, -1, -1, -1, -1},
836 {-1, -1, -1, -1, -1, -1, -1, -1}},
837 {{-1, 0, 7, 3, -1, -1, 2, 2},
838 {-1, 0, 7, 3, -1, -1, 2, -1},
839 {-1, 0, 7, 3, -1, -1, 2, 2},
840 {-1, 0, 7, 3, -1, 3, 1, -1},
841 {-1, 0, 7, 3, -1, 6, 4, 5},
842 {-1, 0, 7, 3, -1, 7, 0, -1},
843 {-1, 0, 7, 3, -1, 2, 3, 4},
844 {-1, 0, 7, 3, -1, 5, 6, -1},
845 {-1, -1, -1, -1, -1, 7, 0, 1},
846 {-1, -1, -1, -1, -1, -1, -1, -1}},
847 {{-1, -1, -1, 7, 7, 7, 7, -1},
848 { 3, 4, 5, -1, -1, -1, 7, -1},
849 { 2, -1, -1, -1, -1, -1, -1, 3},
850 { 7, -1, -1, -1, -1, -1, 4, -1},
851 { 7, -1, -1, -1, 3, 4, 5, 6},
852 { 7, -1, -1, 2, 0, 1, 2, -1},
853 { 6, -1, -1, -1, 3, 4, 5, 6},
854 { 0, 1, -1, -1, -1, -1, -1, -1},
855 { 2, 3, 4, -1, -1, -1, -1, -1},
856 { 5, 6, 0, -1, -1, -1, -1, -1}},
857 {{-1, 7, -1, -1, -1, -1, 2, -1},
858 { 1, 1, -1, -1, -1, 3, 3, -1},
859 {-1, 2, -1, -1, -1, -1, 4, -1},
860 { 3, 3, -1, -1, -1, 5, 5, -1},
861 {-1, 4, -1, -1, -1, -1, 6, -1},
862 { 5, 5, -1, -1, -1, 1, 1, -1},
863 {-1, 6, -1, -1, -1, -1, 7, -1},
864 {-1, -1, -1, -1, -1, -1, -1, -1},
865 {-1, -1, -1, -1, -1, -1, -1, -1},
866 {-1, -1, -1, -1, -1, -1, -1, -1}},
867 {{-1, 4, -1, -1, -1, -1, 4, -1},
868 { 2, -1, -1, 1, -1, -1, 2, -1},
869 { 5, -1, -1, 0, 0, -1, -1, 5},
870 { 5, -1, -1, 1, -1, -1, 6, -1},
871 {-1, 4, 2, 7, 7, 5, 4, -1},
872 {-1, -1, -1, 6, -1, -1, -1, -1},
873 {-1, -1, -1, 3, 3, -1, -1, -1},
874 {-1, -1, -1, 7, -1, -1, -1, -1},
875 {-1, -1, -1, -1, -1, -1, -1, -1},
876 {-1, -1, -1, -1, -1, -1, -1, -1}},
877 {{-1, 1, -1, -1, 2, 3, 4, -1},
878 { 2, -1, -1, 3, 0, 4, -1, -1},
879 { 4, -1, -1, 2, 3, 1, -1, -1},
880 { 3, -1, 4, 3, 0, -1, -1, -1},
881 { 4, -1, -1, 2, 5, 1, -1, -1},
882 { 3, -1, 4, 5, 0, 4, -1, -1},
883 {-1, -1, -1, -1, -1, -1, -1, -1},
884 {-1, -1, -1, -1, -1, -1, -1, -1},
885 {-1, -1, -1, -1, -1, -1, -1, -1},
886 {-1, -1, -1, -1, -1, -1, -1, -1}},
887 {{ 2, -1, -1, 1, 1, -1, -1, 2},
888 { 2, -1, 3, 3, 3, -1, 2, -1},
889 {-1, 2, -1, 4, 4, -1, 2, -1},
890 {-1, 7, 7, 0, 7, 7, -1, -1},
891 {-1, -1, -1, 4, 4, -1, -1, -1},
892 {-1, -1, 5, 7, 5, -1, -1, -1},
893 { 6, 3, 2, 6, 4, 2, 3, 6},
894 { 5, -1, -1, -1, -1, -1, 1, -1},
895 {-1, -1, -1, -1, -1, -1, -1, -1},
896 {-1, -1, -1, -1, -1, -1, -1, -1}},
897 {{ 4, 2, 3, 5, 7, 1, 3, 6},
898 { 1, -1, -1, 1, -1, -1, 1, -1},
899 { 3, 0, 1, 3, 2, 4, 3, 5},
900 { 4, -1, -1, 4, -1, -1, 4, -1},
901 {-1, 5, -1, -1, 5, -1, -1, 5},
902 { 0, 3, 2, 0, 4, 5, 0, -1},
903 {-1, 6, -1, -1, 6, -1, -1, 6},
904 { 7, -1, -1, 7, -1, -1, 7, -1},
905 {-1, -1, -1, -1, -1, -1, -1, -1},
906 {-1, -1, -1, -1, -1, -1, -1, -1}},
907 {{-1, 5, 4, -1, 1, 1, -1, -1},
908 { 5, -1, 4, 1, -1, 1, -1, -1},
909 { 0, -1, -1, -1, -1, -1, 0, -1},
910 { 0, 6, 4, -1, -1, 4, 2, -1},
911 {-1, 4, 3, 5, 2, 6, 3, 6},
912 {-1, 2, 6, -1, -1, 5, 4, -1},
913 {-1, -1, -1, -1, -1, -1, -1, -1},
914 {-1, -1, -1, -1, -1, -1, -1, -1},
915 {-1, -1, -1, -1, -1, -1, -1, -1},
916 {-1, -1, -1, -1, -1, -1, -1, -1}},
917 {{-1, -1, -1, 6, 6, -1, -1, -1},
918 {-1, -1, 5, 5, 4, -1, -1, -1},
919 {-1, -1, 1, 6, 6, 4, -1, -1},
920 {-1, 1, 7, 2, 5, 3, -1, -1},
921 {-1, 2, 7, 2, 1, 5, 3, -1},
922 { 2, 1, 3, 1, 4, 2, 7, -1},
923 {-1, 3, 1, 3, 4, 2, 7, -1},
924 {-1, 3, 5, 5, 6, 6, -1, -1},
925 {-1, -1, -1, -1, -1, -1, -1, -1},
926 {-1, -1, -1, -1, -1, -1, -1, -1}},
927 {{-1, -1, 7, 3, -1, -1, -1, -1},
928 {-1, 1, 7, 6, -1, -1, -1, -1},
929 {-1, 3, 7, 5, 1, 5, -1, -1},
930 { 7, 7, 0, 2, 4, 0, 4, -1},
931 { 7, 1, 4, 6, 5, 6, 5, 7},
932 { 1, 7, 7, 1, 7, 7, 1, -1},
933 {-1, -1, -1, -1, -1, -1, -1, -1},
934 {-1, -1, -1, -1, -1, -1, -1, -1},
935 {-1, -1, -1, -1, -1, -1, -1, -1},
936 {-1, -1, -1, -1, -1, -1, -1, -1}},
937 {{-1, -1, 1, -1, -1, 1, -1, -1},
938 {-1, 5, 6, 1, 5, 6, -1, -1},
939 {-1, 1, 1, 2, 2, 1, 1, -1},
940 { 4, 7, 1, 0, 1, 7, 4, -1},
941 {-1, 3, 7, 5, 7, 5, 3, -1},
942 {-1, 1, 1, 1, 1, 1, -1, -1},
943 {-1, -1, -1, -1, -1, -1, -1, -1},
944 {-1, -1, -1, -1, -1, -1, -1, -1},
945 {-1, -1, -1, -1, -1, -1, -1, -1},
946 {-1, -1, -1, -1, -1, -1, -1, -1}},
947 {{ 4, -1, -1, -1, 5, -1, -1, 4},
948 { 6, 6, 7, 6, -1, 4, 5, -1},
949 { 4, 2, 7, 5, 2, 2, 6, 4},
950 {-1, -1, 4, 1, -1, 5, 2, -1},
951 {-1, 5, 2, 7, 7, -1, 7, 4},
952 { 4, 6, 5, 4, -1, 4, 2, -1},
953 {-1, -1, -1, 4, -1, 4, 1, -1},
954 { 0, 0, 0, 5, -1, -1, -1, -1},
955 {-1, -1, -1, -1, 0, 0, 0, 0},
956 {-1, -1, -1, -1, -1, -1, -1, -1}},
957 {{ 1, -1, -1, -1, 0, 0, -1, -1},
958 { 2, -1, -1, 0, 1, 0, -1, -1},
959 { 3, -1, -1, 0, 2, 2, 0, -1},
960 { 4, -1, 0, 1, 1, 1, 0, -1},
961 { 5, -1, -1, 0, 4, 4, 0, -1},
962 { 6, -1, -1, 4, 4, 4, -1, -1},
963 { 7, -1, -1, -1, 4, 4, -1, -1},
964 {-1, -1, -1, 0, 1, 0, -1, -1},
965 {-1, -1, -1, 0, 1, 1, 0, -1},
966 {-1, -1, -1, -1, -1, -1, -1, -1}},
967 {{-1, -1, 3, -1, -1, 1, 7, -1},
968 {-1, 7, 4, -1, -1, 4, 3, -1},
969 { 1, -1, -1, 0, 2, 0, -1, -1},
970 { 5, 4, -1, 3, -1, -1, -1, -1},
971 { 4, -1, 3, 6, 1, 1, 6, -1},
972 {-1, 1, -1, -1, 4, -1, 1, -1},
973 {-1, 7, 5, -1, -1, -1, 3, -1},
974 {-1, -1, 3, -1, -1, -1, -1, -1},
975 {-1, -1, -1, -1, -1, -1, -1, -1},
976 {-1, -1, -1, -1, -1, -1, -1, -1}},
977 {{ 1, -1, -1, -1, 1, -1, -1, -1},
978 { 2, -1, -1, -1, 2, -1, -1, -1},
979 {-1, 3, -1, -1, 3, 3, -1, -1},
980 {-1, 4, -1, 4, -1, 4, -1, -1},
981 {-1, 5, -1, -1, 5, 5, -1, -1},
982 { 6, -1, -1, 7, 1, 7, -1, -1},
983 { 7, -1, -1, -1, 6, 6, -1, -1},
984 {-1, -1, -1, -1, -1, -1, -1, -1},
985 {-1, -1, -1, -1, -1, -1, -1, -1},
986 {-1, -1, -1, -1, -1, -1, -1, -1}},
987 {{ 2, -1, -1, 6, -1, 2, 5, 1},
988 { 5, -1, 4, -1, 4, -1, 4, -1},
989 { 6, -1, -1, 3, -1, -1, -1, 3},
990 { 4, 2, 0, -1, -1, -1, 5, -1},
991 {-1, -1, -1, 6, -1, 3, 6, -1},
992 {-1, -1, 5, -1, 5, -1, -1, -1},
993 {-1, -1, -1, 3, -1, 4, 2, 5},
994 {-1, -1, -1, -1, -1, -1, -1, -1},
995 {-1, -1, -1, -1, -1, -1, -1, -1},
996 {-1, -1, -1, -1, -1, -1, -1, -1}},
997 {{ 6, -1, -1, -1, 4, -1, -1, 3},
998 { 0, 3, -1, -1, 6, -1, 0, -1},
999 {-1, -1, 7, -1, 1, -1, 3, -1},
1000 { 7, -1, 4, 7, -1, 2, -1, -1},
1001 { 5, 2, 3, 2, 1, 6, -1, 3},
1002 {-1, -1, 0, 4, 3, 5, 4, -1},
1003 {-1, 7, 6, -1, -1, 0, -1, -1},
1004 { 4, 3, -1, -1, -1, 4, 2, -1},
1005 { 0, -1, -1, -1, -1, -1, 6, -1},
1006 {-1, -1, -1, -1, -1, -1, -1, -1}},
1007 {{ 6, 1, 2, 5, 1, 6, 3, 0},
1008 {-1, -1, -1, -1, -1, -1, 4, -1},
1009 { 0, 5, 2, 7, 1, 6, 2, -1},
1010 { 3, -1, -1, -1, -1, -1, -1, -1},
1011 { 6, 7, 6, 4, 0, 5, 2, 6},
1012 {-1, -1, -1, -1, -1, -1, 1, -1},
1013 { 6, 1, 4, 0, 6, 2, 3, -1},
1014 { 0, -1, -1, -1, -1, -1, -1, -1},
1015 {-1, 0, 4, 5, 3, 7, 6, 0},
1016 {-1, -1, -1, -1, -1, -1, -1, -1}},
1017 {{-1, -1, -1, 0, 1, -1, -1, -1},
1018 {-1, -1, 0, 7, 0, -1, -1, -1},
1019 {-1, -1, 1, 2, 2, 0, -1, -1},
1020 {-1, 0, 7, 0, 7, 0, -1, -1},
1021 {-1, 6, -1, 7, 7, -1, 6, -1},
1022 { 4, 1, 6, 6, 6, 4, 1, -1},
1023 {-1, 5, -1, 7, 7, -1, 5, -1},
1024 {-1, -1, -1, -1, -1, -1, -1, -1},
1025 {-1, -1, -1, -1, -1, -1, -1, -1},
1026 {-1, -1, -1, -1, -1, -1, -1, -1}},
1027 {{-1, -1, -1, 5, 6, -1, -1, -1},
1028 {-1, -1, 3, 3, 3, -1, -1, -1},
1029 {-1, -1, 7, 5, 3, 7, -1, -1},
1030 {-1, 3, -1, 6, -1, 3, -1, -1},
1031 { 2, -1, -1, 3, 7, -1, -1, 1},
1032 { 2, 2, -1, 3, -1, 1, 1, -1},
1033 {-1, 0, 2, 5, 6, 1, 0, -1},
1034 {-1, -1, -1, 3, -1, -1, -1, -1},
1035 {-1, -1, -1, 3, 7, -1, -1, -1},
1036 {-1, -1, -1, -1, -1, -1, -1, -1}},
1037 {{-1, 6, -1, -1, -1, -1, 2, -1},
1038 {-1, 2, 6, 0, 6, 0, -1, -1},
1039 {-1, 0, -1, -1, -1, -1, -1, -1},
1040 { 6, -1, -1, -1, -1, -1, -1, -1},
1041 {-1, 3, 3, 2, 0, 6, 0, 0},
1042 {-1, 6, -1, -1, -1, -1, 0, -1},
1043 {-1, -1, -1, 6, 0, 2, 6, -1},
1044 {-1, 2, 0, -1, -1, -1, -1, -1},
1045 {-1, -1, -1, -1, -1, -1, -1, -1},
1046 {-1, -1, -1, -1, -1, -1, -1, -1}},
1047 {{ 0, 7, -1, -1, -1, -1, -1, -1},
1048 { 1, 5, -1, -1, -1, -1, -1, -1},
1049 { 7, 2, 5, -1, -1, -1, -1, -1},
1050 { 6, 3, 4, -1, -1, -1, -1, -1},
1051 { 5, 5, 4, 4, -1, -1, -1, -1},
1052 { 3, 3, 5, 3, -1, -1, -1, -1},
1053 { 1, 2, 2, 5, 3, -1, -1, -1},
1054 { 1, 0, 0, 7, 6, -1, -1, -1},
1055 { 3, 3, 5, 5, 7, 6, -1, -1},
1056 {-1, -1, -1, -1, -1, -1, -1, -1}},
1057 {{-1, -1, 2, 6, 6, 2, -1, -1},
1058 {-1, 2, 1, 1, 0, 2, -1, -1},
1059 {-1, 2, 3, 2, 2, 0, 2, -1},
1060 { 2, 3, 2, 5, 2, 7, 2, -1},
1061 { 2, 4, 2, 5, 2, 7, 2, 0},
1062 { 2, 4, 2, 6, 6, 2, 0, -1},
1063 {-1, 2, 5, 2, 2, 2, 7, 2},
1064 {-1, 2, 5, 6, 6, 7, 2, -1},
1065 {-1, -1, 2, 2, 2, 2, 2, -1},
1066 {-1, -1, -1, -1, -1, -1, -1, -1}},
1067 {{-1, -1, 0, -1, -1, 0, -1, -1},
1068 { 1, 0, 0, 1, 0, 0, 1, -1},
1069 { 1, 7, 7, 5, 5, 7, 7, 1},
1070 { 3, 2, -1, 2, -1, 2, 3, -1},
1071 { 3, 7, -1, 6, 6, -1, 7, 3},
1072 { 7, -1, -1, 6, -1, -1, 7, -1},
1073 { 4, 4, 5, -1, -1, 5, 4, 4},
1074 {-1, -1, -1, -1, -1, -1, -1, -1},
1075 {-1, -1, -1, -1, -1, -1, -1, -1},
1076 {-1, -1, -1, -1, -1, -1, -1, -1}},
1077 {{-1, 6, 3, -1, -1, 3, 6, -1},
1078 { 6, -1, 2, -1, 2, -1, 6, -1},
1079 { 2, -1, 0, 1, 1, 0, -1, 2},
1080 { 5, 0, -1, 7, -1, 0, 5, -1},
1081 {-1, 5, -1, 6, 6, -1, 5, -1},
1082 { 7, 1, 4, -1, 4, 1, 7, -1},
1083 { 7, -1, 4, -1, -1, 4, -1, 7},
1084 { 2, 0, -1, -1, -1, 0, 2, -1},
1085 {-1, 2, -1, -1, -1, -1, 2, -1},
1086 {-1, -1, -1, -1, -1, -1, -1, -1}},
1087 {{ 6, 1, -1, -1, -1, -1, 4, 0},
1088 { 2, 7, 5, 5, 5, 7, 3, -1},
1089 { 6, 1, -1, -1, -1, -1, 4, 0},
1090 { 2, 5, 7, 7, 7, 5, 3, -1},
1091 { 6, 1, -1, -1, -1, -1, 4, 0},
1092 { 2, 0, 6, 6, 6, 0, 3, -1},
1093 { 6, 1, -1, -1, -1, -1, 4, 0},
1094 {-1, -1, -1, -1, -1, -1, -1, -1},
1095 {-1, -1, -1, -1, -1, -1, -1, -1},
1096 {-1, -1, -1, -1, -1, -1, -1, -1}},
1097 {{ 5, -1, -1, 1, 1, -1, -1, 5},
1098 { 5, -1, 4, -1, 4, -1, 5, -1},
1099 {-1, 2, 4, -1, -1, 4, 2, -1},
1100 { 7, 2, -1, -1, -1, 2, 7, -1},
1101 { 0, -1, 0, 4, 4, 0, -1, 0},
1102 { 7, 2, -1, -1, -1, 2, 7, -1},
1103 {-1, 2, 3, -1, -1, 3, 2, -1},
1104 { 5, -1, 3, -1, 3, -1, 5, -1},
1105 { 5, -1, -1, 6, 6, -1, -1, 5},
1106 {-1, -1, -1, -1, -1, -1, -1, -1}},
1107 {{ 2, 2, -1, -1, -1, -1, 5, 5},
1108 { 5, -1, -1, -1, -1, -1, 2, -1},
1109 { 5, -1, -1, -1, -1, -1, -1, 2},
1110 { 1, -1, 1, 5, 1, -1, 3, -1},
1111 { 5, 2, 5, 3, 1, 2, 5, 2},
1112 { 2, 0, 5, -1, 2, 0, 5, -1},
1113 {-1, 3, 7, -1, -1, 3, 7, -1},
1114 {-1, -1, 2, 0, 5, -1, -1, -1},
1115 {-1, -1, -1, -1, -1, -1, -1, -1},
1116 {-1, -1, -1, -1, -1, -1, -1, -1}},
1117 {{ 0, 6, 5, 2, 3, 4, 1, 7},
1118 {-1, -1, -1, -1, 1, -1, -1, -1},
1119 {-1, -1, -1, 1, 1, -1, -1, -1},
1120 {-1, -1, 1, -1, -1, -1, -1, -1},
1121 { 7, 1, 4, 3, 2, 5, 6, 0},
1122 {-1, -1, -1, -1, 1, -1, -1, -1},
1123 {-1, -1, -1, 1, 1, -1, -1, -1},
1124 {-1, -1, 1, -1, -1, -1, -1, -1},
1125 { 0, 6, 5, 2, 3, 4, 1, 7},
1126 {-1, -1, -1, -1, -1, -1, -1, -1}},
1127 {{-1, -1, 1, -1, -1, 1, -1, -1},
1128 {-1, 2, 4, -1, 2, 4, -1, -1},
1129 {-1, 2, 3, 6, 5, 3, 2, -1},
1130 {-1, 6, 5, -1, 6, 5, -1, -1},
1131 {-1, -1, -1, 7, 7, -1, -1, -1},
1132 {-1, -1, -1, 7, -1, -1, -1, -1},
1133 { 1, -1, -1, 7, 7, -1, -1, 3},
1134 { 2, -1, -1, 7, -1, -1, 2, -1},
1135 {-1, 3, 4, 5, 6, 4, 1, -1},
1136 {-1, -1, -1, -1, -1, -1, -1, -1}},
1137 {{ 1, -1, -1, 2, 2, -1, -1, 2},
1138 { 1, 3, 7, 3, 7, 4, 2, -1},
1139 {-1, 1, 6, -1, -1, 6, 2, -1},
1140 { 6, -1, 7, 3, 7, -1, 6, -1},
1141 {-1, 4, 2, -1, -1, 1, 3, -1},
1142 {-1, -1, 2, 6, 1, -1, -1, -1},
1143 {-1, 4, 3, 3, 4, 4, 3, -1},
1144 {-1, -1, -1, -1, -1, -1, -1, -1},
1145 {-1, -1, -1, -1, -1, -1, -1, -1},
1146 {-1, -1, -1, -1, -1, -1, -1, -1}},
1147 {{-1, -1, -1, 5, 6, -1, -1, -1},
1148 {-1, -1, -1, 3, -1, -1, -1, -1},
1149 {-1, -1, -1, 1, 2, -1, -1, -1},
1150 {-1, -1, -1, 4, -1, -1, -1, -1},
1151 {-1, -1, -1, 5, 7, -1, -1, -1},
1152 {-1, -1, -1, 2, -1, -1, -1, -1},
1153 { 6, 5, 4, 3, 2, 1, 7, 5},
1154 {-1, -1, -1, -1, -1, -1, -1, -1},
1155 {-1, -1, -1, -1, -1, -1, -1, -1},
1156 {-1, -1, -1, -1, -1, -1, -1, -1}},
1157 {{-1, 0, -1, 1, -1, 2, -1, -1},
1158 {-1, 4, -1, 5, -1, 6, -1, -1},
1159 {-1, 7, -1, 0, -1, 2, -1, -1},
1160 {-1, 6, -1, 3, -1, 6, -1, -1},
1161 {-1, 1, -1, 1, -1, 2, -1, -1},
1162 {-1, 3, -1, 5, -1, 0, -1, -1},
1163 {-1, 2, -1, 4, -1, 6, -1, -1},
1164 {-1, 3, -1, 6, -1, 7, -1, -1},
1165 {-1, -1, -1, -1, -1, -1, -1, -1},
1166 {-1, -1, -1, -1, -1, -1, -1, -1}},
1167 {{ 1, 1, 2, 2, 3, 3, 4, 4},
1168 { 5, 5, 6, 7, 6, 5, 5, -1},
1169 { 6, 4, 3, 3, 2, 2, 1, 6},
1170 { 4, 6, 5, 7, 6, 3, 1, -1},
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, -1, -1, -1, -1, -1, -1, -1},
1175 {-1, -1, -1, -1, -1, -1, -1, -1},
1176 {-1, -1, -1, -1, -1, -1, -1, -1}},
1177 {{ 7, 4, -1, 1, 2, -1, 4, 7},
1178 { 5, 5, -1, 2, -1, 4, 4, -1},
1179 {-1, 5, -1, 7, 7, -1, 4, -1},
1180 { 1, 0, 6, 7, 6, 0, 2, -1},
1181 {-1, 2, -1, 5, 3, -1, 1, -1},
1182 { 1, 1, -1, -1, -1, 2, 2, -1},
1183 { 6, 1, 4, -1, -1, 4, 2, 6},
1184 { 5, 3, -1, -1, -1, 3, 5, -1},
1185 {-1, -1, -1, -1, -1, -1, -1, -1},
1186 {-1, -1, -1, -1, -1, -1, -1, -1}},
1187 {{ 1, 5, 1, 0, 0, 1, 5, 1},
1188 { 1, 2, 5, -1, 5, 2, 1, -1},
1189 { 3, 6, 1, 2, 2, 1, 6, 3},
1190 { 4, 3, 4, -1, 4, 3, 4, -1},
1191 { 3, 4, 6, 5, 5, 6, 4, 3},
1192 { 0, 2, 3, -1, 3, 2, 0, -1},
1193 { 2, 3, 1, 5, 5, 1, 3, 2},
1194 {-1, -1, -1, -1, -1, -1, -1, -1},
1195 {-1, -1, -1, -1, -1, -1, -1, -1},
1196 {-1, -1, -1, -1, -1, -1, -1, -1}},
1197 {{ 3, 0, 2, 7, 5, 7, 6, 5},
1198 { 6, -1, 1, -1, 2, -1, 1, -1},
1199 {-1, 6, 4, 0, 3, 4, 5, -1},
1200 {-1, 5, -1, 1, -1, 4, -1, -1},
1201 {-1, 7, 3, 5, 6, 5, 3, -1},
1202 { 1, -1, 2, -1, 4, -1, 2, -1},
1203 { 6, 4, 4, 6, 6, 5, 5, 1},
1204 {-1, -1, -1, -1, -1, -1, -1, -1},
1205 {-1, -1, -1, -1, -1, -1, -1, -1},
1206 {-1, -1, -1, -1, -1, -1, -1, -1}}
1209 /* the tile struct
1210 * type is the bubble number 0-7
1211 * fallx is the x axis movement for the falling bubble
1212 * fallvel is the initial upward velocity for the falling bubble
1213 * ingroup denotes a bubble that is part of a group to be removed
1214 * anchored denotes a bubble that is anchored to the ceiling
1216 struct tile {
1217 int type;
1218 int fallx;
1219 int fallvel;
1220 bool ingroup;
1221 bool anchored;
1222 bool delete;
1225 /* the game context struct
1226 * score is the current score
1227 * level is the current level
1228 * highlevel is the highest level beaten
1229 * angle is the current cannon direction
1230 * shots is the number of shots fired since last compression
1231 * compress is the height of the compressor
1232 * onboardcnt is the number of unique bubbles on the playing board
1233 * onboard is the unique bubbles on the playing board
1234 * nextinq is the pointer to the next bubble in the firing queue
1235 * queue is the circular buffer of bubbles to be fired
1236 * elapsedlvl is level elapsed time in 1/100s of seconds
1237 * elapsedshot is the shot elapsed time in 1/100s of seconds
1238 * startedshot is when the current shot began
1239 * resume denotes whether to resume the currently loaded game
1240 * playboard is the game playing board
1242 struct game_context {
1243 unsigned int score;
1244 unsigned int level;
1245 unsigned int highlevel;
1246 int angle;
1247 int shots;
1248 int compress;
1249 int onboardcnt;
1250 int onboard[NUM_BUBBLES];
1251 int nextinq;
1252 int queue[NUM_QUEUE];
1253 long elapsedlvl;
1254 long elapsedshot;
1255 long startedshot;
1256 struct tile playboard[BB_HEIGHT][BB_WIDTH];
1259 struct highscore highscores[NUM_SCORES];
1261 /* used to denote available resume info */
1262 static bool resume = false;
1264 static void bubbles_init(struct game_context* bb);
1265 static bool bubbles_nextlevel(struct game_context* bb);
1266 static void bubbles_getonboard(struct game_context* bb);
1267 static void bubbles_drawboard(struct game_context* bb);
1268 static int bubbles_fire(struct game_context* bb);
1269 static bool bubbles_collision(struct game_context* bb, int y, int x,
1270 int nearrow, int nearcol);
1271 static bool bubbles_ingroup(struct game_context* bb, int row, int col);
1272 static int bubbles_searchgroup(struct game_context* bb, int row, int col);
1273 static int bubbles_remove(struct game_context* bb);
1274 static void bubbles_anchored(struct game_context* bb, int row, int col);
1275 static int bubbles_fall(struct game_context* bb);
1276 static int bubbles_checklevel(struct game_context* bb);
1277 static void bubbles_recordscore(struct game_context* bb);
1278 static void bubbles_savescores(struct game_context* bb);
1279 static bool bubbles_loadgame(struct game_context* bb);
1280 static void bubbles_savegame(struct game_context* bb);
1281 static inline void bubbles_setcolors(void);
1282 static void bubbles_callback(void* param);
1283 static int bubbles_handlebuttons(struct game_context* bb, bool animblock,
1284 int timeout);
1285 static int bubbles(struct game_context* bb);
1287 /*****************************************************************************
1288 * bubbles_init() initializes bubbles data structures.
1289 ******************************************************************************/
1290 static void bubbles_init(struct game_context* bb) {
1291 bubbles_setcolors();
1292 /* seed the rand generator */
1293 rb->srand(*rb->current_tick);
1295 /* check for resumed game */
1296 if (resume)
1298 resume = false;
1299 return;
1302 bb->score = 0;
1303 bubbles_nextlevel(bb);
1306 /*****************************************************************************
1307 * bubbles_nextlevel() sets up the game for the next level, returns false if
1308 * there are no more levels.
1309 ******************************************************************************/
1310 static bool bubbles_nextlevel(struct game_context* bb) {
1311 int i, j, pos;
1313 /* save highest level */
1314 if (bb->level > bb->highlevel)
1315 bb->highlevel = bb->level;
1317 bb->level++;
1319 /* check if there are no more levels */
1320 if(bb->level > NUM_LEVELS) return false;
1323 /* set up the play board */
1324 rb->memset(bb->playboard, 0, sizeof(bb->playboard));
1325 for(i=0; i<BB_LEVEL_HEIGHT; i++) {
1326 for(j=0; j<BB_WIDTH; j++) {
1327 pos = (int)level[bb->level-1][i][j];
1328 if(pos >=0 && pos < NUM_BUBBLES) {
1329 bb->playboard[i][j].type = pos;
1330 } else {
1331 bb->playboard[i][j].type = -1;
1335 for(i=BB_LEVEL_HEIGHT; i<BB_HEIGHT; i++) {
1336 for(j=0; j<BB_WIDTH; j++) {
1337 bb->playboard[i][j].type = -1;
1341 /* fill first bubbles in shot queue */
1342 bubbles_getonboard(bb);
1343 for(i=0; i<NUM_QUEUE; i++) {
1344 bb->queue[i] = bb->onboard[rb->rand()%bb->onboardcnt];
1347 bb->angle = 0;
1348 bb->shots = 0;
1349 bb->compress = 0;
1350 bb->nextinq = 0;
1351 bb->elapsedlvl = 0;
1352 bb->elapsedshot = 0;
1354 return true;
1357 /*****************************************************************************
1358 * bubbles_getonboard() determines which bubble types are on the play board.
1359 ******************************************************************************/
1360 static void bubbles_getonboard(struct game_context* bb) {
1361 int i, j, k;
1362 bool found;
1364 bb->onboardcnt = 0;
1365 rb->memset(bb->onboard, -1, sizeof(bb->onboard));
1367 for(i=0; i<BB_HEIGHT; i++) {
1368 for(j=0; j<BB_WIDTH; j++) {
1369 if(bb->playboard[i][j].type >= 0) {
1370 found = false;
1372 for(k=0; k<bb->onboardcnt; k++) {
1373 if(bb->playboard[i][j].type == bb->onboard[k]) {
1374 found = true;
1375 break;
1379 if(!found) {
1380 bb->onboard[bb->onboardcnt] = bb->playboard[i][j].type;
1381 bb->onboardcnt++;
1384 if(bb->onboardcnt == NUM_BUBBLES) return;
1390 /*****************************************************************************
1391 * bubbles_drawboard() draws the game board to the buffer but does not update
1392 * the lcd.
1393 ******************************************************************************/
1394 static void bubbles_drawboard(struct game_context* bb) {
1395 int i, j;
1396 int w, h;
1397 int colmax, indent;
1398 int tipx, tipy;
1399 bool evenline = false;
1400 char *level = "Level";
1401 char *score = "Score";
1402 char *next = "Next";
1403 char *hurry = "HURRY!";
1404 char str[11];
1406 /* clear screen */
1407 rb->lcd_clear_display();
1409 /* draw background */
1410 #ifdef HAVE_LCD_COLOR
1411 rb->lcd_bitmap(bubbles_background, 0, 0, LCD_WIDTH, LCD_HEIGHT);
1412 #endif
1414 /* display play board */
1415 for(i=0; i<BB_HEIGHT; i++) {
1416 colmax = BB_WIDTH;
1417 if(evenline) {
1418 colmax--;
1419 indent = ROW_INDENT;
1420 } else {
1421 indent = 0;
1423 evenline = !evenline;
1425 for(j=0; j<colmax; j++) {
1426 if(bb->playboard[i][j].type >= 0 && !bb->playboard[i][j].delete) {
1427 rb->lcd_bitmap_part(bubbles_emblem,
1428 0, EMBLEM_HEIGHT*bb->playboard[i][j].type, EMBLEM_WIDTH,
1429 XOFS+indent+BUBBLE_WIDTH*j+(BUBBLE_WIDTH-EMBLEM_WIDTH)/2,
1430 ROW_HEIGHT*i+(BUBBLE_HEIGHT-EMBLEM_HEIGHT)/2+bb->compress*ROW_HEIGHT,
1431 EMBLEM_WIDTH, EMBLEM_HEIGHT);
1432 rb->lcd_set_drawmode(DRMODE_FG);
1433 rb->lcd_mono_bitmap((const unsigned char *)bubbles_bubble,
1434 XOFS+indent+BUBBLE_WIDTH*j,
1435 ROW_HEIGHT*i+bb->compress*ROW_HEIGHT,
1436 BUBBLE_WIDTH, BUBBLE_HEIGHT);
1437 rb->lcd_set_drawmode(DRMODE_SOLID);
1442 /* display bubble to be shot */
1443 rb->lcd_bitmap_part(bubbles_emblem,
1444 0, EMBLEM_HEIGHT*bb->queue[bb->nextinq], EMBLEM_WIDTH,
1445 SHOTX+(BUBBLE_WIDTH-EMBLEM_WIDTH)/2,
1446 SHOTY+(BUBBLE_HEIGHT-EMBLEM_HEIGHT)/2,
1447 EMBLEM_WIDTH, EMBLEM_HEIGHT);
1448 rb->lcd_set_drawmode(DRMODE_FG);
1449 rb->lcd_mono_bitmap((const unsigned char *)bubbles_bubble,
1450 SHOTX, SHOTY,
1451 BUBBLE_WIDTH, BUBBLE_HEIGHT);
1452 rb->lcd_set_drawmode(DRMODE_SOLID);
1454 /* display next bubble to be shot */
1455 rb->lcd_bitmap_part(bubbles_emblem,
1456 0, EMBLEM_HEIGHT*bb->queue[(bb->nextinq+1)%NUM_QUEUE], EMBLEM_WIDTH,
1457 XOFS/2-BUBBLE_WIDTH/2+(BUBBLE_WIDTH-EMBLEM_WIDTH)/2,
1458 SHOTY+(BUBBLE_HEIGHT-EMBLEM_HEIGHT)/2,
1459 EMBLEM_WIDTH, EMBLEM_HEIGHT);
1460 rb->lcd_set_drawmode(DRMODE_FG);
1461 rb->lcd_mono_bitmap((const unsigned char *)bubbles_bubble,
1462 XOFS/2-BUBBLE_WIDTH/2, SHOTY,
1463 BUBBLE_WIDTH, BUBBLE_HEIGHT);
1464 rb->lcd_set_drawmode(DRMODE_SOLID);
1466 /* draw bounding lines */
1467 #ifndef HAVE_LCD_COLOR
1468 rb->lcd_vline(XOFS-1, 0, LCD_HEIGHT);
1469 rb->lcd_vline(XOFS+BUBBLE_WIDTH*BB_WIDTH, 0, LCD_HEIGHT);
1470 #endif
1471 rb->lcd_hline(XOFS, XOFS+BUBBLE_WIDTH*BB_WIDTH-1, bb->compress*ROW_HEIGHT-1);
1472 rb->lcd_hline(XOFS, XOFS+BUBBLE_WIDTH*BB_WIDTH-1,
1473 ROW_HEIGHT*(BB_HEIGHT-2)+BUBBLE_HEIGHT);
1475 /* draw arrow */
1476 tipx = SHOTX+BUBBLE_WIDTH/2+(((fp14_sin(bb->angle)>>4)*BUBBLE_WIDTH*3/2)>>10);
1477 tipy = SHOTY+BUBBLE_HEIGHT/2-(((fp14_cos(bb->angle)>>4)*BUBBLE_HEIGHT*3/2)>>10);
1479 rb->lcd_drawline(SHOTX+BUBBLE_WIDTH/2+(((fp14_sin(bb->angle)>>4)*BUBBLE_WIDTH/2)>>10),
1480 SHOTY+BUBBLE_HEIGHT/2-(((fp14_cos(bb->angle)>>4)*BUBBLE_HEIGHT/2)>>10),
1481 tipx, tipy);
1482 xlcd_filltriangle(tipx, tipy,
1483 tipx+(((fp14_sin(bb->angle-135)>>4)*BUBBLE_WIDTH/3)>>10),
1484 tipy-(((fp14_cos(bb->angle-135)>>4)*BUBBLE_HEIGHT/3)>>10),
1485 tipx+(((fp14_sin(bb->angle+135)>>4)*BUBBLE_WIDTH/3)>>10),
1486 tipy-(((fp14_cos(bb->angle+135)>>4)*BUBBLE_HEIGHT/3)>>10));
1488 /* draw text */
1489 rb->lcd_getstringsize(level, &w, &h);
1490 rb->lcd_putsxy(XOFS/2-w/2, 2, level);
1492 rb->snprintf(str, 4, "%d", bb->level);
1493 rb->lcd_getstringsize(str, &w, &h);
1494 rb->lcd_putsxy(XOFS/2-w/2, 11, str);
1496 rb->lcd_getstringsize(score, &w, &h);
1497 rb->lcd_putsxy(XOFS/2-w/2, 29, score);
1499 rb->snprintf(str, 10, "%d", bb->score);
1500 rb->lcd_getstringsize(str, &w, &h);
1501 rb->lcd_putsxy(XOFS/2-w/2, 38, str);
1503 rb->lcd_getstringsize(next, &w, &h);
1504 rb->lcd_putsxy(XOFS/2-w/2, SHOTY-9, next);
1506 if(bb->elapsedshot >= (MAX_SHOTTIME*7)/10) {
1507 rb->lcd_getstringsize(hurry, &w, &h);
1508 rb->lcd_putsxy(LCD_WIDTH/2-w/2, LCD_HEIGHT/2-h/2, hurry);
1512 /*****************************************************************************
1513 * bubbles_fire() fires the current bubble, reloads the cannon, attaches
1514 * bubble to playboard, removes appropriate bubbles, and advances the
1515 * the compressor.
1516 ******************************************************************************/
1517 static int bubbles_fire(struct game_context* bb) {
1518 int bubblecur;
1519 long shotxinc, shotyinc;
1520 long shotxofs, shotyofs;
1521 int shotxdirec = 1;
1522 long tempxofs, tempyofs;
1523 int nearrow, nearcol;
1524 int lastrow = BB_HEIGHT-1;
1525 int lastcol = (BB_WIDTH-1)/2;
1526 int buttonres;
1527 long lasttick, currenttick;
1529 /* get current bubble */
1530 bubblecur = bb->queue[bb->nextinq];
1531 shotxinc = ((fp14_sin(bb->angle)>>4)*BUBBLE_WIDTH)/3;
1532 shotyinc = ((-1*(fp14_cos(bb->angle)>>4))*BUBBLE_HEIGHT)/3;
1533 shotxofs = shotyofs = 0;
1535 /* advance the queue */
1536 bb->queue[bb->nextinq] = bb->onboard[rb->rand()%bb->onboardcnt];
1537 bb->nextinq = (bb->nextinq+1)%NUM_QUEUE;
1538 bubbles_drawboard(bb);
1539 rb->lcd_update_rect(0, 0, XOFS, LCD_HEIGHT);
1541 /* move the bubble across the play board */
1542 lasttick = *rb->current_tick;
1544 while(true) {
1545 /* move the bubble one step */
1546 shotyofs += shotyinc;
1547 shotxofs += shotxinc*shotxdirec;
1549 /* check for bounce off sides */
1550 if(SHOTX+(shotxofs>>10) < XOFS) {
1551 shotxofs += 2*((XOFS<<10)-(((SHOTX)<<10)+shotxofs));
1552 shotxdirec *= -1;
1553 } else if(SHOTX+(shotxofs>>10) > XOFS+(BB_WIDTH-1)*BUBBLE_WIDTH) {
1554 shotxofs -= 2*((((SHOTX)<<10)+shotxofs)-
1555 ((XOFS<<10)+(((BB_WIDTH-1)*BUBBLE_WIDTH)<<10)));
1556 shotxdirec *= -1;
1559 tempxofs = shotxofs>>10;
1560 tempyofs = shotyofs>>10;
1562 /* display shot */
1563 bubbles_drawboard(bb);
1564 rb->lcd_bitmap_part(bubbles_emblem, 0, EMBLEM_HEIGHT*bubblecur, EMBLEM_WIDTH,
1565 SHOTX+tempxofs+(BUBBLE_WIDTH-EMBLEM_WIDTH)/2,
1566 SHOTY+tempyofs+(BUBBLE_HEIGHT-EMBLEM_HEIGHT)/2,
1567 EMBLEM_WIDTH, EMBLEM_HEIGHT);
1568 rb->lcd_set_drawmode(DRMODE_FG);
1569 rb->lcd_mono_bitmap((const unsigned char *)bubbles_bubble,
1570 SHOTX+tempxofs, SHOTY+tempyofs,
1571 BUBBLE_WIDTH, BUBBLE_HEIGHT);
1572 rb->lcd_set_drawmode(DRMODE_SOLID);
1573 rb->lcd_update_rect(XOFS, 0, BB_WIDTH*BUBBLE_WIDTH, LCD_HEIGHT);
1575 /* find nearest position */
1576 nearrow = ((SHOTY+tempyofs)-
1577 (bb->compress*ROW_HEIGHT)+
1578 (ROW_HEIGHT/2))/ROW_HEIGHT;
1579 if(nearrow >= BB_HEIGHT) nearrow = BB_HEIGHT-1;
1581 if(nearrow%2) { /* odd row */
1582 nearcol = ((SHOTX+tempxofs)-
1583 (XOFS+ROW_INDENT)+
1584 (BUBBLE_WIDTH/2))/BUBBLE_WIDTH;
1585 if(nearcol >= BB_WIDTH-1) nearcol = BB_WIDTH-2;
1586 } else { /* even row */
1587 nearcol = ((SHOTX+tempxofs)-XOFS+(BUBBLE_WIDTH/2))/BUBBLE_WIDTH;
1588 if(nearcol >= BB_WIDTH) nearcol = BB_WIDTH-1;
1590 if(nearcol < 0) nearcol = 0;
1592 /* if nearest position is occupied attach to last position */
1593 if(bb->playboard[nearrow][nearcol].type >= 0) {
1594 bb->playboard[lastrow][lastcol].type = bubblecur;
1595 break;
1598 /* save last position */
1599 lastrow = nearrow;
1600 lastcol = nearcol;
1602 /* if collision with neighbor then attach shot */
1603 if(bubbles_collision(bb, SHOTY+tempyofs, SHOTX+tempxofs,
1604 nearrow, nearcol)) {
1605 bb->playboard[nearrow][nearcol].type = bubblecur;
1606 break;
1609 /* if at top then attach shot to the ceiling */
1610 if(nearrow == 0 && SHOTY+tempyofs <= bb->compress*ROW_HEIGHT) {
1611 bb->playboard[nearrow][nearcol].type = bubblecur;
1612 break;
1615 /* handle button events */
1616 buttonres = bubbles_handlebuttons(bb, true, 0);
1617 if(buttonres != BB_NONE) return buttonres;
1619 /* framerate limiting */
1620 currenttick = *rb->current_tick;
1621 if(currenttick-lasttick < HZ/MAX_FPS) {
1622 rb->sleep((HZ/MAX_FPS)-(currenttick-lasttick));
1623 } else {
1624 rb->yield();
1626 lasttick = currenttick;
1629 bubbles_drawboard(bb);
1630 rb->lcd_update();
1632 /* clear appropriate bubbles from playing board */
1633 if(bubbles_ingroup(bb, lastrow, lastcol)) {
1634 buttonres = bubbles_remove(bb);
1635 if(buttonres != BB_NONE) return buttonres;
1638 /* update shots and compress amount */
1639 bb->shots++;
1640 if(bb->shots >= NUM_COMPRESS) {
1641 bb->shots = 0;
1642 bb->compress++;
1645 return BB_NONE;
1648 /*****************************************************************************
1649 * bubbles_collision() determines if a fired bubble has collided with another
1650 * bubble.
1651 ******************************************************************************/
1652 static bool bubbles_collision(struct game_context* bb, int y, int x,
1653 int nearrow, int nearcol) {
1654 int nx, ny;
1655 int adj = nearrow%2;
1657 /* check neighbors */
1658 if(nearcol-1 >= 0) {
1659 if(bb->playboard[nearrow][nearcol-1].type >= 0) {
1660 nx = XOFS+(nearrow%2 ? ROW_INDENT : 0)+BUBBLE_WIDTH*(nearcol-1);
1661 ny = ROW_HEIGHT*nearrow+bb->compress*ROW_HEIGHT;
1662 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1666 if(nearcol-1+adj >= 0) {
1667 if(nearrow-1 >= 0) {
1668 if(bb->playboard[nearrow-1][nearcol-1+adj].type >= 0) {
1669 nx = XOFS+((nearrow-1)%2 ? ROW_INDENT : 0)+
1670 BUBBLE_WIDTH*(nearcol-1+adj);
1671 ny = ROW_HEIGHT*(nearrow-1)+bb->compress*ROW_HEIGHT;
1672 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1676 if(nearrow+1 < BB_HEIGHT) {
1677 if(bb->playboard[nearrow+1][nearcol-1+adj].type >= 0) {
1678 nx = XOFS+((nearrow+1)%2 ? ROW_INDENT : 0)+
1679 BUBBLE_WIDTH*(nearcol-1+adj);
1680 ny = ROW_HEIGHT*(nearrow+1)+bb->compress*ROW_HEIGHT;
1681 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1686 if(nearcol+adj >= 0) {
1687 if(nearrow-1 >= 0) {
1688 if(bb->playboard[nearrow-1][nearcol+adj].type >= 0) {
1689 nx = XOFS+((nearrow-1)%2 ? ROW_INDENT : 0)+
1690 BUBBLE_WIDTH*(nearcol+adj);
1691 ny = ROW_HEIGHT*(nearrow-1)+bb->compress*ROW_HEIGHT;
1692 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1696 if(nearrow+1 < BB_HEIGHT) {
1697 if(bb->playboard[nearrow+1][nearcol+adj].type >= 0) {
1698 nx = XOFS+((nearrow+1)%2 ? ROW_INDENT : 0)+
1699 BUBBLE_WIDTH*(nearcol+adj);
1700 ny = ROW_HEIGHT*(nearrow+1)+bb->compress*ROW_HEIGHT;
1701 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1706 if(nearcol+1 < BB_WIDTH-adj) {
1707 if(bb->playboard[nearrow][nearcol+1].type >= 0) {
1708 nx = XOFS+(nearrow%2 ? ROW_INDENT : 0)+BUBBLE_WIDTH*(nearcol+1);
1709 ny = ROW_HEIGHT*nearrow+bb->compress*ROW_HEIGHT;
1710 if((x-nx)*(x-nx)+(y-ny)*(y-ny) < MIN_DISTANCE) return true;
1714 return false;
1717 /*****************************************************************************
1718 * bubbles_ingroup() marks all bubbles that form the current group.
1719 ******************************************************************************/
1720 static bool bubbles_ingroup(struct game_context* bb, int row, int col) {
1721 int i, j;
1722 int count;
1724 count = bubbles_searchgroup(bb, row, col);
1726 /* unmark group if too small */
1727 if(count < 3) {
1728 for(i=0; i<BB_HEIGHT; i++) {
1729 for(j=0; j<BB_WIDTH; j++) {
1730 bb->playboard[i][j].ingroup = false;
1734 return false;
1737 return true;
1740 /*****************************************************************************
1741 * bubbles_searchgroup() return the size of the group of bubbles of the same
1742 * type that the current bubble belongs to.
1743 ******************************************************************************/
1744 static int bubbles_searchgroup(struct game_context* bb, int row, int col) {
1745 int i, adj;
1746 int myrow, mycol, mytype;
1747 int count = 0;
1749 struct coord {
1750 int row;
1751 int col;
1752 } search[(2*BB_WIDTH-1)*(BB_HEIGHT/2)];
1754 /* search initial bubble */
1755 bb->playboard[row][col].ingroup = true;
1756 search[count].row = row;
1757 search[count].col = col;
1758 count++;
1760 /* breadth-first search neighbors */
1761 for(i=0; i<count; i++) {
1762 myrow = search[i].row;
1763 mycol = search[i].col;
1764 mytype = bb->playboard[myrow][mycol].type;
1765 adj = myrow%2;
1767 if(mycol-1 >= 0) {
1768 if(bb->playboard[myrow][mycol-1].type == mytype &&
1769 !bb->playboard[myrow][mycol-1].ingroup) {
1770 bb->playboard[myrow][mycol-1].ingroup = true;
1771 search[count].row = myrow;
1772 search[count].col = mycol-1;
1773 count++;
1777 if(mycol-1+adj >= 0) {
1778 if(myrow-1 >= 0) {
1779 if(bb->playboard[myrow-1][mycol-1+adj].type == mytype &&
1780 !bb->playboard[myrow-1][mycol-1+adj].ingroup) {
1781 bb->playboard[myrow-1][mycol-1+adj].ingroup = true;
1782 search[count].row = myrow-1;
1783 search[count].col = mycol-1+adj;
1784 count++;
1788 if(myrow+1 < BB_HEIGHT) {
1789 if(bb->playboard[myrow+1][mycol-1+adj].type == mytype &&
1790 !bb->playboard[myrow+1][mycol-1+adj].ingroup) {
1791 bb->playboard[myrow+1][mycol-1+adj].ingroup = true;
1792 search[count].row = myrow+1;
1793 search[count].col = mycol-1+adj;
1794 count++;
1799 if(mycol+adj >= 0) {
1800 if(myrow-1 >= 0) {
1801 if(bb->playboard[myrow-1][mycol+adj].type == mytype &&
1802 !bb->playboard[myrow-1][mycol+adj].ingroup) {
1803 bb->playboard[myrow-1][mycol+adj].ingroup = true;
1804 search[count].row = myrow-1;
1805 search[count].col = mycol+adj;
1806 count++;
1810 if(myrow+1 < BB_HEIGHT) {
1811 if(bb->playboard[myrow+1][mycol+adj].type == mytype &&
1812 !bb->playboard[myrow+1][mycol+adj].ingroup) {
1813 bb->playboard[myrow+1][mycol+adj].ingroup = true;
1814 search[count].row = myrow+1;
1815 search[count].col = mycol+adj;
1816 count++;
1821 if(mycol+1 < BB_WIDTH-adj) {
1822 if(bb->playboard[myrow][mycol+1].type == mytype &&
1823 !bb->playboard[myrow][mycol+1].ingroup) {
1824 bb->playboard[myrow][mycol+1].ingroup = true;
1825 search[count].row = myrow;
1826 search[count].col = mycol+1;
1827 count++;
1832 return count;
1835 /*****************************************************************************
1836 * bubbles_remove() removes all bubbles in the current group and all
1837 * unanchored bubbles from the play board.
1838 ******************************************************************************/
1839 static int bubbles_remove(struct game_context* bb) {
1840 int i, j;
1841 int buttonres;
1843 /* determine all anchored bubbles */
1844 for(j=0; j<BB_WIDTH; j++) {
1845 if(bb->playboard[0][j].type >= 0 && !bb->playboard[0][j].ingroup) {
1846 bubbles_anchored(bb, 0, j);
1850 /* mark bubbles to be deleted */
1851 for(i=0; i<BB_HEIGHT; i++) {
1852 for(j=0; j<BB_WIDTH; j++) {
1853 if(bb->playboard[i][j].type >= 0 &&
1854 (!bb->playboard[i][j].anchored || bb->playboard[i][j].ingroup)) {
1855 bb->playboard[i][j].delete = true;
1860 /* animate falling bubbles */
1861 buttonres = bubbles_fall(bb);
1862 if(buttonres != BB_NONE) return buttonres;
1864 /* remove bubbles */
1865 for(i=0; i<BB_HEIGHT; i++) {
1866 for(j=0; j<BB_WIDTH; j++) {
1867 if(bb->playboard[i][j].delete) {
1868 bb->playboard[i][j].ingroup = false;
1869 bb->playboard[i][j].type = -1;
1870 bb->playboard[i][j].delete = false;
1871 } else {
1872 bb->playboard[i][j].anchored = false;
1877 bubbles_getonboard(bb);
1879 return BB_NONE;
1882 /*****************************************************************************
1883 * bubbles_anchored() marks all bubbles that are anchored in some way to the
1884 * current bubble.
1885 ******************************************************************************/
1886 static void bubbles_anchored(struct game_context* bb, int row, int col) {
1887 int i, adj;
1888 int myrow, mycol, mytype;
1889 int count = 0;
1891 struct coord {
1892 int row;
1893 int col;
1894 } search[(2*BB_WIDTH-1)*(BB_HEIGHT/2)];
1896 /* search initial bubble */
1897 bb->playboard[row][col].anchored = true;
1898 search[count].row = row;
1899 search[count].col = col;
1900 count++;
1902 /* breadth-first search neighbors */
1903 for(i=0; i<count; i++) {
1904 myrow = search[i].row;
1905 mycol = search[i].col;
1906 mytype = bb->playboard[myrow][mycol].type;
1907 adj = myrow%2;
1909 if(mycol-1 >= 0) {
1910 if(bb->playboard[myrow][mycol-1].type >= 0 &&
1911 !bb->playboard[myrow][mycol-1].ingroup &&
1912 !bb->playboard[myrow][mycol-1].anchored) {
1913 bb->playboard[myrow][mycol-1].anchored = true;
1914 search[count].row = myrow;
1915 search[count].col = mycol-1;
1916 count++;
1920 if(mycol-1+adj >= 0) {
1921 if(myrow-1 >= 0) {
1922 if(bb->playboard[myrow-1][mycol-1+adj].type >= 0 &&
1923 !bb->playboard[myrow-1][mycol-1+adj].ingroup &&
1924 !bb->playboard[myrow-1][mycol-1+adj].anchored) {
1925 bb->playboard[myrow-1][mycol-1+adj].anchored = true;
1926 search[count].row = myrow-1;
1927 search[count].col = mycol-1+adj;
1928 count++;
1932 if(myrow+1 < BB_HEIGHT) {
1933 if(bb->playboard[myrow+1][mycol-1+adj].type >= 0 &&
1934 !bb->playboard[myrow+1][mycol-1+adj].ingroup &&
1935 !bb->playboard[myrow+1][mycol-1+adj].anchored) {
1936 bb->playboard[myrow+1][mycol-1+adj].anchored = true;
1937 search[count].row = myrow+1;
1938 search[count].col = mycol-1+adj;
1939 count++;
1944 if(mycol+adj >= 0) {
1945 if(myrow-1 >= 0) {
1946 if(bb->playboard[myrow-1][mycol+adj].type >= 0 &&
1947 !bb->playboard[myrow-1][mycol+adj].ingroup &&
1948 !bb->playboard[myrow-1][mycol+adj].anchored) {
1949 bb->playboard[myrow-1][mycol+adj].anchored = true;
1950 search[count].row = myrow-1;
1951 search[count].col = mycol+adj;
1952 count++;
1956 if(myrow+1 < BB_HEIGHT) {
1957 if(bb->playboard[myrow+1][mycol+adj].type >= 0 &&
1958 !bb->playboard[myrow+1][mycol+adj].ingroup &&
1959 !bb->playboard[myrow+1][mycol+adj].anchored) {
1960 bb->playboard[myrow+1][mycol+adj].anchored = true;
1961 search[count].row = myrow+1;
1962 search[count].col = mycol+adj;
1963 count++;
1968 if(mycol+1 < BB_WIDTH-adj) {
1969 if(bb->playboard[myrow][mycol+1].type >= 0 &&
1970 !bb->playboard[myrow][mycol+1].ingroup &&
1971 !bb->playboard[myrow][mycol+1].anchored) {
1972 bb->playboard[myrow][mycol+1].anchored = true;
1973 search[count].row = myrow;
1974 search[count].col = mycol+1;
1975 count++;
1981 /*****************************************************************************
1982 * bubbles_fall() makes removed bubbles fall from the screen.
1983 ******************************************************************************/
1984 static int bubbles_fall(struct game_context* bb) {
1985 int i, j;
1986 int count;
1987 int indent;
1988 int xofs, yofs;
1989 int buttonres;
1990 bool onscreen;
1991 long lasttick, currenttick;
1993 /* give all falling bubbles an x axis movement */
1994 for(i=0; i<BB_HEIGHT; i++) {
1995 for(j=0; j<BB_WIDTH; j++) {
1996 if(bb->playboard[i][j].delete) {
1997 bb->playboard[i][j].fallx = rb->rand()%25 - 12;
1998 bb->playboard[i][j].fallvel = rb->rand()%5 + 6;
2003 /* draw bubbles falling off the screen
2004 * follows y=x^2-8x scaled to bubble size
2006 lasttick = *rb->current_tick;
2008 for(count=1; ;count++) {
2009 onscreen = false;
2010 bubbles_drawboard(bb);
2012 for(i=0; i<BB_HEIGHT; i++) {
2013 for(j=0; j<BB_WIDTH; j++) {
2014 if(bb->playboard[i][j].delete) {
2015 indent = (i%2 ? ROW_INDENT : 0);
2016 xofs = ((bb->playboard[i][j].fallx*count)*BUBBLE_WIDTH)/48;
2017 yofs = ((count*count - bb->playboard[i][j].fallvel*count)*
2018 BUBBLE_HEIGHT)/20;
2020 /* draw bubble if it is still on the screen */
2021 if(ROW_HEIGHT*i+bb->compress*ROW_HEIGHT+yofs
2022 <= LCD_HEIGHT) {
2023 onscreen = true;
2025 rb->lcd_bitmap_part(bubbles_emblem, 0,
2026 EMBLEM_HEIGHT*bb->playboard[i][j].type, EMBLEM_WIDTH,
2027 XOFS+indent+BUBBLE_WIDTH*j+
2028 (BUBBLE_WIDTH-EMBLEM_WIDTH)/2+xofs,
2029 ROW_HEIGHT*i+(BUBBLE_HEIGHT-EMBLEM_HEIGHT)/2+
2030 bb->compress*ROW_HEIGHT+yofs,
2031 EMBLEM_WIDTH, EMBLEM_HEIGHT);
2032 rb->lcd_set_drawmode(DRMODE_FG);
2033 rb->lcd_mono_bitmap(
2034 (const unsigned char *)bubbles_bubble,
2035 XOFS+indent+BUBBLE_WIDTH*j+xofs,
2036 ROW_HEIGHT*i+bb->compress*ROW_HEIGHT+yofs,
2037 BUBBLE_WIDTH, BUBBLE_HEIGHT);
2038 rb->lcd_set_drawmode(DRMODE_SOLID);
2044 rb->lcd_update();
2046 /* break out if all bubbles are off the screen */
2047 if(!onscreen) break;
2049 /* handle button events */
2050 buttonres = bubbles_handlebuttons(bb, true, 0);
2051 if(buttonres != BB_NONE) return buttonres;
2053 /* framerate limiting */
2054 currenttick = *rb->current_tick;
2055 if(currenttick-lasttick < HZ/MAX_FPS) {
2056 rb->sleep((HZ/MAX_FPS)-(currenttick-lasttick));
2057 } else {
2058 rb->yield();
2060 lasttick = currenttick;
2063 return BB_NONE;
2066 /*****************************************************************************
2067 * bubbles_checklevel() checks the state of the playboard for a win or loss.
2068 ******************************************************************************/
2069 static int bubbles_checklevel(struct game_context* bb) {
2070 int i, j;
2071 int points;
2072 char str[13];
2074 bubbles_drawboard(bb);
2075 rb->lcd_update();
2077 /* check for bubbles below cut off point */
2078 for(i=0; i<=bb->compress; i++) {
2079 for(j=0; j<BB_WIDTH; j++) {
2080 if(bb->playboard[BB_HEIGHT-1-i][j].type >= 0) return BB_LOSE;
2084 /* check for bubbles above cut off point */
2085 for(i=0; i<BB_HEIGHT-1-bb->compress; i++) {
2086 for(j=0; j<BB_WIDTH; j++) {
2087 if(bb->playboard[i][j].type >= 0) return BB_NONE;
2091 /* level complete, record score */
2092 points = 100 - bb->elapsedlvl/100;
2093 if(points > 0) {
2094 bb->score += points;
2095 } else {
2096 points = 0;
2099 rb->snprintf(str, 12, "%d points", points);
2100 rb->splash(HZ, str);
2102 /* advance to the next level */
2103 if(!bubbles_nextlevel(bb)) {
2104 return BB_WIN;
2107 bubbles_drawboard(bb);
2108 rb->lcd_update();
2109 rb->snprintf(str, 12, "Level %d", bb->level);
2110 rb->splash(HZ, str);
2111 bubbles_drawboard(bb);
2112 rb->lcd_update();
2114 return BB_NONE;
2117 /*****************************************************************************
2118 * bubbles_recordscore() inserts a high score into the high scores list and
2119 * returns the high score position.
2120 ******************************************************************************/
2121 static void bubbles_recordscore(struct game_context* bb) {
2123 int position;
2125 position = highscore_update(bb->score, bb->level, "",
2126 highscores, NUM_SCORES);
2127 if (position==0)
2128 rb->splash(HZ*2, "New High Score");
2129 if (position != -1)
2130 highscore_show(position, highscores, NUM_SCORES);
2133 /*****************************************************************************
2134 * bubbles_loadscores() loads the high scores saved file.
2135 ******************************************************************************/
2136 static void bubbles_loadscores(struct game_context* bb) {
2138 int i;
2139 int highlevel = 0;
2140 /* highlevel and highscores */
2141 highscore_load(SCORE_FILE, highscores, NUM_SCORES);
2143 for (i = 0; i < NUM_SCORES; i++)
2145 if (highscores[i].level >= highlevel)
2147 highlevel = highscores[i].level+1;
2151 if (bb->highlevel < (unsigned)highlevel)
2152 bb->highlevel = highlevel;
2155 /*****************************************************************************
2156 * bubbles_savescores() saves the high scores saved file.
2157 ******************************************************************************/
2158 static void bubbles_savescores(struct game_context* bb) {
2160 /* highscores */
2161 (void)bb;
2162 highscore_save(SCORE_FILE, highscores, NUM_SCORES+1);
2165 /*****************************************************************************
2166 * bubbles_loadgame() loads the saved game and returns load success.
2167 ******************************************************************************/
2168 static bool bubbles_loadgame(struct game_context* bb) {
2169 int fd;
2171 bool ret = true;
2172 /* open game file */
2173 fd = rb->open(SAVE_FILE, O_RDONLY);
2174 if(fd < 0) return false;
2176 /* read in saved game */
2177 if(rb->read(fd, bb, sizeof(struct game_context))
2178 < (long)sizeof(struct game_context))
2180 ret = false;
2183 rb->close(fd);
2184 return ret;
2187 /*****************************************************************************
2188 * bubbles_savegame() saves the current game state.
2189 ******************************************************************************/
2190 static void bubbles_savegame(struct game_context* bb) {
2191 int fd;
2193 if (!resume) /* nothing to save */
2194 return;
2195 /* write out the game state to the save file */
2196 fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
2197 if (fd < 0)
2199 rb->splash(HZ/2, "Failed to save game");
2200 return;
2202 if (rb->write(fd, bb, sizeof(struct game_context)) <= 0)
2204 rb->splash(HZ/2, "Failed to save game");
2207 rb->close(fd);
2211 /*****************************************************************************
2212 * bubbles_setcolors() set the foreground and background colors.
2213 ******************************************************************************/
2214 static inline void bubbles_setcolors(void) {
2215 #ifdef HAVE_LCD_COLOR
2216 rb->lcd_set_background(LCD_RGBPACK(181,181,222));
2217 rb->lcd_set_foreground(LCD_BLACK);
2218 #endif
2221 /*****************************************************************************
2222 * bubbles_callback() is the default event handler callback which is called
2223 * on usb connect and shutdown.
2224 ******************************************************************************/
2225 static void bubbles_callback(void* param) {
2226 struct game_context* bb = (struct game_context*) param;
2227 bubbles_savescores(bb);
2230 /*****************************************************************************
2231 * bubbles_handlebuttons() handles button events during a game.
2232 ******************************************************************************/
2233 static int bubbles_handlebuttons(struct game_context* bb, bool animblock,
2234 int timeout) {
2235 int button;
2236 int buttonres;
2237 long start;
2238 const struct button_mapping *plugin_contexts[]
2239 #if (CONFIG_KEYPAD != SANSA_E200_PAD) && \
2240 (CONFIG_KEYPAD != SANSA_FUZE_PAD)
2241 = {generic_left_right_fire,generic_actions};
2242 #else
2243 = {generic_directions,generic_actions};
2244 #endif
2246 if (timeout < 0)
2247 timeout = 0;
2248 button = pluginlib_getaction(timeout,plugin_contexts,2);
2249 #if defined(HAS_BUTTON_HOLD) && !defined(HAVE_REMOTE_LCD_AS_MAIN)
2250 /* FIXME: Should probably check remote hold here */
2251 if (rb->button_hold())
2252 button = BUBBLES_START;
2253 #endif
2255 switch(button){
2256 case BUBBLES_LEFT_REP:
2257 if(bb->angle > MIN_ANGLE) bb->angle -= ANGLE_STEP_REP;
2258 case BUBBLES_LEFT: /* change angle to the left */
2259 if(bb->angle > MIN_ANGLE) bb->angle -= ANGLE_STEP;
2260 break;
2262 case BUBBLES_RIGHT_REP:
2263 if(bb->angle < MAX_ANGLE) bb->angle += ANGLE_STEP_REP;
2264 case BUBBLES_RIGHT: /* change angle to the right */
2265 if(bb->angle < MAX_ANGLE) bb->angle += ANGLE_STEP;
2266 break;
2268 case BUBBLES_SELECT: /* fire the shot */
2269 if(!animblock) {
2270 bb->elapsedlvl += bb->elapsedshot;
2271 bb->elapsedshot = 0;
2272 buttonres = bubbles_fire(bb);
2273 if(buttonres != BB_NONE) return buttonres;
2274 buttonres = bubbles_checklevel(bb);
2275 if(buttonres != BB_NONE) return buttonres;
2276 bb->startedshot = *rb->current_tick;
2278 break;
2280 case BUBBLES_START: /* pause the game */
2281 start = *rb->current_tick;
2282 rb->splash(0, "Paused");
2283 while(pluginlib_getaction(TIMEOUT_BLOCK,plugin_contexts,2)
2284 != (BUBBLES_START));
2285 bb->startedshot += *rb->current_tick-start;
2286 bubbles_drawboard(bb);
2287 rb->lcd_update();
2288 break;
2290 case BUBBLES_RESUME: /* save and end the game */
2291 case BUBBLES_QUIT: /* end the game */
2292 if(!animblock) {
2293 resume = true;
2294 return BB_END;
2296 break;
2298 case ACTION_UNKNOWN:
2299 case ACTION_NONE: /* no button pressed */
2300 break;
2302 default:
2303 if(rb->default_event_handler_ex(button, bubbles_callback,
2304 (void*) bb) == SYS_USB_CONNECTED)
2305 return BB_USB;
2306 break;
2309 return BB_NONE;
2312 /*****************************************************************************
2313 * bubbles() is the main game subroutine, it returns the final game status.
2314 ******************************************************************************/
2315 static int bubbles(struct game_context* bb) {
2316 int buttonres;
2317 unsigned int startlevel = 0;
2318 bool startgame = false;
2319 long timeout;
2321 /********************
2322 * menu *
2323 ********************/
2324 MENUITEM_STRINGLIST(menu,"Bubbles Menu",NULL,
2325 "Resume Game", "Start New Game",
2326 "Level", "High Scores", "Playback Control",
2327 "Quit", "Quit and Save");
2328 while(!startgame){
2329 switch (rb->do_menu(&menu, NULL, NULL, false))
2331 case 0: /* resume game */
2332 if (!resume)
2334 rb->splash(HZ/2, "Nothing to resume");
2335 break;
2337 else
2339 startlevel = bb->level - 1;
2340 startgame = true;
2342 /* delete saved file */
2343 rb->remove(SAVE_FILE);
2344 break;
2345 case 1: /* new game */
2346 bb->level = startlevel;
2347 startgame = true;
2348 resume = false;
2349 break;
2350 case 2: /* choose level */
2351 startlevel++;
2352 rb->set_int("Choose start level", "", UNIT_INT, &startlevel,
2353 NULL, 1, 1, bb->highlevel+1, NULL);
2354 startlevel--;
2355 break;
2356 case 3: /* High scores */
2357 highscore_show(NUM_SCORES, highscores, NUM_SCORES);
2358 break;
2359 case 4: /* Playback Control */
2360 playback_control(NULL);
2361 break;
2362 case 5: /* quit */
2363 return BB_QUIT;
2364 case 6: /* quit and save */
2365 return BB_QUIT_AND_SAVE;
2366 case MENU_ATTACHED_USB:
2367 bubbles_callback(bb);
2368 return BB_USB;
2371 /********************
2372 * init *
2373 ********************/
2374 bubbles_init(bb);
2375 bubbles_drawboard(bb);
2376 rb->lcd_update();
2378 /**********************
2379 * play *
2380 **********************/
2381 bb->startedshot = *rb->current_tick;
2383 while(true) {
2384 /* refresh the board */
2385 bubbles_drawboard(bb);
2386 rb->lcd_update();
2388 /* manange idle framerate */
2389 bb->elapsedshot = *rb->current_tick-bb->startedshot;
2391 if(MAX_SHOTTIME-bb->elapsedshot < HZ/2) {
2392 timeout = MAX_SHOTTIME-bb->elapsedshot;
2393 } else {
2394 timeout = HZ/2;
2397 /* handle button events */
2398 buttonres = bubbles_handlebuttons(bb, false, timeout);
2399 if(buttonres != BB_NONE) return buttonres;
2401 /* handle timing */
2402 bb->elapsedshot = *rb->current_tick-bb->startedshot;
2404 if(bb->elapsedshot > MAX_SHOTTIME) {
2405 bb->elapsedlvl += bb->elapsedshot;
2406 bb->elapsedshot = 0;
2407 buttonres = bubbles_fire(bb);
2408 if(buttonres != BB_NONE) return buttonres;
2409 buttonres = bubbles_checklevel(bb);
2410 if(buttonres != BB_NONE) return buttonres;
2411 bb->startedshot = *rb->current_tick;
2416 /*****************************************************************************
2417 * plugin entry point.
2418 ******************************************************************************/
2419 enum plugin_status plugin_start(const void* parameter) {
2420 static struct game_context bb;
2421 bool exit = false;
2422 enum plugin_status ret = PLUGIN_OK;
2424 /* plugin init */
2425 (void)parameter;
2426 /* end of plugin init */
2428 /* load files */
2429 resume = bubbles_loadgame(&bb);
2430 bubbles_loadscores(&bb);
2431 rb->lcd_clear_display();
2433 /* start app */
2434 #if LCD_DEPTH > 1
2435 rb->lcd_set_backdrop(NULL);
2436 #endif
2437 rb->lcd_setfont(FONT_SYSFIXED);
2439 while(!exit) {
2440 switch(bubbles(&bb)){
2441 case BB_WIN:
2442 rb->splash(HZ*2, "You Win!");
2443 /* record high level */
2444 if( NUM_LEVELS-1 > bb.highlevel) {
2445 bb.highlevel = NUM_LEVELS-1;
2447 /* record high score */
2448 bubbles_recordscore(&bb);
2449 break;
2451 case BB_LOSE:
2452 resume = false;
2453 rb->splash(HZ*2, "Game Over");
2454 /* record high score */
2455 bubbles_recordscore(&bb);
2456 /* fall through to BB_END */
2458 case BB_END:
2459 break;
2461 case BB_USB:
2462 ret = PLUGIN_USB_CONNECTED;
2463 break;
2465 case BB_QUIT_AND_SAVE:
2466 rb->splash(HZ/2, "Saving Game and Scors");
2467 bubbles_savescores(&bb);
2468 bubbles_savegame(&bb);
2469 /* fall through */
2471 case BB_QUIT:
2472 exit = true;
2473 break;
2475 default:
2476 break;
2480 rb->lcd_setfont(FONT_UI);
2481 return ret;
2484 #endif