forked from len0rd/rockbox
new menu system, consolidated button assignments, ipod mini support
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8821 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
42295c438d
commit
0b489779ce
4 changed files with 367 additions and 206 deletions
|
@ -33,10 +33,7 @@ mandelbrot.c
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
solitaire.c
|
solitaire.c
|
||||||
#if (LCD_WIDTH != 138)
|
|
||||||
/* These need adjusting for the Mini's screen */
|
|
||||||
bejeweled.c
|
bejeweled.c
|
||||||
#endif
|
|
||||||
bounce.c
|
bounce.c
|
||||||
#if (LCD_WIDTH != 138) && (LCD_WIDTH != 128)
|
#if (LCD_WIDTH != 138) && (LCD_WIDTH != 128)
|
||||||
/* These need adjusting for the Mini's and iRiver if'p screen */
|
/* These need adjusting for the Mini's and iRiver if'p screen */
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
bejeweled_jewels.112x64x1.bmp
|
bejeweled_jewels.112x64x1.bmp
|
||||||
#elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 64)
|
#elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 64)
|
||||||
bejeweled_jewels.112x64x1.bmp
|
bejeweled_jewels.112x64x1.bmp
|
||||||
|
#elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
|
||||||
|
bejeweled_jewels.138x110x1.bmp
|
||||||
#elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && !defined(HAVE_LCD_COLOR)
|
#elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && !defined(HAVE_LCD_COLOR)
|
||||||
bejeweled_jewels.160x128x1.bmp
|
bejeweled_jewels.160x128x1.bmp
|
||||||
#elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && defined(HAVE_LCD_COLOR)
|
#elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && defined(HAVE_LCD_COLOR)
|
||||||
|
|
BIN
apps/plugins/bitmaps/native/jewels.138x110x1.bmp
Executable file
BIN
apps/plugins/bitmaps/native/jewels.138x110x1.bmp
Executable file
Binary file not shown.
After Width: | Height: | Size: 478 B |
|
@ -25,71 +25,56 @@
|
||||||
|
|
||||||
PLUGIN_HEADER
|
PLUGIN_HEADER
|
||||||
|
|
||||||
/* button definitions */
|
/* button definitions, every keypad must only have directions & select */
|
||||||
#if CONFIG_KEYPAD == RECORDER_PAD
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
||||||
#define BEJEWELED_UP BUTTON_UP
|
#define BEJEWELED_UP BUTTON_UP
|
||||||
#define BEJEWELED_DOWN BUTTON_DOWN
|
#define BEJEWELED_DOWN BUTTON_DOWN
|
||||||
#define BEJEWELED_LEFT BUTTON_LEFT
|
#define BEJEWELED_LEFT BUTTON_LEFT
|
||||||
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
||||||
#define BEJEWELED_QUIT BUTTON_OFF
|
|
||||||
#define BEJEWELED_START BUTTON_ON
|
|
||||||
#define BEJEWELED_SELECT BUTTON_PLAY
|
#define BEJEWELED_SELECT BUTTON_PLAY
|
||||||
#define BEJEWELED_RESUME BUTTON_F1
|
#define BEJEWELED_CANCEL BUTTON_OFF
|
||||||
|
|
||||||
#elif CONFIG_KEYPAD == ONDIO_PAD
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
||||||
#define BEJEWELED_UP BUTTON_UP
|
#define BEJEWELED_UP BUTTON_UP
|
||||||
#define BEJEWELED_DOWN BUTTON_DOWN
|
#define BEJEWELED_DOWN BUTTON_DOWN
|
||||||
#define BEJEWELED_LEFT BUTTON_LEFT
|
#define BEJEWELED_LEFT BUTTON_LEFT
|
||||||
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
||||||
#define BEJEWELED_QUIT BUTTON_OFF
|
#define BEJEWELED_SELECT BUTTON_MENU
|
||||||
#define BEJEWELED_START BUTTON_RIGHT
|
#define BEJEWELED_CANCEL BUTTON_OFF
|
||||||
#define BEJEWELED_SELECT (BUTTON_MENU|BUTTON_REL)
|
|
||||||
#define BEJEWELED_SELECT_PRE BUTTON_MENU
|
|
||||||
#define BEJEWELED_RESUME (BUTTON_MENU|BUTTON_OFF)
|
|
||||||
|
|
||||||
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
|
||||||
#define BEJEWELED_UP BUTTON_UP
|
#define BEJEWELED_UP BUTTON_UP
|
||||||
#define BEJEWELED_DOWN BUTTON_DOWN
|
#define BEJEWELED_DOWN BUTTON_DOWN
|
||||||
#define BEJEWELED_LEFT BUTTON_LEFT
|
#define BEJEWELED_LEFT BUTTON_LEFT
|
||||||
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
||||||
#define BEJEWELED_QUIT BUTTON_OFF
|
|
||||||
#define BEJEWELED_START BUTTON_ON
|
|
||||||
#define BEJEWELED_SELECT BUTTON_SELECT
|
#define BEJEWELED_SELECT BUTTON_SELECT
|
||||||
#define BEJEWELED_RESUME BUTTON_MODE
|
#define BEJEWELED_CANCEL BUTTON_OFF
|
||||||
|
|
||||||
#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD)
|
#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD)
|
||||||
#define BEJEWELED_SCROLLWHEEL
|
#define BEJEWELED_SCROLLWHEEL
|
||||||
#define BEJEWELED_UP BUTTON_MENU
|
#define BEJEWELED_UP BUTTON_MENU
|
||||||
#define BEJEWELED_DOWN BUTTON_PLAY
|
#define BEJEWELED_DOWN BUTTON_PLAY
|
||||||
#define BEJEWELED_LEFT BUTTON_LEFT
|
#define BEJEWELED_LEFT BUTTON_LEFT
|
||||||
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
||||||
#define BEJEWELED_PREV BUTTON_SCROLL_BACK
|
#define BEJEWELED_PREV BUTTON_SCROLL_BACK
|
||||||
#define BEJEWELED_NEXT BUTTON_SCROLL_FWD
|
#define BEJEWELED_NEXT BUTTON_SCROLL_FWD
|
||||||
#define BEJEWELED_QUIT (BUTTON_SELECT|BUTTON_MENU)
|
#define BEJEWELED_SELECT BUTTON_SELECT
|
||||||
#define BEJEWELED_START BUTTON_PLAY
|
|
||||||
#define BEJEWELED_SELECT (BUTTON_SELECT|BUTTON_REL)
|
|
||||||
#define BEJEWELED_SELECT_PRE BUTTON_SELECT
|
|
||||||
#define BEJEWELED_RESUME (BUTTON_SELECT|BUTTON_PLAY)
|
|
||||||
|
|
||||||
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
|
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
|
||||||
#define BEJEWELED_UP BUTTON_UP
|
#define BEJEWELED_UP BUTTON_UP
|
||||||
#define BEJEWELED_DOWN BUTTON_DOWN
|
#define BEJEWELED_DOWN BUTTON_DOWN
|
||||||
#define BEJEWELED_LEFT BUTTON_LEFT
|
#define BEJEWELED_LEFT BUTTON_LEFT
|
||||||
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
||||||
#define BEJEWELED_QUIT BUTTON_PLAY
|
|
||||||
#define BEJEWELED_START BUTTON_MODE
|
|
||||||
#define BEJEWELED_SELECT BUTTON_SELECT
|
#define BEJEWELED_SELECT BUTTON_SELECT
|
||||||
#define BEJEWELED_RESUME BUTTON_EQ
|
#define BEJEWELED_CANCEL BUTTON_PLAY
|
||||||
|
|
||||||
#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
|
#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
|
||||||
#define BEJEWELED_UP BUTTON_UP
|
#define BEJEWELED_UP BUTTON_UP
|
||||||
#define BEJEWELED_DOWN BUTTON_DOWN
|
#define BEJEWELED_DOWN BUTTON_DOWN
|
||||||
#define BEJEWELED_LEFT BUTTON_LEFT
|
#define BEJEWELED_LEFT BUTTON_LEFT
|
||||||
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
#define BEJEWELED_RIGHT BUTTON_RIGHT
|
||||||
#define BEJEWELED_QUIT BUTTON_POWER
|
|
||||||
#define BEJEWELED_START BUTTON_PLAY
|
|
||||||
#define BEJEWELED_SELECT BUTTON_MENU
|
#define BEJEWELED_SELECT BUTTON_MENU
|
||||||
#define BEJEWELED_RESUME BUTTON_REC
|
#define BEJEWELED_CANCEL BUTTON_PLAY
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error BEJEWELED: Unsupported keypad
|
#error BEJEWELED: Unsupported keypad
|
||||||
|
@ -123,6 +108,13 @@ PLUGIN_HEADER
|
||||||
#define YOFS 0
|
#define YOFS 0
|
||||||
#define NUM_SCORES 10
|
#define NUM_SCORES 10
|
||||||
|
|
||||||
|
/* use 13x13 tiles (iPod Mini) */
|
||||||
|
#elif (LCD_HEIGHT == 110) && (LCD_WIDTH == 138)
|
||||||
|
#define TILE_WIDTH 13
|
||||||
|
#define TILE_HEIGHT 13
|
||||||
|
#define YOFS 6
|
||||||
|
#define NUM_SCORES 10
|
||||||
|
|
||||||
/* use 10x8 tiles (iFP 700) */
|
/* use 10x8 tiles (iFP 700) */
|
||||||
#elif (LCD_HEIGHT == 64) && (LCD_WIDTH == 128)
|
#elif (LCD_HEIGHT == 64) && (LCD_WIDTH == 128)
|
||||||
#define TILE_WIDTH 10
|
#define TILE_WIDTH 10
|
||||||
|
@ -141,14 +133,6 @@ PLUGIN_HEADER
|
||||||
#error BEJEWELED: Unsupported LCD
|
#error BEJEWELED: Unsupported LCD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* tile background colors */
|
|
||||||
#if defined(HAVE_LCD_COLOR)
|
|
||||||
static const unsigned bejeweled_bkgd[2] = {
|
|
||||||
LCD_RGBPACK(104, 63, 63),
|
|
||||||
LCD_RGBPACK(83, 44, 44)
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* save files */
|
/* save files */
|
||||||
#define SCORE_FILE PLUGIN_DIR "/bejeweled.score"
|
#define SCORE_FILE PLUGIN_DIR "/bejeweled.score"
|
||||||
#define SAVE_FILE PLUGIN_DIR "/bejeweled.save"
|
#define SAVE_FILE PLUGIN_DIR "/bejeweled.save"
|
||||||
|
@ -173,7 +157,54 @@ static const unsigned bejeweled_bkgd[2] = {
|
||||||
#define LEVEL_PTS 100
|
#define LEVEL_PTS 100
|
||||||
|
|
||||||
/* animation frame rate */
|
/* animation frame rate */
|
||||||
#define FPS 20
|
#define MAX_FPS 20
|
||||||
|
|
||||||
|
/* menu values */
|
||||||
|
#define FONT_HEIGHT 8
|
||||||
|
#define MAX_MITEMS 5
|
||||||
|
#define MENU_WIDTH 100
|
||||||
|
|
||||||
|
/* menu results */
|
||||||
|
enum menu_result {
|
||||||
|
MRES_NONE,
|
||||||
|
MRES_NEW,
|
||||||
|
MRES_SAVE,
|
||||||
|
MRES_RESUME,
|
||||||
|
MRES_SCORES,
|
||||||
|
MRES_HELP,
|
||||||
|
MRES_QUIT
|
||||||
|
};
|
||||||
|
|
||||||
|
/* menu commands */
|
||||||
|
enum menu_cmd {
|
||||||
|
MCMD_NONE,
|
||||||
|
MCMD_NEXT,
|
||||||
|
MCMD_PREV,
|
||||||
|
MCMD_SELECT
|
||||||
|
};
|
||||||
|
|
||||||
|
/* menus */
|
||||||
|
struct bejeweled_menu {
|
||||||
|
char *title;
|
||||||
|
bool hasframe;
|
||||||
|
int selected;
|
||||||
|
int itemcnt;
|
||||||
|
struct bejeweled_menuitem {
|
||||||
|
char *text;
|
||||||
|
enum menu_result res;
|
||||||
|
} items[MAX_MITEMS];
|
||||||
|
} bjmenu[] = {
|
||||||
|
{"Bejeweled", false, 0, 5,
|
||||||
|
{{"New Game", MRES_NEW},
|
||||||
|
{"Resume Game", MRES_RESUME},
|
||||||
|
{"High Scores", MRES_SCORES},
|
||||||
|
{"Help", MRES_HELP},
|
||||||
|
{"Quit", MRES_QUIT}}},
|
||||||
|
{"Menu", true, 0, 3,
|
||||||
|
{{"Resume Game", MRES_RESUME},
|
||||||
|
{"Save Game", MRES_SAVE},
|
||||||
|
{"End Game", MRES_QUIT}}}
|
||||||
|
};
|
||||||
|
|
||||||
/* global rockbox api */
|
/* global rockbox api */
|
||||||
static struct plugin_api* rb;
|
static struct plugin_api* rb;
|
||||||
|
@ -181,6 +212,14 @@ static struct plugin_api* rb;
|
||||||
/* external bitmaps */
|
/* external bitmaps */
|
||||||
extern const fb_data bejeweled_jewels[];
|
extern const fb_data bejeweled_jewels[];
|
||||||
|
|
||||||
|
/* tile background colors */
|
||||||
|
#ifdef HAVE_LCD_COLOR
|
||||||
|
static const unsigned bejeweled_bkgd[2] = {
|
||||||
|
LCD_RGBPACK(104, 63, 63),
|
||||||
|
LCD_RGBPACK(83, 44, 44)
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/* the tile struct
|
/* the tile struct
|
||||||
* type is the jewel number 0-7
|
* type is the jewel number 0-7
|
||||||
* falling if the jewel is falling
|
* falling if the jewel is falling
|
||||||
|
@ -318,12 +357,76 @@ static void bejeweled_drawboard(struct game_context* bj) {
|
||||||
rb->snprintf(str, 6, "%d", (bj->level-1)*LEVEL_PTS+bj->score);
|
rb->snprintf(str, 6, "%d", (bj->level-1)*LEVEL_PTS+bj->score);
|
||||||
rb->lcd_getstringsize(str, &w, &h);
|
rb->lcd_getstringsize(str, &w, &h);
|
||||||
rb->lcd_putsxy(LCD_WIDTH-(LCD_WIDTH-BJ_WIDTH*TILE_WIDTH)/2-w/2,
|
rb->lcd_putsxy(LCD_WIDTH-(LCD_WIDTH-BJ_WIDTH*TILE_WIDTH)/2-w/2,
|
||||||
LCD_HEIGHT-8,
|
LCD_HEIGHT-8, str);
|
||||||
str);
|
|
||||||
|
|
||||||
rb->lcd_update();
|
rb->lcd_update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* bejeweled_showmenu() displays the chosen menu after performing the chosen
|
||||||
|
* menu command.
|
||||||
|
******************************************************************************/
|
||||||
|
static enum menu_result bejeweled_showmenu(struct bejeweled_menu* menu,
|
||||||
|
enum menu_cmd cmd) {
|
||||||
|
int i;
|
||||||
|
int w, h;
|
||||||
|
int firstline;
|
||||||
|
int adj;
|
||||||
|
|
||||||
|
/* handle menu command */
|
||||||
|
switch(cmd) {
|
||||||
|
case MCMD_NEXT:
|
||||||
|
menu->selected = (menu->selected+1)%menu->itemcnt;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MCMD_PREV:
|
||||||
|
menu->selected = (menu->selected-1+menu->itemcnt)%menu->itemcnt;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MCMD_SELECT:
|
||||||
|
return menu->items[menu->selected].res;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clear menu area */
|
||||||
|
firstline = (LCD_HEIGHT/FONT_HEIGHT-(menu->itemcnt+3))/2;
|
||||||
|
|
||||||
|
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
||||||
|
rb->lcd_fillrect((LCD_WIDTH-MENU_WIDTH)/2, firstline*FONT_HEIGHT,
|
||||||
|
MENU_WIDTH, (menu->itemcnt+3)*FONT_HEIGHT);
|
||||||
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
||||||
|
|
||||||
|
if(menu->hasframe) {
|
||||||
|
rb->lcd_drawrect((LCD_WIDTH-MENU_WIDTH)/2-1, firstline*FONT_HEIGHT-1,
|
||||||
|
MENU_WIDTH+2, (menu->itemcnt+3)*FONT_HEIGHT+2);
|
||||||
|
rb->lcd_hline((LCD_WIDTH-MENU_WIDTH)/2-1,
|
||||||
|
(LCD_WIDTH-MENU_WIDTH)/2-1+MENU_WIDTH+2,
|
||||||
|
(firstline+1)*FONT_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* draw menu items */
|
||||||
|
rb->lcd_getstringsize(menu->title, &w, &h);
|
||||||
|
rb->lcd_putsxy((LCD_WIDTH-w)/2, firstline*FONT_HEIGHT, menu->title);
|
||||||
|
|
||||||
|
for(i=0; i<menu->itemcnt; i++) {
|
||||||
|
if(i == menu->selected) {
|
||||||
|
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
||||||
|
}
|
||||||
|
rb->lcd_putsxy((LCD_WIDTH-MENU_WIDTH)/2, (firstline+i+2)*FONT_HEIGHT,
|
||||||
|
menu->items[i].text);
|
||||||
|
if(i == menu->selected) {
|
||||||
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
adj = (firstline == 0 ? 0 : 1);
|
||||||
|
rb->lcd_update_rect((LCD_WIDTH-MENU_WIDTH)/2-1, firstline*FONT_HEIGHT-adj,
|
||||||
|
MENU_WIDTH+2, (menu->itemcnt+3)*FONT_HEIGHT+2*adj);
|
||||||
|
return MRES_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* bejeweled_putjewels() makes the jewels fall to fill empty spots and adds
|
* bejeweled_putjewels() makes the jewels fall to fill empty spots and adds
|
||||||
* new random jewels at the empty spots at the top of each row.
|
* new random jewels at the empty spots at the top of each row.
|
||||||
|
@ -412,13 +515,15 @@ static void bejeweled_putjewels(struct game_context* bj){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rb->lcd_update();
|
rb->lcd_update_rect(0, 0, TILE_WIDTH*8, LCD_HEIGHT);
|
||||||
bejeweled_setcolors();
|
bejeweled_setcolors();
|
||||||
|
|
||||||
/* framerate limiting */
|
/* framerate limiting */
|
||||||
currenttick = *rb->current_tick;
|
currenttick = *rb->current_tick;
|
||||||
if(currenttick-lasttick < HZ/FPS) {
|
if(currenttick-lasttick < HZ/MAX_FPS) {
|
||||||
rb->sleep((HZ/FPS)-(currenttick-lasttick));
|
rb->sleep((HZ/MAX_FPS)-(currenttick-lasttick));
|
||||||
|
} else {
|
||||||
|
rb->yield();
|
||||||
}
|
}
|
||||||
lasttick = currenttick;
|
lasttick = currenttick;
|
||||||
}
|
}
|
||||||
|
@ -650,13 +755,15 @@ static unsigned int bejeweled_swapjewels(struct game_context* bj,
|
||||||
rb->lcd_set_drawmode(DRMODE_SOLID);
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rb->lcd_update();
|
rb->lcd_update_rect(0, 0, TILE_WIDTH*8, LCD_HEIGHT);
|
||||||
bejeweled_setcolors();
|
bejeweled_setcolors();
|
||||||
|
|
||||||
/* framerate limiting */
|
/* framerate limiting */
|
||||||
currenttick = *rb->current_tick;
|
currenttick = *rb->current_tick;
|
||||||
if(currenttick-lasttick < HZ/FPS) {
|
if(currenttick-lasttick < HZ/MAX_FPS) {
|
||||||
rb->sleep((HZ/FPS)-(currenttick-lasttick));
|
rb->sleep((HZ/MAX_FPS)-(currenttick-lasttick));
|
||||||
|
} else {
|
||||||
|
rb->yield();
|
||||||
}
|
}
|
||||||
lasttick = currenttick;
|
lasttick = currenttick;
|
||||||
}
|
}
|
||||||
|
@ -939,12 +1046,12 @@ static int bejeweled(struct game_context* bj) {
|
||||||
int i, j;
|
int i, j;
|
||||||
int w, h;
|
int w, h;
|
||||||
int button;
|
int button;
|
||||||
int lastbutton = BUTTON_NONE;
|
|
||||||
char str[18];
|
char str[18];
|
||||||
char *title = "Bejeweled";
|
|
||||||
bool startgame = false;
|
bool startgame = false;
|
||||||
bool showscores = false;
|
bool inmenu = false;
|
||||||
bool selected = false;
|
bool selected = false;
|
||||||
|
enum menu_cmd cmd = MCMD_NONE;
|
||||||
|
enum menu_result res;
|
||||||
|
|
||||||
/* the cursor coordinates */
|
/* the cursor coordinates */
|
||||||
int x=0, y=0;
|
int x=0, y=0;
|
||||||
|
@ -955,128 +1062,138 @@ static int bejeweled(struct game_context* bj) {
|
||||||
/********************
|
/********************
|
||||||
* menu *
|
* menu *
|
||||||
********************/
|
********************/
|
||||||
while(!startgame){
|
rb->lcd_clear_display();
|
||||||
rb->lcd_clear_display();
|
|
||||||
|
|
||||||
if(!showscores) {
|
while(!startgame) {
|
||||||
/* welcome screen to display key bindings */
|
res = bejeweled_showmenu(&bjmenu[0], cmd);
|
||||||
rb->lcd_getstringsize(title, &w, &h);
|
cmd = MCMD_NONE;
|
||||||
rb->lcd_putsxy((LCD_WIDTH-w)/2, 0, title);
|
|
||||||
#if CONFIG_KEYPAD == RECORDER_PAD
|
rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]);
|
||||||
rb->lcd_puts(0, 1, "ON to start");
|
rb->lcd_getstringsize(str, &w, &h);
|
||||||
rb->lcd_puts(0, 2, "F1 to save/resume");
|
rb->lcd_putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT-8, str);
|
||||||
rb->lcd_puts(0, 3, "OFF to exit");
|
rb->lcd_update();
|
||||||
rb->lcd_puts(0, 4, "PLAY to select");
|
|
||||||
rb->lcd_puts(0, 5, "& show high scores");
|
switch(res) {
|
||||||
rb->lcd_puts(0, 6, "Directions to move");
|
case MRES_NEW:
|
||||||
rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]);
|
startgame = true;
|
||||||
rb->lcd_puts(0, 7, str);
|
continue;
|
||||||
#elif CONFIG_KEYPAD == ONDIO_PAD
|
|
||||||
rb->lcd_puts(0, 1, "RIGHT to start");
|
case MRES_RESUME:
|
||||||
rb->lcd_puts(0, 2, "MENU+OFF to sv/res");
|
if(!bejeweled_loadgame(bj)) {
|
||||||
rb->lcd_puts(0, 3, "OFF to exit");
|
rb->splash(HZ*2, true, "Nothing to resume");
|
||||||
rb->lcd_puts(0, 4, "MENU to select");
|
rb->lcd_clear_display();
|
||||||
rb->lcd_puts(0, 5, "& show high scores");
|
} else {
|
||||||
rb->lcd_puts(0, 6, "Directions to move");
|
startgame = true;
|
||||||
rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]);
|
}
|
||||||
rb->lcd_puts(0, 7, str);
|
continue;
|
||||||
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
|
|
||||||
rb->lcd_puts(0, 2, "ON to start");
|
case MRES_SCORES:
|
||||||
rb->lcd_puts(0, 3, "MODE to save/resume");
|
rb->lcd_clear_display();
|
||||||
rb->lcd_puts(0, 4, "OFF to exit");
|
|
||||||
rb->lcd_puts(0, 5, "SELECT to select");
|
/* room for a title? */
|
||||||
rb->lcd_puts(0, 6, " and show high scores");
|
j = 0;
|
||||||
rb->lcd_puts(0, 7, "Directions to move");
|
if(LCD_HEIGHT-NUM_SCORES*8 >= 8) {
|
||||||
rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]);
|
rb->snprintf(str, 12, "%s", "High Scores");
|
||||||
rb->lcd_puts(0, 9, str);
|
rb->lcd_getstringsize(str, &w, &h);
|
||||||
#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD)
|
rb->lcd_putsxy((LCD_WIDTH-w)/2, 0, str);
|
||||||
rb->lcd_puts(0, 2, "PLAY to start");
|
j = 2;
|
||||||
rb->lcd_puts(0, 3, "SELECT+PLAY to save/resume");
|
}
|
||||||
rb->lcd_puts(0, 4, "SELECT+MENU to exit");
|
|
||||||
rb->lcd_puts(0, 5, "SELECT to select");
|
/* print high scores */
|
||||||
rb->lcd_puts(0, 6, " and show high scores");
|
for(i=0; i<NUM_SCORES; i++) {
|
||||||
rb->lcd_puts(0, 7, "Scroll or Directions to move");
|
rb->snprintf(str, 11, "#%02d: %d", i+1, bj->highscores[i]);
|
||||||
rb->lcd_puts(0, 8, "Directions to swap");
|
rb->lcd_puts(0, i+j, str);
|
||||||
rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]);
|
}
|
||||||
rb->lcd_puts(0, 10, str);
|
|
||||||
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
|
rb->lcd_update();
|
||||||
rb->lcd_puts(0, 1, "MODE to start");
|
while(true) {
|
||||||
rb->lcd_puts(0, 2, "EQ to save/resume");
|
button = rb->button_get(true);
|
||||||
rb->lcd_puts(0, 3, "PLAY to exit");
|
if(button != BUTTON_NONE && !(button&BUTTON_REL)) break;
|
||||||
rb->lcd_puts(0, 4, "SELECT to select");
|
}
|
||||||
rb->lcd_puts(0, 5, "& show high scores");
|
rb->lcd_clear_display();
|
||||||
rb->lcd_puts(0, 6, "Directions to move");
|
continue;
|
||||||
rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]);
|
|
||||||
rb->lcd_puts(0, 7, str);
|
case MRES_HELP:
|
||||||
#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
|
/* welcome screen to display key bindings */
|
||||||
rb->lcd_puts(0, 2, "PLAY to start");
|
rb->lcd_clear_display();
|
||||||
rb->lcd_puts(0, 3, "REC to save/resume");
|
rb->snprintf(str, 5, "%s", "Help");
|
||||||
rb->lcd_puts(0, 4, "POWER to exit");
|
|
||||||
rb->lcd_puts(0, 5, "MENU to select");
|
|
||||||
rb->lcd_puts(0, 6, " and show high scores");
|
|
||||||
rb->lcd_puts(0, 7, "Directions to move");
|
|
||||||
rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]);
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
/* room for a title? */
|
|
||||||
j = 0;
|
|
||||||
if(LCD_HEIGHT-NUM_SCORES*8 >= 8) {
|
|
||||||
rb->snprintf(str, 12, "%s", "High Scores");
|
|
||||||
rb->lcd_getstringsize(str, &w, &h);
|
rb->lcd_getstringsize(str, &w, &h);
|
||||||
rb->lcd_putsxy((LCD_WIDTH-w)/2, 0, str);
|
rb->lcd_putsxy((LCD_WIDTH-w)/2, 0, str);
|
||||||
j = 2;
|
#if (LCD_HEIGHT <= 64)
|
||||||
}
|
rb->lcd_puts(0, 2, "Controls:");
|
||||||
|
rb->lcd_puts(0, 3, "Directions = move");
|
||||||
|
rb->lcd_puts(0, 4, "SELECT = select");
|
||||||
|
rb->lcd_puts(0, 5, "Long SELECT = menu");
|
||||||
|
#elif (LCD_HEIGHT <= 132)
|
||||||
|
rb->lcd_puts(0, 2, "Swap pairs of jewels to");
|
||||||
|
rb->lcd_puts(0, 3, "form connected segments");
|
||||||
|
rb->lcd_puts(0, 4, "of three or more of the");
|
||||||
|
rb->lcd_puts(0, 5, "same type.");
|
||||||
|
rb->lcd_puts(0, 7, "Controls:");
|
||||||
|
rb->lcd_puts(0, 8, "Directions to move");
|
||||||
|
rb->lcd_puts(0, 9, "SELECT to select");
|
||||||
|
rb->lcd_puts(0, 10, "Long SELECT to show menu");
|
||||||
|
#else
|
||||||
|
rb->lcd_puts(0, 2, "Swap pairs of jewels to form");
|
||||||
|
rb->lcd_puts(0, 3, "connected segments of three");
|
||||||
|
rb->lcd_puts(0, 4, "or more of the same type.");
|
||||||
|
rb->lcd_puts(0, 6, "Controls:");
|
||||||
|
rb->lcd_puts(0, 7, "Directions to move cursor");
|
||||||
|
rb->lcd_puts(0, 8, "SELECT to select");
|
||||||
|
rb->lcd_puts(0, 9, "Long SELECT to show menu");
|
||||||
|
#endif
|
||||||
|
rb->lcd_update();
|
||||||
|
while(true) {
|
||||||
|
button = rb->button_get(true);
|
||||||
|
if(button != BUTTON_NONE && !(button&BUTTON_REL)) break;
|
||||||
|
}
|
||||||
|
rb->lcd_clear_display();
|
||||||
|
continue;
|
||||||
|
|
||||||
/* print high scores */
|
case MRES_QUIT:
|
||||||
for(i=0; i<NUM_SCORES; i++) {
|
return BJ_QUIT;
|
||||||
rb->snprintf(str, 11, "#%02d: %d", i+1, bj->highscores[i]);
|
|
||||||
rb->lcd_puts(0, i+j, str);
|
default:
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb->lcd_update();
|
|
||||||
|
|
||||||
/* handle menu button presses */
|
/* handle menu button presses */
|
||||||
button = rb->button_get(true);
|
button = rb->button_get(true);
|
||||||
switch(button){
|
switch(button){
|
||||||
case BEJEWELED_START: /* start playing */
|
#ifdef BEJEWELED_SCROLLWHEEL
|
||||||
startgame = true;
|
case BEJEWELED_PREV:
|
||||||
break;
|
|
||||||
|
|
||||||
case BEJEWELED_QUIT: /* quit program */
|
|
||||||
if(showscores) {
|
|
||||||
showscores = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return BJ_QUIT;
|
|
||||||
|
|
||||||
case BEJEWELED_RESUME:/* resume game */
|
|
||||||
if(!bejeweled_loadgame(bj)) {
|
|
||||||
rb->splash(HZ*2, true, "Nothing to resume");
|
|
||||||
} else {
|
|
||||||
startgame = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BEJEWELED_SELECT:/* toggle high scores */
|
|
||||||
#ifdef BEJEWELED_SELECT_PRE
|
|
||||||
if(lastbutton != BEJEWELED_SELECT_PRE) break;
|
|
||||||
#endif
|
#endif
|
||||||
showscores = !showscores;
|
case BEJEWELED_UP:
|
||||||
|
case (BEJEWELED_UP|BUTTON_REPEAT):
|
||||||
|
cmd = MCMD_PREV;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#ifdef BEJEWELED_SCROLLWHEEL
|
||||||
|
case BEJEWELED_NEXT:
|
||||||
|
#endif
|
||||||
|
case BEJEWELED_DOWN:
|
||||||
|
case (BEJEWELED_DOWN|BUTTON_REPEAT):
|
||||||
|
cmd = MCMD_NEXT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BEJEWELED_SELECT:
|
||||||
|
case BEJEWELED_RIGHT:
|
||||||
|
cmd = MCMD_SELECT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
#ifdef BEJEWELED_CANCEL
|
||||||
|
case BEJEWELED_CANCEL:
|
||||||
|
return BJ_QUIT;
|
||||||
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if(rb->default_event_handler_ex(button, bejeweled_callback,
|
if(rb->default_event_handler_ex(button, bejeweled_callback,
|
||||||
(void*) bj) == SYS_USB_CONNECTED)
|
(void*) bj) == SYS_USB_CONNECTED)
|
||||||
return BJ_USB;
|
return BJ_USB;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(button != BUTTON_NONE) lastbutton = button;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastbutton = BUTTON_NONE;
|
|
||||||
|
|
||||||
/********************
|
/********************
|
||||||
* init *
|
* init *
|
||||||
********************/
|
********************/
|
||||||
|
@ -1094,33 +1211,47 @@ static int bejeweled(struct game_context* bj) {
|
||||||
* play *
|
* play *
|
||||||
**********************/
|
**********************/
|
||||||
while(true) {
|
while(true) {
|
||||||
/* refresh the board */
|
if(!inmenu) {
|
||||||
bejeweled_drawboard(bj);
|
/* refresh the board */
|
||||||
|
bejeweled_drawboard(bj);
|
||||||
|
|
||||||
/* display the cursor */
|
/* display the cursor */
|
||||||
if(selected) {
|
if(selected) {
|
||||||
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
||||||
rb->lcd_fillrect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS,
|
rb->lcd_fillrect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS,
|
||||||
TILE_WIDTH, TILE_HEIGHT);
|
TILE_WIDTH, TILE_HEIGHT);
|
||||||
rb->lcd_set_drawmode(DRMODE_SOLID);
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
||||||
|
} else {
|
||||||
|
rb->lcd_drawrect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS,
|
||||||
|
TILE_WIDTH, TILE_HEIGHT);
|
||||||
|
}
|
||||||
|
rb->lcd_update_rect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS,
|
||||||
|
TILE_WIDTH, TILE_HEIGHT);
|
||||||
} else {
|
} else {
|
||||||
rb->lcd_drawrect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS,
|
res = bejeweled_showmenu(&bjmenu[1], cmd);
|
||||||
TILE_WIDTH, TILE_HEIGHT);
|
cmd = MCMD_NONE;
|
||||||
|
switch(res) {
|
||||||
|
case MRES_RESUME:
|
||||||
|
inmenu = false;
|
||||||
|
selected = false;
|
||||||
|
continue;
|
||||||
|
|
||||||
|
case MRES_SAVE:
|
||||||
|
rb->splash(HZ, true, "Saving game...");
|
||||||
|
bejeweled_savegame(bj);
|
||||||
|
return BJ_END;
|
||||||
|
|
||||||
|
case MRES_QUIT:
|
||||||
|
return BJ_END;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rb->lcd_update_rect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS,
|
|
||||||
TILE_WIDTH, TILE_HEIGHT);
|
|
||||||
|
|
||||||
/* handle game button presses */
|
/* handle game button presses */
|
||||||
button = rb->button_get(true);
|
button = rb->button_get(true);
|
||||||
switch(button){
|
switch(button){
|
||||||
case BEJEWELED_RESUME: /* save and end game */
|
|
||||||
rb->splash(HZ, true, "Saving game...");
|
|
||||||
bejeweled_savegame(bj);
|
|
||||||
return BJ_END;
|
|
||||||
|
|
||||||
case BEJEWELED_QUIT: /* end game */
|
|
||||||
return BJ_END;
|
|
||||||
|
|
||||||
case BEJEWELED_LEFT: /* move cursor left */
|
case BEJEWELED_LEFT: /* move cursor left */
|
||||||
case (BEJEWELED_LEFT|BUTTON_REPEAT):
|
case (BEJEWELED_LEFT|BUTTON_REPEAT):
|
||||||
if(selected) {
|
if(selected) {
|
||||||
|
@ -1134,66 +1265,98 @@ static int bejeweled(struct game_context* bj) {
|
||||||
|
|
||||||
case BEJEWELED_RIGHT: /* move cursor right */
|
case BEJEWELED_RIGHT: /* move cursor right */
|
||||||
case (BEJEWELED_RIGHT|BUTTON_REPEAT):
|
case (BEJEWELED_RIGHT|BUTTON_REPEAT):
|
||||||
if(selected) {
|
if(!inmenu) {
|
||||||
bj->score += bejeweled_swapjewels(bj, x, y, SWAP_RIGHT);
|
if(selected) {
|
||||||
selected = false;
|
bj->score += bejeweled_swapjewels(bj, x, y, SWAP_RIGHT);
|
||||||
if (!bejeweled_movesavail(bj)) return BJ_LOSE;
|
selected = false;
|
||||||
|
if (!bejeweled_movesavail(bj)) return BJ_LOSE;
|
||||||
|
} else {
|
||||||
|
x = (x+1)%BJ_WIDTH;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
x = (x+1)%BJ_WIDTH;
|
cmd = MCMD_SELECT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BEJEWELED_DOWN: /* move cursor down */
|
case BEJEWELED_DOWN: /* move cursor down */
|
||||||
case (BEJEWELED_DOWN|BUTTON_REPEAT):
|
case (BEJEWELED_DOWN|BUTTON_REPEAT):
|
||||||
if(selected) {
|
if(!inmenu) {
|
||||||
bj->score += bejeweled_swapjewels(bj, x, y, SWAP_DOWN);
|
if(selected) {
|
||||||
selected = false;
|
bj->score += bejeweled_swapjewels(bj, x, y, SWAP_DOWN);
|
||||||
if (!bejeweled_movesavail(bj)) return BJ_LOSE;
|
selected = false;
|
||||||
|
if (!bejeweled_movesavail(bj)) return BJ_LOSE;
|
||||||
|
} else {
|
||||||
|
y = (y+1)%(BJ_HEIGHT-1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
y = (y+1)%(BJ_HEIGHT-1);
|
cmd = MCMD_NEXT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BEJEWELED_UP: /* move cursor up */
|
case BEJEWELED_UP: /* move cursor up */
|
||||||
case (BEJEWELED_UP|BUTTON_REPEAT):
|
case (BEJEWELED_UP|BUTTON_REPEAT):
|
||||||
if(selected) {
|
if(!inmenu) {
|
||||||
bj->score += bejeweled_swapjewels(bj, x, y, SWAP_UP);
|
if(selected) {
|
||||||
selected = false;
|
bj->score += bejeweled_swapjewels(bj, x, y, SWAP_UP);
|
||||||
if (!bejeweled_movesavail(bj)) return BJ_LOSE;
|
selected = false;
|
||||||
|
if (!bejeweled_movesavail(bj)) return BJ_LOSE;
|
||||||
|
} else {
|
||||||
|
y = (y+(BJ_HEIGHT-1)-1)%(BJ_HEIGHT-1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
y = (y+(BJ_HEIGHT-1)-1)%(BJ_HEIGHT-1);
|
cmd = MCMD_PREV;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef BEJEWELED_SCROLLWHEEL
|
#ifdef BEJEWELED_SCROLLWHEEL
|
||||||
case BEJEWELED_PREV: /* scroll backwards */
|
case BEJEWELED_PREV: /* scroll backwards */
|
||||||
case (BEJEWELED_PREV|BUTTON_REPEAT):
|
case (BEJEWELED_PREV|BUTTON_REPEAT):
|
||||||
if(!selected) {
|
if(!inmenu) {
|
||||||
if(x == 0) {
|
if(!selected) {
|
||||||
y = (y+(BJ_HEIGHT-1)-1)%(BJ_HEIGHT-1);
|
if(x == 0) {
|
||||||
|
y = (y+(BJ_HEIGHT-1)-1)%(BJ_HEIGHT-1);
|
||||||
|
}
|
||||||
|
x = (x+BJ_WIDTH-1)%BJ_WIDTH;
|
||||||
}
|
}
|
||||||
x = (x+BJ_WIDTH-1)%BJ_WIDTH;
|
} else {
|
||||||
|
cmd = MCMD_PREV;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BEJEWELED_NEXT: /* scroll forwards */
|
case BEJEWELED_NEXT: /* scroll forwards */
|
||||||
case (BEJEWELED_NEXT|BUTTON_REPEAT):
|
case (BEJEWELED_NEXT|BUTTON_REPEAT):
|
||||||
if(!selected) {
|
if(!inmenu) {
|
||||||
if(x == BJ_WIDTH-1) {
|
if(!selected) {
|
||||||
y = (y+1)%(BJ_HEIGHT-1);
|
if(x == BJ_WIDTH-1) {
|
||||||
|
y = (y+1)%(BJ_HEIGHT-1);
|
||||||
|
}
|
||||||
|
x = (x+1)%BJ_WIDTH;
|
||||||
}
|
}
|
||||||
x = (x+1)%BJ_WIDTH;
|
} else {
|
||||||
|
cmd = MCMD_NEXT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case BEJEWELED_SELECT: /* toggle selected */
|
case BEJEWELED_SELECT: /* toggle selected */
|
||||||
#ifdef BEJEWELED_SELECT_PRE
|
if(!inmenu) {
|
||||||
if(lastbutton != BEJEWELED_SELECT_PRE) break;
|
selected = !selected;
|
||||||
#endif
|
} else {
|
||||||
selected = !selected;
|
cmd = MCMD_SELECT;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case (BEJEWELED_SELECT|BUTTON_REPEAT): /* show menu */
|
||||||
|
if(!inmenu) inmenu = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
#ifdef BEJEWELED_CANCEL
|
||||||
|
case BEJEWELED_CANCEL: /* toggle menu */
|
||||||
|
inmenu = !inmenu;
|
||||||
|
selected = false;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if(rb->default_event_handler_ex(button, bejeweled_callback,
|
if(rb->default_event_handler_ex(button, bejeweled_callback,
|
||||||
(void*) bj) == SYS_USB_CONNECTED)
|
(void*) bj) == SYS_USB_CONNECTED)
|
||||||
|
@ -1201,7 +1364,6 @@ static int bejeweled(struct game_context* bj) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(button != BUTTON_NONE) lastbutton = button;
|
|
||||||
if(bj->score >= LEVEL_PTS) bj->score = bejeweled_nextlevel(bj);
|
if(bj->score >= LEVEL_PTS) bj->score = bejeweled_nextlevel(bj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue