summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorKarl Kurbjun <kkurbjun@gmail.com>2009-10-04 22:27:42 +0000
committerKarl Kurbjun <kkurbjun@gmail.com>2009-10-04 22:27:42 +0000
commit03f5edcaa66cc98a227479ee8650e8ee8d3d56f7 (patch)
treeaef21af3d9efb7212676ce992966348f8f961d67 /apps/plugins
parent2a91a9a19eabbd38894bd08ac18250c97cb1f2cf (diff)
downloadrockbox-03f5edcaa66cc98a227479ee8650e8ee8d3d56f7.tar.gz
rockbox-03f5edcaa66cc98a227479ee8650e8ee8d3d56f7.zip
Brickmania: Some code refactoring - no functional changes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22931 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/brickmania.c455
1 files changed, 230 insertions, 225 deletions
diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c
index e5f953ac8d..b6eeeac398 100644
--- a/apps/plugins/brickmania.c
+++ b/apps/plugins/brickmania.c
@@ -45,6 +45,7 @@ PLUGIN_HEADER
45 45
46#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ 46#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
47 (CONFIG_KEYPAD == IRIVER_H300_PAD) 47 (CONFIG_KEYPAD == IRIVER_H300_PAD)
48#define CONTINUE_TEXT "Press NAVI To Continue"
48#define QUIT BUTTON_OFF 49#define QUIT BUTTON_OFF
49#define LEFT BUTTON_LEFT 50#define LEFT BUTTON_LEFT
50#define RIGHT BUTTON_RIGHT 51#define RIGHT BUTTON_RIGHT
@@ -54,6 +55,7 @@ PLUGIN_HEADER
54#define RC_QUIT BUTTON_RC_STOP 55#define RC_QUIT BUTTON_RC_STOP
55 56
56#elif CONFIG_KEYPAD == ONDIO_PAD 57#elif CONFIG_KEYPAD == ONDIO_PAD
58#define CONTINUE_TEXT "MENU To Continue"
57#define QUIT BUTTON_OFF 59#define QUIT BUTTON_OFF
58#define LEFT BUTTON_LEFT 60#define LEFT BUTTON_LEFT
59#define RIGHT BUTTON_RIGHT 61#define RIGHT BUTTON_RIGHT
@@ -165,6 +167,7 @@ CONFIG_KEYPAD == SANSA_M200_PAD
165#define DOWN BUTTON_DOWN 167#define DOWN BUTTON_DOWN
166 168
167#elif CONFIG_KEYPAD == IAUDIO_M3_PAD 169#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
170#define CONTINUE_TEXT "PLAY To Continue"
168#define QUIT BUTTON_RC_REC 171#define QUIT BUTTON_RC_REC
169#define LEFT BUTTON_RC_REW 172#define LEFT BUTTON_RC_REW
170#define RIGHT BUTTON_RC_FF 173#define RIGHT BUTTON_RC_FF
@@ -234,6 +237,13 @@ CONFIG_KEYPAD == SANSA_M200_PAD
234#endif 237#endif
235#endif 238#endif
236 239
240/* Continue text is used as a string later when the game is paused. This allows
241 * targets to specify their own text if needed.
242 */
243#if !defined(CONTINUE_TEXT)
244#define CONTINUE_TEXT "Press SELECT To Continue"
245#endif
246
237#ifndef SCROLL_FWD /* targets without scroll wheel*/ 247#ifndef SCROLL_FWD /* targets without scroll wheel*/
238#define SCROLL_FWD(x) (0) 248#define SCROLL_FWD(x) (0)
239#define SCROLL_BACK(x) (0) 249#define SCROLL_BACK(x) (0)
@@ -804,7 +814,7 @@ int check_lines(line *line1, line *line2, point *hitp)
804 return 0; 814 return 0;
805} 815}
806 816
807static void brickmania_init_game(int new_game) 817static void brickmania_init_game(bool new_game)
808{ 818{
809 int i,j; 819 int i,j;
810 820
@@ -828,7 +838,7 @@ static void brickmania_init_game(int new_game)
828 flip_sides = false; 838 flip_sides = false;
829 num_count = 10; 839 num_count = 10;
830 840
831 if (new_game==1) { 841 if (new_game) {
832 brick_on_board=0; 842 brick_on_board=0;
833 /* add one life per achieved level */ 843 /* add one life per achieved level */
834 if (difficulty==EASY && life<2) { 844 if (difficulty==EASY && life<2) {
@@ -846,7 +856,7 @@ static void brickmania_init_game(int new_game)
846 for(j=0;j<=9;j++) { 856 for(j=0;j<=9;j++) {
847 int bnum = i*10+j; 857 int bnum = i*10+j;
848 brick[bnum].poweruse = false; 858 brick[bnum].poweruse = false;
849 if (new_game==1) { 859 if (new_game) {
850 brick[bnum].power=rb->rand()%25; 860 brick[bnum].power=rb->rand()%25;
851 /* +8 make the game with less powerups */ 861 /* +8 make the game with less powerups */
852 862
@@ -1080,7 +1090,7 @@ static int brickmania_menu(void)
1080 vscore=0; 1090 vscore=0;
1081 life=2; 1091 life=2;
1082 level=0; 1092 level=0;
1083 brickmania_init_game(1); 1093 brickmania_init_game(true);
1084 return 0; 1094 return 0;
1085 case 2: 1095 case 2:
1086 rb->set_option("Difficulty", &difficulty, INT, 1096 rb->set_option("Difficulty", &difficulty, INT,
@@ -1140,7 +1150,7 @@ void brick_hit(int brick_number)
1140 else { 1150 else {
1141 brick[brick_number].used=0; 1151 brick[brick_number].used=0;
1142 /* Was there a powerup on the brick? */ 1152 /* Was there a powerup on the brick? */
1143 if (brick[brick_number].power!=10) { 1153 if (brick[brick_number].power<10) {
1144 /* Activate the powerup */ 1154 /* Activate the powerup */
1145 brick[brick_number].poweruse = true; 1155 brick[brick_number].poweruse = true;
1146 } 1156 }
@@ -1151,43 +1161,44 @@ void brick_hit(int brick_number)
1151 1161
1152static int brickmania_game_loop(void) 1162static int brickmania_game_loop(void)
1153{ 1163{
1154 int j,i,k,bricky,brickx; 1164 int j,i,k;
1155 int sw; 1165 int sw;
1156 char s[30]; 1166 char s[30];
1157 int sec_count=0; 1167 int sec_count=0;
1158 int end; 1168 int end;
1159 1169
1160 /* these lines are used to describe the brick */ 1170 /* pad_line used for powerup/ball checks */
1161 line bot_brick, top_brick, left_brick, rght_brick, pad_line; 1171 line pad_line;
1162 /* This is used for various lines that are checked (ball and powerup) */ 1172 /* This is used for various lines that are checked (ball and powerup) */
1163 line misc_line; 1173 line misc_line;
1164 1174
1165 /* This stores the point that the two lines intersected in a test */ 1175 /* This stores the point that the two lines intersected in a test */
1166 point pt_hit; 1176 point pt_hit;
1167 1177
1168 if (brickmania_menu()!=0) { 1178 if (brickmania_menu()) {
1169 return 1; 1179 return 1;
1170 } 1180 }
1171 resume = false; 1181 resume = false;
1172 resume_file = false; 1182 resume_file = false;
1183
1184#ifdef HAVE_LCD_COLOR
1185 rb->lcd_set_background(LCD_BLACK);
1186 rb->lcd_set_foreground(LCD_WHITE);
1187 rb->lcd_set_drawmode(DRMODE_SOLID);
1188 rb->lcd_clear_display();
1189#endif
1173 1190
1174 while(true) { 1191 while(true) {
1175 /* Convert CYCLETIME (in ms) to HZ */ 1192 /* Convert CYCLETIME (in ms) to HZ */
1176 end = *rb->current_tick + (CYCLETIME * HZ) / 1000; 1193 end = *rb->current_tick + (CYCLETIME * HZ) / 1000;
1177 1194
1178 if (life >= 0) { 1195 if (life >= 0) {
1179#ifdef HAVE_LCD_COLOR
1180 rb->lcd_set_background(LCD_BLACK);
1181 rb->lcd_set_drawmode(DRMODE_SOLID);
1182 rb->lcd_clear_display();
1183 rb->lcd_set_background(LCD_BLACK);
1184 rb->lcd_set_foreground(LCD_WHITE);
1185#else
1186 rb->lcd_clear_display(); 1196 rb->lcd_clear_display();
1187#endif
1188 1197
1189 if (flip_sides) { 1198 if (flip_sides)
1190 if (*rb->current_tick>=sec_count) { 1199 {
1200 if (*rb->current_tick>=sec_count)
1201 {
1191 sec_count=*rb->current_tick+HZ; 1202 sec_count=*rb->current_tick+HZ;
1192 if (num_count!=0) 1203 if (num_count!=0)
1193 num_count--; 1204 num_count--;
@@ -1222,17 +1233,9 @@ static int brickmania_game_loop(void)
1222 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s); 1233 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s);
1223 1234
1224 /* continue game */ 1235 /* continue game */
1225 if (game_state==ST_PAUSE) 1236 if (game_state == ST_PAUSE)
1226 { 1237 {
1227#if CONFIG_KEYPAD == ONDIO_PAD 1238 rb->snprintf(s, sizeof(s), CONTINUE_TEXT);
1228 rb->snprintf(s, sizeof(s), "MENU To Continue");
1229#elif CONFIG_KEYPAD == IRIVER_H300_PAD
1230 rb->snprintf(s, sizeof(s), "Press NAVI To Continue");
1231#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
1232 rb->snprintf(s, sizeof(s), "PLAY To Continue");
1233#else
1234 rb->snprintf(s, sizeof(s), "Press SELECT To Continue");
1235#endif
1236 rb->lcd_getstringsize(s, &sw, NULL); 1239 rb->lcd_getstringsize(s, &sw, NULL);
1237 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, INT3(STRINGPOS_NAVI), s); 1240 rb->lcd_putsxy(LCD_WIDTH/2-sw/2, INT3(STRINGPOS_NAVI), s);
1238 1241
@@ -1248,7 +1251,7 @@ static int brickmania_game_loop(void)
1248 brick_on_board--; 1251 brick_on_board--;
1249 1252
1250 /* if the pad is fire */ 1253 /* if the pad is fire */
1251 for(i=0;i<30;i++) 1254 for(i=0; i<30; i++)
1252 { 1255 {
1253 /* If the projectile is active (>0 inactive) */ 1256 /* If the projectile is active (>0 inactive) */
1254 if (fire[i].top >= 0) 1257 if (fire[i].top >= 0)
@@ -1260,34 +1263,34 @@ static int brickmania_game_loop(void)
1260 INT3(fire[i].top + FIRE_LENGTH)); 1263 INT3(fire[i].top + FIRE_LENGTH));
1261 } 1264 }
1262 } 1265 }
1266
1267 /* Setup the pad line-later used in intersection test */
1268 pad_line.p1.x = pad_pos_x;
1269 pad_line.p1.y = PAD_POS_Y;
1270
1271 pad_line.p2.x = pad_pos_x + pad_width;
1272 pad_line.p2.y = PAD_POS_Y;
1263 1273
1264 /* handle all of the bricks */ 1274 /* handle all of the bricks */
1265 for (i=0;i<=7;i++) 1275 for (i=0;i<=7;i++)
1266 { 1276 {
1267 for (j=0;j<=9;j++) 1277 for (j=0;j<=9;j++)
1268 { 1278 {
1269 int brick_width = BRICK_WIDTH; 1279 int brickx;
1270
1271 int bnum = i*10+j; 1280 int bnum = i*10+j;
1272 brickx = LEFTMARGIN + j*BRICK_WIDTH;
1273
1274 /* Setup the pad line - later used for intersection tests*/
1275 pad_line.p1.x = pad_pos_x;
1276 pad_line.p1.y = PAD_POS_Y + PAD_HEIGHT;
1277 1281
1278 pad_line.p2.x = pad_pos_x + pad_width; 1282 /* This brick is not really a brick, it is a powerup if
1279 pad_line.p2.y = PAD_POS_Y + PAD_HEIGHT; 1283 * poweruse is set. Perform appropriate powerup checks.
1280 1284 */
1281 /* This is the only place the that powertop is updated */ 1285 if(brick[bnum].poweruse)
1282 if (brick[bnum].poweruse && brick[bnum].power<9)
1283 { 1286 {
1287 brickx = LEFTMARGIN + j*BRICK_WIDTH +
1288 (BRICK_WIDTH - POWERUP_WIDTH) / 2;
1289
1290 /* Update powertop if the game is not paused */
1284 if (game_state!=ST_PAUSE) 1291 if (game_state!=ST_PAUSE)
1285 brick[bnum].powertop+=SPEED_POWER; 1292 brick[bnum].powertop+=SPEED_POWER;
1286 1293
1287 brick_width = POWERUP_WIDTH;
1288 brickx = LEFTMARGIN + j*BRICK_WIDTH +
1289 ((BRICK_WIDTH - POWERUP_WIDTH) >> 1);
1290
1291 /* Draw the powerup */ 1294 /* Draw the powerup */
1292 rb->lcd_bitmap_part(brickmania_powerups,0, 1295 rb->lcd_bitmap_part(brickmania_powerups,0,
1293 INT3(POWERUP_HEIGHT)*brick[bnum].power, 1296 INT3(POWERUP_HEIGHT)*brick[bnum].power,
@@ -1298,182 +1301,192 @@ static int brickmania_game_loop(void)
1298 INT3(brick[bnum].powertop), 1301 INT3(brick[bnum].powertop),
1299 INT3(POWERUP_WIDTH), 1302 INT3(POWERUP_WIDTH),
1300 INT3(POWERUP_HEIGHT) ); 1303 INT3(POWERUP_HEIGHT) );
1301 } 1304
1305 /* Use misc_line to check if the center of the powerup
1306 * hit the paddle.
1307 */
1308 misc_line.p1.x = brickx + (POWERUP_WIDTH >> 1);
1309 misc_line.p1.y = brick[bnum].powertop + POWERUP_HEIGHT;
1310
1311 misc_line.p2.x = brickx + (POWERUP_WIDTH >> 1);
1312 misc_line.p2.y = SPEED_POWER + brick[bnum].powertop +
1313 POWERUP_HEIGHT;
1302 1314
1303 bricky=brick[bnum].powertop; 1315 /* Check if the powerup will hit the paddle */
1304 1316 if ( check_lines(&misc_line, &pad_line, &pt_hit) )
1305 /* Describe the brick for later collision checks */ 1317 {
1306 /* Setup the bottom of the brick */ 1318 switch(brick[bnum].power) {
1307 bot_brick.p1.x = brickx; 1319 case 0: /* Extra Life */
1308 bot_brick.p1.y = bricky + BRICK_HEIGHT; 1320 life++;
1309 1321 score += 50;
1310 bot_brick.p2.x = brickx + brick_width; 1322 break;
1311 bot_brick.p2.y = bricky + BRICK_HEIGHT; 1323 case 1: /* Loose a life */
1324 life--;
1325 if (life>=0)
1326 {
1327 brickmania_init_game(false);
1328 brickmania_sleep(2);
1329 }
1330 break;
1331 case 2: /* Make the paddle sticky */
1332 score += 34;
1333 pad_type = STICKY;
1334 break;
1335 case 3: /* Give the paddle shooter */
1336 score += 47;
1337 pad_type = SHOOTER;
1338 for(k=0;k<used_balls;k++)
1339 ball[k].glue=false;
1340 break;
1341 case 4: /* Normal brick */
1342 score += 23;
1343 pad_type = PLAIN;
1344 for(k=0;k<used_balls;k++)
1345 ball[k].glue=false;
1346 flip_sides=false;
1347
1348 pad_pos_x += (pad_width-PAD_WIDTH)/2;
1349 pad_width = PAD_WIDTH;
1350 break;
1351 case 5: /* Flip the paddle */
1352 score += 23;
1353 sec_count = *rb->current_tick+HZ;
1354 num_count = 10;
1355 flip_sides = true;
1356 break;
1357 case 6: /* Extra Ball */
1358 score += 23;
1359 if(used_balls<MAX_BALLS)
1360 {
1361 /* Set the speed */
1362 if(rb->rand()%2 == 0)
1363 ball[used_balls].speedx=-SPEED_4Q_X;
1364 else
1365 ball[used_balls].speedx= SPEED_4Q_X;
1366
1367 ball[used_balls].speedy= SPEED_4Q_Y;
1368
1369 /* Ball is not glued */
1370 ball[used_balls].glue= false;
1371 used_balls++;
1372 }
1373 break;
1374 case 7: /* Long paddle */
1375 score+=23;
1376 if (pad_width==PAD_WIDTH)
1377 {
1378 pad_width = LONG_PAD_WIDTH;
1379 pad_pos_x -= (LONG_PAD_WIDTH -
1380 PAD_WIDTH)/2;
1381 }
1382 else if (pad_width==SHORT_PAD_WIDTH)
1383 {
1384 pad_width = PAD_WIDTH;
1385 pad_pos_x-=(PAD_WIDTH-
1386 SHORT_PAD_WIDTH)/2;
1387 }
1388
1389 if (pad_pos_x < 0)
1390 pad_pos_x = 0;
1391 else if(pad_pos_x + pad_width >
1392 GAMESCREEN_WIDTH)
1393 pad_pos_x = GAMESCREEN_WIDTH-pad_width;
1394 break;
1395 case 8: /* Short Paddle */
1396 if (pad_width==PAD_WIDTH)
1397 {
1398 pad_width=SHORT_PAD_WIDTH;
1399 pad_pos_x+=(PAD_WIDTH-
1400 SHORT_PAD_WIDTH)/2;
1401 }
1402 else if (pad_width==LONG_PAD_WIDTH)
1403 {
1404 pad_width=PAD_WIDTH;
1405 pad_pos_x+=(LONG_PAD_WIDTH-PAD_WIDTH)/2;
1406 }
1407 break;
1408 }
1409 /* Disable the powerup (it was picked up) */
1410 brick[bnum].poweruse = false;
1411 }
1412
1413 if (brick[bnum].powertop>PAD_POS_Y)
1414 {
1415 /* Disable the powerup (it was missed) */
1416 brick[bnum].poweruse = false;
1417 }
1418 }
1419 /* The brick is a brick, but it may or may not be in use */
1420 else if(brick[bnum].used)
1421 {
1422 /* these lines are used to describe the brick */
1423 line bot_brick, top_brick, left_brick, rght_brick;
1424 brickx = LEFTMARGIN + j*BRICK_WIDTH;
1425
1426 /* Describe the brick for later collision checks */
1427 /* Setup the bottom of the brick */
1428 bot_brick.p1.x = brickx;
1429 bot_brick.p1.y = brick[bnum].powertop + BRICK_HEIGHT;
1312 1430
1313 /* Setup the top of the brick */ 1431 bot_brick.p2.x = brickx + BRICK_WIDTH;
1314 top_brick.p1.x = brickx; 1432 bot_brick.p2.y = brick[bnum].powertop + BRICK_HEIGHT;
1315 top_brick.p1.y = bricky; 1433
1316 1434 /* Setup the top of the brick */
1317 top_brick.p2.x = brickx + brick_width; 1435 top_brick.p1.x = brickx;
1318 top_brick.p2.y = bricky; 1436 top_brick.p1.y = brick[bnum].powertop;
1319 1437
1320 /* Setup the left of the brick */ 1438 top_brick.p2.x = brickx + BRICK_WIDTH;
1321 left_brick.p1.x = brickx; 1439 top_brick.p2.y = brick[bnum].powertop;
1322 left_brick.p1.y = bricky; 1440
1323 1441 /* Setup the left of the brick */
1324 left_brick.p2.x = brickx; 1442 left_brick.p1.x = brickx;
1325 left_brick.p2.y = bricky + BRICK_HEIGHT; 1443 left_brick.p1.y = brick[bnum].powertop;
1326 1444
1327 /* Setup the right of the brick */ 1445 left_brick.p2.x = brickx;
1328 rght_brick.p1.x = brickx + brick_width; 1446 left_brick.p2.y = brick[bnum].powertop + BRICK_HEIGHT;
1329 rght_brick.p1.y = bricky; 1447
1330 1448 /* Setup the right of the brick */
1331 rght_brick.p2.x = brickx + brick_width; 1449 rght_brick.p1.x = brickx + BRICK_WIDTH;
1332 rght_brick.p2.y = bricky + BRICK_HEIGHT; 1450 rght_brick.p1.y = brick[bnum].powertop;
1333 1451
1334 /* Use misc_line to check if the center of the powerup hit 1452 rght_brick.p2.x = brickx + BRICK_WIDTH;
1335 * the paddle. 1453 rght_brick.p2.y = brick[bnum].powertop + BRICK_HEIGHT;
1336 */
1337 misc_line.p1.x = brickx + (brick_width >> 1);
1338 misc_line.p1.y = brick[bnum].powertop + POWERUP_HEIGHT;
1339 1454
1340 misc_line.p2.x = brickx + (brick_width >> 1); 1455 /* Check if any of the active fires hit a brick */
1341 misc_line.p2.y = SPEED_POWER + brick[bnum].powertop + 1456 if (pad_type == SHOOTER)
1342 POWERUP_HEIGHT; 1457 {
1343 1458 for (k=0;k<30;k++)
1344 /* Check if the powerup will hit the paddle */ 1459 {
1345 if (brick[bnum].poweruse && /* Is the powerup active? */ 1460 /* Use misc_line to check if fire hit brick */
1346 check_lines(&misc_line, &pad_line, &pt_hit) ) 1461 misc_line.p1.x = fire[k].x_pos;
1347 { 1462 misc_line.p1.y = fire[k].top;
1348 switch(brick[bnum].power) {
1349 case 0: /* Extra Life */
1350 life++;
1351 score += 50;
1352 break;
1353 case 1: /* Loose a life */
1354 life--;
1355 if (life>=0)
1356 {
1357 brickmania_init_game(0);
1358 brickmania_sleep(2);
1359 }
1360 break;
1361 case 2: /* Make the paddle sticky */
1362 score += 34;
1363 pad_type = STICKY;
1364 break;
1365 case 3: /* Give the paddle shooter */
1366 score += 47;
1367 pad_type = SHOOTER;
1368 for(k=0;k<used_balls;k++)
1369 ball[k].glue=false;
1370 break;
1371 case 4: /* Normal brick */
1372 score += 23;
1373 pad_type = PLAIN;
1374 for(k=0;k<used_balls;k++)
1375 ball[k].glue=false;
1376 flip_sides=false;
1377
1378 pad_pos_x += (pad_width-PAD_WIDTH)/2;
1379 pad_width = PAD_WIDTH;
1380 break;
1381 case 5: /* Flip the paddle */
1382 score += 23;
1383 sec_count = *rb->current_tick+HZ;
1384 num_count = 10;
1385 flip_sides = true;
1386 break;
1387 case 6: /* Extra Ball */
1388 score += 23;
1389 if(used_balls<MAX_BALLS)
1390 {
1391 /* Set the speed */
1392 ball[used_balls].speedx= rb->rand()%2 == 0 ?
1393 -SPEED_4Q_X : SPEED_4Q_X;
1394 ball[used_balls].speedy= SPEED_4Q_Y;
1395
1396 /* Ball is not glued */
1397 ball[used_balls].glue= false;
1398 used_balls++;
1399 }
1400 break;
1401 case 7: /* Long paddle */
1402 score+=23;
1403 if (pad_width==PAD_WIDTH)
1404 {
1405 pad_width = LONG_PAD_WIDTH;
1406 pad_pos_x -= (LONG_PAD_WIDTH -PAD_WIDTH)/2;
1407 }
1408 else if (pad_width==SHORT_PAD_WIDTH)
1409 {
1410 pad_width = PAD_WIDTH;
1411 pad_pos_x-=(PAD_WIDTH-SHORT_PAD_WIDTH)/2;
1412 }
1413 1463
1414 if (pad_pos_x < 0) 1464 misc_line.p2.x = fire[k].x_pos;
1415 pad_pos_x = 0; 1465 misc_line.p2.y = fire[k].top + SPEED_FIRE;
1416 else if(pad_pos_x+pad_width > GAMESCREEN_WIDTH) 1466
1417 pad_pos_x = GAMESCREEN_WIDTH-pad_width; 1467 /* If the fire hit the brick take care of it */
1418 break; 1468 if (fire[k].top > 0 &&
1419 case 8: /* Short Paddle */ 1469 check_lines(&misc_line, &bot_brick,
1420 if (pad_width==PAD_WIDTH) 1470 &pt_hit))
1421 {
1422 pad_width=SHORT_PAD_WIDTH;
1423 pad_pos_x+=(PAD_WIDTH-SHORT_PAD_WIDTH)/2;
1424 }
1425 else if (pad_width==LONG_PAD_WIDTH)
1426 { 1471 {
1427 pad_width=PAD_WIDTH; 1472 score+=13;
1428 pad_pos_x+=(LONG_PAD_WIDTH-PAD_WIDTH)/2; 1473 /* De-activate the fire */
1474 fire[k].top=-1;
1475 brick_hit(bnum);
1429 } 1476 }
1430 break;
1431 }
1432 /* Disable the powerup (it was picked up) */
1433 brick[bnum].poweruse = false;
1434 }
1435
1436 if (brick[bnum].powertop>PAD_POS_Y)
1437 {
1438 /* Disable the powerup (it was missed) */
1439 brick[bnum].poweruse = false;
1440 }
1441
1442 /* Check if any of the active fires hit a brick */
1443 if (pad_type == SHOOTER)
1444 {
1445 for (k=0;k<30;k++)
1446 {
1447 /* Use misc_line to check if fire hit brick */
1448 misc_line.p1.x = fire[k].x_pos;
1449 misc_line.p1.y = fire[k].top;
1450
1451 misc_line.p2.x = fire[k].x_pos;
1452 misc_line.p2.y = fire[k].top + SPEED_FIRE;
1453
1454 /* If the fire hit the brick take care of it */
1455 if (brick[bnum].used && fire[k].top > 0 &&
1456 check_lines(&misc_line, &bot_brick, &pt_hit))
1457 {
1458 score+=13;
1459 /* De-activate the fire */
1460 fire[k].top=-1;
1461 brick_hit(bnum);
1462 } 1477 }
1463 } 1478 }
1464 }
1465 1479
1466 /* Draw the brick if it is used*/ 1480 /* Draw the brick */
1467 if (brick[bnum].used)
1468 {
1469 rb->lcd_bitmap_part(brickmania_bricks,0, 1481 rb->lcd_bitmap_part(brickmania_bricks,0,
1470 INT3(BRICK_HEIGHT)*brick[bnum].color, 1482 INT3(BRICK_HEIGHT)*brick[bnum].color,
1471 STRIDE( SCREEN_MAIN, 1483 STRIDE( SCREEN_MAIN,
1472 BMPWIDTH_brickmania_bricks, 1484 BMPWIDTH_brickmania_bricks,
1473 BMPHEIGHT_brickmania_bricks), 1485 BMPHEIGHT_brickmania_bricks),
1474 INT3(brickx), 1486 INT3(brickx),
1475 INT3(bricky), 1487 INT3(brick[bnum].powertop),
1476 INT3(BRICK_WIDTH), INT3(BRICK_HEIGHT) ); 1488 INT3(BRICK_WIDTH), INT3(BRICK_HEIGHT) );
1489
1477#ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */ 1490#ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */
1478 if (brick[bnum].hiteffect > 0) 1491 if (brick[bnum].hiteffect > 0)
1479 rb->lcd_bitmap_transparent_part(brickmania_break,0, 1492 rb->lcd_bitmap_transparent_part(brickmania_break,0,
@@ -1482,14 +1495,12 @@ static int brickmania_game_loop(void)
1482 BMPWIDTH_brickmania_break, 1495 BMPWIDTH_brickmania_break,
1483 BMPHEIGHT_brickmania_break), 1496 BMPHEIGHT_brickmania_break),
1484 INT3(brickx), 1497 INT3(brickx),
1485 INT3(bricky), 1498 INT3(brick[bnum].powertop),
1486 INT3(BRICK_WIDTH), INT3(BRICK_HEIGHT) ); 1499 INT3(BRICK_WIDTH), INT3(BRICK_HEIGHT) );
1487#endif 1500#endif
1488 } 1501
1489 /* Check if the ball collided with the brick */ 1502 /* Check if any balls collided with the brick */
1490 for(k=0;k<used_balls;k++) 1503 for(k=0; k<used_balls; k++)
1491 {
1492 if (brick[bnum].used)
1493 { 1504 {
1494 /* Setup the ball path to describe the current ball 1505 /* Setup the ball path to describe the current ball
1495 * position and the line it makes to its next 1506 * position and the line it makes to its next
@@ -1549,8 +1560,9 @@ static int brickmania_game_loop(void)
1549 ball[k].tempx = pt_hit.x + HALFBALL; 1560 ball[k].tempx = pt_hit.x + HALFBALL;
1550 brick_hit(bnum); 1561 brick_hit(bnum);
1551 } 1562 }
1552 } 1563 } /* for k */
1553 } /* for k */ 1564 } /* if(used) */
1565
1554 } /* for j */ 1566 } /* for j */
1555 } /* for i */ 1567 } /* for i */
1556 1568
@@ -1567,15 +1579,6 @@ static int brickmania_game_loop(void)
1567 INT3(pad_pos_x), INT3(PAD_POS_Y), 1579 INT3(pad_pos_x), INT3(PAD_POS_Y),
1568 INT3(pad_width), INT3(PAD_HEIGHT) ); 1580 INT3(pad_width), INT3(PAD_HEIGHT) );
1569 1581
1570 /* Setup the pad line for ball collision checks (done again
1571 * because of the power up checks above.
1572 */
1573 pad_line.p1.x = pad_pos_x;
1574 pad_line.p1.y = PAD_POS_Y;
1575
1576 pad_line.p2.x = pad_pos_x + pad_width;
1577 pad_line.p2.y = PAD_POS_Y;
1578
1579 /* If the game is not paused continue */ 1582 /* If the game is not paused continue */
1580 if (game_state!=ST_PAUSE) 1583 if (game_state!=ST_PAUSE)
1581 { 1584 {
@@ -1623,7 +1626,7 @@ static int brickmania_game_loop(void)
1623 if (life>=0) 1626 if (life>=0)
1624 { 1627 {
1625 /* No lives left reset game */ 1628 /* No lives left reset game */
1626 brickmania_init_game(0); 1629 brickmania_init_game(false);
1627 brickmania_sleep(2); 1630 brickmania_sleep(2);
1628 } 1631 }
1629 } 1632 }
@@ -1764,7 +1767,7 @@ static int brickmania_game_loop(void)
1764 level++; 1767 level++;
1765 if (difficulty==NORMAL) 1768 if (difficulty==NORMAL)
1766 score+=100; 1769 score+=100;
1767 brickmania_init_game(1); 1770 brickmania_init_game(true);
1768 brickmania_sleep(2); 1771 brickmania_sleep(2);
1769 } 1772 }
1770 else 1773 else
@@ -1990,8 +1993,10 @@ enum plugin_status plugin_start(const void* parameter)
1990 rb->srand( *rb->current_tick ); 1993 rb->srand( *rb->current_tick );
1991 brickmania_loadgame(); 1994 brickmania_loadgame();
1992 resume_file = resume; 1995 resume_file = resume;
1993 while(brickmania_game_loop() == 0) { 1996 while(!brickmania_game_loop())
1994 if(!resume) { 1997 {
1998 if(!resume)
1999 {
1995 int position = highscore_update(score, level+1, "", highest, 2000 int position = highscore_update(score, level+1, "", highest,
1996 NUM_SCORES); 2001 NUM_SCORES);
1997 if (position == 0) 2002 if (position == 0)