diff options
author | Dave Chapman <dave@dchapman.com> | 2006-01-27 10:02:13 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2006-01-27 10:02:13 +0000 |
commit | 553c9e2fcea3854d2d024e851a0b4b37f8265b9e (patch) | |
tree | e0735761a957aa9c35c08fefacc95fd0ff687ab8 /apps | |
parent | 2047f79f75cb17bdc07c4015f0b71ec6607a3b93 (diff) | |
download | rockbox-553c9e2fcea3854d2d024e851a0b4b37f8265b9e.tar.gz rockbox-553c9e2fcea3854d2d024e851a0b4b37f8265b9e.zip |
Portability enhancements - make the menu bitmap positions #defines, introduce a game loop timer (to fix the speed on all targets) and fix the menu on targets with 320x240 LCDs.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8464 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/bitmaps/native/SOURCES | 6 | ||||
-rw-r--r-- | apps/plugins/bitmaps/native/brickmania_menu_bg.320x240x16.bmp | bin | 0 -> 230454 bytes | |||
-rw-r--r-- | apps/plugins/brickmania.c | 154 |
3 files changed, 101 insertions, 59 deletions
diff --git a/apps/plugins/bitmaps/native/SOURCES b/apps/plugins/bitmaps/native/SOURCES index ecd8334f3e..5b96f30323 100644 --- a/apps/plugins/bitmaps/native/SOURCES +++ b/apps/plugins/bitmaps/native/SOURCES | |||
@@ -18,11 +18,15 @@ sudoku_inverse.220x176x16.bmp | |||
18 | /* Brickmania */ | 18 | /* Brickmania */ |
19 | 19 | ||
20 | #if (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH == 16) | 20 | #if (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH == 16) |
21 | #if (LCD_WIDTH == 320) | ||
22 | brickmania_menu_bg.320x240x16.bmp | ||
23 | #else | ||
24 | brickmania_menu_bg.220x176x16.bmp | ||
25 | #endif | ||
21 | brickmania_ball.220x176x16.bmp | 26 | brickmania_ball.220x176x16.bmp |
22 | brickmania_bricks.220x176x16.bmp | 27 | brickmania_bricks.220x176x16.bmp |
23 | brickmania_gameover.220x176x16.bmp | 28 | brickmania_gameover.220x176x16.bmp |
24 | brickmania_help.220x176x16.bmp | 29 | brickmania_help.220x176x16.bmp |
25 | brickmania_menu_bg.220x176x16.bmp | ||
26 | brickmania_no_resume.220x176x16.bmp | 30 | brickmania_no_resume.220x176x16.bmp |
27 | brickmania_pads.220x176x16.bmp | 31 | brickmania_pads.220x176x16.bmp |
28 | brickmania_powerups.220x176x16.bmp | 32 | brickmania_powerups.220x176x16.bmp |
diff --git a/apps/plugins/bitmaps/native/brickmania_menu_bg.320x240x16.bmp b/apps/plugins/bitmaps/native/brickmania_menu_bg.320x240x16.bmp new file mode 100644 index 0000000000..de6cc658b9 --- /dev/null +++ b/apps/plugins/bitmaps/native/brickmania_menu_bg.320x240x16.bmp | |||
Binary files differ | |||
diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c index 56b29d5871..78d18a38d5 100644 --- a/apps/plugins/brickmania.c +++ b/apps/plugins/brickmania.c | |||
@@ -22,6 +22,12 @@ | |||
22 | 22 | ||
23 | PLUGIN_HEADER | 23 | PLUGIN_HEADER |
24 | 24 | ||
25 | /* The time (in ms) for one iteration through the game loop - decrease this | ||
26 | to speed up the game - note that current_tick is (currently) only accurate | ||
27 | to 10ms. | ||
28 | */ | ||
29 | #define CYCLETIME 30 | ||
30 | |||
25 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) | 31 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) |
26 | 32 | ||
27 | #define QUIT BUTTON_OFF | 33 | #define QUIT BUTTON_OFF |
@@ -31,6 +37,10 @@ PLUGIN_HEADER | |||
31 | #define UP BUTTON_UP | 37 | #define UP BUTTON_UP |
32 | #define DOWN BUTTON_DOWN | 38 | #define DOWN BUTTON_DOWN |
33 | 39 | ||
40 | /* H100 and H300 don't have scroll events */ | ||
41 | #define SCROLL_FWD(x) (0) | ||
42 | #define SCROLL_BACK(x) (0) | ||
43 | |||
34 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) | 44 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) |
35 | 45 | ||
36 | #define QUIT BUTTON_MENU | 46 | #define QUIT BUTTON_MENU |
@@ -40,6 +50,9 @@ PLUGIN_HEADER | |||
40 | #define UP BUTTON_SCROLL_BACK | 50 | #define UP BUTTON_SCROLL_BACK |
41 | #define DOWN BUTTON_SCROLL_FWD | 51 | #define DOWN BUTTON_SCROLL_FWD |
42 | 52 | ||
53 | #define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD) | ||
54 | #define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK) | ||
55 | |||
43 | #else | 56 | #else |
44 | #error Unsupported keypad | 57 | #error Unsupported keypad |
45 | #endif | 58 | #endif |
@@ -71,6 +84,11 @@ extern const fb_data brickmania_bricks[]; | |||
71 | 84 | ||
72 | /* TO DO: This needs adjusting correctly for larger than 220x176 LCDS */ | 85 | /* TO DO: This needs adjusting correctly for larger than 220x176 LCDS */ |
73 | #if (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) | 86 | #if (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) |
87 | |||
88 | /* Offsets for LCDS > 220x176 */ | ||
89 | #define XOFS ((LCD_WIDTH-220)/2) | ||
90 | #define YOFS ((LCD_HEIGHT-176)/2) | ||
91 | |||
74 | #define PAD_WIDTH 40 | 92 | #define PAD_WIDTH 40 |
75 | #define PAD_HEIGHT 5 | 93 | #define PAD_HEIGHT 5 |
76 | #define PAD_POS_Y LCD_HEIGHT - 7 | 94 | #define PAD_POS_Y LCD_HEIGHT - 7 |
@@ -108,6 +126,18 @@ extern const fb_data brickmania_bricks[]; | |||
108 | #define BMPHEIGHT_powerup 6 | 126 | #define BMPHEIGHT_powerup 6 |
109 | #define BMPWIDTH_powerup 10 | 127 | #define BMPWIDTH_powerup 10 |
110 | 128 | ||
129 | #define BMPXOFS_resume (62+XOFS) | ||
130 | #define BMPYOFS_resume (100+YOFS) | ||
131 | #define BMPXOFS_quit (93+XOFS) | ||
132 | #define BMPYOFS_quit (138+YOFS) | ||
133 | #define BMPXOFS_start (55+XOFS) | ||
134 | #define BMPYOFS_start (78+YOFS) | ||
135 | #define BMPXOFS_help (92+XOFS) | ||
136 | #define BMPYOFS_help (118+YOFS) | ||
137 | #define HIGHSCORE_XPOS (7+XOFS) | ||
138 | #define HIGHSCORE_YPOS (56+YOFS) | ||
139 | |||
140 | |||
111 | #else | 141 | #else |
112 | #error Unsupported LCD Size | 142 | #error Unsupported LCD Size |
113 | #endif | 143 | #endif |
@@ -498,44 +528,46 @@ int game_menu(int when) | |||
498 | int button,cur=0; | 528 | int button,cur=0; |
499 | char str[10]; | 529 | char str[10]; |
500 | 530 | ||
501 | rb->lcd_clear_display(); | 531 | rb->lcd_bitmap(brickmania_menu_bg,0,0,LCD_WIDTH,LCD_HEIGHT); |
502 | rb->lcd_bitmap(brickmania_menu_bg,0,0,220,176); | ||
503 | while (true) { | 532 | while (true) { |
504 | for(i=0;i<MENU_LENGTH;i++) { | 533 | for(i=0;i<MENU_LENGTH;i++) { |
505 | if (cur==0) | 534 | if (cur==0) |
506 | rb->lcd_bitmap(brickmania_sel_start,55,78, | 535 | rb->lcd_bitmap(brickmania_sel_start, |
536 | BMPXOFS_start,BMPYOFS_start, | ||
507 | BMPWIDTH_sel_start,BMPHEIGHT_sel_start); | 537 | BMPWIDTH_sel_start,BMPHEIGHT_sel_start); |
508 | else | 538 | else |
509 | rb->lcd_bitmap(brickmania_start,55,78, | 539 | rb->lcd_bitmap(brickmania_start,BMPXOFS_start,BMPYOFS_start, |
510 | BMPWIDTH_start,BMPHEIGHT_start); | 540 | BMPWIDTH_start,BMPHEIGHT_start); |
511 | 541 | ||
512 | if (when==1) { | 542 | if (when==1) { |
513 | if (cur==1) | 543 | if (cur==1) |
514 | rb->lcd_bitmap(brickmania_sel_resume,62,100, | 544 | rb->lcd_bitmap(brickmania_sel_resume, |
545 | BMPXOFS_resume,BMPYOFS_resume, | ||
515 | BMPWIDTH_sel_resume,BMPHEIGHT_sel_resume); | 546 | BMPWIDTH_sel_resume,BMPHEIGHT_sel_resume); |
516 | else | 547 | else |
517 | rb->lcd_bitmap(brickmania_resume,62,100, | 548 | rb->lcd_bitmap(brickmania_resume, |
549 | BMPXOFS_resume,BMPYOFS_resume, | ||
518 | BMPWIDTH_resume,BMPHEIGHT_resume); | 550 | BMPWIDTH_resume,BMPHEIGHT_resume); |
519 | 551 | ||
520 | } else { | 552 | } else { |
521 | rb->lcd_bitmap(brickmania_no_resume,62,100, | 553 | rb->lcd_bitmap(brickmania_no_resume, |
554 | BMPXOFS_resume,BMPYOFS_resume, | ||
522 | BMPWIDTH_no_resume,BMPHEIGHT_no_resume); | 555 | BMPWIDTH_no_resume,BMPHEIGHT_no_resume); |
523 | } | 556 | } |
524 | 557 | ||
525 | 558 | ||
526 | if (cur==2) | 559 | if (cur==2) |
527 | rb->lcd_bitmap(brickmania_sel_help,92,118, | 560 | rb->lcd_bitmap(brickmania_sel_help,BMPXOFS_help,BMPYOFS_help, |
528 | BMPWIDTH_sel_help,BMPHEIGHT_sel_help); | 561 | BMPWIDTH_sel_help,BMPHEIGHT_sel_help); |
529 | else | 562 | else |
530 | rb->lcd_bitmap(brickmania_help,92,118, | 563 | rb->lcd_bitmap(brickmania_help,BMPXOFS_help,BMPYOFS_help, |
531 | BMPWIDTH_help,BMPHEIGHT_help); | 564 | BMPWIDTH_help,BMPHEIGHT_help); |
532 | 565 | ||
533 | |||
534 | if (cur==3) | 566 | if (cur==3) |
535 | rb->lcd_bitmap(brickmania_sel_quit,93,138, | 567 | rb->lcd_bitmap(brickmania_sel_quit,BMPXOFS_quit,BMPYOFS_quit, |
536 | BMPWIDTH_sel_quit,BMPHEIGHT_sel_quit); | 568 | BMPWIDTH_sel_quit,BMPHEIGHT_sel_quit); |
537 | else | 569 | else |
538 | rb->lcd_bitmap(brickmania_quit,93,138, | 570 | rb->lcd_bitmap(brickmania_quit,BMPXOFS_quit,BMPYOFS_quit, |
539 | BMPWIDTH_quit,BMPHEIGHT_quit); | 571 | BMPWIDTH_quit,BMPHEIGHT_quit); |
540 | } | 572 | } |
541 | 573 | ||
@@ -543,11 +575,11 @@ int game_menu(int when) | |||
543 | rb->lcd_setfont(FONT_SYSFIXED); | 575 | rb->lcd_setfont(FONT_SYSFIXED); |
544 | rb->lcd_set_background(LCD_RGBPACK(0,0,140)); | 576 | rb->lcd_set_background(LCD_RGBPACK(0,0,140)); |
545 | rb->lcd_set_foreground(LCD_WHITE); | 577 | rb->lcd_set_foreground(LCD_WHITE); |
546 | rb->lcd_putsxy(7, 56, "High Score"); | 578 | rb->lcd_putsxy(HIGHSCORE_XPOS, HIGHSCORE_YPOS, "High Score"); |
547 | rb->snprintf(str, sizeof(str), "%d", highscore); | 579 | rb->snprintf(str, sizeof(str), "%d", highscore); |
548 | rb->lcd_getstringsize("High Score", &sw, NULL); | 580 | rb->lcd_getstringsize("High Score", &sw, NULL); |
549 | rb->lcd_getstringsize(str, &w, NULL); | 581 | rb->lcd_getstringsize(str, &w, NULL); |
550 | rb->lcd_putsxy(7+sw/2-w/2, 65, str); | 582 | rb->lcd_putsxy(HIGHSCORE_XPOS+sw/2-w/2, HIGHSCORE_YPOS+9, str); |
551 | rb->lcd_setfont(FONT_UI); | 583 | rb->lcd_setfont(FONT_UI); |
552 | 584 | ||
553 | rb->lcd_update(); | 585 | rb->lcd_update(); |
@@ -690,6 +722,7 @@ int game_loop(void){ | |||
690 | int j,i,k,bricky,brickx; | 722 | int j,i,k,bricky,brickx; |
691 | char s[20]; | 723 | char s[20]; |
692 | int sec_count=0,num_count=10; | 724 | int sec_count=0,num_count=10; |
725 | int end; | ||
693 | 726 | ||
694 | rb->srand( *rb->current_tick ); | 727 | rb->srand( *rb->current_tick ); |
695 | 728 | ||
@@ -713,7 +746,10 @@ int game_loop(void){ | |||
713 | break; | 746 | break; |
714 | } | 747 | } |
715 | 748 | ||
716 | while(true) { | 749 | while(true) { |
750 | /* Convert CYCLETIME (in ms) to HZ */ | ||
751 | end = *rb->current_tick + (CYCLETIME * HZ) / 1000; | ||
752 | |||
717 | if (life >= 0) { | 753 | if (life >= 0) { |
718 | rb->lcd_set_background(LCD_BLACK); | 754 | rb->lcd_set_background(LCD_BLACK); |
719 | rb->lcd_set_drawmode(DRMODE_SOLID); | 755 | rb->lcd_set_drawmode(DRMODE_SOLID); |
@@ -733,7 +769,7 @@ int game_loop(void){ | |||
733 | rb->lcd_getstringsize(s, &sw, NULL); | 769 | rb->lcd_getstringsize(s, &sw, NULL); |
734 | rb->lcd_putsxy(LCD_WIDTH/2-2, 150, s); | 770 | rb->lcd_putsxy(LCD_WIDTH/2-2, 150, s); |
735 | } | 771 | } |
736 | 772 | ||
737 | /* write life num */ | 773 | /* write life num */ |
738 | rb->snprintf(s, sizeof(s), "Life: %d", life); | 774 | rb->snprintf(s, sizeof(s), "Life: %d", life); |
739 | rb->lcd_putsxy(2, 2, s); | 775 | rb->lcd_putsxy(2, 2, s); |
@@ -742,7 +778,6 @@ int game_loop(void){ | |||
742 | rb->lcd_getstringsize(s, &sw, NULL); | 778 | rb->lcd_getstringsize(s, &sw, NULL); |
743 | rb->lcd_putsxy(LCD_WIDTH-sw-2, 2, s); | 779 | rb->lcd_putsxy(LCD_WIDTH-sw-2, 2, s); |
744 | 780 | ||
745 | |||
746 | if (vscore<score) vscore++; | 781 | if (vscore<score) vscore++; |
747 | rb->snprintf(s, sizeof(s), "%d", vscore); | 782 | rb->snprintf(s, sizeof(s), "%d", vscore); |
748 | rb->lcd_getstringsize(s, &sw, NULL); | 783 | rb->lcd_getstringsize(s, &sw, NULL); |
@@ -1033,58 +1068,59 @@ int game_loop(void){ | |||
1033 | } | 1068 | } |
1034 | 1069 | ||
1035 | int move_button,button; | 1070 | int move_button,button; |
1036 | int time = 3; /* number of ticks this function will loop reading keys */ | 1071 | int button_right,button_left; |
1037 | int start = *rb->current_tick; | 1072 | button=rb->button_get(false); |
1038 | int end = start + time; | ||
1039 | button=rb->button_get_w_tmo(end - *rb->current_tick); | ||
1040 | move_button=rb->button_status(); | 1073 | move_button=rb->button_status(); |
1041 | 1074 | ||
1042 | if ((move_button & RIGHT && flip_sides==false) || (flip_sides==true && move_button & LEFT)) { | 1075 | button_right=((move_button & RIGHT) || (SCROLL_FWD(button))); |
1076 | button_left=((move_button & LEFT) || (SCROLL_BACK(button))); | ||
1077 | |||
1078 | if ((button_right && flip_sides==false) || (button_left && flip_sides==true)) { | ||
1043 | if (pad_pos_x+8+PAD_WIDTH > LCD_WIDTH) { | 1079 | if (pad_pos_x+8+PAD_WIDTH > LCD_WIDTH) { |
1044 | if (start_game==1 || on_the_pad==1) ball_pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH; | 1080 | if (start_game==1 || on_the_pad==1) ball_pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH; |
1045 | pad_pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH; | 1081 | pad_pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH; |
1046 | } else { | 1082 | } else { |
1047 | if ((start_game==1 || on_the_pad==1)) | 1083 | if ((start_game==1 || on_the_pad==1)) |
1048 | ball_pos_x+=8; | 1084 | ball_pos_x+=8; |
1049 | pad_pos_x+=8; | 1085 | pad_pos_x+=8; |
1050 | } | 1086 | } |
1051 | } else if ((move_button & LEFT && flip_sides==false) || (flip_sides==true && move_button & RIGHT)) { | 1087 | } else if ((button_left && flip_sides==false) || (button_right && flip_sides==true)) { |
1052 | if (pad_pos_x-8 < 0) { | 1088 | if (pad_pos_x-8 < 0) { |
1053 | if (start_game==1 || on_the_pad==1) ball_pos_x-=pad_pos_x; | 1089 | if (start_game==1 || on_the_pad==1) ball_pos_x-=pad_pos_x; |
1054 | pad_pos_x-=pad_pos_x; | 1090 | pad_pos_x-=pad_pos_x; |
1055 | } else { | 1091 | } else { |
1056 | if (start_game==1 || on_the_pad==1) ball_pos_x-=8; | 1092 | if (start_game==1 || on_the_pad==1) ball_pos_x-=8; |
1057 | pad_pos_x-=8; | 1093 | pad_pos_x-=8; |
1058 | } | ||
1059 | } | 1094 | } |
1095 | } | ||
1060 | 1096 | ||
1061 | 1097 | ||
1062 | switch(button){ | 1098 | switch(button) { |
1063 | case SELECT: | 1099 | case SELECT: |
1064 | if (start_game==1 && con_game!=1 && pad_type!=1) { | 1100 | if (start_game==1 && con_game!=1 && pad_type!=1) { |
1065 | bally=-4; | 1101 | bally=-4; |
1066 | ballx=pad_pos_x+(PAD_WIDTH/2)-2>=LCD_WIDTH/2?2:-2; | 1102 | ballx=pad_pos_x+(PAD_WIDTH/2)-2>=LCD_WIDTH/2?2:-2; |
1103 | start_game =0; | ||
1104 | } else if (pad_type==1 && on_the_pad==1) { | ||
1105 | on_the_pad=0; | ||
1106 | if (start_game!=1 && con_game==1) { | ||
1067 | start_game =0; | 1107 | start_game =0; |
1068 | } else if (pad_type==1 && on_the_pad==1) { | ||
1069 | on_the_pad=0; | ||
1070 | if (start_game!=1 && con_game==1) { | ||
1071 | start_game =0; | ||
1072 | con_game=0; | ||
1073 | } | ||
1074 | } else if (pad_type==2 && con_game!=1) { | ||
1075 | int tfire; | ||
1076 | tfire=fire_space(); | ||
1077 | fire[tfire].top=PAD_POS_Y-7; | ||
1078 | fire[tfire].left=pad_pos_x+1; | ||
1079 | tfire=fire_space(); | ||
1080 | fire[tfire].top=PAD_POS_Y-7; | ||
1081 | fire[tfire].left=pad_pos_x+PAD_WIDTH-1; | ||
1082 | } else if (con_game==1 && start_game!=1) { | ||
1083 | ballx=x; | ||
1084 | bally=y; | ||
1085 | con_game=0; | 1108 | con_game=0; |
1086 | } | 1109 | } |
1087 | break; | 1110 | } else if (pad_type==2 && con_game!=1) { |
1111 | int tfire; | ||
1112 | tfire=fire_space(); | ||
1113 | fire[tfire].top=PAD_POS_Y-7; | ||
1114 | fire[tfire].left=pad_pos_x+1; | ||
1115 | tfire=fire_space(); | ||
1116 | fire[tfire].top=PAD_POS_Y-7; | ||
1117 | fire[tfire].left=pad_pos_x+PAD_WIDTH-1; | ||
1118 | } else if (con_game==1 && start_game!=1) { | ||
1119 | ballx=x; | ||
1120 | bally=y; | ||
1121 | con_game=0; | ||
1122 | } | ||
1123 | break; | ||
1088 | case QUIT: | 1124 | case QUIT: |
1089 | switch(game_menu(1)){ | 1125 | switch(game_menu(1)){ |
1090 | case 0: | 1126 | case 0: |
@@ -1140,6 +1176,8 @@ int game_loop(void){ | |||
1140 | break; | 1176 | break; |
1141 | } | 1177 | } |
1142 | } | 1178 | } |
1179 | if (end > *rb->current_tick) | ||
1180 | rb->sleep(end-*rb->current_tick); | ||
1143 | } | 1181 | } |
1144 | } | 1182 | } |
1145 | 1183 | ||