1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008-2009 Rene Peinthor
11 * Contribution from Johannes Schwarz (new menu system, use of highscore lib)
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
21 #include "lib/highscore.h"
22 #include "lib/playback_control.h"
23 #include "lib/display_text.h"
27 #if (CONFIG_KEYPAD == SANSA_E200_PAD)
28 #define CLIX_BUTTON_QUIT BUTTON_POWER
29 #define CLIX_BUTTON_UP BUTTON_UP
30 #define CLIX_BUTTON_DOWN BUTTON_DOWN
31 #define CLIX_BUTTON_SCROLL_FWD BUTTON_SCROLL_FWD
32 #define CLIX_BUTTON_SCROLL_BACK BUTTON_SCROLL_BACK
33 #define CLIX_BUTTON_LEFT BUTTON_LEFT
34 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
35 #define CLIX_BUTTON_CLICK BUTTON_SELECT
37 #elif (CONFIG_KEYPAD == SANSA_CLIP_PAD)
38 #define CLIX_BUTTON_QUIT BUTTON_POWER
39 #define CLIX_BUTTON_UP BUTTON_UP
40 #define CLIX_BUTTON_DOWN BUTTON_DOWN
41 #define CLIX_BUTTON_LEFT BUTTON_LEFT
42 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
43 #define CLIX_BUTTON_CLICK BUTTON_SELECT
45 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
46 #define CLIX_BUTTON_QUIT BUTTON_HOME
47 #define CLIX_BUTTON_UP BUTTON_UP
48 #define CLIX_BUTTON_DOWN BUTTON_DOWN
49 #define CLIX_BUTTON_SCROLL_FWD BUTTON_SCROLL_FWD
50 #define CLIX_BUTTON_SCROLL_BACK BUTTON_SCROLL_BACK
51 #define CLIX_BUTTON_LEFT BUTTON_LEFT
52 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
53 #define CLIX_BUTTON_CLICK BUTTON_SELECT
55 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
56 #define CLIX_BUTTON_QUIT BUTTON_POWER
57 #define CLIX_BUTTON_UP BUTTON_UP
58 #define CLIX_BUTTON_DOWN BUTTON_DOWN
59 #define CLIX_BUTTON_SCROLL_FWD BUTTON_VOL_UP
60 #define CLIX_BUTTON_SCROLL_BACK BUTTON_VOL_DOWN
61 #define CLIX_BUTTON_LEFT BUTTON_LEFT
62 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
63 #define CLIX_BUTTON_CLICK BUTTON_SELECT
65 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
66 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
67 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
68 #define CLIX_BUTTON_QUIT (BUTTON_SELECT | BUTTON_MENU)
69 #define CLIX_BUTTON_UP BUTTON_MENU
70 #define CLIX_BUTTON_DOWN BUTTON_PLAY
71 #define CLIX_BUTTON_SCROLL_FWD BUTTON_SCROLL_FWD
72 #define CLIX_BUTTON_SCROLL_BACK BUTTON_SCROLL_BACK
73 #define CLIX_BUTTON_CLICK BUTTON_SELECT
74 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
75 #define CLIX_BUTTON_LEFT BUTTON_LEFT
77 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
78 #define CLIX_BUTTON_QUIT BUTTON_POWER
79 #define CLIX_BUTTON_LEFT BUTTON_LEFT
80 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
81 #define CLIX_BUTTON_CLICK BUTTON_SELECT
82 #define CLIX_BUTTON_UP BUTTON_UP
83 #define CLIX_BUTTON_DOWN BUTTON_DOWN
85 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
86 #define CLIX_BUTTON_QUIT BUTTON_BACK
87 #define CLIX_BUTTON_LEFT BUTTON_LEFT
88 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
89 #define CLIX_BUTTON_CLICK BUTTON_SELECT
90 #define CLIX_BUTTON_UP BUTTON_UP
91 #define CLIX_BUTTON_DOWN BUTTON_DOWN
93 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
94 #define CLIX_BUTTON_QUIT BUTTON_POWER
95 #define CLIX_BUTTON_LEFT BUTTON_LEFT
96 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
97 #define CLIX_BUTTON_CLICK BUTTON_PLAY
98 #define CLIX_BUTTON_UP BUTTON_SCROLL_UP
99 #define CLIX_BUTTON_DOWN BUTTON_SCROLL_DOWN
101 #elif CONFIG_KEYPAD == IAUDIO67_PAD
102 #define CLIX_BUTTON_QUIT BUTTON_POWER
103 #define CLIX_BUTTON_LEFT BUTTON_LEFT
104 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
105 #define CLIX_BUTTON_CLICK BUTTON_PLAY
106 #define CLIX_BUTTON_UP BUTTON_STOP
107 #define CLIX_BUTTON_DOWN BUTTON_PLAY
109 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
110 #define CLIX_BUTTON_QUIT BUTTON_POWER
111 #define CLIX_BUTTON_LEFT BUTTON_LEFT
112 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
113 #define CLIX_BUTTON_CLICK BUTTON_SELECT
114 #define CLIX_BUTTON_UP BUTTON_UP
115 #define CLIX_BUTTON_DOWN BUTTON_DOWN
117 #elif (CONFIG_KEYPAD == IRIVER_H300_PAD)
118 #define CLIX_BUTTON_QUIT BUTTON_OFF
119 #define CLIX_BUTTON_LEFT BUTTON_LEFT
120 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
121 #define CLIX_BUTTON_CLICK BUTTON_SELECT
122 #define CLIX_BUTTON_UP BUTTON_UP
123 #define CLIX_BUTTON_DOWN BUTTON_DOWN
125 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
126 #define CLIX_BUTTON_QUIT BUTTON_BACK
127 #define CLIX_BUTTON_LEFT BUTTON_LEFT
128 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
129 #define CLIX_BUTTON_CLICK BUTTON_SELECT
130 #define CLIX_BUTTON_UP BUTTON_UP
131 #define CLIX_BUTTON_DOWN BUTTON_DOWN
133 #elif (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
134 #define CLIX_BUTTON_QUIT BUTTON_POWER
135 #define CLIX_BUTTON_LEFT BUTTON_LEFT
136 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
137 #define CLIX_BUTTON_CLICK BUTTON_SELECT
138 #define CLIX_BUTTON_UP BUTTON_UP
139 #define CLIX_BUTTON_DOWN BUTTON_DOWN
141 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD)
142 #define CLIX_BUTTON_QUIT BUTTON_POWER
143 #define CLIX_BUTTON_LEFT BUTTON_PREV
144 #define CLIX_BUTTON_RIGHT BUTTON_NEXT
145 #define CLIX_BUTTON_CLICK BUTTON_PLAY
146 #define CLIX_BUTTON_UP BUTTON_UP
147 #define CLIX_BUTTON_DOWN BUTTON_DOWN
149 #elif CONFIG_KEYPAD == COWON_D2_PAD
150 #define CLIX_BUTTON_QUIT BUTTON_POWER
152 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
153 #define CLIX_BUTTON_QUIT BUTTON_POWER
154 #define CLIX_BUTTON_CLICK BUTTON_MENU
155 #elif (CONFIG_KEYPAD == ONDAVX777_PAD)
156 #define CLIX_BUTTON_QUIT BUTTON_POWER
158 #elif (CONFIG_KEYPAD == MROBE500_PAD)
159 #define CLIX_BUTTON_QUIT BUTTON_POWER
161 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
162 #define CLIX_BUTTON_QUIT BUTTON_REC
163 #define CLIX_BUTTON_LEFT BUTTON_LEFT
164 #define CLIX_BUTTON_RIGHT BUTTON_RIGHT
165 #define CLIX_BUTTON_CLICK BUTTON_PLAY
166 #define CLIX_BUTTON_UP BUTTON_UP
167 #define CLIX_BUTTON_DOWN BUTTON_DOWN
173 #ifndef CLIX_BUTTON_CLICK
174 #define CLIX_BUTTON_CLICK BUTTON_CENTER
177 #define HIGHSCORE_FILE PLUGIN_GAMES_DIR "/clix.score"
179 struct highscore highest
[NUM_SCORES
];
182 #define BLINK_TICKCOUNT 25
185 #if (LCD_WIDTH >= LCD_HEIGHT)
186 #define BOARD_WIDTH 18
187 #define BOARD_HEIGHT 12
189 #define BOARD_WIDTH 12
190 #define BOARD_HEIGHT 18
194 #if (LCD_WIDTH/BOARD_WIDTH) > (LCD_HEIGHT/BOARD_HEIGHT)
195 #define CELL_SIZE (LCD_HEIGHT/BOARD_HEIGHT)
197 #define CELL_SIZE (LCD_WIDTH/BOARD_WIDTH)
200 #elif (LCD_WIDTH >= 306 && LCD_HEIGHT>= 204)
203 #elif (LCD_WIDTH >= 270 && LCD_HEIGHT>= 180)
206 #elif (LCD_WIDTH >= 234 && LCD_HEIGHT>= 156)
209 #elif (LCD_WIDTH >= 198 && LCD_HEIGHT>= 132)
212 #elif (LCD_WIDTH >= 162 && LCD_HEIGHT>= 108)
215 #elif (LCD_WIDTH >= 126 && LCD_HEIGHT>= 84)
218 #elif (LCD_WIDTH >= 60)
222 #define XYPOS(x,y) ((y) * BOARD_WIDTH + x)
223 #define XOFS LCD_WIDTH/2-(BOARD_WIDTH * (CELL_SIZE + 1)/2)
224 #define YOFS (LCD_HEIGHT+10)/2-(BOARD_HEIGHT * (CELL_SIZE + 1)/2)
227 struct clix_game_state_t
{
228 int level
; /* current level */
229 int score
; /* current game score */
230 int x
,y
; /* current positions of the cursor */
231 int board
[BOARD_WIDTH
* BOARD_HEIGHT
]; /* play board*/
232 /* state of selected fields,maybe we can store this in the play board too */
233 bool board_selected
[ BOARD_WIDTH
* BOARD_HEIGHT
];
236 bool blink
; /* true if selected CELLS are currently white */
239 /* game state enum */
246 /* cell color enum */
261 /* recursive function to check if a neighbour cell is of the same color
262 if so call the function with the neighbours position
264 static void clix_set_selected(struct clix_game_state_t
* state
,
265 const int x
, const int y
)
267 state
->selected_count
++;
268 state
->board_selected
[ XYPOS( x
, y
)] = true;
269 int current_color
= state
->board
[ XYPOS( x
, y
)];
272 state
->board
[ XYPOS( x
- 1, y
)] == current_color
&&
273 state
->board_selected
[ XYPOS(x
- 1, y
)] == false)
274 clix_set_selected( state
, x
- 1, y
);
276 if( (y
+ 1) < BOARD_HEIGHT
&&
277 state
->board
[ XYPOS( x
, y
+ 1)] == current_color
&&
278 state
->board_selected
[ XYPOS(x
, y
+ 1)] == false)
279 clix_set_selected( state
, x
, y
+ 1);
281 if( (x
+ 1) < BOARD_WIDTH
&&
282 state
->board
[ XYPOS( x
+ 1, y
)] == current_color
&&
283 state
->board_selected
[ XYPOS(x
+ 1, y
)] == false)
284 clix_set_selected( state
, x
+ 1, y
);
287 state
->board
[ XYPOS( x
, y
- 1)] == current_color
&&
288 state
->board_selected
[ XYPOS(x
, y
- 1)] == false)
289 clix_set_selected( state
, x
, y
- 1);
292 /* updates "blinking" cells by finding out which one is a valid neighbours */
293 static void clix_update_selected(struct clix_game_state_t
* state
)
297 for( i
= 0; i
< BOARD_WIDTH
* BOARD_HEIGHT
; ++i
)
299 state
->board_selected
[i
] = false;
301 state
->selected_count
= 0;
303 /* recursion starts here */
304 clix_set_selected( state
, state
->x
, state
->y
);
307 /* inits the board with new random colors according to the level */
308 static void clix_init_new_level(struct clix_game_state_t
* state
)
313 state
->y
= BOARD_HEIGHT
/ 2;
314 state
->x
= BOARD_WIDTH
/ 2;
316 rb
->srand( *rb
->current_tick
);
317 /* create a random colored board, according to the current level */
318 for(i
= 0; i
< BOARD_HEIGHT
* BOARD_WIDTH
; ++i
)
320 r
= rb
->rand() % (state
->level
+ 1);
325 /* this inits the game state structure */
326 static void clix_init(struct clix_game_state_t
* state
)
330 state
->blink
= false;
331 state
->status
= CLIX_CONTINUE
;
333 clix_init_new_level(state
);
335 clix_update_selected(state
);
338 /* Function for drawing a cell */
339 static void clix_draw_cell(struct clix_game_state_t
* state
, const int x
, const int y
)
344 realx
+= x
* (CELL_SIZE
+ 1);
345 realy
+= y
* (CELL_SIZE
+ 1);
347 if (state
->blink
&& state
->board_selected
[ XYPOS( x
, y
)]) {
348 rb
->lcd_set_foreground(LCD_WHITE
);
350 switch (state
->board
[ XYPOS( x
, y
)])
353 rb
->lcd_set_foreground( LCD_RGBPACK( 25, 25, 255));
356 rb
->lcd_set_foreground( LCD_RGBPACK( 25, 255, 25));
359 rb
->lcd_set_foreground( LCD_RGBPACK( 255, 25, 25));
362 rb
->lcd_set_foreground( LCD_RGBPACK( 225, 225, 25));
365 rb
->lcd_set_foreground( LCD_RGBPACK( 230, 140, 15));
368 rb
->lcd_set_foreground( LCD_RGBPACK( 25, 245, 230));
371 rb
->lcd_set_foreground( LCD_RGBPACK(139, 69, 19));
374 rb
->lcd_set_foreground( LCD_RGBPACK(255, 105, 180));
377 rb
->lcd_set_foreground( LCD_RGBPACK( 0, 100, 0));
380 rb
->lcd_set_foreground( LCD_RGBPACK( 280, 32, 144));
383 rb
->lcd_set_foreground( LCD_BLACK
);
388 rb
->lcd_fillrect( realx
, realy
, CELL_SIZE
, CELL_SIZE
);
391 if ( x
== state
->x
&& y
== state
->y
) {
392 rb
->lcd_set_foreground( LCD_WHITE
);
393 rb
->lcd_drawrect( realx
- 1, realy
- 1, CELL_SIZE
+ 2, CELL_SIZE
+ 2);
397 /* main function of drawing the whole board and score... */
398 static void clix_draw(struct clix_game_state_t
* state
)
404 rb
->lcd_clear_display();
405 rb
->lcd_set_foreground( LCD_WHITE
);
407 rb
->lcd_putsxy( MARGIN
, MARGIN
, "Score:");
408 rb
->snprintf( str
, sizeof(str
), "%d", state
->score
);
409 rb
->lcd_putsxy( 43, MARGIN
, str
);
411 rb
->lcd_putsxy( 75, MARGIN
, "L:");
412 rb
->snprintf( str
, sizeof(str
), "%d", state
->level
);
413 rb
->lcd_putsxy( 90, MARGIN
, str
);
415 rb
->lcd_putsxy( 75, MARGIN
, "Level:");
416 rb
->snprintf( str
, sizeof(str
), "%d", state
->level
);
417 rb
->lcd_putsxy( 113, MARGIN
, str
);
419 for( i
= 0; i
< BOARD_WIDTH
; ++i
)
421 for( j
= 0; j
< BOARD_HEIGHT
; ++j
)
423 clix_draw_cell( state
, i
, j
);
430 static void clix_move_cursor(struct clix_game_state_t
* state
, const bool left
)
438 while(state
->board
[ XYPOS( x
, y
)] == CC_BLACK
&& y
< BOARD_HEIGHT
) y
++;
439 if (y
< BOARD_HEIGHT
) {
453 if( x
< BOARD_WIDTH
- 1)
459 } while ( y
!= state
->y
);
463 /* returns the color of the given position, if out of bounds return CC_BLACK */
464 static int clix_get_color(struct clix_game_state_t
* state
, const int x
, const int y
)
466 if( x
>= 0 && x
< BOARD_WIDTH
&& y
>= 0 && y
< BOARD_HEIGHT
)
467 return state
->board
[XYPOS( x
, y
)];
472 static int clix_clear_selected(struct clix_game_state_t
* state
)
476 state
->status
= CLIX_CLEARED
;
478 /* clear the selected blocks */
479 for( i
= 0; i
< BOARD_WIDTH
; ++i
)
481 for( j
= 0; j
< BOARD_HEIGHT
; ++j
)
483 if( state
->board_selected
[ XYPOS( i
, j
)] )
485 state
->board_selected
[ XYPOS( i
, j
)] = false;
486 state
->board
[ XYPOS( i
, j
)] = CC_BLACK
;
492 state
->score
+= state
->selected_count
* state
->level
;
493 state
->selected_count
= 0;
495 /* let blocks falling down */
496 for( i
= BOARD_WIDTH
- 1; i
>= 0; --i
)
498 for( j
= BOARD_HEIGHT
- 1; j
>= 0; --j
)
501 while( (y
+ 1) < BOARD_HEIGHT
&&
502 state
->board
[ XYPOS( i
, y
+ 1)] == CC_BLACK
507 state
->board
[ XYPOS( i
, y
)] = state
->board
[ XYPOS( i
, j
)];
508 state
->board
[ XYPOS( i
, j
)] = CC_BLACK
;
513 /* move columns to left side */
514 for( i
= 0; i
< BOARD_WIDTH
; ++i
)
517 while( (x
- 1) >= 0 &&
518 state
->board
[ XYPOS( x
- 1, BOARD_HEIGHT
- 1)] == CC_BLACK
523 for( j
= 0; j
< BOARD_HEIGHT
; ++j
)
525 state
->board
[ XYPOS( x
, j
)] = state
->board
[ XYPOS( i
, j
)];
526 state
->board
[ XYPOS( i
, j
)] = CC_BLACK
;
531 if(state
->board
[ XYPOS( 0, BOARD_HEIGHT
- 1)] != CC_BLACK
)
532 state
->status
= CLIX_CONTINUE
;
534 if (state
->status
!= CLIX_CLEARED
) {
535 /* check if a move is still possible, otherwise the game is over.
536 tart from the left bottom, because there are the last fields
537 at the end of the game.
539 for( i
= 0; i
< BOARD_WIDTH
; ++i
)
541 for( j
= BOARD_HEIGHT
- 1; j
>= 0; --j
)
543 int color
= state
->board
[ XYPOS( i
, j
)];
544 if (color
!= CC_BLACK
) {
545 if (color
== clix_get_color( state
, i
- 1, j
) ||
546 color
== clix_get_color( state
, i
+ 1, j
) ||
547 color
== clix_get_color( state
, i
, j
- 1) ||
548 color
== clix_get_color( state
, i
, j
+ 1)
551 /* end the loop, but in a diffrent way than usually*/
558 /* if the loops ended without a possible move, the game is over */
559 if( i
== BOARD_WIDTH
&& j
== -1)
560 state
->status
= CLIX_GAMEOVER
;
562 /* set cursor to the right position */
563 if (state
->status
== CLIX_CONTINUE
) {
564 clix_move_cursor( state
, true);
565 clix_update_selected( state
);
569 return state
->status
;
572 static bool clix_help(void)
574 #define WORDS (sizeof help_text / sizeof (char*))
575 static char *help_text
[] = {
576 "Clix", "", "Aim", "",
577 "Remove", "all", "blocks", "from", "the", "board", "to", "achieve",
578 "the", "next", "level.", "You", "can", "only", "remove", "blocks,",
579 "if", "at", "least", "two", "blocks", "with", "the", "same", "color",
580 "have", "a", "direct", "connection.", "The", "more", "blocks", "you",
581 "remove", "per", "turn,", "the", "more", "points", "you", "get."
583 static struct style_text formation
[]={
584 { 0, TEXT_CENTER
|TEXT_UNDERLINE
},
590 rb
->lcd_setfont(FONT_UI
);
591 rb
->lcd_set_foreground(LCD_WHITE
);
592 if (display_text(WORDS
, help_text
, formation
, NULL
))
595 button
= rb
->button_get(true);
596 if ( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
598 } while( ( button
== BUTTON_NONE
)
599 || ( button
& (BUTTON_REL
|BUTTON_REPEAT
) ) );
600 rb
->lcd_setfont(FONT_SYSFIXED
);
605 static int clix_menu_cb(int action
, const struct menu_item_ex
*this_item
)
607 if(action
== ACTION_REQUEST_MENUITEM
608 && !_ingame
&& ((intptr_t)this_item
)==0)
609 return ACTION_EXIT_MENUITEM
;
613 static int clix_menu(struct clix_game_state_t
* state
, bool ingame
)
615 rb
->button_clear_queue();
617 bool leave_menu
=false;
622 MENUITEM_STRINGLIST (main_menu
, "Clix Menu", clix_menu_cb
,
630 #ifdef HAVE_TOUCHSCREEN
631 /* Entering Menu, set the touchscreen to the global setting */
632 rb
->touchscreen_set_mode(rb
->global_settings
->touch_mode
);
635 while (!leave_menu
) {
637 switch (rb
->do_menu(&main_menu
, &choice
, NULL
, false)) {
654 highscore_show(NUM_SCORES
, highest
, NUM_SCORES
, true);
657 playback_control(NULL
);
660 case MENU_ATTACHED_USB
:
669 #ifdef HAVE_TOUCHSCREEN
670 /* Leaving the menu, set back to pointer mode */
671 rb
->touchscreen_set_mode(TOUCHSCREEN_POINT
);
677 static int clix_handle_game(struct clix_game_state_t
* state
)
679 if (clix_menu(state
, 0))
683 int blink_tick
= *rb
->current_tick
+ BLINK_TICKCOUNT
;
691 int lastbutton
= BUTTON_NONE
;
695 if (TIME_AFTER(*rb
->current_tick
, blink_tick
)) {
696 state
->blink
= !state
->blink
;
697 blink_tick
= *rb
->current_tick
+ BLINK_TICKCOUNT
;
700 time
= 6; /* number of ticks this function will loop reading keys */
701 start
= *rb
->current_tick
;
703 while(TIME_BEFORE(*rb
->current_tick
, end
))
708 button
= rb
->button_get_w_tmo(end
- *rb
->current_tick
);
709 #ifdef HAVE_TOUCHSCREEN
710 if(button
& BUTTON_TOUCHSCREEN
)
712 int x
= rb
->button_get_data() >> 16;
713 int y
= rb
->button_get_data() & 0xffff;
722 if(x
< BOARD_WIDTH
&& y
< BOARD_HEIGHT
723 && state
->board
[XYPOS(x
, y
)] != CC_BLACK
)
725 if(state
->x
== x
&& state
->y
== y
)
726 button
= CLIX_BUTTON_CLICK
;
738 #ifndef HAVE_TOUCHSCREEN
739 #ifdef CLIX_BUTTON_SCROLL_BACK
740 case CLIX_BUTTON_SCROLL_BACK
:
741 case CLIX_BUTTON_SCROLL_BACK
|BUTTON_REPEAT
:
745 state
->board
[ XYPOS( state
->x
, state
->y
- 1)] ==
748 state
->y
= BOARD_HEIGHT
- 1;
752 clix_move_cursor(state
, true);
754 case CLIX_BUTTON_RIGHT
:
755 if( state
->x
== (BOARD_WIDTH
- 1))
760 clix_move_cursor(state
, false);
762 #ifdef CLIX_BUTTON_SCROLL_FWD
763 case CLIX_BUTTON_SCROLL_FWD
:
764 case CLIX_BUTTON_SCROLL_FWD
|BUTTON_REPEAT
:
766 case CLIX_BUTTON_DOWN
:
767 if( state
->y
== (BOARD_HEIGHT
- 1))
772 clix_move_cursor( state
, true);
774 case CLIX_BUTTON_LEFT
:
776 state
->x
= BOARD_WIDTH
- 1;
780 clix_move_cursor(state
, true);
784 case CLIX_BUTTON_CLICK
:
786 if (state
->selected_count
> 1) {
787 switch( clix_clear_selected( state
))
790 state
->score
+= state
->level
* 100;
792 if (state
->level
< NUM_LEVELS
) {
793 rb
->splash(HZ
*2, "Great! Next Level!");
795 clix_init_new_level( state
);
796 clix_update_selected( state
);
799 rb
->splash(HZ
*2, "Congratulation!!!");
800 rb
->lcd_clear_display();
801 rb
->splash(HZ
*2, "You have finished the game.");
802 if (clix_menu(state
, 0))
808 rb
->splash(HZ
*2, "Game Over!");
809 rb
->lcd_clear_display();
810 position
=highscore_update(state
->score
,
814 rb
->splash(HZ
*2, "New High Score");
816 highscore_show(position
, highest
,
818 if (clix_menu(state
, 0))
822 rb
->sleep(10); /* prevent repeating clicks */
828 case CLIX_BUTTON_QUIT
:
829 if (clix_menu(state
, 1) != 0) {
830 rb
->button_clear_queue();
839 if(button
!= BUTTON_NONE
)
842 if( (oldx
!= state
->x
|| oldy
!= state
->y
) &&
843 state
->board_selected
[ XYPOS( oldx
, oldy
)] !=
844 state
->board_selected
[ XYPOS( state
->x
, state
->y
)]
847 clix_update_selected(state
);
855 /* this is the plugin entry point */
856 enum plugin_status
plugin_start(const void* parameter
)
860 rb
->lcd_set_backdrop(NULL
);
861 rb
->lcd_set_foreground(LCD_WHITE
);
862 rb
->lcd_set_background(LCD_BLACK
);
863 rb
->lcd_setfont(FONT_SYSFIXED
);
864 #ifdef HAVE_TOUCHSCREEN
865 rb
->touchscreen_set_mode(TOUCHSCREEN_POINT
);
868 highscore_load(HIGHSCORE_FILE
, highest
, NUM_SCORES
);
870 struct clix_game_state_t state
;
871 clix_handle_game( &state
);
873 highscore_save(HIGHSCORE_FILE
, highest
, NUM_SCORES
);