--- ./patch_rockbox/apps/plugins/brickmania.c 2009-03-14 17:48:42.000000000 +0100 +++ change_rockbox/apps/plugins/brickmania.c 2009-03-17 23:14:09.000000000 +0100 @@ -20,27 +20,23 @@ ****************************************************************************/ #include "plugin.h" -#include "lib/configfile.h" /* Part of libplugin */ +#include "lib/configfile.h" #include "lib/helper.h" #include "lib/playback_control.h" PLUGIN_HEADER - -#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) - +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ + (CONFIG_KEYPAD == IRIVER_H300_PAD) #define QUIT BUTTON_OFF #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT #define SELECT BUTTON_SELECT #define UP BUTTON_UP #define DOWN BUTTON_DOWN - #define RC_QUIT BUTTON_RC_STOP - #elif CONFIG_KEYPAD == ONDIO_PAD - #define QUIT BUTTON_OFF #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT @@ -48,9 +44,7 @@ #define UP BUTTON_UP #define DOWN BUTTON_DOWN - #elif CONFIG_KEYPAD == RECORDER_PAD - #define QUIT BUTTON_OFF #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT @@ -58,9 +52,7 @@ #define UP BUTTON_UP #define DOWN BUTTON_DOWN - #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD - #define QUIT BUTTON_OFF #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT @@ -68,24 +60,19 @@ #define UP BUTTON_UP #define DOWN BUTTON_DOWN - #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ (CONFIG_KEYPAD == IPOD_3G_PAD) || \ (CONFIG_KEYPAD == IPOD_1G2G_PAD) - #define QUIT BUTTON_MENU #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT #define SELECT BUTTON_SELECT #define UP BUTTON_SCROLL_BACK #define DOWN BUTTON_SCROLL_FWD - #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD) #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK) - #elif (CONFIG_KEYPAD == GIGABEAT_PAD) - #define QUIT BUTTON_POWER #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT @@ -93,9 +80,7 @@ #define UP BUTTON_UP #define DOWN BUTTON_DOWN - #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD - #define QUIT BUTTON_POWER #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT @@ -103,25 +88,19 @@ #define UP BUTTON_UP #define DOWN BUTTON_DOWN - #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \ (CONFIG_KEYPAD == SANSA_FUZE_PAD) - -#define QUIT BUTTON_POWER -#define LEFT BUTTON_LEFT -#define RIGHT BUTTON_RIGHT -#define SELECT BUTTON_SELECT -#define UP BUTTON_SCROLL_BACK -#define DOWN BUTTON_SCROLL_FWD - +#define QUIT BUTTON_POWER +#define LEFT BUTTON_LEFT +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD) #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK) - -#elif CONFIG_KEYPAD == SANSA_C200_PAD || \ -CONFIG_KEYPAD == SANSA_CLIP_PAD || \ -CONFIG_KEYPAD == SANSA_M200_PAD - +#elif (CONFIG_KEYPAD == SANSA_C200_PAD) || \ + (CONFIG_KEYPAD == SANSA_M200_PAD) #define QUIT BUTTON_POWER #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT @@ -131,9 +110,15 @@ #define UP BUTTON_UP #define DOWN BUTTON_DOWN +#elif CONFIG_KEYPAD == SANSA_CLIP_PAD +#define QUIT BUTTON_POWER +#define LEFT BUTTON_LEFT +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN #elif CONFIG_KEYPAD == IRIVER_H10_PAD - #define QUIT BUTTON_POWER #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT @@ -142,7 +127,6 @@ #define DOWN BUTTON_SCROLL_DOWN #elif CONFIG_KEYPAD == GIGABEAT_S_PAD - #define QUIT BUTTON_BACK #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT @@ -151,7 +135,6 @@ #define DOWN BUTTON_DOWN #elif (CONFIG_KEYPAD == MROBE100_PAD) - #define QUIT BUTTON_POWER #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT @@ -160,21 +143,18 @@ #define DOWN BUTTON_DOWN #elif CONFIG_KEYPAD == IAUDIO_M3_PAD - #define QUIT BUTTON_RC_REC #define LEFT BUTTON_RC_REW #define RIGHT BUTTON_RC_FF #define SELECT BUTTON_RC_PLAY #define UP BUTTON_RC_VOL_UP #define DOWN BUTTON_RC_VOL_DOWN - #define RC_QUIT BUTTON_REC #elif CONFIG_KEYPAD == COWOND2_PAD #define QUIT BUTTON_POWER #elif CONFIG_KEYPAD == CREATIVEZVM_PAD - #define QUIT BUTTON_BACK #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT @@ -183,7 +163,6 @@ #define DOWN BUTTON_DOWN #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD - #define QUIT BUTTON_POWER #define LEFT BUTTON_LEFT #define RIGHT BUTTON_RIGHT @@ -196,6 +175,9 @@ #endif #ifdef HAVE_TOUCHSCREEN +#ifndef QUIT +#define QUIT BUTTON_TOUCHSCREEN +#endif #ifndef LEFT #define LEFT BUTTON_MIDLEFT #endif @@ -218,24 +200,6 @@ #define SCROLL_BACK(x) (0) #endif - -enum menu_items { - BM_START, - BM_RESUME, - BM_HELP, - BM_HIGHSCORE, - BM_PLAYBACK_CONTROL, - BM_QUIT -}; - -MENUITEM_STRINGLIST (main_menu, "Brickmania", NULL, - "Start", - "Resume", - "Help", - "High Score", - "Playback Control", - "Quit"); - #include "pluginbitmaps/brickmania_pads.h" #include "pluginbitmaps/brickmania_bricks.h" #include "pluginbitmaps/brickmania_powerups.h" @@ -746,6 +710,7 @@ int cur_level=0; int brick_on_board=0; int used_balls=1; +int difficult=0; typedef struct cube { int powertop; @@ -776,15 +741,16 @@ } sfire; sfire fire[30]; - int highscore; -#define MAX_POINTS 200000 /* i dont think it needs to be more */ +#define MAX_POINTS 500000 /* i dont think it needs to be more */ +#define HIGH_SCORE "brickmania.score" static struct configdata config[] = { {TYPE_INT, 0, MAX_POINTS, { .int_p = &highscore }, "highscore", NULL} }; -void int_game(int new_game) + +static void brickmania_int_game(int new_game) { int i,j; @@ -807,9 +773,12 @@ flip_sides=false; - if (new_game==1) + if (new_game==1) { brick_on_board=0; - + /* add one life per achieved level */ + if (difficult==0 && life<2) + life++; + } for(i=0;i<=7;i++) { for(j=0;j<=9;j++) { brick[i*10+j].poweruse=(levels[cur_level][i][j]==0?0:1); @@ -836,12 +805,15 @@ int sw,i,w; -/* sleep timer counting the score */ -void sleep (int secs) +/* brickmania_sleep timer counting the score */ +static void brickmania_sleep(int secs) { bool done=false; char s[20]; int count=0; + /* dublicate score */ + if (difficult==1) + score=score*2; while (!done) { @@ -866,72 +838,125 @@ } -/* forward declaration, used in game_menu */ -int help(int when); +/* forward declaration, used in brickmania_game_menu */ +static int brickmania_help(void); +static int brickmania_choose_difficult(void); -#define HIGH_SCORE "brickmania.score" -int game_menu(int when) +static int brickmania_game_menu(int when) { - /* clear any previous button presses (especially when coming from - * game over, but it doesn't hurt to do it always) - */ rb->button_clear_queue(); - int choice = 0; - while (1) { - choice = rb->do_menu(&main_menu, &choice, NULL, false); + if (when==1) { + MENUITEM_STRINGLIST (main_menu, "Brickmania Menu", NULL, + "Resume Game", + "Restart Game", + "Difficulty", + "Help", + "High Score", + "Playback Control", + "Quit"); + + while (1) { + choice = rb->do_menu(&main_menu, &choice, NULL, false); + switch (choice) { + case 0: + con_game=1; + return 0; + case 1: + score=0; + vscore=0; + life=2; + cur_level=0; + brickmania_int_game(1); + return 0; + case 2: + brickmania_choose_difficult(); + break; + case 3: + brickmania_help(); + break; + case 4: + rb->splashf(HZ*2, "High Score: %d", highscore); + break; + case 5: + playback_control(NULL); + break; + case 6: + return 1; + case MENU_ATTACHED_USB: + return 1; + default: + break; + } + } + } + else { + MENUITEM_STRINGLIST (main_menu, "Brickmania Menu", NULL, + "Start New Game", + "Difficulty", + "Help", + "High Score", + "Playback Control", + "Quit"); + + while (1) { + choice = rb->do_menu(&main_menu, &choice, NULL, false); + switch (choice) { + case 0: + score=0; + vscore=0; + life=2; + cur_level=0; + brickmania_int_game(1); + return 0; + case 1: + brickmania_choose_difficult(); + break; + case 2: + brickmania_help(); + break; + case 3: + rb->splashf(HZ*2, "High Score: %d", highscore); + break; + case 4: + playback_control(NULL); + break; + case 5: + return 1; + case MENU_ATTACHED_USB: + return 1; + default: + break; + } + } + } +} +/* submenu to choose difficult */ +static int brickmania_choose_difficult(void) +{ + rb->button_clear_queue(); + int choice = difficult; + MENUITEM_STRINGLIST (main_menu, "Brickmania Difficulty", NULL, + "Easy", + "Hard",); + choice = rb->do_menu(&main_menu, &choice, NULL, false); switch (choice) { - case BM_START: - score=0; - vscore=0; - life=2; - cur_level=0; - int_game(1); - return choice; - - case BM_RESUME: - /* resume if we can */ - if (when==1) - return choice; - else - rb->splash(HZ/2, "Nothing to resume!"); + case 0: + difficult=0; break; - - case BM_HELP: - if (help(when)==1) - return BM_QUIT; - else - return choice; - - case BM_HIGHSCORE: - rb->splashf(HZ*2, "High Score: %d", highscore); - break; - - case BM_PLAYBACK_CONTROL: - playback_control(NULL); + case 1: + difficult=1; break; - - case BM_QUIT: - case MENU_ATTACHED_USB: - return BM_QUIT; - - case GO_TO_ROOT: - case GO_TO_PREVIOUS: - /* Resume if we can resume, otherwise quit */ - if (when==1) - return BM_RESUME; - else - return BM_QUIT; - default: break; } - } + rb->button_clear_queue(); + return 0; } -int help(int when) +static int brickmania_help(void) { int w,h; int button; @@ -942,7 +967,7 @@ int maxY=180; int maxX=215; - while(true) { + while(1) { #ifdef HAVE_LCD_COLOR rb->lcd_set_background(LCD_BLACK); rb->lcd_clear_display(); @@ -1019,36 +1044,23 @@ #ifdef RC_QUIT case RC_QUIT: #endif -#ifdef HAVE_TOUCHSCREEN - case BUTTON_TOUCHSCREEN: -#endif case QUIT: - switch (game_menu(when)) { - case BM_RESUME: - con_game=1; - break; - case BM_QUIT: - return 1; - default: - break; - } return 0; - break; - case LEFT: - case LEFT | BUTTON_REPEAT: #ifdef ALTLEFT case ALTLEFT: case ALTLEFT | BUTTON_REPEAT: #endif + case LEFT: + case LEFT | BUTTON_REPEAT: if( xoffset<0) xoffset+=2; break; - case RIGHT: - case RIGHT | BUTTON_REPEAT: #ifdef ALTRIGHT case ALTRIGHT: case ALTRIGHT | BUTTON_REPEAT: #endif + case RIGHT: + case RIGHT | BUTTON_REPEAT: if(xoffset+maxX > LCD_WIDTH) xoffset-=2; break; @@ -1062,19 +1074,16 @@ if(yoffset+maxY > LCD_HEIGHT) yoffset-=2; break; - default: if(rb->default_event_handler(button) == SYS_USB_CONNECTED) return 1; break; } - rb->yield(); } - return 0; } -int pad_check(int ballxc, int mode, int pon ,int ballnum) +static int brickmania_pad_check(int ballxc, int mode, int pon ,int ballnum) { /* pon: positive(1) or negative(0) */ @@ -1091,7 +1100,7 @@ } } -int fire_space(void) +static int brickmania_fire_space(void) { int t; for(t=0;t<=30;t++) @@ -1101,7 +1110,7 @@ return 0; } -int game_loop(void) +static int brickmania_game_loop(void) { int j,i,k,bricky,brickx; char s[30]; @@ -1112,14 +1121,8 @@ configfile_load(HIGH_SCORE,config,1,0); - switch(game_menu(0)) { - case BM_RESUME: - con_game=1; - break; - case BM_QUIT: - return 1; - default: - break; + if (brickmania_game_menu(0)!=0) { + return 1; } while(true) { @@ -1249,8 +1252,8 @@ case 1: life--; if (life>=0) { - int_game(0); - sleep(2); + brickmania_int_game(0); + brickmania_sleep(2); } break; case 2: @@ -1533,8 +1536,8 @@ } else { life--; if (life>=0) { - int_game(0); - sleep(2); + brickmania_int_game(0); + brickmania_sleep(2); } } } @@ -1561,7 +1564,7 @@ ball[k].y = -2; if (ball[k].pos_x != 0 && ball[k].pos_x+BALL!=LCD_WIDTH) - ball[k].x = pad_check(6,0,ball[k].pos_x+2<= + ball[k].x = brickmania_pad_check(6,0,ball[k].pos_x+2<= pad_pos_x+(PAD_WIDTH/2)? 0:1,k); @@ -1578,7 +1581,7 @@ ball[k].y = -3; if (ball[k].pos_x != 0 && ball[k].pos_x+BALL!=LCD_WIDTH) - ball[k].x = pad_check(4,0,ball[k].pos_x+2<= + ball[k].x = brickmania_pad_check(4,0,ball[k].pos_x+2<= pad_pos_x+(PAD_WIDTH/2)? 0:1,k); @@ -1595,7 +1598,7 @@ ball[k].y = -4; if (ball[k].pos_x != 0 && ball[k].pos_x+BALL!=LCD_WIDTH) - ball[k].x = pad_check(3,0,ball[k].pos_x+2<= + ball[k].x = brickmania_pad_check(3,0,ball[k].pos_x+2<= pad_pos_x+(PAD_WIDTH/2)? 0:1,k); @@ -1611,7 +1614,7 @@ ball[k].y = -4; if (ball[k].pos_x != 0 && ball[k].pos_x+BALL!=LCD_WIDTH) - ball[k].x = pad_check(2,1,0,k); + ball[k].x = brickmania_pad_check(2,1,0,k); } else { @@ -1643,8 +1646,8 @@ if (cur_level+1lcd_getstringsize("Congratulations!", &sw, NULL); @@ -1663,22 +1666,16 @@ vscore=score; rb->lcd_update(); if (score>highscore) { - sleep(2); + brickmania_sleep(2); highscore=score; rb->splash(HZ*2, "New High Score"); } else { - sleep(3); + brickmania_sleep(3); } - switch(game_menu(0)) { - case BM_RESUME: - con_game=1; - break; - case BM_QUIT: - return 1; - default: - break; + if (brickmania_game_menu(0)!=0) { + return 1; } } } @@ -1790,10 +1787,10 @@ } } else if (pad_type==2 && con_game!=1) { int tfire; - tfire=fire_space(); + tfire=brickmania_fire_space(); fire[tfire].top=PAD_POS_Y-7; fire[tfire].left=pad_pos_x+1; - tfire=fire_space(); + tfire=brickmania_fire_space(); fire[tfire].top=PAD_POS_Y-7; fire[tfire].left=pad_pos_x+PAD_WIDTH-1; } else if (con_game==1 && start_game!=1) { @@ -1808,16 +1805,8 @@ case RC_QUIT: #endif case QUIT: - switch(game_menu(1)) { - case BM_RESUME: - for(k=0;klcd_update(); if (score>highscore) { - sleep(2); + brickmania_sleep(2); highscore=score; rb->splash(HZ*2, "New High Score"); } else { - sleep(3); + brickmania_sleep(3); } for(k=0;k *rb->current_tick) @@ -1892,7 +1875,7 @@ backlight_force_on(); /* backlight control in lib/helper.c */ /* now go ahead and have fun! */ - while (game_loop()!=1); + brickmania_game_loop(); configfile_save(HIGH_SCORE,config,1,0);