summaryrefslogtreecommitdiff
path: root/apps/plugins/brickmania.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/brickmania.c')
-rw-r--r--apps/plugins/brickmania.c667
1 files changed, 330 insertions, 337 deletions
diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c
index c2bcd3da0c..e89eb2d748 100644
--- a/apps/plugins/brickmania.c
+++ b/apps/plugins/brickmania.c
@@ -247,34 +247,22 @@ CONFIG_KEYPAD == SANSA_M200_PAD
247 247
248#define TOPMARGIN (BRICK_HEIGHT * 2) 248#define TOPMARGIN (BRICK_HEIGHT * 2)
249 249
250#define HIGHSCORE_XPOS (LCD_WIDTH - 60)
251#define HIGHSCORE_YPOS 0
252
253#define STRINGPOS_FINISH (LCD_HEIGHT - (LCD_HEIGHT / 6))
254#define STRINGPOS_CONGRATS (STRINGPOS_FINISH - 20)
255#define STRINGPOS_NAVI (STRINGPOS_FINISH - 10)
256#define STRINGPOS_FLIP (STRINGPOS_FINISH - 10)
257
258#if LCD_WIDTH<=LCD_HEIGHT 250#if LCD_WIDTH<=LCD_HEIGHT
259/* Maintain a 4/3 ratio (Width/Height) */ 251/* Maintain a 4/3 ratio (Width/Height) */
260#define GAMESCREEN_HEIGHT (LCD_WIDTH * 3 / 4) 252#define GAMESCREEN_HEIGHT (LCD_WIDTH * 3 / 4)
261#define BMPYOFS_start (LCD_HEIGHT / 2)
262#else 253#else
263#define GAMESCREEN_HEIGHT LCD_HEIGHT 254#define GAMESCREEN_HEIGHT LCD_HEIGHT
264#define BMPYOFS_start (LCD_HEIGHT / 3)
265#endif 255#endif
266 256
267/* calculate menu item offsets from the first defined and the height*/ 257#define STRINGPOS_FINISH (GAMESCREEN_HEIGHT - (GAMESCREEN_HEIGHT / 6))
268#define BMPYOFS_resume (BMPYOFS_start + MENU_ITEMHEIGHT) 258#define STRINGPOS_CONGRATS (STRINGPOS_FINISH - 20)
269#define BMPYOFS_help (BMPYOFS_start + 2*MENU_ITEMHEIGHT) 259#define STRINGPOS_NAVI (STRINGPOS_FINISH - 10)
270#define BMPYOFS_quit (BMPYOFS_start + 3*MENU_ITEMHEIGHT) 260#define STRINGPOS_FLIP (STRINGPOS_FINISH - 10)
271 261
272/*calculate paddle y-position */ 262/*calculate paddle y-position */
273#define PAD_POS_Y (GAMESCREEN_HEIGHT - PAD_HEIGHT - 1) 263#define PAD_POS_Y (GAMESCREEN_HEIGHT - PAD_HEIGHT - 1)
274 264
275 265
276#define MARGIN 5
277
278int levels_num = 29; 266int levels_num = 29;
279 267
280static unsigned char levels[29][8][10] = { 268static unsigned char levels[29][8][10] = {
@@ -573,23 +561,22 @@ static unsigned char levels[29][8][10] = {
573#define MAX_BALLS 10 561#define MAX_BALLS 10
574 562
575enum difficulty_options { 563enum difficulty_options {
576 EASY, HARD 564 EASY, NORMAL
577}; 565};
578 566
579int pad_pos_x; 567int pad_pos_x;
580int x[MAX_BALLS],y[MAX_BALLS];
581int life; 568int life;
582int start_game,con_game; 569enum { ST_READY, ST_START, ST_PAUSE } game_state = ST_READY;
583int pad_type; 570int pad_type;
584int score=0,vscore=0; 571int score=0,vscore=0;
585bool flip_sides=false; 572bool flip_sides=false;
586int level=0; 573int level=0;
587int brick_on_board=0; 574int brick_on_board=0;
588int used_balls=1; 575int used_balls=1;
589bool saved_game=false; 576int difficulty = NORMAL;
590int l_score=0;
591int difficulty = EASY;
592int pad_width; 577int pad_width;
578int num_count;
579bool resume = false;
593 580
594typedef struct cube { 581typedef struct cube {
595 int powertop; 582 int powertop;
@@ -621,21 +608,17 @@ typedef struct sfire {
621sfire fire[30]; 608sfire fire[30];
622 609
623#define CONFIG_FILE_NAME "brickmania.cfg" 610#define CONFIG_FILE_NAME "brickmania.cfg"
611#define SAVE_FILE PLUGIN_GAMES_DIR "/brickmania.save"
612#define HIGH_SCORE PLUGIN_GAMES_DIR "/brickmania.score"
613#define NUM_SCORES 5
624 614
625static struct configdata config[] = { 615static struct configdata config[] = {
626 {TYPE_INT, 0, 1, { .int_p = &difficulty }, "difficulty", NULL}, 616 {TYPE_INT, 0, 1, { .int_p = &difficulty }, "difficulty", NULL},
627 {TYPE_BOOL, 0, 1, { .bool_p = &saved_game }, "saved_game", NULL},
628 {TYPE_INT, 0, 40000, { .int_p = &l_score }, "l_score", NULL},
629 {TYPE_INT, 0, 29, { .int_p = &level }, "level", NULL},
630 {TYPE_INT, 0, 30, { .int_p = &life }, "life", NULL},
631}; 617};
632 618
633#define HIGH_SCORE PLUGIN_GAMES_DIR "/brickmania.score"
634#define NUM_SCORES 5
635
636struct highscore highest[NUM_SCORES]; 619struct highscore highest[NUM_SCORES];
637 620
638static void brickmania_int_game(int new_game) 621static void brickmania_init_game(int new_game)
639{ 622{
640 int i,j; 623 int i,j;
641 624
@@ -652,11 +635,11 @@ static void brickmania_int_game(int new_game)
652 } 635 }
653 636
654 used_balls=1; 637 used_balls=1;
655 start_game =1; 638 game_state=ST_READY;
656 con_game =0;
657 pad_type=0; 639 pad_type=0;
658 pad_width=PAD_WIDTH; 640 pad_width=PAD_WIDTH;
659 flip_sides=false; 641 flip_sides=false;
642 num_count=10;
660 643
661 if (new_game==1) { 644 if (new_game==1) {
662 brick_on_board=0; 645 brick_on_board=0;
@@ -666,11 +649,12 @@ static void brickmania_int_game(int new_game)
666 life++; 649 life++;
667 } 650 }
668 } 651 }
652 for(i=0;i<30;i++) {
653 fire[i].top=-8;
654 }
669 for(i=0;i<=7;i++) { 655 for(i=0;i<=7;i++) {
670 for(j=0;j<=9;j++) { 656 for(j=0;j<=9;j++) {
671 brick[i*10+j].poweruse=(levels[level][i][j]==0?0:1); 657 brick[i*10+j].poweruse=(levels[level][i][j]==0?0:1);
672 if (i*10+j<=30)
673 fire[i*10+j].top=-8;
674 if (new_game==1) { 658 if (new_game==1) {
675 brick[i*10+j].power=rb->rand()%25; 659 brick[i*10+j].power=rb->rand()%25;
676 /* +8 make the game with less powerups */ 660 /* +8 make the game with less powerups */
@@ -690,7 +674,66 @@ static void brickmania_int_game(int new_game)
690 } 674 }
691} 675}
692 676
693int sw,i,w; 677static void brickmania_loadgame(void)
678{
679 int fd;
680
681 resume = false;
682
683 /* open game file */
684 fd = rb->open(SAVE_FILE, O_RDONLY);
685 if(fd < 0) return;
686
687 /* read in saved game */
688 while(true) {
689 if(rb->read(fd, &pad_pos_x, sizeof(pad_pos_x)) <= 0) break;
690 if(rb->read(fd, &life, sizeof(life)) <= 0) break;
691 if(rb->read(fd, &game_state, sizeof(game_state)) <= 0) break;
692 if(rb->read(fd, &pad_type, sizeof(pad_type)) <= 0) break;
693 if(rb->read(fd, &score, sizeof(score)) <= 0) break;
694 if(rb->read(fd, &flip_sides, sizeof(flip_sides)) <= 0) break;
695 if(rb->read(fd, &level, sizeof(level)) <= 0) break;
696 if(rb->read(fd, &brick_on_board, sizeof(brick_on_board)) <= 0) break;
697 if(rb->read(fd, &used_balls, sizeof(used_balls)) <= 0) break;
698 if(rb->read(fd, &pad_width, sizeof(pad_width)) <= 0) break;
699 if(rb->read(fd, &num_count, sizeof(num_count)) <= 0) break;
700 if(rb->read(fd, &brick, sizeof(brick)) <= 0) break;
701 if(rb->read(fd, &ball, sizeof(ball)) <= 0) break;
702 if(rb->read(fd, &fire, sizeof(fire)) <= 0) break;
703 vscore = score;
704 resume = true;
705 break;
706 }
707
708 rb->close(fd);
709
710 /* delete saved file */
711 rb->remove(SAVE_FILE);
712 return;
713}
714
715static void brickmania_savegame(void)
716{
717 int fd;
718
719 /* write out the game state to the save file */
720 fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
721 rb->write(fd, &pad_pos_x, sizeof(pad_pos_x));
722 rb->write(fd, &life, sizeof(life));
723 rb->write(fd, &game_state, sizeof(game_state));
724 rb->write(fd, &pad_type, sizeof(pad_type));
725 rb->write(fd, &score, sizeof(score));
726 rb->write(fd, &flip_sides, sizeof(flip_sides));
727 rb->write(fd, &level, sizeof(level));
728 rb->write(fd, &brick_on_board, sizeof(brick_on_board));
729 rb->write(fd, &used_balls, sizeof(used_balls));
730 rb->write(fd, &pad_width, sizeof(pad_width));
731 rb->write(fd, &num_count, sizeof(num_count));
732 rb->write(fd, &brick, sizeof(brick));
733 rb->write(fd, &ball, sizeof(ball));
734 rb->write(fd, &fire, sizeof(fire));
735 rb->close(fd);
736}
694 737
695/* brickmania_sleep timer counting the score */ 738/* brickmania_sleep timer counting the score */
696static void brickmania_sleep(int secs) 739static void brickmania_sleep(int secs)
@@ -698,6 +741,7 @@ static void brickmania_sleep(int secs)
698 bool done=false; 741 bool done=false;
699 char s[20]; 742 char s[20];
700 int count=0; 743 int count=0;
744 int sw, w;
701 745
702 while (!done) { 746 while (!done) {
703 if (vscore == score) { 747 if (vscore == score) {
@@ -725,7 +769,6 @@ static void brickmania_sleep(int secs)
725 769
726static int brickmania_help(void) 770static int brickmania_help(void)
727{ 771{
728 rb->lcd_setfont(FONT_UI);
729#define WORDS (sizeof help_text / sizeof (char*)) 772#define WORDS (sizeof help_text / sizeof (char*))
730 static char *help_text[] = { 773 static char *help_text[] = {
731 "Brickmania", "", "Aim", "", 774 "Brickmania", "", "Aim", "",
@@ -744,7 +787,7 @@ static int brickmania_help(void)
744#endif 787#endif
745 "Releases", "the", "ball/Fire!", "", 788 "Releases", "the", "ball/Fire!", "",
746#if CONFIG_KEYPAD == IAUDIO_M3_PAD 789#if CONFIG_KEYPAD == IAUDIO_M3_PAD
747 "REC:", 790 "REC:",
748#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \ 791#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
749 (CONFIG_KEYPAD == CREATIVEZVM_PAD) 792 (CONFIG_KEYPAD == CREATIVEZVM_PAD)
750 "BACK:", 793 "BACK:",
@@ -772,7 +815,7 @@ static int brickmania_help(void)
772 "B", "Ball:", "generates", "another", "ball", "", 815 "B", "Ball:", "generates", "another", "ball", "",
773 "FL", "Flip:", "flips", "left / right", "movement", "", 816 "FL", "Flip:", "flips", "left / right", "movement", "",
774 "<->", "or", "<E>:", "enlarges", "the", "paddle", "", 817 "<->", "or", "<E>:", "enlarges", "the", "paddle", "",
775 ">-<", "or", ">B<:", "shrinks", "the", "paddle", "", 818 ">-<", "or", ">S<:", "shrinks", "the", "paddle", "",
776 }; 819 };
777 static struct style_text formation[]={ 820 static struct style_text formation[]={
778 { 0, TEXT_CENTER|TEXT_UNDERLINE }, 821 { 0, TEXT_CENTER|TEXT_UNDERLINE },
@@ -788,76 +831,64 @@ static int brickmania_help(void)
788 { 80, C_RED }, 831 { 80, C_RED },
789 { -1, 0 } 832 { -1, 0 }
790 }; 833 };
791 834 int button;
835
836 rb->lcd_setfont(FONT_UI);
792#ifdef HAVE_LCD_COLOR 837#ifdef HAVE_LCD_COLOR
793 rb->lcd_set_background(LCD_BLACK); 838 rb->lcd_set_background(LCD_BLACK);
794 rb->lcd_set_foreground(LCD_WHITE); 839 rb->lcd_set_foreground(LCD_WHITE);
795#endif 840#endif
796 int button; 841
797 if (display_text(WORDS, help_text, formation, NULL)==PLUGIN_USB_CONNECTED) 842 if (display_text(WORDS, help_text, formation, NULL))
798 return PLUGIN_USB_CONNECTED; 843 return 1;
799 do { 844 do {
800 button = rb->button_get(true); 845 button = rb->button_get(true);
801 if (button == SYS_USB_CONNECTED) { 846 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
802 return PLUGIN_USB_CONNECTED; 847 return 1;
803 } 848 }
804 } while( ( button == BUTTON_NONE ) 849 } while( ( button == BUTTON_NONE )
805 || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); 850 || ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
806 rb->lcd_setfont(FONT_SYSFIXED); 851 rb->lcd_setfont(FONT_SYSFIXED);
807 return 0; 852 return 0;
808} 853}
809 854
810static bool _ingame;
811static int brickmania_menu_cb(int action, const struct menu_item_ex *this_item) 855static int brickmania_menu_cb(int action, const struct menu_item_ex *this_item)
812{ 856{
857 int i = ((intptr_t)this_item);
813 if(action == ACTION_REQUEST_MENUITEM 858 if(action == ACTION_REQUEST_MENUITEM
814 && !_ingame && ((intptr_t)this_item)==0) 859 && !resume && (i==0 || i==6))
815 return ACTION_EXIT_MENUITEM; 860 return ACTION_EXIT_MENUITEM;
816 return action; 861 return action;
817} 862}
818 863
819static int brickmania_menu(bool ingame) 864static int brickmania_menu(void)
820{ 865{
821 rb->button_clear_queue(); 866 int selected = 0;
822 int choice = 0;
823 867
824 _ingame = ingame;
825
826 static struct opt_items options[] = { 868 static struct opt_items options[] = {
827 { "Easy", -1 }, 869 { "Easy", -1 },
828 { "Hard", -1 }, 870 { "Normal", -1 },
829 }; 871 };
830 872
831 MENUITEM_STRINGLIST (main_menu, "Brickmania Menu", brickmania_menu_cb, 873 MENUITEM_STRINGLIST(main_menu, "Brickmania Menu", brickmania_menu_cb,
832 "Resume Game", 874 "Resume Game", "Start New Game",
833 "Start New Game", 875 "Difficulty", "Help", "High Scores",
834 "Difficulty", 876 "Playback Control",
835 "Help", 877 "Quit without Saving", "Quit");
836 "High Score", 878
837 "Playback Control", 879 rb->button_clear_queue();
838 "Quit");
839
840 while (true) { 880 while (true) {
841 switch (rb->do_menu(&main_menu, &choice, NULL, false)) { 881 switch (rb->do_menu(&main_menu, &selected, NULL, false)) {
842 case 0: 882 case 0:
843 if (saved_game) { 883 if(game_state!=ST_READY)
844 saved_game = false; 884 game_state = ST_PAUSE;
845 vscore=l_score-1;
846 score=l_score;
847 brickmania_int_game(1);
848 } else {
849 int i;
850 for(i=0;i<used_balls;i++)
851 if (ball[i].x!=0 && ball[i].y !=0)
852 con_game=1;
853 }
854 return 0; 885 return 0;
855 case 1: 886 case 1:
856 score=0; 887 score=0;
857 vscore=0; 888 vscore=0;
858 life=2; 889 life=2;
859 level=0; 890 level=0;
860 brickmania_int_game(1); 891 brickmania_init_game(1);
861 return 0; 892 return 0;
862 case 2: 893 case 2:
863 rb->set_option("Difficulty", &difficulty, INT, options, 2, NULL); 894 rb->set_option("Difficulty", &difficulty, INT, options, 2, NULL);
@@ -870,16 +901,15 @@ static int brickmania_menu(bool ingame)
870 highscore_show(NUM_SCORES, highest, NUM_SCORES); 901 highscore_show(NUM_SCORES, highest, NUM_SCORES);
871 break; 902 break;
872 case 5: 903 case 5:
873 playback_control(NULL); 904 if (playback_control(NULL))
905 return 1;
874 break; 906 break;
875 case 6: 907 case 6:
876 if (level>0 && ingame) { 908 return 1;
877 saved_game=true; 909 case 7:
878 rb->splash(HZ*1, "Saving last achieved level ..."); 910 if (resume) {
879 configfile_save(CONFIG_FILE_NAME,config,5,0); 911 rb->splash(HZ*1, "Saving game ...");
880 } else { 912 brickmania_savegame();
881 saved_game=false;
882 configfile_save(CONFIG_FILE_NAME,config,1,0);
883 } 913 }
884 return 1; 914 return 1;
885 case MENU_ATTACHED_USB: 915 case MENU_ATTACHED_USB:
@@ -910,7 +940,7 @@ static int brickmania_pad_check(int ballxc, int mode, int pon ,int ballnum)
910static int brickmania_fire_space(void) 940static int brickmania_fire_space(void)
911{ 941{
912 int t; 942 int t;
913 for(t=0;t<=30;t++) 943 for(t=0;t<30;t++)
914 if (fire[t].top+7 < 0) 944 if (fire[t].top+7 < 0)
915 return t; 945 return t;
916 946
@@ -920,23 +950,15 @@ static int brickmania_fire_space(void)
920static int brickmania_game_loop(void) 950static int brickmania_game_loop(void)
921{ 951{
922 int j,i,k,bricky,brickx; 952 int j,i,k,bricky,brickx;
953 int sw;
923 char s[30]; 954 char s[30];
924 int sec_count=0,num_count=10; 955 int sec_count=0;
925 int end; 956 int end;
926 int position;
927
928 configfile_load(CONFIG_FILE_NAME,config,5,0);
929 957
930 rb->srand( *rb->current_tick ); 958 if (brickmania_menu()!=0) {
931 if (saved_game) { 959 return 1;
932 if (brickmania_menu(true)!=0) {
933 return 1;
934 }
935 } else {
936 if (brickmania_menu(false)!=0) {
937 return 1;
938 }
939 } 960 }
961 resume = false;
940 962
941 while(true) { 963 while(true) {
942 /* Convert CYCLETIME (in ms) to HZ */ 964 /* Convert CYCLETIME (in ms) to HZ */
@@ -1000,7 +1022,7 @@ static int brickmania_game_loop(void)
1000#endif 1022#endif
1001 1023
1002 /* continue game */ 1024 /* continue game */
1003 if (con_game== 1 && start_game!=1) { 1025 if (game_state==ST_PAUSE) {
1004#if CONFIG_KEYPAD == ONDIO_PAD 1026#if CONFIG_KEYPAD == ONDIO_PAD
1005 rb->snprintf(s, sizeof(s), "MENU To Continue"); 1027 rb->snprintf(s, sizeof(s), "MENU To Continue");
1006#elif CONFIG_KEYPAD == IRIVER_H300_PAD 1028#elif CONFIG_KEYPAD == IRIVER_H300_PAD
@@ -1025,9 +1047,9 @@ static int brickmania_game_loop(void)
1025 brick_on_board--; 1047 brick_on_board--;
1026 1048
1027 /* if the pad is fire */ 1049 /* if the pad is fire */
1028 for(i=0;i<=30;i++) { 1050 for(i=0;i<30;i++) {
1029 if (fire[i].top+7>0) { 1051 if (fire[i].top+7>0) {
1030 if (con_game!=1) 1052 if (game_state!=ST_PAUSE)
1031 fire[i].top-=4; 1053 fire[i].top-=4;
1032 rb->lcd_vline(fire[i].left, fire[i].top, fire[i].top+7); 1054 rb->lcd_vline(fire[i].left, fire[i].top, fire[i].top+7);
1033 } 1055 }
@@ -1038,15 +1060,14 @@ static int brickmania_game_loop(void)
1038 for (j=0;j<=9;j++) { 1060 for (j=0;j<=9;j++) {
1039 if (brick[i*10+j].power<9) { 1061 if (brick[i*10+j].power<9) {
1040 if (brick[i*10+j].poweruse==2) { 1062 if (brick[i*10+j].poweruse==2) {
1041 if (con_game!=1) 1063 if (game_state!=ST_PAUSE)
1042 brick[i*10+j].powertop+=2; 1064 brick[i*10+j].powertop+=2;
1043 rb->lcd_bitmap_part(brickmania_powerups,0, 1065 rb->lcd_bitmap_part(brickmania_powerups,0,
1044 POWERUP_HEIGHT*brick[i*10+j 1066 POWERUP_HEIGHT*brick[i*10+j
1045 ].power, 1067 ].power,
1046 POWERUP_WIDTH, 1068 POWERUP_WIDTH,
1047 LEFTMARGIN+j*BRICK_WIDTH+ 1069 LEFTMARGIN+j*BRICK_WIDTH+
1048 (BRICK_WIDTH/2- 1070 (BRICK_WIDTH/2-POWERUP_WIDTH/2),
1049 POWERUP_WIDTH/2),
1050 brick[i*10+j].powertop, 1071 brick[i*10+j].powertop,
1051 POWERUP_WIDTH, 1072 POWERUP_WIDTH,
1052 POWERUP_HEIGHT); 1073 POWERUP_HEIGHT);
@@ -1065,7 +1086,7 @@ static int brickmania_game_loop(void)
1065 case 1: 1086 case 1:
1066 life--; 1087 life--;
1067 if (life>=0) { 1088 if (life>=0) {
1068 brickmania_int_game(0); 1089 brickmania_init_game(0);
1069 brickmania_sleep(2); 1090 brickmania_sleep(2);
1070 } 1091 }
1071 break; 1092 break;
@@ -1096,10 +1117,13 @@ static int brickmania_game_loop(void)
1096 break; 1117 break;
1097 case 6: 1118 case 6:
1098 score+=23; 1119 score+=23;
1099 used_balls++; 1120 if(used_balls<MAX_BALLS) {
1100 ball[used_balls-1].x= rb->rand()%1 == 0 ? 1121 ball[used_balls].x= rb->rand()%2 == 0 ?
1101 -1 : 1; 1122 -1 : 1;
1102 ball[used_balls-1].y= -4; 1123 ball[used_balls].y= -4;
1124 ball[used_balls].glue= false;
1125 used_balls++;
1126 }
1103 break; 1127 break;
1104 case 7: 1128 case 7:
1105 score+=23; 1129 score+=23;
@@ -1136,7 +1160,7 @@ static int brickmania_game_loop(void)
1136 brickx=LEFTMARGIN+j*BRICK_WIDTH; 1160 brickx=LEFTMARGIN+j*BRICK_WIDTH;
1137 bricky=TOPMARGIN+i*BRICK_HEIGHT; 1161 bricky=TOPMARGIN+i*BRICK_HEIGHT;
1138 if (pad_type==2) { 1162 if (pad_type==2) {
1139 for (k=0;k<=30;k++) { 1163 for (k=0;k<30;k++) {
1140 if (fire[k].top+7>0) { 1164 if (fire[k].top+7>0) {
1141 if (brick[i*10+j].used==1 && 1165 if (brick[i*10+j].used==1 &&
1142 (fire[k].left+1 >= brickx && 1166 (fire[k].left+1 >= brickx &&
@@ -1169,14 +1193,12 @@ static int brickmania_game_loop(void)
1169 BRICK_WIDTH, BRICK_HEIGHT); 1193 BRICK_WIDTH, BRICK_HEIGHT);
1170#ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */ 1194#ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */
1171 if (brick[i*10+j].hiteffect>0) 1195 if (brick[i*10+j].hiteffect>0)
1172 rb->lcd_bitmap_transparent_part(brickmania_break, 1196 rb->lcd_bitmap_transparent_part(brickmania_break,0,
1173 0,
1174 BRICK_HEIGHT*brick[i*10+j].hiteffect, 1197 BRICK_HEIGHT*brick[i*10+j].hiteffect,
1175 BRICK_WIDTH, 1198 BRICK_WIDTH,
1176 LEFTMARGIN+j*BRICK_WIDTH, 1199 LEFTMARGIN+j*BRICK_WIDTH,
1177 TOPMARGIN+i*BRICK_HEIGHT, 1200 TOPMARGIN+i*BRICK_HEIGHT,
1178 BRICK_WIDTH, 1201 BRICK_WIDTH, BRICK_HEIGHT);
1179 BRICK_HEIGHT);
1180#endif 1202#endif
1181 } 1203 }
1182 /* Somewhere in here collision checking is done b/w ball and 1204 /* Somewhere in here collision checking is done b/w ball and
@@ -1330,167 +1352,170 @@ static int brickmania_game_loop(void)
1330 } /* for i */ 1352 } /* for i */
1331 1353
1332 /* draw the pad */ 1354 /* draw the pad */
1333 rb->lcd_bitmap_part(pad_width==PAD_WIDTH?brickmania_pads:pad_width==LONG_PAD_WIDTH?brickmania_long_pads:brickmania_short_pads,0,pad_type*PAD_HEIGHT, 1355 rb->lcd_bitmap_part(pad_width==PAD_WIDTH?brickmania_pads:
1334 pad_width,pad_pos_x, PAD_POS_Y, pad_width, 1356 pad_width==LONG_PAD_WIDTH?brickmania_long_pads:
1335 PAD_HEIGHT); 1357 brickmania_short_pads,
1336 1358 0,pad_type*PAD_HEIGHT,pad_width,
1337 for(k=0;k<used_balls;k++) { 1359 pad_pos_x, PAD_POS_Y, pad_width, PAD_HEIGHT);
1338 1360
1339 if ((ball[k].pos_x >= pad_pos_x && 1361 if (game_state!=ST_PAUSE) {
1340 ball[k].pos_x <= pad_pos_x+pad_width) && 1362 for(k=0;k<used_balls;k++) {
1341 (PAD_POS_Y-4<ball[k].pos_y+BALL && 1363
1342 PAD_POS_Y>ball[k].pos_y+BALL) && (ball[k].y >0)) 1364 if ((ball[k].pos_x >= pad_pos_x &&
1343 ball[k].tempy=PAD_POS_Y-ball[k].pos_y-BALL; 1365 ball[k].pos_x <= pad_pos_x+pad_width) &&
1344 else if ((4>ball[k].pos_y && 0<ball[k].pos_y) && 1366 (PAD_POS_Y-4<ball[k].pos_y+BALL &&
1345 (ball[k].y <0)) 1367 PAD_POS_Y>ball[k].pos_y+BALL) && (ball[k].y >0))
1346 ball[k].tempy=-ball[k].pos_y; 1368 ball[k].tempy=PAD_POS_Y-ball[k].pos_y-BALL;
1347 if ((LCD_WIDTH-4<ball[k].pos_x+BALL && 1369 else if ((4>ball[k].pos_y && 0<ball[k].pos_y) &&
1348 LCD_WIDTH>ball[k].pos_x+BALL) && (ball[k].x >0)) 1370 (ball[k].y <0))
1349 ball[k].tempx=LCD_WIDTH-ball[k].pos_x-BALL; 1371 ball[k].tempy=-ball[k].pos_y;
1350 else if ((4>ball[k].pos_x && 0<ball[k].pos_x) && 1372 if ((LCD_WIDTH-4<ball[k].pos_x+BALL &&
1351 (ball[k].x <0)) 1373 LCD_WIDTH>ball[k].pos_x+BALL) && (ball[k].x >0))
1352 ball[k].tempx=-ball[k].pos_x; 1374 ball[k].tempx=LCD_WIDTH-ball[k].pos_x-BALL;
1353 1375 else if ((4>ball[k].pos_x && 0<ball[k].pos_x) &&
1354 /* top line */ 1376 (ball[k].x <0))
1355 if (ball[k].pos_y<= 0) 1377 ball[k].tempx=-ball[k].pos_x;
1356 ball[k].y = ball[k].y*-1; 1378
1357 /* bottom line */ 1379 /* top line */
1358 else if (ball[k].pos_y+BALL >= GAMESCREEN_HEIGHT) { 1380 if (ball[k].pos_y<= 0)
1359 if (used_balls>1) { 1381 ball[k].y = ball[k].y*-1;
1360 used_balls--; 1382 /* bottom line */
1361 ball[k].pos_x = ball[used_balls].pos_x; 1383 else if (ball[k].pos_y+BALL >= GAMESCREEN_HEIGHT) {
1362 ball[k].pos_y = ball[used_balls].pos_y; 1384 if (used_balls>1) {
1363 ball[k].y = ball[used_balls].y; 1385 used_balls--;
1364 ball[k].tempy = ball[used_balls].tempy; 1386 ball[k].pos_x = ball[used_balls].pos_x;
1365 ball[k].x = ball[used_balls].x; 1387 ball[k].pos_y = ball[used_balls].pos_y;
1366 ball[k].tempx = ball[used_balls].tempx; 1388 ball[k].y = ball[used_balls].y;
1367 ball[k].glue = ball[used_balls].glue; 1389 ball[k].tempy = ball[used_balls].tempy;
1368 1390 ball[k].x = ball[used_balls].x;
1369 ball[used_balls].x=0; 1391 ball[k].tempx = ball[used_balls].tempx;
1370 ball[used_balls].y=0; 1392 ball[k].glue = ball[used_balls].glue;
1371 ball[used_balls].tempy=0; 1393
1372 ball[used_balls].tempx=0; 1394 ball[used_balls].x=0;
1373 ball[used_balls].pos_y=PAD_POS_Y-BALL; 1395 ball[used_balls].y=0;
1374 ball[used_balls].pos_x=pad_pos_x+(pad_width/2)-2; 1396 ball[used_balls].tempy=0;
1375 1397 ball[used_balls].tempx=0;
1376 k--; 1398 ball[used_balls].pos_y=PAD_POS_Y-BALL;
1377 continue; 1399 ball[used_balls].pos_x=pad_pos_x+(pad_width/2)-2;
1378 } else { 1400
1379 life--; 1401 k--;
1380 if (life>=0) { 1402 continue;
1381 brickmania_int_game(0); 1403 } else {
1382 brickmania_sleep(2); 1404 life--;
1405 if (life>=0) {
1406 brickmania_init_game(0);
1407 brickmania_sleep(2);
1408 }
1383 } 1409 }
1384 } 1410 }
1385 }
1386 1411
1387 /* left line ,right line */ 1412 /* left line ,right line */
1388 if ((ball[k].pos_x <= 0) || 1413 if ((ball[k].pos_x <= 0) ||
1389 (ball[k].pos_x+BALL >= LCD_WIDTH)) { 1414 (ball[k].pos_x+BALL >= LCD_WIDTH)) {
1390 ball[k].x = ball[k].x*-1; 1415 ball[k].x = ball[k].x*-1;
1391 ball[k].pos_x = ball[k].pos_x <= 0 ? 0 : LCD_WIDTH-BALL; 1416 ball[k].pos_x = ball[k].pos_x <= 0 ? 0 : LCD_WIDTH-BALL;
1392 } 1417 }
1393 1418
1394 if ((ball[k].pos_y+BALL >= PAD_POS_Y && 1419 if ((ball[k].pos_y+BALL >= PAD_POS_Y &&
1395 (ball[k].pos_x >= pad_pos_x && 1420 (ball[k].pos_x >= pad_pos_x &&
1396 ball[k].pos_x <= pad_pos_x+pad_width)) && 1421 ball[k].pos_x <= pad_pos_x+pad_width)) &&
1397 start_game != 1 && !ball[k].glue) { 1422 game_state!=ST_READY && !ball[k].glue) {
1398 1423
1399 if ((ball[k].pos_x+HALFBALL >= pad_pos_x && 1424 if ((ball[k].pos_x+HALFBALL >= pad_pos_x &&
1400 ball[k].pos_x+HALFBALL <= 1425 ball[k].pos_x+HALFBALL <=
1401 pad_pos_x+(pad_width/2/4)) || 1426 pad_pos_x+(pad_width/2/4)) ||
1402 (ball[k].pos_x +HALFBALL>= 1427 (ball[k].pos_x +HALFBALL>=
1403 pad_pos_x+(pad_width-(pad_width/2/4)) && 1428 pad_pos_x+(pad_width-(pad_width/2/4)) &&
1404 ball[k].pos_x+HALFBALL <= pad_pos_x+pad_width)) { 1429 ball[k].pos_x+HALFBALL <= pad_pos_x+pad_width)) {
1405 1430
1406 ball[k].y = -2; 1431 ball[k].y = -2;
1407 if (ball[k].pos_x != 0 && 1432 if (ball[k].pos_x != 0 &&
1408 ball[k].pos_x+BALL!=LCD_WIDTH) 1433 ball[k].pos_x+BALL!=LCD_WIDTH)
1409 ball[k].x = brickmania_pad_check(6,0,ball[k].pos_x+2<= 1434 ball[k].x = brickmania_pad_check(6,0,
1410 pad_pos_x+(pad_width/2)? 1435 ball[k].pos_x+2<=pad_pos_x+
1411 0:1,k); 1436 (pad_width/2)?0:1,k);
1412 1437
1413 } 1438 }
1414 else if ((ball[k].pos_x+HALFBALL >= 1439 else if ((ball[k].pos_x+HALFBALL >=
1415 pad_pos_x+(pad_width/2/4) && 1440 pad_pos_x+(pad_width/2/4) &&
1416 ball[k].pos_x+HALFBALL <= 1441 ball[k].pos_x+HALFBALL <=
1417 pad_pos_x+2*(pad_width/2/4)) || 1442 pad_pos_x+2*(pad_width/2/4)) ||
1418 (ball[k].pos_x+HALFBALL >= 1443 (ball[k].pos_x+HALFBALL >=
1419 pad_pos_x+(pad_width-2*(pad_width/2/4)) && 1444 pad_pos_x+(pad_width-2*(pad_width/2/4)) &&
1420 ball[k].pos_x+HALFBALL <= 1445 ball[k].pos_x+HALFBALL <=
1421 pad_pos_x+(pad_width-(pad_width/2/4)) )) { 1446 pad_pos_x+(pad_width-(pad_width/2/4)) )) {
1422 1447
1423 ball[k].y = -3; 1448 ball[k].y = -3;
1424 if (ball[k].pos_x != 0 && 1449 if (ball[k].pos_x != 0 &&
1425 ball[k].pos_x+BALL!=LCD_WIDTH) 1450 ball[k].pos_x+BALL!=LCD_WIDTH)
1426 ball[k].x = brickmania_pad_check(4,0,ball[k].pos_x+2<= 1451 ball[k].x = brickmania_pad_check(4,0,
1427 pad_pos_x+(pad_width/2)? 1452 ball[k].pos_x+2<=pad_pos_x+
1428 0:1,k); 1453 (pad_width/2)?0:1,k);
1429 1454
1430 } 1455 }
1431 else if ((ball[k].pos_x+HALFBALL >= 1456 else if ((ball[k].pos_x+HALFBALL >=
1432 pad_pos_x+2*(pad_width/2/4) && 1457 pad_pos_x+2*(pad_width/2/4) &&
1433 ball[k].pos_x+HALFBALL <= 1458 ball[k].pos_x+HALFBALL <=
1434 pad_pos_x+3*(pad_width/2/4)) || 1459 pad_pos_x+3*(pad_width/2/4)) ||
1435 (ball[k].pos_x+2 >= 1460 (ball[k].pos_x+2 >=
1436 pad_pos_x+(pad_width-3*(pad_width/2/4)) && 1461 pad_pos_x+(pad_width-3*(pad_width/2/4)) &&
1437 ball[k].pos_x+2 <= 1462 ball[k].pos_x+2 <=
1438 pad_pos_x+ ((pad_width/2)-2*(pad_width/2/4)) )) { 1463 pad_pos_x+ ((pad_width/2)-2*(pad_width/2/4)) )) {
1439 1464
1440 ball[k].y = -4; 1465 ball[k].y = -4;
1441 if (ball[k].pos_x != 0 && 1466 if (ball[k].pos_x != 0 &&
1442 ball[k].pos_x+BALL!=LCD_WIDTH) 1467 ball[k].pos_x+BALL!=LCD_WIDTH)
1443 ball[k].x = brickmania_pad_check(3,0,ball[k].pos_x+2<= 1468 ball[k].x = brickmania_pad_check(3,0,
1444 pad_pos_x+(pad_width/2)? 1469 ball[k].pos_x+2<=pad_pos_x+
1445 0:1,k); 1470 (pad_width/2)?0:1,k);
1446 1471
1447 } 1472 }
1448 else if ((ball[k].pos_x+HALFBALL >= 1473 else if ((ball[k].pos_x+HALFBALL >=
1449 pad_pos_x+3*(pad_width/2/4) && 1474 pad_pos_x+3*(pad_width/2/4) &&
1450 ball[k].pos_x+HALFBALL <= 1475 ball[k].pos_x+HALFBALL <=
1451 pad_pos_x+4*(pad_width/2/4)-2) || 1476 pad_pos_x+4*(pad_width/2/4)-2) ||
1452 (ball[k].pos_x+2 >= pad_pos_x+(pad_width/2+2) && 1477 (ball[k].pos_x+2 >= pad_pos_x+(pad_width/2+2) &&
1453 ball[k].pos_x+2 <= 1478 ball[k].pos_x+2 <=
1454 pad_pos_x+(pad_width-3*(pad_width/2/4)) )) { 1479 pad_pos_x+(pad_width-3*(pad_width/2/4)) )) {
1455 1480
1456 ball[k].y = -4; 1481 ball[k].y = -4;
1457 if (ball[k].pos_x != 0 && 1482 if (ball[k].pos_x != 0 &&
1458 ball[k].pos_x+BALL!=LCD_WIDTH) 1483 ball[k].pos_x+BALL!=LCD_WIDTH)
1459 ball[k].x = brickmania_pad_check(2,1,0,k); 1484 ball[k].x = brickmania_pad_check(2,1,0,k);
1460 1485
1486 }
1487 else {
1488 ball[k].y = -4;
1489 }
1461 } 1490 }
1462 else {
1463 ball[k].y = -4;
1464 }
1465 }
1466 1491
1467 if (!ball[k].glue) { 1492 if (!ball[k].glue) {
1468 ball[k].pos_x+=ball[k].tempx!=0?ball[k].tempx:ball[k].x; 1493 ball[k].pos_x+=ball[k].tempx!=0?ball[k].tempx:ball[k].x;
1469 ball[k].pos_y+=ball[k].tempy!=0?ball[k].tempy:ball[k].y; 1494 ball[k].pos_y+=ball[k].tempy!=0?ball[k].tempy:ball[k].y;
1470 1495
1471 ball[k].tempy=0; 1496 ball[k].tempy=0;
1472 ball[k].tempx=0; 1497 ball[k].tempx=0;
1473 } 1498 }
1474 1499
1475 if (ball[k].pos_y+5 >= PAD_POS_Y && 1500 if (ball[k].pos_y+5 >= PAD_POS_Y &&
1476 (pad_type==1 && !ball[k].glue) && 1501 (pad_type==1 && !ball[k].glue) &&
1477 (ball[k].pos_x >= pad_pos_x && 1502 (ball[k].pos_x >= pad_pos_x &&
1478 ball[k].pos_x <= pad_pos_x+pad_width)) { 1503 ball[k].pos_x <= pad_pos_x+pad_width)) {
1479 ball[k].y=0; 1504 ball[k].y=0;
1480 ball[k].pos_y=PAD_POS_Y-BALL; 1505 ball[k].pos_y=PAD_POS_Y-BALL;
1481 ball[k].glue=true; 1506 ball[k].glue=true;
1482 } 1507 }
1483 } /* for k */ 1508 } /* for k */
1509 }
1484 1510
1485 rb->lcd_update(); 1511 rb->lcd_update();
1486 1512
1487 if (brick_on_board < 0) { 1513 if (brick_on_board < 0) {
1488 if (level+1<levels_num) { 1514 if (level+1<levels_num) {
1489 level++; 1515 level++;
1490 if (difficulty==HARD) 1516 if (difficulty==NORMAL)
1491 score+=100; 1517 score+=100;
1492 l_score=score; 1518 brickmania_init_game(1);
1493 brickmania_int_game(1);
1494 brickmania_sleep(2); 1519 brickmania_sleep(2);
1495 } 1520 }
1496 else { 1521 else {
@@ -1508,22 +1533,9 @@ static int brickmania_game_loop(void)
1508 "You have finished the game!"); 1533 "You have finished the game!");
1509#endif 1534#endif
1510 vscore=score; 1535 vscore=score;
1511 rb->lcd_clear_display();
1512 rb->lcd_update(); 1536 rb->lcd_update();
1513 rb->sleep(2); 1537 brickmania_sleep(2);
1514 position=highscore_update(score, level+1, "", 1538 return 0;
1515 highest,NUM_SCORES);
1516 if (position == 0) {
1517 rb->splash(HZ*2, "New High Score");
1518 }
1519 if (position != -1) {
1520 highscore_show(position, highest, NUM_SCORES);
1521 } else {
1522 brickmania_sleep(3);
1523 }
1524 if (brickmania_menu(false)!=0) {
1525 return 0;
1526 }
1527 } 1539 }
1528 } 1540 }
1529 1541
@@ -1534,7 +1546,7 @@ static int brickmania_game_loop(void)
1534#if defined(HAS_BUTTON_HOLD) && !defined(HAVE_REMOTE_LCD_AS_MAIN) 1546#if defined(HAS_BUTTON_HOLD) && !defined(HAVE_REMOTE_LCD_AS_MAIN)
1535 /* FIXME: Should probably check remote hold here */ 1547 /* FIXME: Should probably check remote hold here */
1536 if (rb->button_hold()) 1548 if (rb->button_hold())
1537 button = QUIT; 1549 button = QUIT;
1538#endif 1550#endif
1539 1551
1540#ifdef HAVE_TOUCHSCREEN 1552#ifdef HAVE_TOUCHSCREEN
@@ -1546,16 +1558,16 @@ static int brickmania_game_loop(void)
1546 if(touch_y >= PAD_POS_Y && touch_y <= PAD_POS_Y+PAD_HEIGHT) 1558 if(touch_y >= PAD_POS_Y && touch_y <= PAD_POS_Y+PAD_HEIGHT)
1547 { 1559 {
1548 pad_pos_x += (flip_sides ? -1 : 1) * ( (touch_x-pad_pos_x-pad_width/2) / 4 ); 1560 pad_pos_x += (flip_sides ? -1 : 1) * ( (touch_x-pad_pos_x-pad_width/2) / 4 );
1549 1561
1550 if(pad_pos_x < 0) 1562 if(pad_pos_x < 0)
1551 pad_pos_x = 0; 1563 pad_pos_x = 0;
1552 else if(pad_pos_x+pad_width > LCD_WIDTH) 1564 else if(pad_pos_x+pad_width > LCD_WIDTH)
1553 pad_pos_x = LCD_WIDTH-pad_width; 1565 pad_pos_x = LCD_WIDTH-pad_width;
1554 for(k=0;k<used_balls;k++) 1566 for(k=0;k<used_balls;k++)
1555 if ((start_game==1 || ball[k].glue)) 1567 if (game_state==ST_READY || ball[k].glue)
1556 ball[k].pos_x = pad_pos_x+pad_width/2; 1568 ball[k].pos_x = pad_pos_x+pad_width/2;
1557 } 1569 }
1558 1570
1559 if(button & BUTTON_REL) 1571 if(button & BUTTON_REL)
1560 button = SELECT; 1572 button = SELECT;
1561 } 1573 }
@@ -1570,19 +1582,19 @@ static int brickmania_game_loop(void)
1570 button_right=((move_button & RIGHT) || (SCROLL_FWD(button))); 1582 button_right=((move_button & RIGHT) || (SCROLL_FWD(button)));
1571 button_left=((move_button & LEFT) || (SCROLL_BACK(button))); 1583 button_left=((move_button & LEFT) || (SCROLL_BACK(button)));
1572 #endif 1584 #endif
1573 if ((con_game== 1 && start_game!=1) && (button_right || button_left)) 1585 if ((game_state==ST_PAUSE) && (button_right || button_left))
1574 continue; 1586 continue;
1575 if ((button_right && flip_sides==false) || 1587 if ((button_right && flip_sides==false) ||
1576 (button_left && flip_sides==true)) { 1588 (button_left && flip_sides==true)) {
1577 if (pad_pos_x+8+pad_width > LCD_WIDTH) { 1589 if (pad_pos_x+8+pad_width > LCD_WIDTH) {
1578 for(k=0;k<used_balls;k++) 1590 for(k=0;k<used_balls;k++)
1579 if (start_game==1 || ball[k].glue) 1591 if (game_state==ST_READY || ball[k].glue)
1580 ball[k].pos_x+=LCD_WIDTH-pad_pos_x-pad_width; 1592 ball[k].pos_x+=LCD_WIDTH-pad_pos_x-pad_width;
1581 pad_pos_x+=LCD_WIDTH-pad_pos_x-pad_width; 1593 pad_pos_x+=LCD_WIDTH-pad_pos_x-pad_width;
1582 } 1594 }
1583 else { 1595 else {
1584 for(k=0;k<used_balls;k++) 1596 for(k=0;k<used_balls;k++)
1585 if ((start_game==1 || ball[k].glue)) 1597 if ((game_state==ST_READY || ball[k].glue))
1586 ball[k].pos_x+=8; 1598 ball[k].pos_x+=8;
1587 pad_pos_x+=8; 1599 pad_pos_x+=8;
1588 } 1600 }
@@ -1591,13 +1603,13 @@ static int brickmania_game_loop(void)
1591 (button_right && flip_sides==true)) { 1603 (button_right && flip_sides==true)) {
1592 if (pad_pos_x-8 < 0) { 1604 if (pad_pos_x-8 < 0) {
1593 for(k=0;k<used_balls;k++) 1605 for(k=0;k<used_balls;k++)
1594 if (start_game==1 || ball[k].glue) 1606 if (game_state==ST_READY || ball[k].glue)
1595 ball[k].pos_x-=pad_pos_x; 1607 ball[k].pos_x-=pad_pos_x;
1596 pad_pos_x-=pad_pos_x; 1608 pad_pos_x-=pad_pos_x;
1597 } 1609 }
1598 else { 1610 else {
1599 for(k=0;k<used_balls;k++) 1611 for(k=0;k<used_balls;k++)
1600 if (start_game==1 || ball[k].glue) 1612 if (game_state==ST_READY || ball[k].glue)
1601 ball[k].pos_x-=8; 1613 ball[k].pos_x-=8;
1602 pad_pos_x-=8; 1614 pad_pos_x-=8;
1603 } 1615 }
@@ -1610,61 +1622,38 @@ static int brickmania_game_loop(void)
1610 switch(button) { 1622 switch(button) {
1611 case UP: 1623 case UP:
1612 case SELECT: 1624 case SELECT:
1613 if (start_game==1 && con_game!=1 && pad_type!=1) { 1625 if (game_state==ST_READY) {
1614 for(k=0;k<used_balls;k++) { 1626 for(k=0;k<used_balls;k++) {
1615 ball[k].y=-4; 1627 ball[k].y=-4;
1616 ball[k].x=pad_pos_x+(pad_width/2)-2>= 1628 ball[k].x=pad_pos_x+(pad_width/2)-2>=
1617 LCD_WIDTH/2?2:-2; 1629 LCD_WIDTH/2?2:-2;
1618 } 1630 }
1619 start_game =0; 1631 game_state=ST_START;
1632 }
1633 else if (game_state==ST_PAUSE) {
1634 game_state=ST_START;
1620 } 1635 }
1621 else if (pad_type==1) { 1636 else if (pad_type==1) {
1622 for(k=0;k<used_balls;k++) { 1637 for(k=0;k<used_balls;k++) {
1623 if (ball[k].glue) 1638 if (ball[k].glue)
1624 ball[k].glue=false; 1639 ball[k].glue=false;
1625 else if (start_game==1) {
1626 ball[k].x = x[k];
1627 ball[k].y = y[k];
1628 }
1629 }
1630
1631 if (start_game!=1 && con_game==1) {
1632 start_game =0;
1633 con_game=0;
1634 }
1635 } else if (pad_type==2 && con_game!=1) {
1636 int tfire;
1637 tfire=brickmania_fire_space();
1638 fire[tfire].top=PAD_POS_Y-7;
1639 fire[tfire].left=pad_pos_x+1;
1640 tfire=brickmania_fire_space();
1641 fire[tfire].top=PAD_POS_Y-7;
1642 fire[tfire].left=pad_pos_x+pad_width-1;
1643 } else if (con_game==1 && start_game!=1) {
1644 for(k=0;k<used_balls;k++) {
1645 ball[k].x=x[k];
1646 ball[k].y=y[k];
1647 } 1640 }
1648 con_game=0; 1641 }
1642 else if (pad_type==2) {
1643 k=brickmania_fire_space();
1644 fire[k].top=PAD_POS_Y-7;
1645 fire[k].left=pad_pos_x+1;
1646 k=brickmania_fire_space();
1647 fire[k].top=PAD_POS_Y-7;
1648 fire[k].left=pad_pos_x+pad_width-1;
1649 } 1649 }
1650 break; 1650 break;
1651#ifdef RC_QUIT 1651#ifdef RC_QUIT
1652 case RC_QUIT: 1652 case RC_QUIT:
1653#endif 1653#endif
1654 case QUIT: 1654 case QUIT:
1655 if (brickmania_menu(true)!=0) { 1655 resume = true;
1656 return 1; 1656 return 0;
1657 }
1658
1659 for(k=0;k<used_balls;k++) {
1660 if (ball[k].x!=0)
1661 x[k]=ball[k].x;
1662 ball[k].x=0;
1663 if (ball[k].y!=0)
1664 y[k]=ball[k].y;
1665 ball[k].y=0;
1666 }
1667
1668 break; 1657 break;
1669 1658
1670 default: 1659 default:
@@ -1686,38 +1675,26 @@ static int brickmania_game_loop(void)
1686#endif 1675#endif
1687 rb->lcd_update(); 1676 rb->lcd_update();
1688 brickmania_sleep(2); 1677 brickmania_sleep(2);
1689 position=highscore_update(score, level+1, "", highest, NUM_SCORES); 1678 return 0;
1690 if (position == 0) {
1691 rb->splash(HZ*2, "New High Score");
1692 }
1693 if (position != -1) {
1694 highscore_show(position, highest, NUM_SCORES);
1695 } else {
1696 brickmania_sleep(3);
1697 }
1698
1699 for(k=0;k<used_balls;k++) {
1700 ball[k].x=0;
1701 ball[k].y=0;
1702 }
1703
1704 if (brickmania_menu(false)!=0) {
1705 return 0;
1706 }
1707 } 1679 }
1708 if (end > *rb->current_tick) 1680 if (end > *rb->current_tick)
1709 rb->sleep(end-*rb->current_tick); 1681 rb->sleep(end-*rb->current_tick);
1710 else 1682 else
1711 rb->yield(); 1683 rb->yield();
1712 } 1684 }
1685 return 0;
1713} 1686}
1714 1687
1715/* this is the plugin entry point */ 1688/* this is the plugin entry point */
1716enum plugin_status plugin_start(const void* parameter) 1689enum plugin_status plugin_start(const void* parameter)
1717{ 1690{
1718 (void)parameter; 1691 (void)parameter;
1692 int last_difficulty;
1719 1693
1720 highscore_load(HIGH_SCORE,highest,NUM_SCORES); 1694 highscore_load(HIGH_SCORE,highest,NUM_SCORES);
1695 configfile_load(CONFIG_FILE_NAME,config,1,0);
1696 last_difficulty = difficulty;
1697
1721 rb->lcd_setfont(FONT_SYSFIXED); 1698 rb->lcd_setfont(FONT_SYSFIXED);
1722#if LCD_DEPTH > 1 1699#if LCD_DEPTH > 1
1723 rb->lcd_set_backdrop(NULL); 1700 rb->lcd_set_backdrop(NULL);
@@ -1726,9 +1703,25 @@ enum plugin_status plugin_start(const void* parameter)
1726 backlight_force_on(); /* backlight control in lib/helper.c */ 1703 backlight_force_on(); /* backlight control in lib/helper.c */
1727 1704
1728 /* now go ahead and have fun! */ 1705 /* now go ahead and have fun! */
1729 brickmania_game_loop(); 1706 rb->srand( *rb->current_tick );
1707 brickmania_loadgame();
1708 while(brickmania_game_loop() == 0) {
1709 if(!resume) {
1710 int position = highscore_update(score, level+1, "", highest, NUM_SCORES);
1711 if (position == 0) {
1712 rb->splash(HZ*2, "New High Score");
1713 }
1714 if (position != -1) {
1715 highscore_show(position, highest, NUM_SCORES);
1716 } else {
1717 brickmania_sleep(3);
1718 }
1719 }
1720 }
1730 1721
1731 highscore_save(HIGH_SCORE,highest,NUM_SCORES); 1722 highscore_save(HIGH_SCORE,highest,NUM_SCORES);
1723 if(last_difficulty != difficulty)
1724 configfile_save(CONFIG_FILE_NAME,config,1,0);
1732 /* Restore user's original backlight setting */ 1725 /* Restore user's original backlight setting */
1733 rb->lcd_setfont(FONT_UI); 1726 rb->lcd_setfont(FONT_UI);
1734 /* Turn on backlight timeout (revert to settings) */ 1727 /* Turn on backlight timeout (revert to settings) */