Add music, beach fishing, catching, and selectable creature partners

This commit is contained in:
rory committed 2026-10-28 22:22:27 +00:00
1 parent 3469f2e6dd
commit cb77683a87
24 files changed
+1307 -104

No files matched your search

+80 -12
View File
@@ -35,12 +35,40 @@ static void creature(void)
void scaled_creature(int x, int y, int scale, const u16 *palette)
{
rectangle(x - 7 * scale, y, 14 * scale, 2 * scale,
indoors() ? RGB(15, 11, 8) : RGB(8, 16, 7));
indoors() ? RGB(15, 11, 8) : current_room == BEACH ? RGB(22, 20, 12) : RGB(8, 16, 7));
blit_sprite(x - 8 * scale, y - 16 * scale, creature_art, 16, 16, palette, scale, 0);
}
#include "wild_creatures.h"
/* Downsample route artwork to the same 16-pixel follower footprint as Sprout. */
void draw_member(int member, int x, int y, int small)
{
static const u16 gold[] = {
0, RGB(9, 8, 6), RGB(23, 15, 5), RGB(30, 23, 7),
RGB(31, 28, 14), RGB(31, 31, 28), RGB(29, 13, 10), RGB(17, 8, 7)
};
if (!member) { draw_sprout(x, y, small ? 1 : 3); return; }
enum Species kind = (enum Species)caught_species[member - 1];
if (kind == GOLDEN) { scaled_creature(x, y, small ? 1 : 3, gold); return; }
if (!small) { draw_wild_creature(kind, x, y); return; }
static char pixels[4][16][17];
static const char *rows[4][16];
static int ready;
if (!ready) {
for (int k = 0; k < 4; ++k)
for (int row = 0; row < 16; ++row) {
rows[k][row] = pixels[k][row];
for (int col = 0; col < 16; ++col)
pixels[k][row][col] = wild_art[k].rows[row * 3 / 2][col * 3 / 2];
}
ready = 1;
}
rectangle(x - 7, y, 14, 2, indoors() ? RGB(15, 11, 8) :
current_room == BEACH ? RGB(22, 20, 12) : RGB(8, 16, 7));
sprite(x - 8, y - 16, rows[kind - FERNFOX], 16, wild_art[kind - FERNFOX].palette, 0);
}
void draw_wild_creature(enum Species enemy, int x, int y)
{
const struct WildArt *art = &wild_art[enemy - FERNFOX];
@@ -99,6 +127,31 @@ TEST_INTERNAL const char *const person_side_art[] = {
".....111111.....", ".....1AA1A1.....", ".....1AA1A1.....", ".....111111....."
};
/* Distinct long-haired girl silhouette, with front, back, and side views. */
TEST_INTERNAL const char *const girl_art[] = {
".....111111.....", "....14444441....", "...1434444341...", "...1444444441...",
"..144444444441..", "..144666666441..", "..144616616441..", "..144666666441..",
"...1466776641...", "...1446666441...", "...1441881441...", "...1418998141...",
"...1168998611...", "..161889988161..", "..161888888161..", "...1618888161...",
"....18888881....", "....1AA11AA1....", "....1AA11AA1....", "....111..111...."
};
TEST_INTERNAL const char *const girl_back_art[] = {
".....111111.....", "....14444441....", "...1434444341...", "...1444444441...",
"...1444444441...", "...1444444441...", "...1244444421...", "...1244444421...",
"...1444444441...", "....14444441....", "....18444481....", "...1881441881...",
"..1618BBBB8161..", "..1618BCCB8161..", "..1618BCCB8161..", "..1668BBBB8661..",
"...1111111111...", "....1AA11AA1....", "....1AA11AA1....", "....111..111...."
};
TEST_INTERNAL const char *const girl_side_art[] = {
"......11111.....", ".....1444441....", "....143444441...", "....144444441...",
"...1444444441...", "..14444466661...", "..14444461661...", "..14444466661...",
"..14444167761...", "...144411661....", "...14441881.....", "....14418881....",
"....14188881....", ".....1881661....", ".....1881661....", ".....188161.....",
".....111111.....", ".....1AA1A1.....", ".....1AA1A1.....", ".....111111....."
};
static u16 lighter(u16 color)
{
int r = color & 31, g = (color >> 5) & 31, b = (color >> 10) & 31;
@@ -112,22 +165,33 @@ static u16 darker(u16 color)
}
/* x and y mark the feet. The art fits inside the original erase area. */
TEST_INTERNAL void person(int x, int y, int step, u16 clothes, u16 hat, enum Facing facing)
TEST_INTERNAL void styled_person(int x, int y, int step, u16 clothes, u16 hair_or_hat,
enum Facing facing, enum CharacterStyle style)
{
u16 palette[] = {
0, RGB(5, 7, 9), darker(hat), hat, RGB(11, 8, 7),
0, RGB(5, 7, 9), darker(hair_or_hat),
style == GIRL_STYLE ? lighter(hair_or_hat) : hair_or_hat,
style == GIRL_STYLE ? hair_or_hat : RGB(11, 8, 7),
RGB(24, 16, 12), RGB(31, 25, 19), RGB(25, 13, 12),
clothes, lighter(clothes), RGB(9, 12, 17), RGB(24, 17, 8), RGB(30, 24, 12)
};
rectangle(x - 7, y - 1, 15, 3,
indoors() ? RGB(15, 11, 8) : RGB(8, 16, 7));
const char *const *art = facing == FACING_UP ? person_back_art :
facing == FACING_DOWN ? person_art : person_side_art;
indoors() ? RGB(15, 11, 8) : current_room == BEACH ? RGB(22, 20, 12) : RGB(8, 16, 7));
const char *const *art;
if (style == GIRL_STYLE)
art = facing == FACING_UP ? girl_back_art : facing == FACING_DOWN ? girl_art : girl_side_art;
else
art = facing == FACING_UP ? person_back_art : facing == FACING_DOWN ? person_art : person_side_art;
sprite(x - 8, y - 19, art, 20, palette, facing == FACING_LEFT);
rectangle(x - 4, y, 3, 2 - step, palette[1]);
rectangle(x + 1, y, 3, 1 + step, palette[1]);
}
TEST_INTERNAL void person(int x, int y, int step, u16 clothes, u16 hat, enum Facing facing)
{
styled_person(x, y, step, clothes, hat, facing, BOY_STYLE);
}
static void player(int x, int y, int step)
{
person(x, y, step, shirt, RGB(28, 8, 9), player_facing);
@@ -135,7 +199,7 @@ static void player(int x, int y, int step)
void actors(int x, int y, int step)
{
enum { HERO, SPROUT, MILA, GOLDEN, PROFESSOR, RANGER };
enum { HERO, SPROUT, MILA, GOLDEN_ACTOR, PROFESSOR, RANGER, FISHER };
struct Actor { int x, y, kind; } list[4];
int count = 0;
if (partner_owned && follower_ready)
@@ -145,10 +209,11 @@ void actors(int x, int y, int step)
list[count++] = (struct Actor){PROF_X, PROF_Y, PROFESSOR};
}
if (current_room == OUTSIDE) {
list[count++] = (struct Actor){182, 104, GOLDEN};
if (!has_caught(GOLDEN)) list[count++] = (struct Actor){182, 104, GOLDEN_ACTOR};
list[count++] = (struct Actor){NPC_X, NPC_Y, MILA};
}
if (current_room == ROUTE) list[count++] = (struct Actor){RANGER_X, RANGER_Y, RANGER};
if (current_room == BEACH) list[count++] = (struct Actor){FISHER_X, FISHER_Y, FISHER};
/* Stable depth ordering keeps Sprout behind the hero on equal feet. */
for (int i = 1; i < count; ++i) {
struct Actor actor = list[i];
@@ -162,12 +227,15 @@ void actors(int x, int y, int step)
for (int i = 0; i < count; ++i) {
struct Actor actor = list[i];
if (actor.kind == HERO) player(actor.x, actor.y, step);
else if (actor.kind == SPROUT) draw_sprout(actor.x, actor.y, 1);
else if (actor.kind == GOLDEN) creature();
else if (actor.kind == SPROUT) draw_member(active_member, actor.x, actor.y, 1);
else if (actor.kind == GOLDEN_ACTOR) creature();
else if (actor.kind == MILA)
person(actor.x, actor.y, 0, RGB(4, 21, 13), RGB(12, 7, 4), FACING_DOWN);
styled_person(actor.x, actor.y, 0, RGB(4, 21, 13), RGB(12, 7, 4), FACING_DOWN, GIRL_STYLE);
else if (actor.kind == RANGER)
person(actor.x, actor.y, 0, RGB(27, 16, 7), RGB(6, 15, 11), FACING_DOWN);
else person(actor.x, actor.y, 0, RGB(29, 30, 27), RGB(20, 21, 19), FACING_DOWN);
else if (actor.kind == FISHER)
styled_person(actor.x, actor.y, 0, RGB(5, 23, 26), RGB(26, 12, 7), FACING_DOWN, GIRL_STYLE);
else styled_person(actor.x, actor.y, 0, RGB(29, 30, 27), RGB(20, 21, 19),
FACING_DOWN, GIRL_STYLE);
}
}
+171
View File
@@ -0,0 +1,171 @@
#include "audio.h"
/* Original four-bar tunes. Each position is a sixteenth note; H is a tie. */
enum {
REST = 0, H = 255,
C3 = 48, D3 = 50, E3 = 52, FS3 = 54, F3 = 53, G3 = 55, A3 = 57, B3 = 59,
C4 = 60, D4 = 62, E4 = 64, G4 = 67, A4 = 69, B4 = 71,
C5 = 72, D5 = 74, E5 = 76, F5 = 77, FS5 = 78, G5 = 79, A5 = 81, B5 = 83, C6 = 84
};
static const unsigned char village_lead[64] = {
C5,H,E5,H, G5,H,E5,D5, C5,H,E5,G5, A5,H,G5,H,
F5,H,E5,H, D5,H,G4,H, E5,H,D5,C5, D5,H,G4,H,
E5,H,G5,H, C6,H,B5,A5, G5,H,E5,H, D5,E5,G5,H,
F5,H,A5,H, G5,H,E5,H, D5,H,B4,D5, C5,H,H,REST
};
static const unsigned char village_bass[16] = {
C3,G3,E3,G3, F3,C4,G3,B3, A3,E3,F3,C4, G3,D3,G3,C3
};
static const unsigned char trail_lead[64] = {
A4,H,C5,H, E5,H,H,H, D5,H,C5,H, B4,H,E4,H,
A4,H,C5,H, D5,H,E5,H, C5,H,A4,H, G4,H,H,REST,
C5,H,E5,H, G5,H,E5,H, D5,H,C5,H, B4,H,G4,H,
A4,H,B4,C5, E5,H,D5,H, C5,H,B4,H, A4,H,H,REST
};
static const unsigned char trail_bass[16] = {
A3,E3,C4,E3, F3,C4,A3,C4, G3,D3,B3,D3, A3,E3,A3,E3
};
static const unsigned char battle_lead[64] = {
E5,B4,E5,G5, FS5,D5,FS5,A5, G5,E5,B5,G5, FS5,D5,B4,REST,
E5,B4,E5,G5, A5,G5,FS5,E5, D5,B4,D5,FS5, G5,H,FS5,REST,
C5,G4,C5,E5, G5,E5,C6,G5, D5,A4,D5,FS5, A5,FS5,D5,REST,
E5,G5,B5,A5, G5,FS5,E5,D5, B4,D5,FS5,B4, E5,H,H,REST
};
static const unsigned char battle_bass[16] = {
E3,B3,E3,G3, C3,G3,C4,G3, D3,A3,D3,FS3, E3,B3,E3,B3
};
TEST_INTERNAL const struct MusicSong music_songs[MUSIC_TRACK_COUNT] = {
{village_lead, village_bass, 112, 5, 0x80, 1},
{trail_lead, trail_bass, 94, 4, 0x80, 0},
{battle_lead, battle_bass, 160, 6, 0x40, 2}
};
TEST_INTERNAL struct MusicPlayback music_state;
/* Square-wave register = 2048 - round(131072 / frequency). MIDI C3..C6. */
static const u16 pitches[37] = {
1046,1102,1155,1205,1253,1297,1339,1379,1417,1452,1486,1517,
1547,1575,1602,1627,1650,1673,1694,1714,1732,1750,1767,1783,
1798,1812,1825,1837,1849,1860,1871,1881,1890,1899,1907,1915,1923
};
#ifdef GAME_TEST
u16 music_registers[SOUND_REGISTER_COUNT];
unsigned music_write_count;
#endif
static void sound_write(enum SoundRegister reg, u16 value)
{
#ifdef GAME_TEST
music_registers[reg] = value;
++music_write_count;
#else
static const unsigned addresses[SOUND_REGISTER_COUNT] = {
0x04000084, 0x04000080, 0x04000082, 0x04000060,
0x04000062, 0x04000064, 0x04000068, 0x0400006c,
0x04000078, 0x0400007c
};
*(volatile u16 *)addresses[reg] = value;
#endif
}
TEST_INTERNAL enum MusicTrack music_choose_track(enum Room room, enum BattlePhase phase)
{
if (phase != BATTLE_OFF) return MUSIC_BATTLE;
return room == OUTSIDE || room == MELLON_GARDEN ? MUSIC_VILLAGE : MUSIC_TRAIL;
}
TEST_INTERNAL u16 music_frequency(unsigned note)
{
return note >= C3 && note <= C6 ? pitches[note - C3] : 0;
}
static void silence_voices(void)
{
sound_write(SOUND_LEAD_ENV, 0);
sound_write(SOUND_BASS_ENV, 0);
sound_write(SOUND_NOISE_ENV, 0);
}
static unsigned resolved_lead(const struct MusicSong *song, int step)
{
for (int count = 0; count < 64; ++count) {
unsigned note = song->lead[(step - count + 64) % 64];
if (note != H) return note;
}
return REST;
}
static void play_step(int force)
{
if (music_state.muted) return;
const struct MusicSong *song = &music_songs[music_state.track];
unsigned lead = force ? resolved_lead(song, music_state.step) : song->lead[music_state.step];
if (lead != H) {
unsigned envelope = song->percussion == 2 ? 2u : song->percussion == 0 ? 5u : 3u;
sound_write(SOUND_LEAD_ENV, lead == REST ? 0 :
(u16)((song->volume << 12) | (envelope << 8) | song->duty));
if (lead != REST) sound_write(SOUND_LEAD_FREQ, (u16)(0x8000 | music_frequency(lead)));
}
if (force || music_state.step % 4 == 0) {
unsigned bass = song->bass[music_state.step / 4];
sound_write(SOUND_BASS_ENV, bass == REST ? 0 : 0x3080);
if (bass != REST) sound_write(SOUND_BASS_FREQ, (u16)(0x8000 | music_frequency(bass)));
}
int beat = song->percussion == 2 ? music_state.step % 2 == 0 :
song->percussion == 1 && music_state.step % 4 == 0;
if (beat) {
sound_write(SOUND_NOISE_ENV, 0x2138); /* Quiet 31 ms percussion hit. */
sound_write(SOUND_NOISE_FREQ, music_state.step % 8 == 4 ? 0xc045 : 0xc035);
}
}
void music_init(unsigned now)
{
music_state.track = music_choose_track(current_room, battle.phase);
music_state.last = now;
music_state.phase = 0;
music_state.step = 0;
music_state.muted = 0;
sound_write(SOUND_MASTER, 0x0080);
sound_write(SOUND_RATIO, 0x0001); /* PSG at 50%; no PCM, DMA, or timer use. */
sound_write(SOUND_SWEEP, 0x0008); /* Sweep disabled. */
silence_voices();
sound_write(SOUND_MIX, 0xbb77); /* Square 1+2 and noise, both speakers. */
play_step(1);
}
void music_update(unsigned now)
{
unsigned elapsed = now - music_state.last;
music_state.last = now;
enum MusicTrack wanted = music_choose_track(current_room, battle.phase);
if (wanted != music_state.track) {
music_state.track = wanted;
music_state.step = 0;
music_state.phase = 0;
if (!music_state.muted) { silence_voices(); play_step(1); }
return;
}
/* Skip missed notes after a stall; never replay them in a busy loop. */
if (elapsed > MOVEMENT_CLOCK_HZ * 4u) elapsed = MOVEMENT_CLOCK_HZ * 4u;
unsigned total = music_state.phase + elapsed * music_songs[wanted].bpm * 4u;
unsigned steps = total / (MOVEMENT_CLOCK_HZ * 60u);
music_state.phase = total % (MOVEMENT_CLOCK_HZ * 60u);
if (steps) {
music_state.step = (music_state.step + (int)(steps % 64)) % 64;
play_step(steps > 1);
}
}
void music_toggle_mute(void)
{
music_state.muted = !music_state.muted;
if (music_state.muted) {
sound_write(SOUND_MIX, 0);
silence_voices();
} else {
sound_write(SOUND_MIX, 0xbb77);
play_step(1);
}
}
+36
View File
@@ -0,0 +1,36 @@
#ifndef AUDIO_H
#define AUDIO_H
#include "game.h"
enum MusicTrack { MUSIC_VILLAGE, MUSIC_TRAIL, MUSIC_BATTLE, MUSIC_TRACK_COUNT };
enum SoundRegister {
SOUND_MASTER, SOUND_MIX, SOUND_RATIO, SOUND_SWEEP,
SOUND_LEAD_ENV, SOUND_LEAD_FREQ, SOUND_BASS_ENV, SOUND_BASS_FREQ,
SOUND_NOISE_ENV, SOUND_NOISE_FREQ, SOUND_REGISTER_COUNT
};
struct MusicPlayback {
enum MusicTrack track;
unsigned last, phase;
int step, muted;
};
struct MusicSong {
const unsigned char *lead, *bass;
unsigned bpm;
int volume, duty, percussion;
};
void music_init(unsigned now);
void music_update(unsigned now);
void music_toggle_mute(void);
#ifdef GAME_TEST
extern struct MusicPlayback music_state;
extern const struct MusicSong music_songs[MUSIC_TRACK_COUNT];
extern u16 music_registers[SOUND_REGISTER_COUNT];
extern unsigned music_write_count;
enum MusicTrack music_choose_track(enum Room room, enum BattlePhase phase);
u16 music_frequency(unsigned note);
#endif
#endif
+85 -23
View File
@@ -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();
}
+96
View File
@@ -0,0 +1,96 @@
#include "game.h"
int near_water(int x, int y)
{
return current_room == BEACH && x >= 17 && x <= 222 &&
y >= beach_shoreline(x) - 8 && y <= beach_shoreline(x) - 5;
}
int cast_rod(int x, int y)
{
if (!rod_owned || !near_water(x, y) || player_facing != FACING_DOWN) return 0;
return start_battle(TIDEFIN);
}
int beach_shoreline(int x)
{
return 104 + ((x / 24) % 3) * 2;
}
static u16 palm_pixel(int x, int y, int center, u16 ground)
{
int dx = x - center, dy = y - 48;
int distance = dx < 0 ? -dx : dx;
if (y >= 48 && y < 70) {
int lean = (y - 48) / 6;
if (dx >= lean - 1 && dx <= lean + 2)
ground = (dx == lean - 1 || y % 5 == 0) ? RGB(13, 9, 6) : RGB(25, 18, 10);
}
if (distance <= 15 && dy >= -5 + distance / 2 && dy <= -2 + distance / 2)
ground = dy == -2 + distance / 2 ? RGB(4, 13, 8) : RGB(8, 22, 10);
if (dy >= -12 && dy <= 1 && distance <= (dy + 13) / 4)
ground = dx < 0 ? RGB(5, 17, 9) : RGB(15, 27, 11);
if (dy >= -7 && dy <= 5 && distance >= 3 && distance <= 11 &&
dy >= distance - 11 && dy <= distance - 8)
ground = dy == distance - 11 ? RGB(17, 27, 11) : RGB(5, 18, 9);
if (dy >= -1 && dy <= 2 && (dx == -1 || dx == 2)) ground = RGB(15, 10, 6);
return ground;
}
u16 beach_scenery(int x, int y)
{
if (y < 18 || y >= 142) return RGB(29, 30, 25);
int shore = beach_shoreline(x);
u16 color = RGB(31, 28, 19);
if ((x * 3 + y * 7) % 59 < 2) color = RGB(28, 24, 15);
if ((x * 7 + y * 3) % 71 == 0) color = RGB(31, 31, 24);
/* A grassy bank separates the beach from Mellon's garden to the north. */
if (y < 36) {
color = RGB(9, 21, 10);
if ((x & 15) == 4 && (y & 7) >= 5) color = RGB(5, 15, 8);
if ((x & 15) == 10 && (y & 7) == 2) color = RGB(16, 27, 12);
if (y >= 32) color = RGB(5, 13, 8);
} else if (y < 46) {
color = (y == 36 || y == 43 || x % 16 == 0) ? RGB(18, 14, 9) : RGB(27, 21, 12);
if (y == 45) color = RGB(22, 18, 11);
}
if (x >= 97 && x < 120 && y < 70) {
color = RGB(29, 27, 18);
if (x == 97 || x == 119) color = RGB(24, 23, 14);
if ((x & 7) == 3 && (y & 7) == 5) color = RGB(26, 23, 15);
}
/* Wet sand, a foamy waterline, turquoise shallows, and deep blue sea. */
if (y >= shore - 4) color = RGB(26, 24, 17);
if (y >= shore) color = RGB(29, 31, 28);
if (y >= shore + 2) color = RGB(15, 28, 28);
if (y >= shore + 6) color = RGB(7, 23, 29);
if (y >= 128) color = RGB(5, 18, 27);
if (y >= shore + 7 && y % 11 == 0 && (x + y * 3) % 27 < 11)
color = RGB(24, 31, 30);
if (y >= shore + 8 && y % 11 == 1 && (x + y * 3) % 27 < 8)
color = RGB(12, 26, 30);
color = palm_pixel(x, y, 28, color);
color = palm_pixel(x, y, 210, color);
/* A blue-and-white towel beneath a striped sun umbrella. */
if (x >= 43 && x < 67 && y >= 89 && y < 96) {
color = y % 3 == 0 ? RGB(30, 31, 28) : RGB(8, 20, 27);
if (x == 43 || x == 66) color = RGB(23, 28, 27);
}
if (x >= 54 && x < 57 && y >= 75 && y < 94)
color = x == 54 ? RGB(15, 10, 7) : RGB(26, 20, 12);
int ux = x - 55, uy = y - 77;
if (uy <= 0 && uy >= -10 && ux * ux + uy * uy * 3 < 225) {
color = ((x / 5) & 1) ? RGB(31, 14, 12) : RGB(31, 29, 20);
if (ux * ux + uy * uy * 3 > 177 || uy == 0) color = RGB(20, 9, 9);
if (uy == -8) color = RGB(31, 24, 18);
}
/* Two tiny shells and an orange starfish, all safe to walk over. */
if (((x >= 89 && x < 95) || (x >= 172 && x < 178)) && y >= 87 && y < 91)
color = (x % 2 == 0 || y == 90) ? RGB(26, 17, 16) : RGB(31, 26, 23);
int sx = x - 142, sy = y - 94;
if ((sx >= -3 && sx <= 3 && sy == 0) || (sx == 0 && sy >= -3 && sy <= 3) ||
(sx == -2 && sy == 2) || (sx == 2 && sy == 2)) color = RGB(30, 16, 7);
if (sx == 0 && sy == 0) color = RGB(31, 24, 10);
return color;
}
+33 -7
View File
@@ -7,21 +7,27 @@ typedef unsigned short u16;
#define WIDTH 240
#define HEIGHT 160
enum { A = 1, B = 2, SELECT = 4, START = 8, RIGHT = 16, LEFT = 32, UP = 64, DOWN = 128 };
enum { A = 1, B = 2, SELECT = 4, START = 8, RIGHT = 16, LEFT = 32, UP = 64, DOWN = 128,
R_BUTTON = 256 };
enum { MOVEMENT_HZ = 60, MOVEMENT_CLOCK_HZ = 16384, WALK_SPEED = 2, MAX_MOVEMENT_TICKS = 5 };
enum { NPC_X = 146, NPC_Y = 106, PROF_X = 113, PROF_Y = 92, RANGER_X = 83, RANGER_Y = 97 };
enum Room { OUTSIDE, COTTAGE, ROUTE, MELLON_GARDEN, MELLON_HOUSE };
enum Room { OUTSIDE, COTTAGE, ROUTE, MELLON_GARDEN, MELLON_HOUSE, BEACH };
enum Facing { FACING_DOWN, FACING_UP, FACING_LEFT, FACING_RIGHT };
enum CharacterStyle { BOY_STYLE, GIRL_STYLE };
enum { DIALOGUE_X = 8, DIALOGUE_Y = 96, DIALOGUE_W = 224, DIALOGUE_H = 44 };
enum { FOLLOW_STEPS = 14, SPROUT_HP = 24, GOLDEN_HP = 18 };
enum BattlePhase { BATTLE_OFF, BATTLE_TURN, BATTLE_WON, BATTLE_LOST, BATTLE_FLED };
enum Species { GOLDEN, FERNFOX, EMBERWING, PEBBLIT, SPECIES_COUNT };
enum BattlePhase { BATTLE_OFF, BATTLE_TURN, BATTLE_WON, BATTLE_LOST, BATTLE_FLED, BATTLE_CAUGHT };
enum Species { GOLDEN, FERNFOX, EMBERWING, PEBBLIT, TIDEFIN, SPECIES_COUNT };
enum { FISHER_X = 178, FISHER_Y = 80 };
enum { CAUGHT_CAPACITY = 5, SAVE_RECORD_SIZE = 15 };
enum BattleNotice { NOTICE_NONE, NOTICE_NO_BALLS, NOTICE_TEAM_FULL, NOTICE_BROKE_FREE };
enum WalkResult { WALK_NORMAL, WALK_MAP_CHANGED, WALK_ENCOUNTER };
struct BattleState {
enum BattlePhase phase;
enum Species enemy;
int sprout_hp, enemy_hp, move, turns;
enum BattleNotice notice;
};
extern struct BattleState battle;
@@ -53,6 +59,19 @@ extern unsigned random_state;
extern int grass_steps;
extern int partner_owned;
extern int ball_count, balls_given;
extern int rod_owned;
int near_water(int x, int y);
int cast_rod(int x, int y);
int start_battle(enum Species enemy);
extern int caught_count;
extern int active_member;
int choose_partner(int member);
int partner_hp(void);
const char *partner_name(void);
const char *partner_move(void);
void draw_member(int member, int x, int y, int small);
extern unsigned char caught_species[CAUGHT_CAPACITY];
extern const struct SpeciesInfo species[SPECIES_COUNT];
void reset_dirty_rows(void);
void mark_dirty(int x, int y, int w, int h);
@@ -64,6 +83,8 @@ void blit_sprite(int x, int y, const char *const *art, int width, int rows,
void sprite(int x, int y, const char *const *art, int rows, const u16 *palette,
int mirrored);
int in_tall_grass(int x, int y);
int beach_shoreline(int x);
u16 beach_scenery(int x, int y);
void restore(int x, int y, int w, int h);
void pause_movement_at(unsigned now);
int movement_ticks_at(unsigned now);
@@ -86,6 +107,8 @@ int battle_input(unsigned pressed);
void draw_battle_hud(void);
void draw_battle(void);
void load_progress(void);
void save_progress(void);
int has_caught(enum Species kind);
int near_npc(int x, int y);
int begin_conversation(int x, int y);
int advance_conversation(int page);
@@ -94,6 +117,7 @@ void status(const char *message);
void location_status(int x, int y);
void draw_scene(int x, int y);
void draw_team(void);
void draw_team_member(int member);
#ifdef GAME_TEST
extern const unsigned char large_alphabet[26][7];
@@ -107,7 +131,7 @@ extern const char *const creature_art[16];
extern const char *const person_art[20];
extern const char *const person_back_art[20];
extern const char *const person_side_art[20];
extern const struct SpeciesInfo species[SPECIES_COUNT];
extern const char *const girl_art[20], *const girl_back_art[20], *const girl_side_art[20];
extern int gift_conversation;
extern const char *const dialogue[][2];
extern const char *const professor_dialogue[][2];
@@ -118,7 +142,8 @@ extern int trail_head, ball_gift_conversation;
extern unsigned rectangle_calls, sprite_decodes, sprite_row_marks;
extern const int DIALOGUE_PAGES;
extern const char *const fernfox_art[24], *const emberwing_art[24], *const pebblit_art[24];
extern const struct WildArt wild_art[3];
extern const char *const tidefin_art[24];
extern const struct WildArt wild_art[4];
u16 cottage_scenery(int x, int y);
u16 route_scenery(int x, int y);
u16 village_scenery(int x, int y);
@@ -129,8 +154,9 @@ enum Facing facing_for_keys(unsigned keys, enum Facing previous);
int use_map_exit(int *x, int *y, unsigned keys);
int can_walk(int x, int y);
void person(int x, int y, int step, u16 clothes, u16 hat, enum Facing facing);
void styled_person(int x, int y, int step, u16 clothes, u16 hair_or_hat,
enum Facing facing, enum CharacterStyle style);
unsigned next_random(void);
int start_battle(enum Species enemy);
int next_dialogue_page(int page);
int receive_partner(void);
int receive_balls(void);
+38 -8
View File
@@ -10,7 +10,9 @@ void status(const char *message)
void location_status(int x, int y)
{
if (near_map_exit(x, y)) {
if (current_room == MELLON_GARDEN) status("WALK LEFT TO GREENLEAF VILLAGE");
if (current_room == MELLON_GARDEN)
status(x < 25 ? "WALK LEFT TO GREENLEAF VILLAGE" : "WALK DOWN TO SEASHELL BEACH");
else if (current_room == BEACH) status("WALK UP TO MELLONS GARDEN");
else if (current_room == ROUTE) status("WALK UP TO GREENLEAF VILLAGE");
else status(x >= 216 ? "WALK RIGHT TO PROFESSOR MELLON" : "WALK DOWN TO SUNPETAL TRAIL");
}
@@ -20,6 +22,9 @@ void location_status(int x, int y)
else if (near_door(x, y)) status(indoors() ? "A GO OUTSIDE" : "A OPEN DOOR");
else if (current_room == MELLON_GARDEN) status("PROFESSOR MELLONS GARDEN");
else if (current_room == MELLON_HOUSE) status("PROFESSOR MELLONS HOUSE");
else if (current_room == BEACH && near_npc(x, y)) status("A TALK TO FISHER CORAL");
else if (near_water(x, y)) status(rod_owned ? "FACE DOWN A USE POKE ROD" : "ASK FISHER CORAL FOR A POKE ROD");
else if (current_room == BEACH) status("SEASHELL BEACH");
else if (partner_owned && near_golden(x, y) && !near_npc(x, y)) status("A BATTLE THE GOLDEN CREATURE");
else status(current_room == COTTAGE ? "INSIDE THE COTTAGE" : "GREENLEAF VILLAGE");
}
@@ -28,29 +33,53 @@ void draw_scene(int x, int y)
{
restore(0, 0, WIDTH, HEIGHT);
location_status(x, y);
text(8, 148, "ARROWS MOVE A USE SELECT TEAM START RESET", RGB(5, 9, 11));
text(8, 148, "ARROWS MOVE A USE SELECT TEAM START RESET R MUSIC", RGB(5, 9, 11));
actors(x, y, 0);
}
void draw_team(void)
{
draw_team_member(0);
}
void draw_team_member(int member)
{
if (member < 0 || member > caught_count ||
(member > 0 && caught_species[member - 1] >= SPECIES_COUNT)) member = 0;
u16 ink = RGB(5, 8, 11), cream = RGB(30, 30, 26);
rectangle(0, 0, WIDTH, HEIGHT, RGB(15, 24, 20));
status("YOUR TEAM");
rectangle(8, 25, 224, 112, ink);
rectangle(10, 27, 220, 108, cream);
if (partner_owned) {
draw_sprout(50, 105, 3);
large_text(94, 42, "SPROUT", ink);
large_text(94, 58, "GRASS TYPE", RGB(7, 17, 11));
large_text(94, 73, "LEVEL FIVE", ink);
if (member == 0) {
draw_sprout(50, 105, 3);
large_text(94, 42, "SPROUT", ink);
large_text(94, 58, "GRASS TYPE", RGB(7, 17, 11));
large_text(94, 73, "LEVEL FIVE", ink);
} else {
enum Species kind = (enum Species)caught_species[member - 1];
if (kind == GOLDEN) {
static const u16 gold[] = {
0, RGB(9, 8, 6), RGB(23, 15, 5), RGB(30, 23, 7),
RGB(31, 28, 14), RGB(31, 31, 28), RGB(29, 13, 10), RGB(17, 8, 7)
};
scaled_creature(50, 105, 3, gold);
} else draw_wild_creature(kind, 50, 105);
large_text(94, 42, species[kind].name, ink);
large_text(94, 58, species[kind].type, RGB(7, 17, 11));
large_text(94, 73, species[kind].level, ink);
}
char position[] = {(char)('1' + member), ' ', 'O', 'F', ' ', (char)('1' + caught_count), 0};
text(194, 32, position, ink);
text(94, 89, "HEALTH FULL", ink);
if (member == active_member) text(94, 109, "FOLLOWING AND BATTLING", ink);
rectangle(94, 99, 106, 6, RGB(7, 14, 11));
rectangle(95, 100, 104, 4, RGB(10, 25, 12));
} else {
large_text(28, 57, "NO PARTNER YET", ink);
large_text(28, 76, "VISIT PROFESSOR MELLON", ink);
text(28, 96, "HIS HOUSE IS EAST OF GREENLEAF VILLAGE", ink);
text(28, 96, "HER HOUSE IS EAST OF GREENLEAF VILLAGE", ink);
}
/* A small bag summary is visible even before you receive Sprout. */
rectangle(24, 118, 8, 8, ink);
@@ -64,6 +93,7 @@ void draw_team(void)
count_text[count_index++] = (char)('0' + ball_count % 10);
count_text[count_index] = 0;
text(88, 119, count_text, ink);
if (rod_owned) text(133, 119, "POKE ROD", ink);
rectangle(0, 142, WIDTH, 18, cream);
text(8, 148, "SELECT OR A OR B TO RETURN", ink);
text(8, 148, "ARROWS TEAM A CHOOSE PARTNER B BACK", ink);
}
+37 -3
View File
@@ -1,5 +1,6 @@
/* Our first GBA game. No downloaded game art or existing ROM is used. */
#include "game.h"
#include "audio.h"
#ifndef GAME_TEST
#define DISPLAY (*(volatile u16 *)0x04000000)
@@ -66,8 +67,10 @@ int main(void)
int x = 108, y = 103, frame = 0, greeting = 0;
int dialogue_page = -1; /* -1 means we are not talking. */
int team_open = 0;
int team_member = 0;
unsigned previous = 0;
start_movement_timer();
music_init(movement_time());
load_progress();
reset_follower(x, y);
reset_dirty_rows();
@@ -81,6 +84,8 @@ int main(void)
unsigned pressed = keys & ~previous;
previous = keys;
unsigned now = movement_time();
music_update(now);
if (pressed & R_BUTTON) music_toggle_mute();
int movement_ticks = 0;
if (team_open || battle.phase != BATTLE_OFF || dialogue_page >= 0)
pause_movement_at(now);
@@ -88,7 +93,16 @@ int main(void)
movement_ticks = movement_ticks_at(now);
random_state += 0x9e3779b9u; /* Mix in how long the player waits. */
if (team_open) {
if (pressed & (SELECT | A | B)) {
if (partner_owned && (pressed & (LEFT | RIGHT))) {
int members = caught_count + 1;
team_member = (team_member + ((pressed & RIGHT) ? 1 : members - 1)) % members;
DISPLAY = 0x0080;
draw_team_member(team_member);
present_frame();
DISPLAY = 0x0403;
pause_movement_at(movement_time());
} else if (pressed & (SELECT | A | B)) {
if ((pressed & A) && choose_partner(team_member)) reset_follower(x, y);
team_open = 0;
DISPLAY = 0x0080;
draw_scene(x, y);
@@ -106,7 +120,7 @@ int main(void)
greeting = 180;
DISPLAY = 0x0080;
draw_scene(x, y);
status("SPROUT RESTED AND IS READY AGAIN");
status("YOUR PARTNER RESTED AND IS READY AGAIN");
present_frame();
DISPLAY = 0x0403;
pause_movement_at(movement_time());
@@ -143,6 +157,7 @@ int main(void)
}
if (pressed & SELECT) {
team_open = 1;
team_member = 0;
DISPLAY = 0x0080;
draw_team();
present_frame();
@@ -192,7 +207,10 @@ int main(void)
restore(170, 54, 15, 24);
actors(x, y, 0);
present_frame();
for (int tick = 0; tick < 12; ++tick) wait_for_frame();
for (int tick = 0; tick < 12; ++tick) {
wait_for_frame();
music_update(movement_time());
}
}
use_door(&x, &y);
greeting = 0;
@@ -207,6 +225,7 @@ int main(void)
dialogue_page = 0;
greeting = 0;
status(current_room == ROUTE ? "TALKING TO RANGER FINN" :
current_room == BEACH ? "TALKING TO FISHER CORAL" :
current_room == MELLON_HOUSE ? "TALKING TO PROFESSOR MELLON" : "TALKING TO MILA");
} else if (current_room == ROUTE) {
status(near_route_sign(x, y) ? "GREENLEAF VILLAGE IS TO THE NORTH" :
@@ -218,6 +237,20 @@ int main(void)
} else if (current_room == MELLON_GARDEN) {
status("PROFESSOR MELLON IS INSIDE THE HOUSE");
greeting = 180;
} else if (current_room == BEACH) {
if (cast_rod(x, y)) {
greeting = 0;
DISPLAY = 0x0080;
draw_battle();
present_frame();
DISPLAY = 0x0403;
pause_movement_at(movement_time());
continue;
}
status(!rod_owned ? "TALK TO FISHER CORAL FOR A POKE ROD" :
!partner_owned ? "GET SPROUT FROM PROFESSOR MELLON FIRST" :
"FACE DOWN AT THE WATER AND PRESS A");
greeting = 180;
} else if (begin_battle(x, y)) {
greeting = 0;
DISPLAY = 0x0080;
@@ -248,6 +281,7 @@ int main(void)
near_map_exit(old_x, old_y) != near_map_exit(x, y) ||
near_route_sign(old_x, old_y) != near_route_sign(x, y) ||
near_npc(old_x, old_y) != near_npc(x, y) ||
near_water(old_x, old_y) != near_water(x, y) ||
near_golden(old_x, old_y) != near_golden(x, y)))
location_status(x, y);
}
+4 -3
View File
@@ -310,10 +310,10 @@ TEST_INTERNAL u16 mellon_garden_scenery(int x, int y)
{
u16 color = village_scenery(x, y);
if (y < 18 || y >= 142) return color;
/* This garden connects west to town, not east or south. */
/* Connect west to town and south to the beach; the east boundary stays closed. */
if (x < 8 && y > 106 && y < 120) color = RGB(29, 27, 18);
if ((x >= 232 && y > 106 && y < 120) ||
(y >= 136 && x > 96 && x < 120)) color = RGB(9, 20, 10);
if (x >= 232 && y > 106 && y < 120) color = RGB(9, 20, 10);
if (x >= 97 && x < 120 && y >= 128) color = RGB(31, 28, 19);
/* Melon beds take the place of the village pond. */
if (x >= 22 && x < 76 && y >= 44 && y < 86) {
color = RGB(20, 15, 9);
@@ -364,6 +364,7 @@ TEST_INTERNAL u16 scenery(int x, int y)
if (current_room == COTTAGE) return cottage_scenery(x, y);
if (current_room == MELLON_GARDEN) return mellon_garden_scenery(x, y);
if (current_room == MELLON_HOUSE) return mellon_house_scenery(x, y);
if (current_room == BEACH) return beach_scenery(x, y);
return village_scenery(x, y);
}
+106 -14
View File
@@ -3,6 +3,11 @@
int partner_owned = 0;
TEST_INTERNAL int gift_conversation = 0;
int ball_count = 0, balls_given = 0;
int rod_owned;
static int rod_gift_conversation;
int caught_count;
int active_member;
unsigned char caught_species[CAUGHT_CAPACITY];
TEST_INTERNAL int ball_gift_conversation = 0;
/* mGBA detects this marker and provides cartridge SRAM for the gift record. */
@@ -13,7 +18,10 @@ static const char save_signature[] __attribute__((used)) = "SRAM_V113";
void load_progress(void)
{
partner_owned = ball_count = balls_given = 0;
partner_owned = ball_count = balls_given = caught_count = 0;
rod_owned = 0;
active_member = 0;
for (int i = 0; i < CAUGHT_CAPACITY; ++i) caught_species[i] = 0xff;
if (SAVE_MEMORY[0] != 'F' || SAVE_MEMORY[1] != 'Q' ||
SAVE_MEMORY[2] != 'S' || SAVE_MEMORY[3] != 'P') return;
/* Keep Sprout from the original version-one save format. */
@@ -22,30 +30,95 @@ void load_progress(void)
return;
}
unsigned flags = SAVE_MEMORY[5], count = SAVE_MEMORY[6];
if (SAVE_MEMORY[4] != 2 || flags > 3 || count > 99 ||
(!(flags & 2) && count != 0) || SAVE_MEMORY[8] != 0x5a ||
SAVE_MEMORY[7] != (0xa5 ^ 2 ^ flags ^ count)) return;
unsigned version = SAVE_MEMORY[4];
if (flags > (version == 5 ? 47u : version == 4 ? 7u : 3u) || count > 99 || (!(flags & 2) && count != 0)) return;
if (SAVE_MEMORY[4] == 2) {
if (SAVE_MEMORY[8] != 0x5a || SAVE_MEMORY[7] != (0xa5 ^ 2 ^ flags ^ count)) return;
} else if (version == 3 || version == 4 || version == 5) {
unsigned members = SAVE_MEMORY[7];
if (members > CAUGHT_CAPACITY || (members && !(flags & 1)) || SAVE_MEMORY[14] != 0x5a)
return;
if (version == 5 && ((flags >> 3) > members || ((flags >> 3) && !(flags & 1)))) return;
unsigned checksum = 0xa5 ^ version ^ flags ^ count ^ members;
for (unsigned i = 0; i < CAUGHT_CAPACITY; ++i) {
unsigned kind = SAVE_MEMORY[8 + i];
if (i < members ? kind >= SPECIES_COUNT : kind != 0xff) return;
checksum ^= kind;
}
if (SAVE_MEMORY[13] != checksum) return;
caught_count = (int)members;
for (int i = 0; i < caught_count; ++i) caught_species[i] = SAVE_MEMORY[8 + i];
} else {
return;
}
partner_owned = !!(flags & 1);
balls_given = !!(flags & 2);
rod_owned = !!(flags & 4);
ball_count = (int)count;
active_member = version == 5 ? (int)(flags >> 3) : 0;
}
static void save_progress(void)
int choose_partner(int member)
{
unsigned flags = (partner_owned ? 1u : 0u) | (balls_given ? 2u : 0u);
if (!partner_owned || battle.phase != BATTLE_OFF || member < 0 || member > caught_count)
return 0;
active_member = member;
save_progress();
return 1;
}
const char *partner_name(void)
{
return active_member ? species[caught_species[active_member - 1]].name : "SPROUT";
}
int partner_hp(void)
{
return active_member ? species[caught_species[active_member - 1]].hp : SPROUT_HP;
}
const char *partner_move(void)
{
if (!active_member) return "LEAF TAP";
switch (caught_species[active_member - 1]) {
case GOLDEN: return "BUMP";
case FERNFOX: return "LEAF TAP";
case EMBERWING: return "SPARK";
case PEBBLIT: return "ROLL";
default: return "WATER JET";
}
}
void save_progress(void)
{
unsigned flags = (partner_owned ? 1u : 0u) | (balls_given ? 2u : 0u) | (rod_owned ? 4u : 0u) | ((unsigned)active_member << 3);
unsigned checksum = 0xa5 ^ 5 ^ flags ^ (unsigned)ball_count ^ (unsigned)caught_count;
/* Commit the first magic byte last so an interrupted write is invalid. */
SAVE_MEMORY[0] = 0;
SAVE_MEMORY[1] = 'Q';
SAVE_MEMORY[2] = 'S';
SAVE_MEMORY[3] = 'P';
SAVE_MEMORY[4] = 2;
SAVE_MEMORY[4] = 5;
SAVE_MEMORY[5] = (unsigned char)flags;
SAVE_MEMORY[6] = (unsigned char)ball_count;
SAVE_MEMORY[7] = (unsigned char)(0xa5 ^ 2 ^ flags ^ (unsigned)ball_count);
SAVE_MEMORY[8] = 0x5a;
SAVE_MEMORY[7] = (unsigned char)caught_count;
for (int i = 0; i < CAUGHT_CAPACITY; ++i) {
unsigned kind = i < caught_count ? caught_species[i] : 0xff;
SAVE_MEMORY[8 + i] = (unsigned char)kind;
checksum ^= kind;
}
SAVE_MEMORY[13] = (unsigned char)checksum;
SAVE_MEMORY[14] = 0x5a;
SAVE_MEMORY[0] = 'F';
}
int has_caught(enum Species kind)
{
for (int i = 0; i < caught_count; ++i)
if (caught_species[i] == (unsigned)kind) return 1;
return 0;
}
/* Change these lines to write Mila's conversation! Use CAPITAL letters. */
TEST_INTERNAL const char *const dialogue[][2] = {
{"HELLO I AM MILA", "WELCOME TO OUR VILLAGE"},
@@ -66,15 +139,27 @@ TEST_INTERNAL const char *const professor_followup[DIALOGUE_PAGES][2] = {
};
TEST_INTERNAL const char *const ranger_dialogue[DIALOGUE_PAGES][2] = {
{"HI I AM RANGER FINN", "HERE ARE FIVE POKE BALLS FOR YOU"},
{"YOU RECEIVED FIVE POKE BALLS", "KEEP THEM SAFE FOR YOUR ADVENTURE"}
{"YOU RECEIVED FIVE POKE BALLS", "PRESS SELECT IN BATTLE TO THROW"}
};
TEST_INTERNAL const char *const ranger_followup[DIALOGUE_PAGES][2] = {
{"YOUR POKE BALLS ARE IN YOUR BAG", "OPEN YOUR TEAM WITH SELECT TO LOOK"},
{"ENJOY EXPLORING SUNPETAL TRAIL", "TAKE GOOD CARE OF YOUR PARTNER"}
{"WEAKEN WILD CREATURES FIRST", "LOW HEALTH MAKES CATCHING EASIER"},
{"OPEN YOUR TEAM WITH SELECT", "USE ARROWS TO SEE YOUR NEW FRIENDS"}
};
static const char *const fisher_dialogue[2][2] = {
{"HI I AM FISHER CORAL", "TAKE THIS POKE ROD FOR FISHING"},
{"YOU RECEIVED A POKE ROD", "FACE THE SEA AND PRESS A"}
};
static const char *const fisher_followup[2][2] = {
{"FACE THE SEA AND PRESS A", "BRING SPROUT TO BATTLE TIDEFIN"},
{"WEAKEN IT THEN THROW A BALL", "PRESS SELECT TO CATCH YOUR FISH"}
};
int near_npc(int x, int y)
{
if (current_room == BEACH)
return x >= FISHER_X - 18 && x <= FISHER_X + 18 &&
y >= FISHER_Y - 18 && y <= FISHER_Y + 12;
if (current_room == ROUTE)
return x >= RANGER_X - 24 && x <= RANGER_X + 24 &&
y >= RANGER_Y - 22 && y <= RANGER_Y + 22;
@@ -95,6 +180,7 @@ int begin_conversation(int x, int y)
if (!near_npc(x, y)) return 0;
gift_conversation = current_room == MELLON_HOUSE && !partner_owned;
ball_gift_conversation = current_room == ROUTE && !balls_given;
rod_gift_conversation = current_room == BEACH && !rod_owned;
return 1;
}
@@ -122,6 +208,11 @@ int advance_conversation(int page)
int next = next_dialogue_page(page);
if (next == 1 && gift_conversation) receive_partner();
if (next == 1 && ball_gift_conversation) receive_balls();
if (next == 1 && rod_gift_conversation && current_room == BEACH && !rod_owned) {
rod_owned = 1;
save_progress();
}
if (next < 0) rod_gift_conversation = 0;
if (next < 0) gift_conversation = ball_gift_conversation = 0;
return next;
}
@@ -136,10 +227,11 @@ void dialogue_box(int page)
rectangle(16, 110, 208, 1, RGB(23, 26, 22));
int professor = current_room == MELLON_HOUSE;
int ranger = current_room == ROUTE;
const char *const (*lines)[2] = ranger ?
const char *const (*lines)[2] = current_room == BEACH ?
(rod_gift_conversation ? fisher_dialogue : fisher_followup) : ranger ?
(ball_gift_conversation ? ranger_dialogue : ranger_followup) : professor ?
(gift_conversation ? professor_dialogue : professor_followup) : dialogue;
large_text(16, 102, ranger ? "RANGER FINN" : professor ? "PROF MELLON" : "MILA", RGB(7, 16, 12));
large_text(16, 102, current_room == BEACH ? "FISHER CORAL" : ranger ? "RANGER FINN" : professor ? "PROF MELLON" : "MILA", RGB(7, 16, 12));
text(192, 103, page == DIALOGUE_PAGES - 1 ? "A CLOSE" : "A NEXT", ink);
large_text(16, 115, lines[page][0], ink);
large_text(16, 127, lines[page][1], ink);
+2 -1
View File
@@ -105,7 +105,8 @@ void large_text(int x, int y, const char *message, u16 color)
}
}
enum { SPRITE_SIZE = 24, SPRITE_CACHE_SIZE = 7 };
/* Keep all artwork images resident, including both character styles and Tidefin. */
enum { SPRITE_SIZE = 24, SPRITE_CACHE_SIZE = 15 };
struct DecodedSprite {
const char *const *art;
unsigned char width, rows;
+26 -1
View File
@@ -96,10 +96,35 @@ static const u16 pebblit_palette[] = {
RGB(9, 23, 26), RGB(26, 31, 30), RGB(11, 11, 15), RGB(18, 25, 28)
};
TEST_INTERNAL const char *const tidefin_art[] = {
"........................", "........................", "........................", "........................",
"............11..........",
"...........1331.........",
".........113331.........",
".......112333211........",
"......12334444321.......",
".....1234455444321..11..",
"....1234445144443211331.",
"....1234445144444333331.",
"....1234444444444333331.",
".....12344664443211131..",
"......12344444321...11..",
".......112333211........",
".........13331..........",
"..........131...........",
"...........1............",
"........................", "........................", "........................", "........................", "........................"
};
static const u16 tidefin_palette[] = {
0, RGB(4, 8, 14), RGB(4, 13, 23), RGB(7, 21, 29),
RGB(16, 28, 30), RGB(31, 31, 28), RGB(28, 15, 18)
};
TEST_INTERNAL const struct WildArt wild_art[] = {
{fernfox_art, fernfox_palette},
{emberwing_art, emberwing_palette},
{pebblit_art, pebblit_palette}
{pebblit_art, pebblit_palette},
{tidefin_art, tidefin_palette}
};
#endif
+22 -5
View File
@@ -79,11 +79,11 @@ int near_map_exit(int x, int y)
{
if (current_room == OUTSIDE && x >= 216 && x <= 222 && y >= 108 && y <= 117)
return 1;
if (current_room == MELLON_GARDEN)
return x >= 17 && x <= 24 && y >= 108 && y <= 117;
if (current_room == MELLON_GARDEN && x >= 17 && x <= 24 && y >= 108 && y <= 117)
return 1;
if (x < 102 || x > 114) return 0;
if (current_room == OUTSIDE) return y >= 124 && y <= 131;
if (current_room == ROUTE) return y >= 47 && y <= 54;
if (current_room == OUTSIDE || current_room == MELLON_GARDEN) return y >= 124 && y <= 131;
if (current_room == ROUTE || current_room == BEACH) return y >= 47 && y <= 54;
return 0;
}
@@ -111,6 +111,16 @@ TEST_INTERNAL int use_map_exit(int *x, int *y, unsigned keys)
*x = 210;
*y = 113;
player_facing = FACING_LEFT;
} else if (current_room == MELLON_GARDEN && *y == 131 && (keys & DOWN)) {
current_room = BEACH;
*x = 108;
*y = 60;
player_facing = FACING_DOWN;
} else if (current_room == BEACH && *y == 47 && (keys & UP)) {
current_room = MELLON_GARDEN;
*x = 108;
*y = 125;
player_facing = FACING_UP;
} else {
return 0;
}
@@ -158,7 +168,8 @@ int use_door(int *x, int *y)
void reset_position(int *x, int *y)
{
*x = indoors() ? 120 : current_room == MELLON_GARDEN ? 31 : 108;
*y = indoors() ? 119 : current_room == ROUTE ? 60 : current_room == MELLON_GARDEN ? 113 : 103;
*y = indoors() ? 119 : (current_room == ROUTE || current_room == BEACH) ? 60 :
current_room == MELLON_GARDEN ? 113 : 103;
player_facing = FACING_DOWN;
grass_steps = 0;
diagonal_fraction = 0;
@@ -167,6 +178,12 @@ void reset_position(int *x, int *y)
TEST_INTERNAL int can_walk(int x, int y)
{
if (current_room == BEACH) {
if (x < 17 || x > 222 || y < 47 || y > beach_shoreline(x) - 5) return 0;
if ((x < 42 || x > 194) && y < 72) return 0; /* Palm trunks. */
if (x > 35 && x < 75 && y > 68 && y < 98) return 0; /* Umbrella and towel. */
return 1;
}
if (current_room == ROUTE) {
if (x < 32 || x > 207 || y < 47 || y > 131) return 0;
if (x > 143 && x < 216 && y < 85) return 0; /* Pond. */