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.c139
1 files changed, 106 insertions, 33 deletions
diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c
index a26ff8edd8..a638fcc5b9 100644
--- a/apps/plugins/brickmania.c
+++ b/apps/plugins/brickmania.c
@@ -9,6 +9,7 @@
9 * 9 *
10 * Copyright (C) 2005, 2006 Ben Basha (Paprica) 10 * Copyright (C) 2005, 2006 Ben Basha (Paprica)
11 * Copyright (C) 2009 Karl Kurbjun 11 * Copyright (C) 2009 Karl Kurbjun
12 * Copyright (C) 2010 Matteo Italia (MItaly)
12 * check_lines is based off an explanation and expanded math presented by Paul 13 * check_lines is based off an explanation and expanded math presented by Paul
13 * Bourke: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ 14 * Bourke: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
14 * 15 *
@@ -392,6 +393,21 @@ CONFIG_KEYPAD == SANSA_M200_PAD
392#endif 393#endif
393#endif 394#endif
394 395
396/* MI: fallback for the suicide combination */
397#ifndef SUICIDE
398/* Some targets do not define DOWN (which isn't actually used in the game) */
399#ifndef DOWN
400#define TWO_KEYS_SUICIDE
401/* No third key to add safety to the suicide button -> press it longer */
402#define SUICIDE (SELECT|QUIT|BUTTON_REPEAT)
403#else
404#define THREE_KEYS_SUICIDE
405/* Three keys provide enough safety to avoid the long press, which may lead to
406 more suicides than necessary :) */
407#define SUICIDE (DOWN|SELECT|QUIT)
408#endif /* #ifndef DOWN */
409#endif /* #ifndef SUICIDE */
410
395/* Continue text is used as a string later when the game is paused. This allows 411/* Continue text is used as a string later when the game is paused. This allows
396 * targets to specify their own text if needed. 412 * targets to specify their own text if needed.
397 */ 413 */
@@ -1441,16 +1457,16 @@ static void brickmania_sleep(int secs)
1441static int brickmania_help(void) 1457static int brickmania_help(void)
1442{ 1458{
1443 static char *help_text[] = { 1459 static char *help_text[] = {
1444 "Brickmania", "", "Aim", "", 1460 "Brickmania", "", "Aim", "", /* 3 */
1445 "Destroy", "all", "the", "bricks", "by", "bouncing", 1461 "Destroy", "all", "the", "bricks", "by", "bouncing", /* 9 */
1446 "the", "ball", "of", "them", "using", "the", "paddle.", "", "", 1462 "the", "ball", "of", "them", "using", "the", "paddle.", "", "", /* 18 */
1447 "Controls", "", 1463 "Controls", "", /* 20 */
1448#if CONFIG_KEYPAD == COWON_D2_PAD 1464#if CONFIG_KEYPAD == COWON_D2_PAD
1449 "- & +:", 1465 "- & +:",
1450#else 1466#else
1451 "< & >:", 1467 "< & >:",
1452#endif 1468#endif
1453 "Moves", "the", "paddle", "", 1469 "Moves", "the", "paddle", "", /* 25 */
1454#if (CONFIG_KEYPAD == IAUDIO_M3_PAD) 1470#if (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1455 "PLAY:", 1471 "PLAY:",
1456#elif CONFIG_KEYPAD == IRIVER_H300_PAD 1472#elif CONFIG_KEYPAD == IRIVER_H300_PAD
@@ -1460,7 +1476,7 @@ static int brickmania_help(void)
1460#else 1476#else
1461 "SELECT:", 1477 "SELECT:",
1462#endif 1478#endif
1463 "Releases", "the", "ball/Fire!", "", 1479 "Releases", "the", "ball/Fire!", "", /* 30 */
1464#if CONFIG_KEYPAD == IAUDIO_M3_PAD 1480#if CONFIG_KEYPAD == IAUDIO_M3_PAD
1465 "REC:", 1481 "REC:",
1466#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \ 1482#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
@@ -1477,30 +1493,52 @@ static int brickmania_help(void)
1477#else 1493#else
1478 "POWER:", 1494 "POWER:",
1479#endif 1495#endif
1480 "Returns", "to", "menu", "", "", 1496 "Returns", "to", "menu", "", /* 35 */
1481 "Specials", "", 1497#if defined(THREE_KEYS_SUICIDE)
1482 "N", "Normal:", "returns", "paddle", "to", "normal", "", 1498 "Press", "Fire,", "Down,", "Quit", "together:",
1483 "D", "DIE!:", "loses", "a", "life", "", 1499#elif defined(TWO_KEYS_SUICIDE)
1484 "L", "Life:", "gains", "a", "life/power", "up", "", 1500 "Hold", "Fire", "and", "Quit", "together:",
1485 "F", "Fire:", "allows", "you", "to", "shoot", "bricks", "", 1501#else
1486 "G", "Glue:", "ball", "sticks", "to", "paddle", "", 1502#error No info about the suicide button, cannot complete help screen.
1487 "B", "Ball:", "generates", "another", "ball", "", 1503#endif
1488 "FL", "Flip:", "flips", "left / right", "movement", "", 1504 "Kills", "all","the", "balls","(suicide)","", /* 46 */
1489 "<->", "or", "<E>:", "enlarges", "the", "paddle", "", 1505 "", /* 47 */
1490 ">-<", "or", ">S<:", "shrinks", "the", "paddle", "", 1506 "Specials", "", /* 49 */
1507 "N", "Normal:", "returns", "paddle", "to", "normal", "", /* 56 */
1508 "D", "DIE!:", "loses", "a", "life", "", /* 62 */
1509 "L", "Life:", "gains", "a", "life/power", "up", "", /* 69 */
1510 "F", "Fire:", "allows", "you", "to", "shoot", "bricks", "", /* 77 */
1511 "G", "Glue:", "ball", "sticks", "to", "paddle", "", /* 84 */
1512 "B", "Ball:", "generates", "another", "ball", "", /* 90 */
1513 "FL", "Flip:", "flips", "left / right", "movement", "", /* 96 */
1514 "<->", "or", "<E>:", "enlarges", "the", "paddle", "", /* 103 */
1515 ">-<", "or", ">S<:", "shrinks", "the", "paddle", "", /* 110 */
1491 }; 1516 };
1492 static struct style_text formation[]={ 1517 static struct style_text formation[]={
1493 { 0, TEXT_CENTER|TEXT_UNDERLINE }, 1518 { 0, TEXT_CENTER|TEXT_UNDERLINE },
1494 { 2, C_RED }, 1519 { 2, C_RED },
1495 { 19, C_RED }, 1520 { 19, C_RED },
1496 { 37, C_RED }, 1521 { 21, TEXT_UNDERLINE},
1497 { 39, C_BLUE }, 1522 { 26, TEXT_UNDERLINE},
1498 { 46, C_RED }, 1523 { 31, TEXT_UNDERLINE},
1499 { 52, C_GREEN }, 1524#if defined(THREE_KEYS_SUICIDE)
1500 { 59, C_ORANGE }, 1525 { 37, TEXT_UNDERLINE},
1501 { 67, C_GREEN }, 1526 { 38, TEXT_UNDERLINE},
1502 { 74, C_YELLOW }, 1527 { 39, TEXT_UNDERLINE},
1503 { 80, C_RED }, 1528#elif defined(TWO_KEYS_SUICIDE)
1529 { 37, TEXT_UNDERLINE},
1530 { 39, TEXT_UNDERLINE},
1531#else
1532#error No info about the suicide button, cannot complete help screen.
1533#endif
1534 { 48, C_RED },
1535 { 50, C_BLUE },
1536 { 57, C_RED },
1537 { 63, C_GREEN },
1538 { 70, C_ORANGE },
1539 { 78, C_GREEN },
1540 { 85, C_YELLOW },
1541 { 91, C_RED },
1504 LAST_STYLE_ITEM 1542 LAST_STYLE_ITEM
1505 }; 1543 };
1506 1544
@@ -1522,9 +1560,13 @@ static int brickmania_menu_cb(int action,
1522{ 1560{
1523 (void)this_list; 1561 (void)this_list;
1524 int i = ((intptr_t)this_item); 1562 int i = ((intptr_t)this_item);
1525 if(action == ACTION_REQUEST_MENUITEM 1563 if(action == ACTION_REQUEST_MENUITEM)
1526 && !resume && (i==0 || i==6)) 1564 {
1527 return ACTION_EXIT_MENUITEM; 1565 if(!resume && (i==0 || i==7))
1566 return ACTION_EXIT_MENUITEM;
1567 if(i==6 && !rb->file_exists(SAVE_FILE))
1568 return ACTION_EXIT_MENUITEM;
1569 }
1528 return action; 1570 return action;
1529} 1571}
1530 1572
@@ -1546,16 +1588,14 @@ static int brickmania_menu(void)
1546 "Resume Game", "Start New Game", 1588 "Resume Game", "Start New Game",
1547 "Difficulty", "Help", "High Scores", 1589 "Difficulty", "Help", "High Scores",
1548 "Playback Control", 1590 "Playback Control",
1591 "Remove savefile",
1549 "Quit without Saving", "Quit"); 1592 "Quit without Saving", "Quit");
1550
1551 rb->button_clear_queue(); 1593 rb->button_clear_queue();
1552 while (true) { 1594 while (true) {
1553 switch (rb->do_menu(&main_menu, &selected, NULL, false)) { 1595 switch (rb->do_menu(&main_menu, &selected, NULL, false)) {
1554 case 0: 1596 case 0:
1555 if(game_state!=ST_READY) 1597 if(game_state!=ST_READY)
1556 game_state = ST_PAUSE; 1598 game_state = ST_PAUSE;
1557 if(resume_file)
1558 rb->remove(SAVE_FILE);
1559 return 0; 1599 return 0;
1560 case 1: 1600 case 1:
1561 score=0; 1601 score=0;
@@ -1580,8 +1620,11 @@ static int brickmania_menu(void)
1580 return 1; 1620 return 1;
1581 break; 1621 break;
1582 case 6: 1622 case 6:
1583 return 1; 1623 rb->remove(SAVE_FILE);
1624 break;
1584 case 7: 1625 case 7:
1626 return 1;
1627 case 8:
1585 if (resume) { 1628 if (resume) {
1586 rb->splash(HZ*1, "Saving game ..."); 1629 rb->splash(HZ*1, "Saving game ...");
1587 brickmania_savegame(); 1630 brickmania_savegame();
@@ -1631,6 +1674,20 @@ static void brick_hit(int i, int j)
1631 } 1674 }
1632} 1675}
1633 1676
1677static void newround(void)
1678{
1679 brickmania_init_game(false);
1680 brickmania_sleep(2);
1681}
1682
1683static void error_newround(const char * message)
1684{
1685 rb->splash(HZ*3,"Some error happened, so the current balls will be killed.");
1686 rb->splashf(HZ*3,"The reason is: %s",message);
1687 rb->splash(HZ*3,"Don't worry, it's my fault, you won't lose any life for this. :)");
1688 newround();
1689}
1690
1634static int brickmania_game_loop(void) 1691static int brickmania_game_loop(void)
1635{ 1692{
1636 int j,i,k; 1693 int j,i,k;
@@ -1723,10 +1780,17 @@ static int brickmania_game_loop(void)
1723 1780
1724 /* draw the ball */ 1781 /* draw the ball */
1725 for(i=0;i<used_balls;i++) 1782 for(i=0;i<used_balls;i++)
1783 {
1784 /* MI: workaround for balls exiting from the screen */
1785 const int H_OFFSCREEN_LIMIT=GAMESCREEN_WIDTH*3/2;
1786 const int V_OFFSCREEN_LIMIT=GAMESCREEN_HEIGHT*3/2;
1787 if(abs(ball[i].pos_x)>H_OFFSCREEN_LIMIT || abs(ball[i].pos_y)>V_OFFSCREEN_LIMIT)
1788 error_newround("Ball went offscreen");
1726 rb->lcd_bitmap(brickmania_ball, 1789 rb->lcd_bitmap(brickmania_ball,
1727 INT3(ball[i].pos_x - HALFBALL), 1790 INT3(ball[i].pos_x - HALFBALL),
1728 INT3(ball[i].pos_y - HALFBALL), 1791 INT3(ball[i].pos_y - HALFBALL),
1729 INT3(BALL), INT3(BALL)); 1792 INT3(BALL), INT3(BALL));
1793 }
1730 1794
1731 if (brick_on_board==0) 1795 if (brick_on_board==0)
1732 brick_on_board--; 1796 brick_on_board--;
@@ -2474,7 +2538,16 @@ static int brickmania_game_loop(void)
2474 resume = true; 2538 resume = true;
2475 return 0; 2539 return 0;
2476 break; 2540 break;
2477 2541
2542 /* MI: added suicide button in case the ball gets stuck or
2543 whatever */
2544 case SUICIDE:
2545 life--;
2546 rb->splash(HZ,"Balls killed!");
2547 if(life>=0)
2548 newround();
2549 rb->button_clear_queue();
2550 break;
2478 default: 2551 default:
2479 if(rb->default_event_handler(button) == SYS_USB_CONNECTED) 2552 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
2480 return 1; 2553 return 1;