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_UP
117 #define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_DOWN
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
183 #define EMPTY_BLOCK 7
185 #define BOARD_WIDTH 10
187 #ifdef HAVE_LCD_BITMAP
189 #define BOARD_HEIGHT 20
191 #if (LCD_WIDTH == 480) && (LCD_HEIGHT == 640)
193 #define BLOCK_WIDTH 30
194 #define BLOCK_HEIGHT 30
197 #define PREVIEW_X 342
198 #define PREVIEW_Y 482
203 #define HIGH_LABEL_X 344
204 #define HIGH_SCORE_Y 326
205 #define HIGH_LEVEL_Y 344
207 #elif (LCD_WIDTH == 320) && (LCD_HEIGHT == 240)
209 #define BLOCK_WIDTH 12
210 #define BLOCK_HEIGHT 12
220 #elif (LCD_WIDTH == 240) && (LCD_HEIGHT == 320)
222 #define BLOCK_WIDTH 15
223 #define BLOCK_HEIGHT 15
226 #define PREVIEW_X 171
227 #define PREVIEW_Y 241
232 #define HIGH_LABEL_X 172
233 #define HIGH_SCORE_Y 163
234 #define HIGH_LEVEL_Y 172
236 #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176)
238 #define BLOCK_WIDTH 8
239 #define BLOCK_HEIGHT 8
242 #define PREVIEW_X 158
243 #define PREVIEW_Y 130
249 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132)
251 #define BLOCK_WIDTH 6
252 #define BLOCK_HEIGHT 6
255 #define PREVIEW_X 126
256 #define PREVIEW_Y 102
262 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 220)
264 #define BLOCK_WIDTH 10
265 #define BLOCK_HEIGHT 10
268 #define PREVIEW_X 124
269 #define PREVIEW_Y 167
274 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
276 #define BLOCK_WIDTH 6
277 #define BLOCK_HEIGHT 6
280 #define PREVIEW_X 114
281 #define PREVIEW_Y 100
287 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128)
289 #define BLOCK_WIDTH 6
290 #define BLOCK_HEIGHT 6
294 #define PREVIEW_Y 100
300 #elif (LCD_WIDTH == 132) && (LCD_HEIGHT == 80)
302 #define BLOCK_WIDTH 4
303 #define BLOCK_HEIGHT 4
313 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 64)
315 #define BLOCK_WIDTH 3
316 #define BLOCK_HEIGHT 3
326 #elif (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
328 #define BLOCK_WIDTH 4
329 #define BLOCK_HEIGHT 3
340 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
342 #define BLOCK_WIDTH 5
343 #define BLOCK_HEIGHT 5
356 #define LEVEL_X LABEL_X
360 #define LINES_X LABEL_X
363 #define MYLCD(fn) rb->lcd_ ## fn
365 extern const fb_data rockblox_background
[];
367 #else /* HAVE_LCD_CHARCELLS */
369 #define BOARD_HEIGHT 14
371 #define BLOCK_WIDTH 1
372 #define BLOCK_HEIGHT 1
378 #define MYLCD(fn) pgfx_ ## fn
382 /* <<Explanation on Rockblox shapes>>
385 %% - O has 1 orientation
388 %% %% - Z has 2 orientations
392 %% %% - S has 2 orientations
396 % %%%% - I has 2 orientations
400 % % % %%% - L has 4 orientations
404 % % % %%% - J has 4 orientations
408 %% % %% % - T has 4 orientations
413 /* must have variable */
414 static struct plugin_api
*rb
;
416 static bool gameover
= false;
417 /* c=current f=figure o=orientation n=next */
418 static int lines
= 0, level
= 0, score
= 0, cx
, cy
, cf
, co
, nf
;
419 static short board
[BOARD_HEIGHT
][BOARD_WIDTH
]; /* 20 rows of 10 blocks */
422 int wheel_events
= 0, last_wheel_event
= 0;
423 bool wheel_enabled
= false;
426 static const short scoring
[4] = { /* scoring for each number of lines */
427 #if BOARD_HEIGHT == 20
428 40 /* single */ , 100 /* double */ , 300 /* triple */ , 1200 /* rockblox */
429 #elif BOARD_HEIGHT == 14 /* Player special values */
430 60 /* single */ , 150 /* double */ , 500 /* triple */ , 2000 /* rockblox */
437 unsigned short color
[3]; /* color of figure (light,middle,shadow) */
439 unsigned short max_or
; /* max orientations */
440 signed short shapeX
[4], shapeY
[4]; /* implementation of figures */
443 /* array of figures */
444 figures
[BLOCKS_NUM
] = {
448 {LCD_RGBPACK (153, 255, 255), LCD_RGBPACK(0, 255, 255),
449 LCD_RGBPACK(0,153,153)},
451 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
460 {LCD_RGBPACK (255, 153, 128), LCD_RGBPACK (255, 0, 0),
461 LCD_RGBPACK (153, 0, 0)},
463 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
472 {LCD_RGBPACK (153, 255, 153), LCD_RGBPACK (0, 255, 0),
473 LCD_RGBPACK (0, 153, 0)},
475 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
484 {LCD_RGBPACK (153, 153, 255), LCD_RGBPACK (0, 0, 255),
485 LCD_RGBPACK (0, 0, 153)},
487 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
496 {LCD_RGBPACK (255, 255, 153), LCD_RGBPACK (255, 255, 0),
497 LCD_RGBPACK (153, 153, 0)},
499 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
508 {LCD_RGBPACK (255, 153, 255), LCD_RGBPACK (255, 0, 255),
509 LCD_RGBPACK (153, 0, 153)},
511 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
520 {LCD_RGBPACK (204, 204, 204), LCD_RGBPACK (153, 153, 153),
521 LCD_RGBPACK (85, 85, 85)},
523 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
531 /* Rockbox File System only supports full filenames inc dir */
532 #define HIGH_SCORE PLUGIN_GAMES_DIR "/rockblox.score"
533 #define MAX_HIGH_SCORES 5
534 /* Default High Scores... */
535 struct highscore Highest
[MAX_HIGH_SCORES
];
537 /* get random number from (0) to (range-1) */
538 static int t_rand (int range
)
540 return rb
->rand () % range
;
543 /* init the board array to have no blocks */
544 static void init_board (void)
547 for (i
= 0; i
< BOARD_WIDTH
; i
++)
548 for (j
= 0; j
< BOARD_HEIGHT
; j
++)
549 board
[j
][i
] = EMPTY_BLOCK
;
552 /* show the score, level and lines */
553 static void show_details (void)
555 char str
[25]; /* for strings */
557 #ifdef HAVE_LCD_BITMAP
559 rb
->lcd_set_foreground (LCD_BLACK
);
560 rb
->lcd_set_background (LCD_WHITE
);
562 rb
->snprintf (str
, sizeof (str
), "%d", score
);
563 rb
->lcd_putsxy (LABEL_X
, SCORE_Y
, str
);
564 rb
->snprintf (str
, sizeof (str
), "%d", level
);
565 rb
->lcd_putsxy (LEVEL_X
, LEVEL_Y
, str
);
566 rb
->snprintf (str
, sizeof (str
), "%d", lines
);
567 rb
->lcd_putsxy (LINES_X
, LINES_Y
, str
);
568 #else /* HAVE_LCD_CHARCELLS */
569 rb
->snprintf (str
, sizeof (str
), "L%d/%d", level
, lines
);
570 rb
->lcd_puts (5, 0, str
);
571 rb
->snprintf (str
, sizeof (str
), "S%d", score
);
572 rb
->lcd_puts (5, 1, str
);
576 static void init_rockblox (void)
580 char str
[25]; /* for strings */
582 highscore_update(score
, level
, Highest
, MAX_HIGH_SCORES
);
588 nf
= t_rand (BLOCKS_NUM
);
590 #ifdef HAVE_LCD_BITMAP
591 rb
->lcd_bitmap (rockblox_background
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
592 #else /* HAVE_LCD_CHARCELLS */
594 pgfx_display_block (3, 0, 3, 1);
595 pgfx_display_block (4, 0, 3, 0);
596 pgfx_clear_display();
597 pgfx_fillrect (3, 0, 2, 14);
598 pgfx_fillrect (15, 7, 2, 7);
603 for (i
= MAX_HIGH_SCORES
-1; i
>=0; i
--)
605 rb
->snprintf (str
, sizeof (str
), "%06d L%1d", Highest
[i
].score
, Highest
[i
].level
);
606 rb
->lcd_putsxy (HIGH_LABEL_X
, HIGH_SCORE_Y
+ (10 * ((MAX_HIGH_SCORES
-1) - i
)), str
);
611 static inline int level_speed(int level
)
613 #if BOARD_HEIGHT == 20
614 return (5*HZ
) / (level
+ 9);
615 #elif BOARD_HEIGHT == 14
616 return (7*HZ
) / (level
+ 9);
620 static int getRelativeX (int figure
, int square
, int orientation
)
622 switch (orientation
) {
624 return figures
[figure
].shapeX
[square
];
626 return figures
[figure
].shapeY
[square
];
628 return -figures
[figure
].shapeX
[square
];
630 return -figures
[figure
].shapeY
[square
];
636 static int getRelativeY (int figure
, int square
, int orientation
)
638 switch (orientation
) {
640 return figures
[figure
].shapeY
[square
];
642 return -figures
[figure
].shapeX
[square
];
644 return -figures
[figure
].shapeY
[square
];
646 return figures
[figure
].shapeX
[square
];
652 /* redraw the while board on the screen */
653 static void refresh_board (void)
655 int i
, j
, x
, y
, block
;
658 rb
->lcd_set_foreground (LCD_BLACK
);
660 MYLCD(set_drawmode
) (DRMODE_SOLID
| DRMODE_INVERSEVID
);
663 MYLCD(fillrect
) (BOARD_X
, BOARD_Y
, BOARD_WIDTH
* BLOCK_WIDTH
,
664 BOARD_HEIGHT
* BLOCK_HEIGHT
);
667 MYLCD(set_drawmode
) (DRMODE_SOLID
);
670 for (i
= 0; i
< BOARD_WIDTH
; i
++)
671 for (j
= 0; j
< BOARD_HEIGHT
; j
++) {
673 if (block
!= EMPTY_BLOCK
) {
674 #ifdef HAVE_LCD_BITMAP
677 rb
->lcd_set_foreground (figures
[block
].color
[1]);
679 rb
->lcd_fillrect (BOARD_X
+ i
* BLOCK_WIDTH
,
680 BOARD_Y
+ j
* BLOCK_HEIGHT
,
681 BLOCK_WIDTH
, BLOCK_HEIGHT
);
684 rb
->lcd_set_foreground (figures
[block
].color
[0]);
686 rb
->lcd_vline (BOARD_X
+ i
* BLOCK_WIDTH
,
687 BOARD_Y
+ j
* BLOCK_HEIGHT
,
688 BOARD_Y
+ (j
+ 1) * BLOCK_HEIGHT
- 2);
689 rb
->lcd_hline (BOARD_X
+ i
* BLOCK_WIDTH
,
690 BOARD_X
+ (i
+ 1) * BLOCK_WIDTH
- 2,
691 BOARD_Y
+ j
* BLOCK_HEIGHT
);
694 rb
->lcd_set_foreground (figures
[block
].color
[2]);
696 rb
->lcd_vline (BOARD_X
+ (i
+ 1) * BLOCK_WIDTH
- 1,
697 BOARD_Y
+ j
* BLOCK_HEIGHT
+ 1,
698 BOARD_Y
+ (j
+ 1) * BLOCK_HEIGHT
- 1);
699 rb
->lcd_hline (BOARD_X
+ i
* BLOCK_WIDTH
+ 1,
700 BOARD_X
+ (i
+ 1) * BLOCK_WIDTH
- 1,
701 BOARD_Y
+ (j
+ 1) * BLOCK_HEIGHT
- 1);
702 #else /* HAVE_LCD_CHARCELLS */
703 pgfx_drawpixel (BOARD_X
+ i
, BOARD_Y
+ j
);
708 for (i
= 0; i
< 4; i
++) {
709 x
= getRelativeX (cf
, i
, co
) + cx
;
710 y
= getRelativeY (cf
, i
, co
) + cy
;
711 #ifdef HAVE_LCD_BITMAP
713 rb
->lcd_set_foreground (figures
[cf
].color
[1]); /* middle drawing */
715 rb
->lcd_fillrect (BOARD_X
+ x
* BLOCK_WIDTH
,
716 BOARD_Y
+ y
* BLOCK_HEIGHT
,
717 BLOCK_WIDTH
, BLOCK_HEIGHT
);
719 rb
->lcd_set_foreground (figures
[cf
].color
[0]); /* light drawing */
721 rb
->lcd_vline (BOARD_X
+ x
* BLOCK_WIDTH
, BOARD_Y
+ y
* BLOCK_HEIGHT
,
722 BOARD_Y
+ (y
+ 1) * BLOCK_HEIGHT
- 2);
723 rb
->lcd_hline (BOARD_X
+ x
* BLOCK_WIDTH
,
724 BOARD_X
+ (x
+ 1) * BLOCK_WIDTH
- 2,
725 BOARD_Y
+ y
* BLOCK_HEIGHT
);
727 rb
->lcd_set_foreground (figures
[cf
].color
[2]); /* shadow drawing */
729 rb
->lcd_vline (BOARD_X
+ (x
+ 1) * BLOCK_WIDTH
- 1,
730 BOARD_Y
+ y
* BLOCK_HEIGHT
+ 1,
731 BOARD_Y
+ (y
+ 1) * BLOCK_HEIGHT
- 1);
732 rb
->lcd_hline (BOARD_X
+ x
* BLOCK_WIDTH
+ 1,
733 BOARD_X
+ (x
+ 1) * BLOCK_WIDTH
- 1,
734 BOARD_Y
+ (y
+ 1) * BLOCK_HEIGHT
- 1);
735 #else /* HAVE_LCD_CHARCELLS */
736 pgfx_drawpixel (BOARD_X
+ x
, BOARD_Y
+ y
);
742 static bool canMoveTo (int x
, int y
, int newOrientation
)
745 for (i
= 0; i
< 4; i
++) {
746 ry
= getRelativeY (cf
, i
, newOrientation
) + y
;
747 rx
= getRelativeX (cf
, i
, newOrientation
) + x
;
748 if ((rx
< 0 || rx
>= BOARD_WIDTH
) ||
749 (ry
< 0 || ry
>= BOARD_HEIGHT
) || (board
[ry
][rx
] != EMPTY_BLOCK
))
755 /* draws the preview of next block in the preview window */
756 static void draw_next_block (void)
759 /* clear preview window first */
761 rb
->lcd_set_foreground (LCD_BLACK
);
763 MYLCD(set_drawmode
) (DRMODE_SOLID
| DRMODE_INVERSEVID
);
767 MYLCD(fillrect
) (PREVIEW_X
, PREVIEW_Y
, BLOCK_WIDTH
* 4, BLOCK_HEIGHT
* 4);
770 MYLCD(set_drawmode
) (DRMODE_SOLID
);
773 /* draw the lightgray rectangles */
775 rb
->lcd_set_foreground (LCD_RGBPACK (40, 40, 40));
777 rb
->lcd_set_foreground (LCD_DARKGRAY
);
781 for (rx
= 0; rx
< 4; rx
++)
782 for (ry
= 0; ry
< 4; ry
++)
783 rb
->lcd_drawrect (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
784 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
, BLOCK_WIDTH
,
788 /* draw the figure */
789 for (i
= 0; i
< 4; i
++) {
790 rx
= getRelativeX (nf
, i
, 0) + 2;
791 ry
= getRelativeY (nf
, i
, 0) + 2;
792 #ifdef HAVE_LCD_BITMAP
794 rb
->lcd_set_foreground (figures
[nf
].color
[1]); /* middle drawing */
796 rb
->lcd_fillrect (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
797 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
,
798 BLOCK_WIDTH
, BLOCK_HEIGHT
);
800 rb
->lcd_set_foreground (figures
[nf
].color
[0]); /* light drawing */
802 rb
->lcd_vline (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
803 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
,
804 PREVIEW_Y
+ (ry
+ 1) * BLOCK_HEIGHT
- 2);
805 rb
->lcd_hline (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
806 PREVIEW_X
+ (rx
+ 1) * BLOCK_WIDTH
- 2,
807 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
);
809 rb
->lcd_set_foreground (figures
[nf
].color
[2]); /* shadow drawing */
811 rb
->lcd_vline (PREVIEW_X
+ (rx
+ 1) * BLOCK_WIDTH
- 1,
812 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
+ 1,
813 PREVIEW_Y
+ (ry
+ 1) * BLOCK_HEIGHT
- 1);
814 rb
->lcd_hline (PREVIEW_X
+ rx
* BLOCK_WIDTH
+ 1,
815 PREVIEW_X
+ (rx
+ 1) * BLOCK_WIDTH
- 1,
816 PREVIEW_Y
+ (ry
+ 1) * BLOCK_HEIGHT
- 1);
817 #else /* HAVE_LCD_CHARCELLS */
818 pgfx_drawpixel (PREVIEW_X
+ rx
, PREVIEW_Y
+ ry
);
824 /* move the block to a relative location */
825 static void move_block (int x
, int y
, int o
)
827 if (canMoveTo (cx
+ x
, cy
+ y
, o
)) {
834 /* try to add a new block to play with (return true if gameover) */
835 static void new_block (void)
840 co
= 0; /* start at the same orientation all time */
841 nf
= t_rand (BLOCKS_NUM
);
842 gameover
= !canMoveTo (cx
, cy
, co
);
848 /* check for filled lines and do what necessary */
849 static int check_lines (void)
854 for (j
= 0; j
< BOARD_HEIGHT
; j
++) {
855 for (i
= 0; ((i
< BOARD_WIDTH
) && (board
[j
][i
] != EMPTY_BLOCK
)); i
++);
856 if (i
== BOARD_WIDTH
) { /* woo hoo, we have a line */
858 for (y
= j
; y
> 0; y
--)
859 for (i
= 0; i
< BOARD_WIDTH
; i
++)
860 board
[y
][i
] = board
[y
- 1][i
]; /* fall line */
867 /* moves down the figure and returns true if gameover */
868 static void move_down (void)
872 if (!canMoveTo (cx
, cy
+ 1, co
)) {
873 /* save figure to board */
874 for (i
= 0; i
< 4; i
++) {
875 rx
= getRelativeX (cf
, i
, co
) + cx
;
876 ry
= getRelativeY (cf
, i
, co
) + cy
;
879 /* check if formed some lines */
882 /* the original scoring from "http://en.wikipedia.org/wiki/Rockblox" */
883 score
+= scoring
[l
- 1] * level
;
885 level
= (int) lines
/ 10 + 1;
891 /* generate a new figure */
894 move_block (0, 1, co
);
897 static int rockblox_loop (void)
900 int lastbutton
= BUTTON_NONE
;
901 long next_down_tick
= *rb
->current_tick
+ level_speed(level
);
906 #ifdef HAS_BUTTON_HOLD
907 if (rb
->button_hold ()) {
908 /* Turn on backlight timeout (revert to settings) */
909 backlight_use_settings(rb
); /* backlight control in lib/helper.c */
910 rb
->splash(0, "Paused");
911 while (rb
->button_hold ())
914 /* Turn off backlight timeout */
915 backlight_force_on(rb
); /* backlight control in lib/helper.c */
917 /* get rid of the splash text */
918 rb
->lcd_bitmap (rockblox_background
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
925 button
= rb
->button_get_w_tmo (MAX(next_down_tick
- *rb
->current_tick
, 1));
927 #ifdef ROCKBLOX_RC_OFF
928 case ROCKBLOX_RC_OFF
:
933 #if defined(ROCKBLOX_ROTATE)
934 case ROCKBLOX_ROTATE
:
936 case ROCKBLOX_ROTATE_RIGHT
:
937 case ROCKBLOX_ROTATE_RIGHT
| BUTTON_REPEAT
:
939 /* if the wheel is disabled, add an event to the stack. */
940 if(wheel_enabled
== false)
943 /* if it's enabled, go ahead and rotate.. */
946 move_block (0, 0, (co
+ 1) % figures
[cf
].max_or
);
949 case ROCKBLOX_ROTATE_LEFT
:
950 case ROCKBLOX_ROTATE_LEFT
| BUTTON_REPEAT
:
952 if(wheel_enabled
== false)
958 (co
+ figures
[cf
].max_or
-
959 1) % figures
[cf
].max_or
);
962 #ifdef ROCKBLOX_ROTATE_RIGHT2
963 case ROCKBLOX_ROTATE_RIGHT2
:
964 move_block (0, 0, (co
+ 1) % figures
[cf
].max_or
);
969 case ROCKBLOX_DOWN
| BUTTON_REPEAT
:
970 move_block (0, 1, co
);
974 case ROCKBLOX_RIGHT
| BUTTON_REPEAT
:
975 move_block (1, 0, co
);
979 case ROCKBLOX_LEFT
| BUTTON_REPEAT
:
980 move_block (-1, 0, co
);
984 #ifdef ROCKBLOX_DROP_PRE
985 if (lastbutton
!= ROCKBLOX_DROP_PRE
)
988 while (canMoveTo (cx
, cy
+ 1, co
))
989 move_block (0, 1, co
);
991 #ifdef ROCKBLOX_RESTART
992 case ROCKBLOX_RESTART
:
993 rb
->splash (HZ
* 1, "Restarting...");
1000 if (rb
->default_event_handler (button
) == SYS_USB_CONNECTED
)
1001 return PLUGIN_USB_CONNECTED
;
1004 if (button
!= BUTTON_NONE
)
1005 lastbutton
= button
;
1008 /* check if we should enable the scroll wheel, if events
1009 * begin to stack up... */
1010 if(wheel_enabled
== false)
1012 /* stopped rotating the wheel, reset the count */
1013 if(wheel_events
== last_wheel_event
)
1015 last_wheel_event
= 0;
1018 /* rotated the wheel a while constantly, enable it. */
1019 else if(wheel_events
> 3)
1021 wheel_enabled
= true;
1024 /* this evens out the last event and the "current" event.
1025 * if we get an event next time through button reading, it will
1026 * remain ahead of last_event. if we don't, they'll end up equaling
1027 * each other.. thus, the scroll count will be reset. */
1028 if(wheel_enabled
== false && wheel_events
> last_wheel_event
)
1033 if (TIME_AFTER(*rb
->current_tick
, next_down_tick
)) {
1035 next_down_tick
+= level_speed(level
);
1036 if (TIME_AFTER(*rb
->current_tick
, next_down_tick
))
1037 /* restart time "raster" when we had to wait longer than usual
1038 * (pause, game restart etc) */
1039 next_down_tick
= *rb
->current_tick
+ level_speed(level
);
1044 rb
->lcd_set_foreground (LCD_BLACK
);
1046 rb
->splash (HZ
* 2, "Game Over");
1057 enum plugin_status
plugin_start (struct plugin_api
*api
, void *parameter
)
1064 rb
->srand (*rb
->current_tick
);
1066 /* Load HighScore if any */
1068 highscore_load(HIGH_SCORE
,Highest
,MAX_HIGH_SCORES
);
1071 rb
->lcd_set_backdrop(NULL
);
1074 #ifdef HAVE_LCD_BITMAP
1075 rb
->lcd_setfont (FONT_SYSFIXED
);
1077 if (!pgfx_init(rb
, 4, 2))
1079 rb
->splash(HZ
*2, "Old LCD :(");
1083 /* Turn off backlight timeout */
1084 backlight_force_on(rb
); /* backlight control in lib/helper.c */
1087 ret
= rockblox_loop ();
1089 #ifdef HAVE_LCD_BITMAP
1090 rb
->lcd_setfont (FONT_UI
);
1094 /* Save user's HighScore */
1095 highscore_save(HIGH_SCORE
,Highest
,MAX_HIGH_SCORES
);
1096 /* Restore user's original backlight setting */
1097 rb
->backlight_set_timeout (rb
->global_settings
->backlight_timeout
);