1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 Eli Sherer
12 * Heavily modified for embedded use by Björn Stenberg (bjorn@haxx.se)
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "highscore.h"
23 #include "playergfx.h"
28 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
29 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
30 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
32 #define ROCKBLOX_OFF (BUTTON_MENU | BUTTON_SELECT)
33 #define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_BACK
34 #define ROCKBLOX_ROTATE_RIGHT2 (BUTTON_MENU | BUTTON_REL)
35 #define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_FWD
36 #define ROCKBLOX_LEFT BUTTON_LEFT
37 #define ROCKBLOX_RIGHT BUTTON_RIGHT
38 #define ROCKBLOX_DOWN BUTTON_PLAY
39 #define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_PLAY)
40 #define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
44 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
45 (CONFIG_KEYPAD == IRIVER_H300_PAD)
47 #define ROCKBLOX_OFF BUTTON_OFF
48 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
49 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
50 #define ROCKBLOX_DOWN BUTTON_DOWN
51 #define ROCKBLOX_LEFT BUTTON_LEFT
52 #define ROCKBLOX_RIGHT BUTTON_RIGHT
53 #define ROCKBLOX_DROP BUTTON_MODE
54 #define ROCKBLOX_RESTART BUTTON_ON
56 #define ROCKBLOX_RC_OFF BUTTON_RC_STOP
58 #elif CONFIG_KEYPAD == RECORDER_PAD
60 #define ROCKBLOX_OFF BUTTON_OFF
61 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
62 #define ROCKBLOX_ROTATE_LEFT BUTTON_PLAY
63 #define ROCKBLOX_DOWN BUTTON_DOWN
64 #define ROCKBLOX_LEFT BUTTON_LEFT
65 #define ROCKBLOX_RIGHT BUTTON_RIGHT
66 #define ROCKBLOX_DROP BUTTON_ON
67 #define ROCKBLOX_RESTART BUTTON_F1
69 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
71 #define ROCKBLOX_OFF BUTTON_OFF
72 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
73 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
74 #define ROCKBLOX_DOWN BUTTON_DOWN
75 #define ROCKBLOX_LEFT BUTTON_LEFT
76 #define ROCKBLOX_RIGHT BUTTON_RIGHT
77 #define ROCKBLOX_DROP BUTTON_ON
78 #define ROCKBLOX_RESTART BUTTON_F1
80 #elif CONFIG_KEYPAD == PLAYER_PAD
82 #define ROCKBLOX_OFF BUTTON_STOP
83 #define ROCKBLOX_ROTATE_RIGHT BUTTON_PLAY
84 #define ROCKBLOX_ROTATE_LEFT (BUTTON_ON|BUTTON_PLAY)
85 #define ROCKBLOX_DOWN BUTTON_MENU
86 #define ROCKBLOX_LEFT BUTTON_LEFT
87 #define ROCKBLOX_RIGHT BUTTON_RIGHT
88 #define ROCKBLOX_DROP_PRE BUTTON_ON
89 #define ROCKBLOX_DROP (BUTTON_ON|BUTTON_REL)
91 #elif CONFIG_KEYPAD == ONDIO_PAD
93 #define ROCKBLOX_OFF BUTTON_OFF
94 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
95 #define ROCKBLOX_ROTATE_LEFT (BUTTON_MENU|BUTTON_UP)
96 #define ROCKBLOX_DOWN BUTTON_DOWN
97 #define ROCKBLOX_LEFT BUTTON_LEFT
98 #define ROCKBLOX_RIGHT BUTTON_RIGHT
99 #define ROCKBLOX_DROP_PRE BUTTON_MENU
100 #define ROCKBLOX_DROP (BUTTON_MENU|BUTTON_REL)
102 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
104 #define ROCKBLOX_OFF BUTTON_POWER
105 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
106 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
107 #define ROCKBLOX_DOWN BUTTON_DOWN
108 #define ROCKBLOX_LEFT BUTTON_LEFT
109 #define ROCKBLOX_RIGHT BUTTON_RIGHT
110 #define ROCKBLOX_DROP BUTTON_REC
111 #define ROCKBLOX_RESTART BUTTON_PLAY
113 #elif CONFIG_KEYPAD == SANSA_E200_PAD
115 #define ROCKBLOX_OFF BUTTON_POWER
116 #define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_BACK
117 #define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_FWD
118 #define ROCKBLOX_DOWN BUTTON_DOWN
119 #define ROCKBLOX_LEFT BUTTON_LEFT
120 #define ROCKBLOX_RIGHT BUTTON_RIGHT
121 #define ROCKBLOX_DROP BUTTON_SELECT
122 #define ROCKBLOX_RESTART BUTTON_REC
124 #elif CONFIG_KEYPAD == SANSA_C200_PAD
126 #define ROCKBLOX_OFF BUTTON_POWER
127 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
128 #define ROCKBLOX_ROTATE_RIGHT2 BUTTON_VOL_DOWN
129 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
130 #define ROCKBLOX_DOWN BUTTON_DOWN
131 #define ROCKBLOX_LEFT BUTTON_LEFT
132 #define ROCKBLOX_RIGHT BUTTON_RIGHT
133 #define ROCKBLOX_DROP BUTTON_SELECT
134 #define ROCKBLOX_RESTART BUTTON_REC
136 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
138 #define ROCKBLOX_OFF BUTTON_POWER
139 #define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_UP
140 #define ROCKBLOX_ROTATE_LEFT BUTTON_REW
141 #define ROCKBLOX_DOWN BUTTON_SCROLL_DOWN
142 #define ROCKBLOX_LEFT BUTTON_LEFT
143 #define ROCKBLOX_RIGHT BUTTON_RIGHT
144 #define ROCKBLOX_DROP BUTTON_FF
145 #define ROCKBLOX_RESTART BUTTON_PLAY
147 #elif CONFIG_KEYPAD == GIGABEAT_PAD
149 #define ROCKBLOX_OFF BUTTON_POWER
150 #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
151 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
152 #define ROCKBLOX_ROTATE BUTTON_UP
153 #define ROCKBLOX_DOWN BUTTON_DOWN
154 #define ROCKBLOX_LEFT BUTTON_LEFT
155 #define ROCKBLOX_RIGHT BUTTON_RIGHT
156 #define ROCKBLOX_DROP BUTTON_SELECT
157 #define ROCKBLOX_RESTART BUTTON_A
159 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
161 #define ROCKBLOX_OFF BUTTON_PLAY
162 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
163 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
164 #define ROCKBLOX_DOWN BUTTON_DOWN
165 #define ROCKBLOX_LEFT BUTTON_LEFT
166 #define ROCKBLOX_RIGHT BUTTON_RIGHT
167 #define ROCKBLOX_DROP BUTTON_MODE
168 #define ROCKBLOX_RESTART BUTTON_EQ
170 #elif CONFIG_KEYPAD == MROBE500_PAD
171 #define ROCKBLOX_OFF BUTTON_POWER
172 #define ROCKBLOX_ROTATE_RIGHT BUTTON_RC_VOL_UP
173 #define ROCKBLOX_ROTATE_LEFT BUTTON_RC_VOL_DOWN
174 #define ROCKBLOX_DOWN BUTTON_RC_DOWN
175 #define ROCKBLOX_LEFT BUTTON_LEFT
176 #define ROCKBLOX_RIGHT BUTTON_RIGHT
177 #define ROCKBLOX_DROP BUTTON_RC_HEART
178 #define ROCKBLOX_RESTART BUTTON_RC_MODE
180 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
181 #define ROCKBLOX_OFF BUTTON_BACK
182 #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
183 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
184 #define ROCKBLOX_ROTATE BUTTON_UP
185 #define ROCKBLOX_DOWN BUTTON_DOWN
186 #define ROCKBLOX_LEFT BUTTON_LEFT
187 #define ROCKBLOX_RIGHT BUTTON_RIGHT
188 #define ROCKBLOX_DROP BUTTON_SELECT
189 #define ROCKBLOX_RESTART BUTTON_PLAY
191 #elif CONFIG_KEYPAD == MROBE100_PAD
193 #define ROCKBLOX_OFF BUTTON_POWER
194 #define ROCKBLOX_ROTATE_RIGHT BUTTON_MENU
195 #define ROCKBLOX_ROTATE_LEFT BUTTON_PLAY
196 #define ROCKBLOX_ROTATE BUTTON_UP
197 #define ROCKBLOX_DOWN BUTTON_DOWN
198 #define ROCKBLOX_LEFT BUTTON_LEFT
199 #define ROCKBLOX_RIGHT BUTTON_RIGHT
200 #define ROCKBLOX_DROP BUTTON_SELECT
201 #define ROCKBLOX_RESTART BUTTON_DISPLAY
203 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
205 #define ROCKBLOX_OFF BUTTON_RC_REC
206 #define ROCKBLOX_ROTATE_RIGHT BUTTON_RC_VOL_DOWN
207 #define ROCKBLOX_ROTATE_LEFT BUTTON_RC_VOL_UP
208 #define ROCKBLOX_DOWN BUTTON_RC_MENU
209 #define ROCKBLOX_LEFT BUTTON_RC_REW
210 #define ROCKBLOX_RIGHT BUTTON_RC_FF
211 #define ROCKBLOX_DROP BUTTON_RC_PLAY
212 #define ROCKBLOX_RESTART BUTTON_RC_MODE
214 #elif CONFIG_KEYPAD == COWOND2_PAD
215 #define ROCKBLOX_OFF BUTTON_POWER
216 #define ROCKBLOX_ROTATE_RIGHT BUTTON_PLUS
217 #define ROCKBLOX_ROTATE_LEFT BUTTON_MINUS
218 #define ROCKBLOX_DOWN BUTTON_DOWN
219 #define ROCKBLOX_LEFT BUTTON_LEFT
220 #define ROCKBLOX_RIGHT BUTTON_RIGHT
221 #define ROCKBLOX_DROP BUTTON_SELECT
222 #define ROCKBLOX_RESTART BUTTON_MENU
225 #error No keymap defined!
229 #define EMPTY_BLOCK 7
231 #define BOARD_WIDTH 10
233 #ifdef HAVE_LCD_BITMAP
235 #define BOARD_HEIGHT 20
237 #if (LCD_WIDTH == 640) && (LCD_HEIGHT == 480)
239 #define BLOCK_WIDTH 30
240 #define BLOCK_HEIGHT 30
243 #define PREVIEW_X 342
244 #define PREVIEW_Y 482
249 #define HIGH_LABEL_X 344
250 #define HIGH_SCORE_Y 326
251 #define HIGH_LEVEL_Y 344
253 #elif (LCD_WIDTH == 480) && (LCD_HEIGHT == 640)
255 #define BLOCK_WIDTH 30
256 #define BLOCK_HEIGHT 30
259 #define PREVIEW_X 342
260 #define PREVIEW_Y 482
265 #define HIGH_LABEL_X 344
266 #define HIGH_SCORE_Y 326
267 #define HIGH_LEVEL_Y 344
269 #elif (LCD_WIDTH == 320) && (LCD_HEIGHT == 240)
271 #define BLOCK_WIDTH 12
272 #define BLOCK_HEIGHT 12
282 #elif (LCD_WIDTH == 240) && (LCD_HEIGHT == 320)
284 #define BLOCK_WIDTH 15
285 #define BLOCK_HEIGHT 15
288 #define PREVIEW_X 171
289 #define PREVIEW_Y 241
294 #define HIGH_LABEL_X 172
295 #define HIGH_SCORE_Y 163
296 #define HIGH_LEVEL_Y 172
298 #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176)
300 #define BLOCK_WIDTH 8
301 #define BLOCK_HEIGHT 8
304 #define PREVIEW_X 158
305 #define PREVIEW_Y 130
311 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132)
313 #define BLOCK_WIDTH 6
314 #define BLOCK_HEIGHT 6
317 #define PREVIEW_X 126
318 #define PREVIEW_Y 102
324 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 220)
326 #define BLOCK_WIDTH 10
327 #define BLOCK_HEIGHT 10
330 #define PREVIEW_X 124
331 #define PREVIEW_Y 167
336 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
338 #define BLOCK_WIDTH 6
339 #define BLOCK_HEIGHT 6
342 #define PREVIEW_X 114
343 #define PREVIEW_Y 100
349 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
351 #define BLOCK_WIDTH 5
352 #define BLOCK_HEIGHT 5
362 #elif (LCD_WIDTH == 132) && (LCD_HEIGHT == 80)
364 #define BLOCK_WIDTH 4
365 #define BLOCK_HEIGHT 4
375 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128)
377 #define BLOCK_WIDTH 6
378 #define BLOCK_HEIGHT 6
382 #define PREVIEW_Y 100
388 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 96)
390 #define BLOCK_WIDTH 4
391 #define BLOCK_HEIGHT 4
401 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 64)
403 #define BLOCK_WIDTH 3
404 #define BLOCK_HEIGHT 3
414 #elif (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
416 #define BLOCK_WIDTH 4
417 #define BLOCK_HEIGHT 3
431 #define LEVEL_X LABEL_X
435 #define LINES_X LABEL_X
438 #define MYLCD(fn) rb->lcd_ ## fn
440 extern const fb_data rockblox_background
[];
442 #else /* HAVE_LCD_CHARCELLS */
444 #define BOARD_HEIGHT 14
446 #define BLOCK_WIDTH 1
447 #define BLOCK_HEIGHT 1
453 #define MYLCD(fn) pgfx_ ## fn
457 /* <<Explanation on Rockblox shapes>>
460 %% - O has 1 orientation
463 %% %% - Z has 2 orientations
467 %% %% - S has 2 orientations
471 % %%%% - I has 2 orientations
475 % % % %%% - L has 4 orientations
479 % % % %%% - J has 4 orientations
483 %% % %% % - T has 4 orientations
488 /* must have variable */
489 static struct plugin_api
*rb
;
491 static bool gameover
= false;
492 /* c=current f=figure o=orientation n=next */
493 static int lines
= 0, level
= 0, score
= 0, cx
, cy
, cf
, co
, nf
;
494 static short board
[BOARD_HEIGHT
][BOARD_WIDTH
]; /* 20 rows of 10 blocks */
497 int wheel_events
= 0, last_wheel_event
= 0;
498 bool wheel_enabled
= false;
501 static const short scoring
[4] = { /* scoring for each number of lines */
502 #if BOARD_HEIGHT == 20
503 40 /* single */ , 100 /* double */ , 300 /* triple */ , 1200 /* rockblox */
504 #elif BOARD_HEIGHT == 14 /* Player special values */
505 60 /* single */ , 150 /* double */ , 500 /* triple */ , 2000 /* rockblox */
512 unsigned short color
[3]; /* color of figure (light,middle,shadow) */
514 unsigned short max_or
; /* max orientations */
515 signed short shapeX
[4], shapeY
[4]; /* implementation of figures */
518 /* array of figures */
519 figures
[BLOCKS_NUM
] = {
523 {LCD_RGBPACK (153, 255, 255), LCD_RGBPACK(0, 255, 255),
524 LCD_RGBPACK(0,153,153)},
526 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
535 {LCD_RGBPACK (255, 153, 128), LCD_RGBPACK (255, 0, 0),
536 LCD_RGBPACK (153, 0, 0)},
538 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
547 {LCD_RGBPACK (153, 255, 153), LCD_RGBPACK (0, 255, 0),
548 LCD_RGBPACK (0, 153, 0)},
550 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
559 {LCD_RGBPACK (153, 153, 255), LCD_RGBPACK (0, 0, 255),
560 LCD_RGBPACK (0, 0, 153)},
562 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
571 {LCD_RGBPACK (255, 255, 153), LCD_RGBPACK (255, 255, 0),
572 LCD_RGBPACK (153, 153, 0)},
574 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
583 {LCD_RGBPACK (255, 153, 255), LCD_RGBPACK (255, 0, 255),
584 LCD_RGBPACK (153, 0, 153)},
586 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
595 {LCD_RGBPACK (204, 204, 204), LCD_RGBPACK (153, 153, 153),
596 LCD_RGBPACK (85, 85, 85)},
598 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
606 /* Rockbox File System only supports full filenames inc dir */
607 #define HIGH_SCORE PLUGIN_GAMES_DIR "/rockblox.score"
608 #define MAX_HIGH_SCORES 5
609 /* Default High Scores... */
610 struct highscore Highest
[MAX_HIGH_SCORES
];
612 /* get random number from (0) to (range-1) */
613 static int t_rand (int range
)
615 return rb
->rand () % range
;
618 /* init the board array to have no blocks */
619 static void init_board (void)
622 for (i
= 0; i
< BOARD_WIDTH
; i
++)
623 for (j
= 0; j
< BOARD_HEIGHT
; j
++)
624 board
[j
][i
] = EMPTY_BLOCK
;
627 /* show the score, level and lines */
628 static void show_details (void)
630 char str
[25]; /* for strings */
632 #ifdef HAVE_LCD_BITMAP
634 rb
->lcd_set_foreground (LCD_BLACK
);
635 rb
->lcd_set_background (LCD_WHITE
);
637 rb
->snprintf (str
, sizeof (str
), "%d", score
);
638 rb
->lcd_putsxy (LABEL_X
, SCORE_Y
, str
);
639 rb
->snprintf (str
, sizeof (str
), "%d", level
);
640 rb
->lcd_putsxy (LEVEL_X
, LEVEL_Y
, str
);
641 rb
->snprintf (str
, sizeof (str
), "%d", lines
);
642 rb
->lcd_putsxy (LINES_X
, LINES_Y
, str
);
643 #else /* HAVE_LCD_CHARCELLS */
644 rb
->snprintf (str
, sizeof (str
), "L%d/%d", level
, lines
);
645 rb
->lcd_puts (5, 0, str
);
646 rb
->snprintf (str
, sizeof (str
), "S%d", score
);
647 rb
->lcd_puts (5, 1, str
);
652 static void show_highscores (void)
655 char str
[25]; /* for strings */
657 for (i
= MAX_HIGH_SCORES
-1; i
>=0; i
--)
659 rb
->snprintf (str
, sizeof (str
), "%06d L%1d", Highest
[i
].score
, Highest
[i
].level
);
660 rb
->lcd_putsxy (HIGH_LABEL_X
, HIGH_SCORE_Y
+ (10 * ((MAX_HIGH_SCORES
-1) - i
)), str
);
665 static void init_rockblox (void)
667 highscore_update(score
, level
, Highest
, MAX_HIGH_SCORES
);
673 nf
= t_rand (BLOCKS_NUM
);
675 #ifdef HAVE_LCD_BITMAP
676 rb
->lcd_bitmap (rockblox_background
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
677 #else /* HAVE_LCD_CHARCELLS */
679 pgfx_display_block (3, 0, 3, 1);
680 pgfx_display_block (4, 0, 3, 0);
681 pgfx_clear_display();
682 pgfx_fillrect (3, 0, 2, 14);
683 pgfx_fillrect (15, 7, 2, 7);
692 static inline int level_speed(int level
)
694 #if BOARD_HEIGHT == 20
695 return (5*HZ
) / (level
+ 9);
696 #elif BOARD_HEIGHT == 14
697 return (7*HZ
) / (level
+ 9);
701 static int getRelativeX (int figure
, int square
, int orientation
)
703 switch (orientation
) {
705 return figures
[figure
].shapeX
[square
];
707 return figures
[figure
].shapeY
[square
];
709 return -figures
[figure
].shapeX
[square
];
711 return -figures
[figure
].shapeY
[square
];
717 static int getRelativeY (int figure
, int square
, int orientation
)
719 switch (orientation
) {
721 return figures
[figure
].shapeY
[square
];
723 return -figures
[figure
].shapeX
[square
];
725 return -figures
[figure
].shapeY
[square
];
727 return figures
[figure
].shapeX
[square
];
733 /* redraw the while board on the screen */
734 static void refresh_board (void)
736 int i
, j
, x
, y
, block
;
739 rb
->lcd_set_foreground (LCD_BLACK
);
741 MYLCD(set_drawmode
) (DRMODE_SOLID
| DRMODE_INVERSEVID
);
744 MYLCD(fillrect
) (BOARD_X
, BOARD_Y
, BOARD_WIDTH
* BLOCK_WIDTH
,
745 BOARD_HEIGHT
* BLOCK_HEIGHT
);
748 MYLCD(set_drawmode
) (DRMODE_SOLID
);
751 for (i
= 0; i
< BOARD_WIDTH
; i
++)
752 for (j
= 0; j
< BOARD_HEIGHT
; j
++) {
754 if (block
!= EMPTY_BLOCK
) {
755 #ifdef HAVE_LCD_BITMAP
758 rb
->lcd_set_foreground (figures
[block
].color
[1]);
760 rb
->lcd_fillrect (BOARD_X
+ i
* BLOCK_WIDTH
,
761 BOARD_Y
+ j
* BLOCK_HEIGHT
,
762 BLOCK_WIDTH
, BLOCK_HEIGHT
);
765 rb
->lcd_set_foreground (figures
[block
].color
[0]);
767 rb
->lcd_vline (BOARD_X
+ i
* BLOCK_WIDTH
,
768 BOARD_Y
+ j
* BLOCK_HEIGHT
,
769 BOARD_Y
+ (j
+ 1) * BLOCK_HEIGHT
- 2);
770 rb
->lcd_hline (BOARD_X
+ i
* BLOCK_WIDTH
,
771 BOARD_X
+ (i
+ 1) * BLOCK_WIDTH
- 2,
772 BOARD_Y
+ j
* BLOCK_HEIGHT
);
775 rb
->lcd_set_foreground (figures
[block
].color
[2]);
777 rb
->lcd_vline (BOARD_X
+ (i
+ 1) * BLOCK_WIDTH
- 1,
778 BOARD_Y
+ j
* BLOCK_HEIGHT
+ 1,
779 BOARD_Y
+ (j
+ 1) * BLOCK_HEIGHT
- 1);
780 rb
->lcd_hline (BOARD_X
+ i
* BLOCK_WIDTH
+ 1,
781 BOARD_X
+ (i
+ 1) * BLOCK_WIDTH
- 1,
782 BOARD_Y
+ (j
+ 1) * BLOCK_HEIGHT
- 1);
783 #else /* HAVE_LCD_CHARCELLS */
784 pgfx_drawpixel (BOARD_X
+ i
, BOARD_Y
+ j
);
789 for (i
= 0; i
< 4; i
++) {
790 x
= getRelativeX (cf
, i
, co
) + cx
;
791 y
= getRelativeY (cf
, i
, co
) + cy
;
792 #ifdef HAVE_LCD_BITMAP
794 rb
->lcd_set_foreground (figures
[cf
].color
[1]); /* middle drawing */
796 rb
->lcd_fillrect (BOARD_X
+ x
* BLOCK_WIDTH
,
797 BOARD_Y
+ y
* BLOCK_HEIGHT
,
798 BLOCK_WIDTH
, BLOCK_HEIGHT
);
800 rb
->lcd_set_foreground (figures
[cf
].color
[0]); /* light drawing */
802 rb
->lcd_vline (BOARD_X
+ x
* BLOCK_WIDTH
, BOARD_Y
+ y
* BLOCK_HEIGHT
,
803 BOARD_Y
+ (y
+ 1) * BLOCK_HEIGHT
- 2);
804 rb
->lcd_hline (BOARD_X
+ x
* BLOCK_WIDTH
,
805 BOARD_X
+ (x
+ 1) * BLOCK_WIDTH
- 2,
806 BOARD_Y
+ y
* BLOCK_HEIGHT
);
808 rb
->lcd_set_foreground (figures
[cf
].color
[2]); /* shadow drawing */
810 rb
->lcd_vline (BOARD_X
+ (x
+ 1) * BLOCK_WIDTH
- 1,
811 BOARD_Y
+ y
* BLOCK_HEIGHT
+ 1,
812 BOARD_Y
+ (y
+ 1) * BLOCK_HEIGHT
- 1);
813 rb
->lcd_hline (BOARD_X
+ x
* BLOCK_WIDTH
+ 1,
814 BOARD_X
+ (x
+ 1) * BLOCK_WIDTH
- 1,
815 BOARD_Y
+ (y
+ 1) * BLOCK_HEIGHT
- 1);
816 #else /* HAVE_LCD_CHARCELLS */
817 pgfx_drawpixel (BOARD_X
+ x
, BOARD_Y
+ y
);
823 static bool canMoveTo (int x
, int y
, int newOrientation
)
826 for (i
= 0; i
< 4; i
++) {
827 ry
= getRelativeY (cf
, i
, newOrientation
) + y
;
828 rx
= getRelativeX (cf
, i
, newOrientation
) + x
;
829 if ((rx
< 0 || rx
>= BOARD_WIDTH
) ||
830 (ry
< 0 || ry
>= BOARD_HEIGHT
) || (board
[ry
][rx
] != EMPTY_BLOCK
))
836 /* draws the preview of next block in the preview window */
837 static void draw_next_block (void)
840 /* clear preview window first */
842 rb
->lcd_set_foreground (LCD_BLACK
);
844 MYLCD(set_drawmode
) (DRMODE_SOLID
| DRMODE_INVERSEVID
);
848 MYLCD(fillrect
) (PREVIEW_X
, PREVIEW_Y
, BLOCK_WIDTH
* 4, BLOCK_HEIGHT
* 4);
851 MYLCD(set_drawmode
) (DRMODE_SOLID
);
854 /* draw the lightgray rectangles */
856 rb
->lcd_set_foreground (LCD_RGBPACK (40, 40, 40));
858 rb
->lcd_set_foreground (LCD_DARKGRAY
);
862 for (rx
= 0; rx
< 4; rx
++)
863 for (ry
= 0; ry
< 4; ry
++)
864 rb
->lcd_drawrect (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
865 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
, BLOCK_WIDTH
,
869 /* draw the figure */
870 for (i
= 0; i
< 4; i
++) {
871 rx
= getRelativeX (nf
, i
, 0) + 2;
872 ry
= getRelativeY (nf
, i
, 0) + 2;
873 #ifdef HAVE_LCD_BITMAP
875 rb
->lcd_set_foreground (figures
[nf
].color
[1]); /* middle drawing */
877 rb
->lcd_fillrect (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
878 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
,
879 BLOCK_WIDTH
, BLOCK_HEIGHT
);
881 rb
->lcd_set_foreground (figures
[nf
].color
[0]); /* light drawing */
883 rb
->lcd_vline (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
884 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
,
885 PREVIEW_Y
+ (ry
+ 1) * BLOCK_HEIGHT
- 2);
886 rb
->lcd_hline (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
887 PREVIEW_X
+ (rx
+ 1) * BLOCK_WIDTH
- 2,
888 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
);
890 rb
->lcd_set_foreground (figures
[nf
].color
[2]); /* shadow drawing */
892 rb
->lcd_vline (PREVIEW_X
+ (rx
+ 1) * BLOCK_WIDTH
- 1,
893 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
+ 1,
894 PREVIEW_Y
+ (ry
+ 1) * BLOCK_HEIGHT
- 1);
895 rb
->lcd_hline (PREVIEW_X
+ rx
* BLOCK_WIDTH
+ 1,
896 PREVIEW_X
+ (rx
+ 1) * BLOCK_WIDTH
- 1,
897 PREVIEW_Y
+ (ry
+ 1) * BLOCK_HEIGHT
- 1);
898 #else /* HAVE_LCD_CHARCELLS */
899 pgfx_drawpixel (PREVIEW_X
+ rx
, PREVIEW_Y
+ ry
);
905 /* move the block to a relative location */
906 static void move_block (int x
, int y
, int o
)
908 if (canMoveTo (cx
+ x
, cy
+ y
, o
)) {
915 /* try to add a new block to play with (return true if gameover) */
916 static void new_block (void)
921 co
= 0; /* start at the same orientation all time */
922 nf
= t_rand (BLOCKS_NUM
);
923 gameover
= !canMoveTo (cx
, cy
, co
);
929 /* check for filled lines and do what necessary */
930 static int check_lines (void)
935 for (j
= 0; j
< BOARD_HEIGHT
; j
++) {
936 for (i
= 0; ((i
< BOARD_WIDTH
) && (board
[j
][i
] != EMPTY_BLOCK
)); i
++);
937 if (i
== BOARD_WIDTH
) { /* woo hoo, we have a line */
939 for (y
= j
; y
> 0; y
--)
940 for (i
= 0; i
< BOARD_WIDTH
; i
++)
941 board
[y
][i
] = board
[y
- 1][i
]; /* fall line */
948 /* moves down the figure and returns true if gameover */
949 static void move_down (void)
953 if (!canMoveTo (cx
, cy
+ 1, co
)) {
954 /* save figure to board */
955 for (i
= 0; i
< 4; i
++) {
956 rx
= getRelativeX (cf
, i
, co
) + cx
;
957 ry
= getRelativeY (cf
, i
, co
) + cy
;
960 /* check if formed some lines */
963 /* the original scoring from "http://en.wikipedia.org/wiki/Rockblox" */
964 score
+= scoring
[l
- 1] * level
;
966 level
= (int) lines
/ 10 + 1;
972 /* generate a new figure */
975 move_block (0, 1, co
);
978 static int rockblox_loop (void)
981 int lastbutton
= BUTTON_NONE
;
982 long next_down_tick
= *rb
->current_tick
+ level_speed(level
);
987 #ifdef HAS_BUTTON_HOLD
988 if (rb
->button_hold ()) {
989 /* Turn on backlight timeout (revert to settings) */
990 backlight_use_settings(rb
); /* backlight control in lib/helper.c */
991 rb
->splash(0, "Paused");
992 while (rb
->button_hold ())
995 /* Turn off backlight timeout */
996 backlight_force_on(rb
); /* backlight control in lib/helper.c */
998 /* get rid of the splash text */
999 rb
->lcd_bitmap (rockblox_background
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
1009 button
= rb
->button_get_w_tmo (MAX(next_down_tick
- *rb
->current_tick
, 1));
1011 #ifdef ROCKBLOX_RC_OFF
1012 case ROCKBLOX_RC_OFF
:
1017 #if defined(ROCKBLOX_ROTATE)
1018 case ROCKBLOX_ROTATE
:
1020 case ROCKBLOX_ROTATE_RIGHT
:
1021 case ROCKBLOX_ROTATE_RIGHT
| BUTTON_REPEAT
:
1023 /* if the wheel is disabled, add an event to the stack. */
1024 if(wheel_enabled
== false)
1027 /* if it's enabled, go ahead and rotate.. */
1030 move_block (0, 0, (co
+ 1) % figures
[cf
].max_or
);
1033 case ROCKBLOX_ROTATE_LEFT
:
1034 case ROCKBLOX_ROTATE_LEFT
| BUTTON_REPEAT
:
1036 if(wheel_enabled
== false)
1042 (co
+ figures
[cf
].max_or
-
1043 1) % figures
[cf
].max_or
);
1046 #ifdef ROCKBLOX_ROTATE_RIGHT2
1047 case ROCKBLOX_ROTATE_RIGHT2
:
1048 move_block (0, 0, (co
+ 1) % figures
[cf
].max_or
);
1053 case ROCKBLOX_DOWN
| BUTTON_REPEAT
:
1054 move_block (0, 1, co
);
1057 case ROCKBLOX_RIGHT
:
1058 case ROCKBLOX_RIGHT
| BUTTON_REPEAT
:
1059 move_block (1, 0, co
);
1063 case ROCKBLOX_LEFT
| BUTTON_REPEAT
:
1064 move_block (-1, 0, co
);
1068 #ifdef ROCKBLOX_DROP_PRE
1069 if (lastbutton
!= ROCKBLOX_DROP_PRE
)
1072 while (canMoveTo (cx
, cy
+ 1, co
))
1073 move_block (0, 1, co
);
1075 #ifdef ROCKBLOX_RESTART
1076 case ROCKBLOX_RESTART
:
1077 rb
->splash (HZ
* 1, "Restarting...");
1084 if (rb
->default_event_handler (button
) == SYS_USB_CONNECTED
)
1085 return PLUGIN_USB_CONNECTED
;
1088 if (button
!= BUTTON_NONE
)
1089 lastbutton
= button
;
1092 /* check if we should enable the scroll wheel, if events
1093 * begin to stack up... */
1094 if(wheel_enabled
== false)
1096 /* stopped rotating the wheel, reset the count */
1097 if(wheel_events
== last_wheel_event
)
1099 last_wheel_event
= 0;
1102 /* rotated the wheel a while constantly, enable it. */
1103 else if(wheel_events
> 3)
1105 wheel_enabled
= true;
1108 /* this evens out the last event and the "current" event.
1109 * if we get an event next time through button reading, it will
1110 * remain ahead of last_event. if we don't, they'll end up equaling
1111 * each other.. thus, the scroll count will be reset. */
1112 if(wheel_enabled
== false && wheel_events
> last_wheel_event
)
1117 if (TIME_AFTER(*rb
->current_tick
, next_down_tick
)) {
1119 next_down_tick
+= level_speed(level
);
1120 if (TIME_AFTER(*rb
->current_tick
, next_down_tick
))
1121 /* restart time "raster" when we had to wait longer than usual
1122 * (pause, game restart etc) */
1123 next_down_tick
= *rb
->current_tick
+ level_speed(level
);
1128 rb
->lcd_set_foreground (LCD_BLACK
);
1130 rb
->splash (HZ
* 2, "Game Over");
1141 enum plugin_status
plugin_start (struct plugin_api
*api
, void *parameter
)
1148 rb
->srand (*rb
->current_tick
);
1150 /* Load HighScore if any */
1152 highscore_load(HIGH_SCORE
,Highest
,MAX_HIGH_SCORES
);
1155 rb
->lcd_set_backdrop(NULL
);
1158 #ifdef HAVE_LCD_BITMAP
1159 rb
->lcd_setfont (FONT_SYSFIXED
);
1161 if (!pgfx_init(rb
, 4, 2))
1163 rb
->splash(HZ
*2, "Old LCD :(");
1167 /* Turn off backlight timeout */
1168 backlight_force_on(rb
); /* backlight control in lib/helper.c */
1171 ret
= rockblox_loop ();
1173 #ifdef HAVE_LCD_BITMAP
1174 rb
->lcd_setfont (FONT_UI
);
1178 /* Save user's HighScore */
1179 highscore_save(HIGH_SCORE
,Highest
,MAX_HIGH_SCORES
);
1180 backlight_use_settings(rb
); /* backlight control in lib/helper.c */