Index: star.c =================================================================== RCS file: /cvsroot/rockbox/apps/plugins/star.c,v retrieving revision 1.10 diff -u -r1.10 star.c --- star.c 6 Jul 2005 22:57:54 -0000 1.10 +++ star.c 25 Nov 2005 03:28:37 -0000 @@ -35,16 +35,9 @@ #define STAR_WIDTH 16 #define STAR_HEIGHT 9 -/* left and top margin */ -#define STAR_OFFSET_X 8 -#define STAR_OFFSET_Y 0 - /* number of level */ #define STAR_LEVEL_COUNT 20 -/* size of a tile */ -#define STAR_TILE_SIZE 6 - /* values of object in the board */ #define STAR_VOID '.' #define STAR_WALL '*' @@ -83,11 +76,13 @@ #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ (CONFIG_KEYPAD == IRIVER_H300_PAD) #define STAR_QUIT BUTTON_OFF -#define STAR_TOGGLE_CONTROL_PRE BUTTON_MODE -#define STAR_TOGGLE_CONTROL (BUTTON_MODE | BUTTON_REL) -#define STAR_LEVEL_UP (BUTTON_MODE | BUTTON_RIGHT) -#define STAR_LEVEL_DOWN (BUTTON_MODE | BUTTON_LEFT) -#define STAR_LEVEL_REPEAT (BUTTON_MODE | BUTTON_UP) +#define STAR_TOGGLE_CONTROL_PRE BUTTON_SELECT +#define STAR_TOGGLE_CONTROL_PRE2 BUTTON_MODE +#define STAR_TOGGLE_CONTROL (BUTTON_SELECT | BUTTON_REL) +#define STAR_TOGGLE_CONTROL2 (BUTTON_MODE | BUTTON_REL) +#define STAR_LEVEL_UP (BUTTON_ON | BUTTON_RIGHT) +#define STAR_LEVEL_DOWN (BUTTON_ON | BUTTON_LEFT) +#define STAR_LEVEL_REPEAT (BUTTON_ON | BUTTON_SELECT) #define STAR_MENU_RUN BUTTON_RIGHT #endif @@ -109,6 +104,31 @@ /* the current board */ static char board[STAR_HEIGHT][STAR_WIDTH]; +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ + (CONFIG_KEYPAD == IRIVER_H300_PAD) +/* size of a tile */ +#define STAR_TILE_SIZE 8 + +/* bitmap of the wall */ +static unsigned char wall_bmp[STAR_TILE_SIZE] + = {0xaa, 0x55,0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55}; + +/* bitmap of the star */ +static unsigned char star_bmp[STAR_TILE_SIZE] + = {0x00, 0x00, 0x18, 0x24, 0x24, 0x18, 0x00, 0x00}; + +/* bitmap of the ball */ +static unsigned char ball_bmp[STAR_TILE_SIZE] + = {0x00, 0x00, 0x18, 0x3c, 0x34, 0x18, 0x00, 0x00}; + +/* bitmap of the block */ +static unsigned char block_bmp[STAR_TILE_SIZE] + = {0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00}; + +#else +/* size of a tile */ +#define STAR_TILE_SIZE 6 + /* bitmap of the wall */ static unsigned char wall_bmp[STAR_TILE_SIZE] = {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55}; @@ -124,6 +144,7 @@ /* bitmap of the block */ static unsigned char block_bmp[STAR_TILE_SIZE] = {0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00}; +#endif /* bitmap of the arrow animation */ static unsigned char arrow_bmp[4][7] = @@ -134,6 +155,11 @@ {0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08} }; + +/* left and top margin */ +#define STAR_OFFSET_X (int)((LCD_WIDTH-STAR_WIDTH*STAR_TILE_SIZE)/2) +#define STAR_OFFSET_Y 0 + /* sequence of the bitmap arrow to follow to do one turn */ static unsigned char anim_arrow[8] = {0, 1, 2, 3, 2, 1, 0}; @@ -427,7 +453,10 @@ switch (key) { case STAR_MENU_RUN: - case BUTTON_DOWN: + case BUTTON_LEFT: + case STAR_QUIT: + case STAR_TOGGLE_CONTROL: + go_on = true; break; @@ -480,15 +509,18 @@ int label_offset_y = label_offset_y = LCD_HEIGHT - char_height; char str_info[32]; - rb->snprintf(str_info, sizeof(str_info), "L:%02d S:%02d C:", - current_level, star_count); + rb->snprintf(str_info, sizeof(str_info), "Lvl:%02d :%02d C:", + current_level+1, star_count); rb->lcd_putsxy(0, label_offset_y, str_info); + rb->lcd_mono_bitmap (star_bmp, 47, label_offset_y, STAR_TILE_SIZE, + STAR_TILE_SIZE); + if (control == STAR_CONTROL_BALL) - rb->lcd_mono_bitmap (ball_bmp, 103, label_offset_y + 1, STAR_TILE_SIZE, + rb->lcd_mono_bitmap (ball_bmp, 95, label_offset_y, STAR_TILE_SIZE, STAR_TILE_SIZE); else - rb->lcd_mono_bitmap (block_bmp, 103, label_offset_y + 1, STAR_TILE_SIZE, + rb->lcd_mono_bitmap (block_bmp, 95, label_offset_y, STAR_TILE_SIZE, STAR_TILE_SIZE); rb->lcd_update_rect(0, label_offset_y, LCD_WIDTH, char_height); @@ -630,13 +662,20 @@ break; case STAR_TOGGLE_CONTROL: +#ifdef STAR_TOGGLE_CONTROL2 + case STAR_TOGGLE_CONTROL2: +#endif #ifdef STAR_TOGGLE_CONTROL_PRE +#ifdef STAR_TOGGLE_CONTROL_PRE2 + if ((lastkey != STAR_TOGGLE_CONTROL_PRE) && + (lastkey != STAR_TOGGLE_CONTROL_PRE2)) + break; +#else if (lastkey != STAR_TOGGLE_CONTROL_PRE) break; #endif -#ifdef STAR_TOGGLE_CONTROL2 - case STAR_TOGGLE_CONTROL2: #endif + if (control == STAR_CONTROL_BALL) control = STAR_CONTROL_BLOCK; else @@ -663,7 +702,7 @@ || board[ball_y + move_y][ball_x + move_x] == STAR_STAR)) { - for (i = 0 ; i < 7 ; i++) + for (i = 0 ; i < STAR_TILE_SIZE+1 ; i++) { rb->lcd_mono_bitmap( ball_bmp, @@ -695,7 +734,7 @@ board[block_y][block_x] = STAR_VOID; while (board[block_y + move_y][block_x + move_x] == STAR_VOID) { - for (i = 0 ; i < 7 ; i++) + for (i = 0 ; i < STAR_TILE_SIZE+1 ; i++) { rb->lcd_mono_bitmap( block_bmp, @@ -732,6 +771,69 @@ } /** + * Display the choose level screen. + */ +static int star_choose_level(void) +{ + int level = current_level; + int key = BUTTON_NONE;; + char str_info[32]; + int lastkey = BUTTON_NONE; + + while (true) + { + rb->lcd_clear_display(); + rb->snprintf(str_info, sizeof(str_info), "Level:%02d / %02d", + level+1,STAR_LEVEL_COUNT); + rb->lcd_putsxy(0, 0, str_info); + rb->lcd_update(); + key = rb->button_get(true); + switch (key) + { + case STAR_QUIT: + return -1; + + case BUTTON_LEFT: + return -1; + break; + +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ + (CONFIG_KEYPAD == IRIVER_H300_PAD) + case BUTTON_SELECT: + case BUTTON_ON: +#endif + case BUTTON_RIGHT: + current_level=level; + return star_run_game(); + break; + + case BUTTON_REPEAT | BUTTON_UP: + case BUTTON_UP: + if(level< STAR_LEVEL_COUNT - 1) + level++; + break; + + case BUTTON_REPEAT | BUTTON_DOWN: + case BUTTON_DOWN: + if(level> 0) + level--; + break; + + default: + if (rb->default_event_handler(key) == SYS_USB_CONNECTED) + { + usb_detected = true; + return 0; + } + break; + } + + if (key != BUTTON_NONE) + lastkey = key; + } +} + +/** * Display the choice menu. */ static int star_menu(void) @@ -741,7 +843,7 @@ int i = 0; bool refresh = true; char anim_state = 0; - unsigned char *menu[4] = {"Start", "Information", "Keys", "Exit"}; + unsigned char *menu[5] = {"Start","Choose level", "Information", "Keys", "Exit"}; int menu_count = sizeof(menu) / sizeof(unsigned char *); int menu_offset_y; int key; @@ -782,7 +884,7 @@ move_y = -1; break; case BUTTON_DOWN: - if (menu_y < 3) + if (menu_y < menu_count-1) move_y = 1; break; @@ -796,10 +898,17 @@ { case 0: if (!star_run_game()) - return usb_detected ? - PLUGIN_USB_CONNECTED : PLUGIN_OK; + if(usb_detected) + return PLUGIN_USB_CONNECTED;// : PLUGIN_OK; + /*return usb_detected ? + PLUGIN_USB_CONNECTED : PLUGIN_OK;*/ break; case 1: + if (!star_choose_level()) + if(usb_detected) + return PLUGIN_USB_CONNECTED;// : PLUGIN_OK; + break; + case 2: star_display_text( "INFO\n\n" "Take all \"o\" to go to the next level. " @@ -807,7 +916,7 @@ "use it as a mobile wall. The block cannot " "take \"o\".", true); break; - case 2: + case 3: #if CONFIG_KEYPAD == RECORDER_PAD star_display_text("KEYS\n\n" "[ON] Toggle Ctl.\n" @@ -822,9 +931,17 @@ "[M <] Prev. level\n" "[M ^] Reset level\n" "[M >] Next level", true); +#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ + (CONFIG_KEYPAD == IRIVER_H300_PAD) + star_display_text("KEYS\n\n" + "[PLAY] Toggle Ctl\n" + "[OFF] Exit\n" + "[ON + Left] Prev. level\n" + "[ON + Right] Next level\n" + "[ON + PLAY] Reset level\n", true); #endif break; - case 3: + case 4: return PLUGIN_OK; } if (usb_detected) @@ -840,11 +957,11 @@ for (i = 0 ; i < char_height ; i++) { rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); - rb->lcd_fillrect (2, 30, 7, 4 * 8); + rb->lcd_fillrect (2, menu_offset_y , 7, menu_count * 8); rb->lcd_set_drawmode(DRMODE_FG); rb->lcd_mono_bitmap(arrow_bmp[anim_arrow[(anim_state & 0x38) >> 3]], 2, menu_offset_y + menu_y * 8 + move_y * i, 7, 8); - rb->lcd_update_rect(2, 30, 8, 4 * 8); + rb->lcd_update_rect(2, menu_offset_y, 8, menu_count * 8); anim_state++; rb->sleep(STAR_SLEEP); }