Add music, beach fishing, catching, and selectable creature partners
This commit is contained in:
1 parent
3469f2e6dd
commit
cb77683a87
24 files changed
+1307
-104
No files matched your search
+85
-23
@@ -1,10 +1,11 @@
|
||||
#include "game.h"
|
||||
|
||||
TEST_INTERNAL const struct SpeciesInfo species[SPECIES_COUNT] = {
|
||||
const struct SpeciesInfo species[SPECIES_COUNT] = {
|
||||
{"GOLDEN", "LV THREE", "WILD GOLDEN CREATURE", "GOLDEN USED BUMP", "NORMAL", GOLDEN_HP, 5, 7},
|
||||
{"FERNFOX", "LV FOUR", "WILD FERNFOX APPEARED", "FERNFOX USED LEAF SWIPE", "GRASS", 18, 4, 7},
|
||||
{"EMBERWING", "LV FOUR", "WILD EMBERWING APPEARED", "EMBERWING USED SPARK", "FIRE", 20, 4, 4},
|
||||
{"PEBBLIT", "LV FIVE", "WILD PEBBLIT APPEARED", "PEBBLIT USED ROLL", "ROCK", 22, 5, 9}
|
||||
{"PEBBLIT", "LV FIVE", "WILD PEBBLIT APPEARED", "PEBBLIT USED ROLL", "ROCK", 22, 5, 9},
|
||||
{"TIDEFIN", "LV FOUR", "HOOKED A WILD TIDEFIN", "TIDEFIN USED SPLASH JET", "WATER", 24, 4, 9}
|
||||
};
|
||||
struct BattleState battle;
|
||||
unsigned random_state = 0x6d2b79f5u;
|
||||
@@ -19,23 +20,25 @@ TEST_INTERNAL unsigned next_random(void)
|
||||
return random_state;
|
||||
}
|
||||
|
||||
TEST_INTERNAL int start_battle(enum Species enemy)
|
||||
int start_battle(enum Species enemy)
|
||||
{
|
||||
if (!partner_owned || battle.phase != BATTLE_OFF || (unsigned)enemy >= SPECIES_COUNT)
|
||||
return 0;
|
||||
battle.phase = BATTLE_TURN;
|
||||
battle.enemy = enemy;
|
||||
battle.sprout_hp = SPROUT_HP;
|
||||
battle.sprout_hp = partner_hp();
|
||||
battle.enemy_hp = species[enemy].hp;
|
||||
battle.move = 0;
|
||||
battle.turns = 0;
|
||||
battle.notice = NOTICE_NONE;
|
||||
grass_steps = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int near_golden(int x, int y)
|
||||
{
|
||||
return current_room == OUTSIDE && x >= 163 && x <= 205 && y >= 84 && y <= 126;
|
||||
return current_room == OUTSIDE && !has_caught(GOLDEN) &&
|
||||
x >= 163 && x <= 205 && y >= 84 && y <= 126;
|
||||
}
|
||||
|
||||
int begin_battle(int x, int y)
|
||||
@@ -55,7 +58,42 @@ int check_grass_encounter(int old_x, int old_y, int x, int y)
|
||||
return start_battle((enum Species)(FERNFOX + next_random() % 3u));
|
||||
}
|
||||
|
||||
/* One fresh button press performs one turn. The golden creature replies. */
|
||||
static void enemy_reply(void)
|
||||
{
|
||||
battle.sprout_hp -= species[battle.enemy].attack;
|
||||
if (battle.sprout_hp <= 0) {
|
||||
battle.sprout_hp = 0;
|
||||
battle.phase = BATTLE_LOST;
|
||||
}
|
||||
}
|
||||
|
||||
/* A weakened creature is easier to catch; quarter health guarantees it. */
|
||||
static unsigned catch_chance(void)
|
||||
{
|
||||
int maximum = species[battle.enemy].hp;
|
||||
if (battle.enemy_hp * 4 <= maximum) return 100;
|
||||
return 35u + (unsigned)((maximum - battle.enemy_hp) * 50 / maximum);
|
||||
}
|
||||
|
||||
static int throw_ball(void)
|
||||
{
|
||||
if (ball_count == 0) { battle.notice = NOTICE_NO_BALLS; return 1; }
|
||||
if (caught_count >= CAUGHT_CAPACITY) { battle.notice = NOTICE_TEAM_FULL; return 1; }
|
||||
--ball_count;
|
||||
++battle.turns;
|
||||
if (next_random() % 100 < catch_chance()) {
|
||||
caught_species[caught_count++] = (unsigned char)battle.enemy;
|
||||
battle.phase = BATTLE_CAUGHT;
|
||||
battle.notice = NOTICE_NONE;
|
||||
} else {
|
||||
battle.notice = NOTICE_BROKE_FREE;
|
||||
enemy_reply();
|
||||
}
|
||||
save_progress(); /* Save spent balls as well as successful catches. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* One fresh button press performs one turn. */
|
||||
int battle_input(unsigned pressed)
|
||||
{
|
||||
if (battle.phase == BATTLE_OFF || !pressed) return 0;
|
||||
@@ -68,20 +106,25 @@ int battle_input(unsigned pressed)
|
||||
battle.phase = BATTLE_FLED;
|
||||
return 1;
|
||||
}
|
||||
if (pressed & SELECT) return throw_ball();
|
||||
if (pressed & (LEFT | RIGHT | A)) battle.notice = NOTICE_NONE;
|
||||
if (pressed & LEFT) battle.move = 0;
|
||||
if (pressed & RIGHT) battle.move = 1;
|
||||
if (!(pressed & A)) return !!(pressed & (LEFT | RIGHT));
|
||||
battle.enemy_hp -= battle.move ? species[battle.enemy].leaf_damage : 4;
|
||||
int damage = 4;
|
||||
if (battle.move) {
|
||||
if (!active_member || caught_species[active_member - 1] == FERNFOX)
|
||||
damage = species[battle.enemy].leaf_damage;
|
||||
else
|
||||
damage = species[caught_species[active_member - 1]].attack + 3;
|
||||
}
|
||||
battle.enemy_hp -= damage;
|
||||
++battle.turns;
|
||||
if (battle.enemy_hp <= 0) {
|
||||
battle.enemy_hp = 0;
|
||||
battle.phase = BATTLE_WON;
|
||||
} else {
|
||||
battle.sprout_hp -= species[battle.enemy].attack;
|
||||
if (battle.sprout_hp <= 0) {
|
||||
battle.sprout_hp = 0;
|
||||
battle.phase = BATTLE_LOST;
|
||||
}
|
||||
enemy_reply();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -99,24 +142,43 @@ void draw_battle_hud(void)
|
||||
{
|
||||
u16 ink = RGB(5, 8, 11), cream = RGB(30, 30, 26);
|
||||
health_bar(16, 44, battle.enemy_hp, species[battle.enemy].hp);
|
||||
health_bar(136, 97, battle.sprout_hp, SPROUT_HP);
|
||||
health_bar(136, 97, battle.sprout_hp, partner_hp());
|
||||
if (battle.phase == BATTLE_CAUGHT) {
|
||||
/* Remove the creature and show its closed ball without a full-screen copy. */
|
||||
rectangle(155, 18, 64, 44, RGB(23, 29, 25));
|
||||
rectangle(155, 62, 64, 14, RGB(18, 26, 15));
|
||||
rectangle(155, battle.enemy == GOLDEN ? 61 : 70, 64, 5, RGB(12, 21, 11));
|
||||
rectangle(179, 57, 10, 12, ink);
|
||||
rectangle(178, 59, 12, 8, ink);
|
||||
rectangle(180, 58, 8, 5, RGB(29, 8, 9));
|
||||
rectangle(180, 64, 8, 4, RGB(31, 31, 28));
|
||||
rectangle(183, 62, 3, 3, ink);
|
||||
rectangle(184, 63, 1, 1, RGB(31, 31, 28));
|
||||
}
|
||||
rectangle(8, 111, 224, 43, ink);
|
||||
rectangle(10, 113, 220, 39, cream);
|
||||
if (battle.phase == BATTLE_TURN) {
|
||||
large_text(22, 119, "TACKLE", ink);
|
||||
large_text(132, 119, "LEAF TAP", ink);
|
||||
large_text(132, 119, partner_move(), ink);
|
||||
int arrow_x = battle.move ? 122 : 12;
|
||||
rectangle(arrow_x, 119, 2, 7, RGB(7, 17, 11));
|
||||
rectangle(arrow_x + 2, 121, 2, 3, RGB(7, 17, 11));
|
||||
text(16, 132, battle.turns ? species[battle.enemy].reply :
|
||||
"WHAT WILL SPROUT DO", ink);
|
||||
text(16, 143, "LEFT RIGHT CHOOSE A ATTACK B RUN", ink);
|
||||
text(190, 119, "BALLS", ink);
|
||||
char count[] = {(char)('0' + ball_count / 10), (char)('0' + ball_count % 10), 0};
|
||||
text(212, 119, count, ink);
|
||||
const char *message = battle.notice == NOTICE_NO_BALLS ? "NO POKE BALLS LEFT" :
|
||||
battle.notice == NOTICE_TEAM_FULL ? "YOUR TEAM IS FULL NO BALL USED" :
|
||||
battle.notice == NOTICE_BROKE_FREE ? "IT BROKE FREE AND ATTACKED" :
|
||||
battle.turns ? species[battle.enemy].reply : "CHOOSE YOUR PARTNERS MOVE";
|
||||
text(16, 132, message, ink);
|
||||
text(16, 143, "ARROWS CHOOSE A HIT SELECT BALL B RUN R MUSIC", ink);
|
||||
} else {
|
||||
const char *result = battle.phase == BATTLE_WON ? "YOU WON" :
|
||||
battle.phase == BATTLE_LOST ? "SPROUT NEEDS A REST" : "YOU GOT AWAY SAFELY";
|
||||
const char *result = battle.phase == BATTLE_CAUGHT ? "CAUGHT IT" : battle.phase == BATTLE_WON ? "YOU WON" :
|
||||
battle.phase == BATTLE_LOST ? "YOUR PARTNER NEEDS A REST" : "YOU GOT AWAY SAFELY";
|
||||
large_text(20, 120, result, ink);
|
||||
text(20, 134, "A BACK TO ADVENTURE", ink);
|
||||
text(20, 144, "SPROUT WILL REST AND RECOVER", ink);
|
||||
text(20, 144, battle.phase == BATTLE_CAUGHT ? "NEW FRIEND SAVED TO YOUR TEAM" :
|
||||
"YOUR PARTNER WILL REST AND RECOVER", ink);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,13 +196,13 @@ void draw_battle(void)
|
||||
};
|
||||
if (battle.enemy == GOLDEN) scaled_creature(184, 62, 2, gold_palette);
|
||||
else draw_wild_creature(battle.enemy, 184, 71);
|
||||
draw_sprout(57, 106, 3);
|
||||
draw_member(active_member, 57, 106, 0);
|
||||
rectangle(10, 24, 106, 29, RGB(30, 30, 26));
|
||||
large_text(16, 28, species[battle.enemy].name, RGB(5, 8, 11));
|
||||
text(16, 37, species[battle.enemy].type, RGB(5, 8, 11));
|
||||
text(69, 37, species[battle.enemy].level, RGB(5, 8, 11));
|
||||
rectangle(130, 76, 102, 31, RGB(30, 30, 26));
|
||||
large_text(136, 80, "SPROUT", RGB(5, 8, 11));
|
||||
text(179, 90, "LV FIVE", RGB(5, 8, 11));
|
||||
large_text(136, 80, partner_name(), RGB(5, 8, 11));
|
||||
text(179, 90, active_member ? species[caught_species[active_member - 1]].level : "LV FIVE", RGB(5, 8, 11));
|
||||
draw_battle_hud();
|
||||
}
|
||||
Reference in new issue
Block a user