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
+1303 -100

No files matched your search

+4 -2
View File
@@ -4,10 +4,11 @@ CC := $(TOOL_PREFIX)gcc
OBJCOPY := $(TOOL_PREFIX)objcopy
CFLAGS := -mcpu=arm7tdmi -marm -O2 -g -Wall -Wextra -Werror -ffreestanding -fno-builtin -fno-common -Wa,--noexecstack
GAME_SOURCES := source/main.c source/video.c source/scenery.c source/world.c \
source/actors.c source/battle.c source/story.c source/hud.c
source/actors.c source/battle.c source/story.c source/hud.c source/audio.c source/beach.c
GAME_OBJECTS := $(GAME_SOURCES:source/%.c=build/%.o)
TEST_SOURCES := tests/test_game.c tests/test_support.c tests/test_maps.c \
tests/test_story.c tests/test_battle.c tests/test_rendering.c tests/test_movement.c
tests/test_story.c tests/test_battle.c tests/test_rendering.c tests/test_movement.c tests/test_audio.c \
tests/test_catching.c
.PHONY: all play check check-host
all: game.gba
@@ -22,6 +23,7 @@ build/%.o: source/%.c source/game.h | build
$(CC) $(CFLAGS) -c $< -o $@
build/actors.o: source/wild_creatures.h
build/audio.o build/main.o: source/audio.h
build/game.elf: build/start.o $(GAME_OBJECTS) gba.ld
$(CC) -mcpu=arm7tdmi -marm -nostdlib -T gba.ld -Wl,-z,noexecstack -Wl,-Map,build/game.map build/start.o $(GAME_OBJECTS) -lgcc -o $@
+23 -9
View File
@@ -22,14 +22,20 @@ The game file is **game.gba**. You can also open it directly in mGBA without reb
- **X at the house door:** stand on the steps below the door and press X to open it and go inside. Walk to the bottom doorway inside and press X to return outside.
- **Leave Greenleaf Village:** follow the central sandy path down through the gap in the bottom fence. Keep walking down to enter **Sunpetal Trail** automatically.
- **Return to the village:** on Sunpetal Trail, follow the central path up to the top edge. Press X beside the wooden sign to read the directions.
- **Visit Professor Mellon:** follow the village's horizontal sandy path right through the fence opening. His blue-roofed house is in the garden. Press X on its steps to enter, then walk close to the professor and press X to talk. Leave through the bottom doorway, then follow the garden path left to return to town.
- **Get your first partner:** talk to Professor Mellon and press X to advance his conversation. He gives you **Sprout**, an original Grass-type partner at level five. This is a one-time gift; later conversations check on Sprout instead.
- **Backspace (GBA Select button):** open your team to see Sprout. Press Backspace, X (A), or Z (B) to return. Movement pauses while the team screen is open.
- **Sprout follows you:** after receiving Sprout, walk a few steps and it follows your path. It travels through doors and map exits with you.
- **Visit Professor Mellon:** follow the village's horizontal sandy path right through the fence opening. Her blue-roofed house is in the garden. Press X on its steps to enter, then walk close to the professor and press X to talk. Leave through the bottom doorway, then follow the garden path left to return to town.
- **Visit Seashell Beach:** from Professor Mellon's garden, follow the central sandy path down through the bottom fence gap. Walk up the beach's northern path to return to the garden. Explore the dry sand, palms, umbrella, shells, and starfish; the sea is not walkable. Sprout comes along, and the beach uses the calm trail music.
- **Go fishing:** talk to **Fisher Coral**, the red-haired person in turquoise on the right side of Seashell Beach. Press X again to receive a **Poké Rod**, saved permanently in your bag. Bring Sprout, walk to the water's edge, face down toward the sea, and press **X** to hook **Tidefin**, an original Water-type fish. Weaken it and press **Backspace** to throw a Poké Ball. The rod is reusable; catching still requires balls from Ranger Finn and space on your team. Older saves keep their gifts and catches.
- **Get your first partner:** talk to Professor Mellon and press X to advance her conversation. She gives you **Sprout**, an original Grass-type partner at level five. This is a one-time gift; later conversations check on Sprout instead.
- **Character artwork:** the player and Ranger Finn use boy sprites; Mila and Professor Mellon use distinct long-haired girl sprites. Mellon keeps her white coat and gray hair. Both styles have front, back, and side views.
- **Backspace (GBA Select button):** open your team. Use Left/Right to browse Sprout and your caught creatures, then press **X (A)** to choose the displayed creature as your following and battling partner. Backspace or Z (B) returns without changing your choice. Your selection is saved automatically. Movement pauses while the team screen is open.
- **Your partner follows you:** Sprout or your selected caught creature follows your path and travels through doors and map exits with you. Each uses its own artwork. Choose Sprout again from the team screen whenever you like.
- **Battle the golden creature:** with Sprout on your team, walk close to the golden creature in Greenleaf Village and press X. Use Left/Right to choose **Tackle** or **Leaf Tap**, then X to attack. The golden creature responds with Bump. Press Z (B) to run away. At the result screen, press X or Z to return to the map. Sprout recovers fully after each battle.
- **Wild encounters:** with Sprout, walk around either tall-grass patch on Sunpetal Trail. **Fernfox** (Grass), **Emberwing** (Fire), or **Pebblit** (Rock) can appear automatically. Each has its own original 24×24 sprite, palette, health, and attack. Encounters only happen while moving in grass, with a short breather between battles. Leaf Tap is stronger against Pebblit and weaker against Emberwing. Fighting and running use the same keys as the golden-creature battle.
- **Get Poké Balls:** talk to **Ranger Finn**, the person in orange just left of Sunpetal Trail's central path. Press X again to receive **five Poké Balls**. This gift is given once. Press Backspace to see the count on the team screen, even if you do not have Sprout yet. Catching creatures is not implemented yet.
- **Get Poké Balls:** talk to **Ranger Finn**, the person in orange just left of Sunpetal Trail's central path. Press X again to receive **five Poké Balls**. This gift is given once. Press Backspace to see the count on the team screen, even if you do not have Sprout yet.
- **Catch a creature:** press **Backspace during a battle** to throw one Poké Ball. Lower health improves the chance; at one-quarter health or less, the catch is guaranteed. A failed throw still uses the ball and lets the creature attack. You cannot catch a fainted creature. Successful catches join your saved team, with room for Sprout plus five catches (duplicates are allowed). A full team does not waste a ball. The village's golden creature disappears from the map once caught. Press X after the catch result, then Backspace and Left/Right to view your new friend. Press X to make it your partner.
- **Battle with caught creatures:** your selected partner fights in both land and fishing battles, using its own maximum health, Tackle, and a second move: Golden's Bump, Fernfox's Leaf Tap, Emberwing's Spark, Pebblit's Roll, or Tidefin's Water Jet. Partners recover fully after battles. Choose partners outside battle, not during a turn.
- **Return (GBA Start button):** return to your starting position in the current map.
- **S (GBA R shoulder button):** mute or unmute the music, including during battles and menus. This setting lasts until you restart the ROM.
If those keys do not match your emulator settings, check mGBA's keyboard input settings.
@@ -49,11 +55,13 @@ Those numbers mean red, green, and blue, each from 0 to 31. Try `RGB(29, 6, 6)`
- `source/game.h`: shared game types and module declarations.
- `source/video.c`: frame buffer, dirty rows, text, and sprite renderer.
- `source/scenery.c`: map artwork and the scenery cache.
- `source/beach.c`: Seashell Beach artwork and shared shoreline boundary.
- `source/world.c`: movement, collisions, doors, map travel, and following.
- `source/actors.c`: character and creature artwork and drawing.
- `source/battle.c`: species, battle rules, and the battle screen.
- `source/story.c`: conversations, gifts, and cartridge SRAM saves.
- `source/hud.c`: map status, scene drawing, and the team screen.
- `source/audio.c` and `source/audio.h`: original chiptune scores and the GBA sound-channel sequencer.
- `source/wild_creatures.h`: original wild-creature sprites and palettes.
- `source/start.s`: code that starts the GBA hardware.
- `gba.ld`: tells the compiler where cartridge code and working memory go.
@@ -61,7 +69,7 @@ Those numbers mean red, green, and blue, each from 0 to 31. Try `RGB(29, 6, 6)`
- `Makefile`: builds the game with the installed ARM compiler.
- `tests/`: cartridge header, NPC interaction, drawing, house entry/exit, and room collision tests. `make check` also generates scene previews in `build/`.
Run `make check-host` to check C game behavior on your Mac using only host clang, generating scene previews in `build/`. It does not need a ROM or the ARM compiler. The C tests are grouped by maps, story, battles, rendering, and movement, with shared helpers in `tests/test_support.c`. `make check` builds the ROM, checks its header, runs the ROM-dependent Python tests, and runs these host checks.
Run `make check-host` to check C game behavior on your Mac using only host clang, generating scene previews in `build/`. It does not need a ROM or the ARM compiler. The C tests are grouped by maps, story, battles, rendering, movement, and audio, with shared helpers in `tests/test_support.c`. Audio tests use fake sound registers rather than your Mac's audio device. `make check` builds the ROM, checks its header, runs the ROM-dependent Python tests, and runs these host checks.
Graphics are drawn into a RAM buffer first. Only the changed spans of each row are copied to the GBA screen during VBlank, so walking does not expose a half-erased character. Full map changes are copied while the display is temporarily blanked.
@@ -73,7 +81,13 @@ Movement has a separate 60 Hz fixed-step clock using cascaded GBA timers 2 and 3
## Saving your partner and items
Receiving Sprout or Finn's Poké Balls automatically writes a small cartridge SRAM save, stored by mGBA alongside the ROM as `game.sav`. Keep that file to retain your partner and item count after reopening the game. Older Sprout-only saves remain compatible. Partner ownership, the ball count, and whether Finn's gift was claimed are saved, but your map and position are not. The golden-creature battle is a repeatable practice battle with two moves, health bars, victory, defeat, and running away. Sprout recovers afterward. Experience and catching creatures are not implemented yet.
Receiving gifts, throwing Poké Balls, and choosing partners automatically write a small cartridge SRAM save, stored by mGBA alongside the ROM as `game.sav`. Keep that file to retain your gifts, caught creatures, remaining balls, and selected partner after reopening the game. Older saves remain compatible and default to Sprout as the active partner. Your map and position are not saved. Partners recover after battles. Experience is not implemented yet.
## Music
Three original four-bar chiptunes loop automatically: a bright village tune (112 BPM), a calmer trail/indoor tune (94 BPM), and a faster battle tune (160 BPM). Two hardware square-wave channels play melody and bass, with quiet noise-channel percussion in the village and battle tracks. Menus and conversations keep the current tune playing; entering a battle switches themes, and leaving it restores the location's theme.
The sequencer reads the existing hardware clock without changing the movement timers. It writes sound registers only on note events, uses no PCM audio buffers or audio DMA, and skips missed notes rather than replaying them in a long loop after a stall. These are original melodies, not music copied from Pokémon. In mGBA, make sure emulator audio is unmuted and your Mac's volume is comfortable.
### Change what Mila says
@@ -104,6 +118,6 @@ We are making an original game. No existing Pokémon ROM or separate BIOS downlo
## Project status
Greenleaf Village connects south to Sunpetal Trail and east to Professor Mellon's garden and house. Both houses have working doors. Mila and the professor have conversations, and Mellon gives you Sprout once. Ranger Finn gives you five Poké Balls once, with a saved inventory count. Sprout is saved to SRAM, appears on your team screen, follows your footsteps, and can battle the village's golden creature. Three wild species appear in the route's tall grass, using distinct shaded sprites rather than recolors. Battles support two moves, species-specific replies, health bars, victory, defeat, running away, and free recovery.
Greenleaf Village connects south to Sunpetal Trail and east to Professor Mellon's garden and house. Seashell Beach is south of the garden, with a return path north. Both houses have working doors. Mila and the professor have conversations, and Mellon gives you Sprout once. Ranger Finn gives you five usable Poké Balls. Sprout follows your footsteps and battles the village's golden creature and three wild route species. Battles support two moves, species-specific replies, health bars, catching, victory, defeat, running away, and free recovery. Caught creatures and spent balls are saved, and the team screen lets you browse up to six members.
All artwork is original; no Pokémon game assets or ROMs are included. Experience, catching creatures, sound, and full progress saving are not implemented yet.
All artwork and music are original; no Pokémon game assets or ROMs are included. Experience, mid-battle partner switching, sound effects, and full progress saving are not implemented yet.
+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);
+34 -4
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) {
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. */
+145
View File
@@ -0,0 +1,145 @@
#include "test_support.h"
#include "../source/audio.h"
static unsigned step_time(enum MusicTrack track, unsigned step)
{
unsigned numerator = step * MOVEMENT_CLOCK_HZ * 60u;
unsigned denominator = music_songs[track].bpm * 4u;
return (numerator + denominator - 1) / denominator;
}
static void assert_sound_ranges(void)
{
assert(music_state.step >= 0 && music_state.step < 64);
assert((music_registers[SOUND_LEAD_FREQ] & 0x7fff) < 2048);
assert((music_registers[SOUND_BASS_FREQ] & 0x7fff) < 2048);
assert((music_registers[SOUND_LEAD_ENV] >> 12) <= 6);
assert((music_registers[SOUND_BASS_ENV] >> 12) <= 3);
assert((music_registers[SOUND_NOISE_ENV] >> 12) <= 2);
}
void check_music(void)
{
for (unsigned note = 48; note <= 84; ++note) {
assert(music_frequency(note) > 0 && music_frequency(note) < 2048);
if (note > 48) assert(music_frequency(note) > music_frequency(note - 1));
}
assert(music_frequency(0) == 0 && music_frequency(255) == 0);
for (int track = MUSIC_VILLAGE; track < MUSIC_TRACK_COUNT; ++track) {
const struct MusicSong *song = &music_songs[track];
assert(song->bpm >= 60 && song->bpm <= 180);
for (int step = 0; step < 64; ++step) {
unsigned note = song->lead[step];
assert(note == 0 || note == 255 || (note >= 48 && note <= 84));
}
for (int step = 0; step < 16; ++step)
assert(song->bass[step] >= 48 && song->bass[step] <= 84);
}
assert(music_choose_track(OUTSIDE, BATTLE_OFF) == MUSIC_VILLAGE);
assert(music_choose_track(MELLON_GARDEN, BATTLE_OFF) == MUSIC_VILLAGE);
assert(music_choose_track(ROUTE, BATTLE_OFF) == MUSIC_TRAIL);
assert(music_choose_track(COTTAGE, BATTLE_OFF) == MUSIC_TRAIL);
assert(music_choose_track(MELLON_HOUSE, BATTLE_OFF) == MUSIC_TRAIL);
assert(music_choose_track(BEACH, BATTLE_OFF) == MUSIC_TRAIL);
for (int phase = BATTLE_TURN; phase <= BATTLE_CAUGHT; ++phase)
assert(music_choose_track(ROUTE, (enum BattlePhase)phase) == MUSIC_BATTLE);
current_room = OUTSIDE;
battle.phase = BATTLE_OFF;
music_init(0);
assert(music_registers[SOUND_MASTER] == 0x80);
assert(music_registers[SOUND_MIX] == 0xbb77 && music_registers[SOUND_RATIO] == 1);
assert(music_registers[SOUND_SWEEP] == 8);
assert(music_state.track == MUSIC_VILLAGE && !music_state.muted);
unsigned writes = music_write_count;
music_update(0);
music_update(step_time(MUSIC_VILLAGE, 1) - 1);
assert(music_state.step == 0 && music_write_count == writes);
music_update(step_time(MUSIC_VILLAGE, 1));
assert(music_state.step == 1 && music_write_count == writes); /* Tie: no retrigger. */
u16 first_pitch = music_registers[SOUND_LEAD_FREQ];
music_update(step_time(MUSIC_VILLAGE, 2));
assert(music_state.step == 2 && music_registers[SOUND_LEAD_FREQ] != first_pitch);
/* Songs keep the same tempo at different rendering/update frequencies. */
const int rates[] = {15, 30, 60, 120};
for (int track = MUSIC_VILLAGE; track < MUSIC_TRACK_COUNT; ++track) {
current_room = track == MUSIC_TRAIL ? ROUTE : OUTSIDE;
battle.phase = track == MUSIC_BATTLE ? BATTLE_TURN : BATTLE_OFF;
for (unsigned rate = 0; rate < sizeof(rates) / sizeof(rates[0]); ++rate) {
music_init(0);
for (int frame = 1; frame <= rates[rate] * 12; ++frame) {
music_update((unsigned)(frame * MOVEMENT_CLOCK_HZ / rates[rate]));
assert_sound_ranges();
}
unsigned steps = 12 * music_songs[track].bpm * 4u / 60u;
unsigned remainder = (12 * MOVEMENT_CLOCK_HZ * music_songs[track].bpm * 4u) %
(MOVEMENT_CLOCK_HZ * 60u);
assert(music_state.track == (enum MusicTrack)track);
assert(music_state.step == (int)(steps % 64) && music_state.phase == remainder);
}
}
/* Scene changes select a tune; overlays and same-theme maps keep the phrase. */
current_room = OUTSIDE;
battle.phase = BATTLE_OFF;
music_init(0);
music_update(step_time(MUSIC_VILLAGE, 5));
int step = music_state.step;
current_room = MELLON_GARDEN;
music_update(music_state.last);
assert(music_state.track == MUSIC_VILLAGE && music_state.step == step);
current_room = ROUTE;
music_update(music_state.last);
assert(music_state.track == MUSIC_TRAIL && music_state.step == 0);
battle.phase = BATTLE_TURN;
music_update(music_state.last);
assert(music_state.track == MUSIC_BATTLE && music_state.step == 0);
battle.phase = BATTLE_WON;
music_update(music_state.last);
assert(music_state.track == MUSIC_BATTLE);
battle.phase = BATTLE_OFF;
music_update(music_state.last);
assert(music_state.track == MUSIC_TRAIL && music_state.step == 0);
/* Muting stops all voices, stays muted across maps, and resumes on ties. */
music_toggle_mute();
assert(music_state.muted && music_registers[SOUND_MIX] == 0);
assert(music_registers[SOUND_LEAD_ENV] == 0 && music_registers[SOUND_BASS_ENV] == 0);
assert(music_registers[SOUND_NOISE_ENV] == 0);
writes = music_write_count;
current_room = OUTSIDE;
music_update(music_state.last);
unsigned start = music_state.last;
music_update(start + step_time(MUSIC_VILLAGE, 1));
assert(music_state.step == 1 && music_write_count == writes);
music_toggle_mute();
assert(!music_state.muted && music_registers[SOUND_MIX] == 0xbb77);
assert(music_registers[SOUND_LEAD_ENV] != 0 && music_registers[SOUND_BASS_ENV] != 0);
assert((music_registers[SOUND_LEAD_FREQ] & 2047) == music_frequency(72));
music_init(0);
for (unsigned index = 1; index <= 63; ++index) music_update(step_time(MUSIC_VILLAGE, index));
assert(music_state.step == 63 && music_registers[SOUND_LEAD_ENV] == 0); /* Rest. */
music_update(step_time(MUSIC_VILLAGE, 64));
assert(music_state.step == 0 && music_registers[SOUND_LEAD_ENV] != 0); /* Loop. */
music_init(0xffffff00u);
music_update(0x00001000u);
assert(music_state.step == 1); /* 32-bit hardware-clock rollover. */
writes = music_write_count;
music_update(music_state.last + MOVEMENT_CLOCK_HZ * 60u);
assert(music_write_count - writes <= 6); /* No missed-note replay loop. */
assert_sound_ranges();
/* The sequencer does not consume movement time or change game/save state. */
pause_movement_at(0);
unsigned char saved[sizeof(test_save)];
memcpy(saved, test_save, sizeof(saved));
music_update(music_state.last + 100);
assert(movement_ticks_at(MOVEMENT_CLOCK_HZ) == MAX_MOVEMENT_TICKS);
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
current_room = OUTSIDE;
battle.phase = BATTLE_OFF;
music_init(0);
puts("Music: 3 original tunes, stable tempo, scene switching, mute, ties, loops, and clock checks passed");
}
+4 -4
View File
@@ -5,7 +5,7 @@ void check_following_and_battle(void)
static u16 expected[WIDTH * HEIGHT], visible[WIDTH * HEIGHT];
static const unsigned directions[] = {RIGHT, DOWN, LEFT, UP};
partner_owned = 1;
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
for (int room = OUTSIDE; room <= BEACH; ++room) {
current_room = (enum Room)room;
int x, y;
reset_position(&x, &y);
@@ -78,7 +78,7 @@ void check_following_and_battle(void)
write_preview("build/battle-preview.ppm");
copy_pending_rows(visible);
assert(!battle_input(0));
assert(!battle_input(SELECT));
assert(battle_input(SELECT) && battle.notice == NOTICE_NO_BALLS);
assert(battle.turns == 0);
assert(battle_input(RIGHT));
assert(battle.move == 1 && battle.enemy_hp == GOLDEN_HP);
@@ -126,7 +126,7 @@ void check_following_and_battle(void)
void check_wild_encounters(void)
{
for (int kind = 0; kind < 3; ++kind) {
for (int kind = 0; kind < 4; ++kind) {
int opaque = 0;
for (int row = 0; row < 24; ++row) {
assert(strlen(wild_art[kind].rows[row]) == 24);
@@ -137,7 +137,7 @@ void check_wild_encounters(void)
++opaque;
}
}
assert(opaque > 180); /* Full original sprites, not palette swaps. */
assert(opaque > (kind == TIDEFIN - FERNFOX ? 100 : 180)); /* Fish has a slimmer silhouette. */
}
partner_owned = 1;
current_room = OUTSIDE;
+285
View File
@@ -0,0 +1,285 @@
#include "test_support.h"
void check_partner_selection(void)
{
static u16 expected[WIDTH * HEIGHT], visible[WIDTH * HEIGHT];
memset(test_save, 0xff, sizeof(test_save));
load_progress();
battle.phase = BATTLE_OFF;
assert(!choose_partner(0));
partner_owned = balls_given = rod_owned = 1;
ball_count = 5;
caught_count = CAUGHT_CAPACITY;
for (int i = 0; i < CAUGHT_CAPACITY; ++i) caught_species[i] = (unsigned char)i;
assert(!choose_partner(-1) && !choose_partner(6));
for (int member = 0; member <= caught_count; ++member) {
assert(choose_partner(member));
load_progress();
assert(active_member == member && rod_owned && ball_count == 5);
assert(strcmp(partner_name(), member ? species[member - 1].name : "SPROUT") == 0);
assert(partner_hp() == (member ? species[member - 1].hp : SPROUT_HP));
for (int room = OUTSIDE; room <= BEACH; ++room) {
current_room = (enum Room)room;
int x, y;
reset_position(&x, &y);
if (current_room == ROUTE) { y = 94; reset_follower(x, y); }
for (int step = 0; step < 20; ++step) {
render_scene(x, y);
copy_pending_rows(visible);
int old_x = x, old_y = y, fx = follower_x, fy = follower_y;
walk_movement(RIGHT, &x, &y, 1);
restore(old_x - 8, old_y - 20, 17, 24);
restore(fx - 8, fy - 20, 17, 24);
actors(x, y, 0);
location_status(x, y);
copy_pending_rows(visible);
memcpy(expected, SCREEN, sizeof(expected));
render_scene(x, y);
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
}
}
assert(start_battle(TIDEFIN));
assert(battle.sprout_hp == partner_hp());
assert(!choose_partner(0)); /* No changing partners mid-turn. */
draw_battle();
if (member == 3) write_preview("build/emberwing-partner-preview.ppm");
assert(battle_input(RIGHT));
assert(battle_input(A) && battle.enemy_hp < species[TIDEFIN].hp);
assert(battle.sprout_hp == partner_hp() - species[TIDEFIN].attack);
assert(battle_input(B) && battle_input(A));
assert(start_battle(GOLDEN) && battle.sprout_hp == partner_hp());
assert(battle_input(B) && battle_input(A));
}
unsigned char saved[sizeof(test_save)];
memcpy(saved, test_save, sizeof(saved));
/* Reject an out-of-range selection even with a correct checksum. */
test_save[5] ^= (5 ^ 6) << 3;
test_save[13] ^= (5 ^ 6) << 3;
load_progress();
assert(!partner_owned && active_member == 0);
memcpy(test_save, saved, sizeof(saved));
test_save[4] = 4;
test_save[5] &= 7;
test_save[13] ^= 5 ^ 4 ^ (5 << 3);
load_progress();
assert(partner_owned && rod_owned && caught_count == 5 && active_member == 0);
memset(test_save, 0xff, sizeof(test_save));
load_progress();
current_room = OUTSIDE;
follower_ready = 0;
puts("Partners: selection, saving, old saves, follower redraws, moves and battle recovery passed");
}
void check_fishing(void)
{
memset(test_save, 0xff, sizeof(test_save));
load_progress();
battle.phase = BATTLE_OFF;
current_room = BEACH;
player_facing = FACING_DOWN;
int x = 120, y = beach_shoreline(120) - 5;
assert(near_water(x, y) && !cast_rod(x, y));
assert(!begin_conversation(x, y));
assert(begin_conversation(FISHER_X - 14, FISHER_Y));
assert(!rod_owned);
assert(advance_conversation(0) == 1 && rod_owned);
assert(test_save[4] == 5);
dialogue_box(1);
write_preview("build/rod-gift-preview.ppm");
assert(advance_conversation(1) == -1);
load_progress();
assert(rod_owned && !partner_owned);
assert(!cast_rod(x, y));
assert(begin_conversation(FISHER_X, FISHER_Y));
unsigned char before[sizeof(test_save)];
memcpy(before, test_save, sizeof(before));
assert(advance_conversation(0) == 1 && advance_conversation(1) == -1);
assert(memcmp(before, test_save, sizeof(before)) == 0);
partner_owned = balls_given = 1;
ball_count = 5;
for (int facing = FACING_UP; facing <= FACING_RIGHT; ++facing) {
player_facing = (enum Facing)facing;
assert(!cast_rod(x, y));
}
player_facing = FACING_DOWN;
assert(!cast_rod(x, 75));
current_room = ROUTE;
assert(!cast_rod(x, y));
current_room = BEACH;
assert(cast_rod(x, y) && battle.enemy == TIDEFIN);
assert(!cast_rod(x, y));
draw_battle();
write_preview("build/fishing-battle-preview.ppm");
battle.enemy_hp = 1;
assert(battle_input(SELECT) && battle.phase == BATTLE_CAUGHT);
assert(ball_count == 4 && has_caught(TIDEFIN));
assert(battle_input(A));
load_progress();
assert(rod_owned && has_caught(TIDEFIN) && ball_count == 4);
draw_team_member(1);
write_preview("build/tidefin-team-preview.ppm");
assert(cast_rod(x, y));
assert(battle_input(B) && battle_input(A));
/* An old save keeps catches and balls without granting a rod. */
test_save[4] = 3;
test_save[5] &= (unsigned char)~4;
test_save[13] ^= 5 ^ 3 ^ 4;
load_progress();
assert(!rod_owned && has_caught(TIDEFIN) && ball_count == 4);
memset(test_save, 0xff, sizeof(test_save));
load_progress();
current_room = OUTSIDE;
follower_ready = 0;
puts("Fishing: rod gift, save migration, shoreline use, water battles and catches passed");
}
void check_catching(void)
{
const unsigned char old_save[] = {'F','Q','S','P',2,3,5,0xa1,0x5a};
memset(test_save, 0xff, sizeof(test_save));
memcpy(test_save, old_save, sizeof(old_save));
load_progress();
assert(partner_owned && balls_given && ball_count == 5 && caught_count == 0);
assert(test_save[4] == 2); /* Preserve an existing save until an action writes it. */
current_room = ROUTE;
assert(start_battle(FERNFOX));
ball_count = 0;
unsigned rng = random_state;
unsigned char before[sizeof(test_save)];
memcpy(before, test_save, sizeof(before));
assert(battle_input(SELECT) && battle.notice == NOTICE_NO_BALLS);
assert(battle.phase == BATTLE_TURN && battle.turns == 0 && battle.sprout_hp == SPROUT_HP);
assert(random_state == rng && memcmp(before, test_save, sizeof(before)) == 0);
ball_count = 5;
random_state = 1; /* Full-health roll 69 fails the 35% catch chance. */
draw_battle();
static u16 visible[WIDTH * HEIGHT], expected[WIDTH * HEIGHT];
copy_pending_rows(visible);
assert(battle_input(SELECT));
assert(ball_count == 4 && caught_count == 0 && battle.turns == 1);
assert(battle.notice == NOTICE_BROKE_FREE && battle.sprout_hp == 20);
assert(test_save[4] == 5 && test_save[6] == 4);
assert(!battle_input(0) && ball_count == 4); /* Holding Select cannot throw twice. */
draw_battle_hud();
assert(pending_pixels() < 16500);
copy_pending_rows(visible);
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
write_preview("build/catch-failed-preview.ppm");
load_progress();
assert(partner_owned && ball_count == 4 && caught_count == 0);
assert(battle_input(RIGHT));
assert(battle_input(A) && battle.enemy_hp == 11);
assert(battle_input(A) && battle.enemy_hp == 4);
int hp = battle.sprout_hp;
draw_battle_hud();
copy_pending_rows(visible);
assert(battle_input(SELECT)); /* Quarter health is a guaranteed catch. */
assert(battle.phase == BATTLE_CAUGHT && battle.sprout_hp == hp);
assert(ball_count == 3 && caught_count == 1 && caught_species[0] == FERNFOX);
assert(has_caught(FERNFOX) && !has_caught(GOLDEN));
draw_battle_hud();
assert(pending_pixels() < 16500);
copy_pending_rows(visible);
memcpy(expected, SCREEN, sizeof(expected));
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
draw_battle();
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
write_preview("build/caught-preview.ppm");
assert(!battle_input(SELECT) && ball_count == 3 && caught_count == 1);
load_progress();
assert(ball_count == 3 && caught_count == 1 && caught_species[0] == FERNFOX);
assert(battle_input(A) && battle.phase == BATTLE_OFF);
draw_team_member(1);
write_preview("build/caught-team-preview.ppm");
/* The village's single golden creature leaves the map after being caught. */
current_room = OUTSIDE;
assert(begin_battle(182, 113));
battle.enemy_hp = 1;
assert(battle_input(SELECT) && battle.phase == BATTLE_CAUGHT);
assert(ball_count == 2 && caught_count == 2 && caught_species[1] == GOLDEN);
assert(!near_golden(182, 113));
assert(battle_input(A));
assert(!begin_battle(182, 113));
reset_follower(108, 103);
render_scene(108, 103);
assert(SCREEN[95 * WIDTH + 181] == scenery(181, 95));
load_progress();
assert(has_caught(GOLDEN) && !near_golden(182, 113));
/* Fill a six-member team, including duplicate wild species. */
current_room = ROUTE;
ball_count = 5;
const enum Species additions[] = {EMBERWING, PEBBLIT, FERNFOX};
for (unsigned i = 0; i < sizeof(additions) / sizeof(additions[0]); ++i) {
assert(start_battle(additions[i]));
battle.enemy_hp = 1;
assert(battle_input(SELECT) && battle.phase == BATTLE_CAUGHT);
assert(battle_input(A));
}
assert(caught_count == CAUGHT_CAPACITY && ball_count == 2);
memcpy(before, test_save, sizeof(before));
assert(start_battle(FERNFOX));
rng = random_state;
assert(battle_input(SELECT) && battle.notice == NOTICE_TEAM_FULL);
assert(ball_count == 2 && battle.turns == 0 && battle.sprout_hp == SPROUT_HP);
assert(random_state == rng && memcmp(before, test_save, sizeof(before)) == 0);
assert(battle_input(B) && battle_input(A));
for (int member = 0; member <= caught_count; ++member) draw_team_member(member);
draw_team();
memcpy(expected, SCREEN, sizeof(expected));
draw_team_member(99);
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
load_progress();
assert(caught_count == 5 && ball_count == 2 && partner_owned);
for (int i = SAVE_RECORD_SIZE; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
for (int byte = 0; byte < SAVE_RECORD_SIZE; ++byte) {
memcpy(test_save, before, sizeof(before));
test_save[byte] ^= 1;
load_progress();
assert(!partner_owned && !balls_given && ball_count == 0 && caught_count == 0);
}
memcpy(test_save, before, sizeof(before));
test_save[7] = 6;
test_save[13] ^= 5 ^ 6; /* Valid checksum, invalid party length. */
load_progress();
assert(!partner_owned && caught_count == 0);
memcpy(test_save, before, sizeof(before));
test_save[8] = SPECIES_COUNT;
test_save[13] ^= FERNFOX ^ SPECIES_COUNT;
load_progress();
assert(!partner_owned && caught_count == 0);
memcpy(test_save, before, sizeof(before));
test_save[5] &= (unsigned char)~1;
test_save[13] ^= 1;
load_progress();
assert(!partner_owned && caught_count == 0); /* No captured team without Sprout. */
/* A failed attempt can end a battle, and the used ball still stays spent. */
memset(test_save, 0xff, sizeof(test_save));
load_progress();
partner_owned = balls_given = 1;
ball_count = 1;
assert(start_battle(EMBERWING));
battle.sprout_hp = 1;
random_state = 1;
assert(battle_input(SELECT) && battle.phase == BATTLE_LOST && ball_count == 0);
load_progress();
assert(partner_owned && balls_given && ball_count == 0 && caught_count == 0);
assert(battle_input(A));
ball_count = 1;
assert(start_battle(PEBBLIT));
battle.enemy_hp = 1;
assert(battle_input(A) && battle.phase == BATTLE_WON);
assert(!battle_input(SELECT) && ball_count == 1); /* Cannot catch a fainted creature. */
assert(battle_input(A));
memset(test_save, 0xff, sizeof(test_save));
load_progress();
current_room = OUTSIDE;
follower_ready = 0;
puts("Catching: ball use, failed/successful catches, team limits, browsing, and save migration passed");
}
+26 -1
View File
@@ -43,6 +43,9 @@ int main(void)
check_art(person_art, 20, 11);
check_art(person_back_art, 20, 13);
check_art(person_side_art, 20, 13);
check_art(girl_art, 20, 13);
check_art(girl_back_art, 20, 13);
check_art(girl_side_art, 20, 13);
check_art(creature_art, 16, 8);
assert(facing_for_keys(UP, FACING_DOWN) == FACING_UP);
assert(facing_for_keys(DOWN, FACING_UP) == FACING_DOWN);
@@ -76,7 +79,7 @@ int main(void)
actors(x, y, 0);
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
}
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
for (int room = OUTSIDE; room <= BEACH; ++room) {
current_room = (enum Room)room;
reset_position(&x, &y);
if (current_room == OUTSIDE) x = 130;
@@ -103,6 +106,23 @@ int main(void)
person(85, 116, 1, shirt, RGB(28, 8, 9), FACING_LEFT);
person(130, 126, 0, shirt, RGB(28, 8, 9), FACING_RIGHT);
write_preview("build/directions-preview.ppm");
for (int facing = FACING_DOWN; facing <= FACING_RIGHT; ++facing) {
int gx = 45 + facing * 45;
styled_person(gx, 75, facing & 1, RGB(4, 21, 13), RGB(12, 7, 4),
(enum Facing)facing, GIRL_STYLE);
styled_person(gx, 125, facing & 1, RGB(29, 30, 27), RGB(20, 21, 19),
(enum Facing)facing, GIRL_STYLE);
}
write_preview("build/girl-directions-preview.ppm");
current_room = MELLON_HOUSE;
render_scene(108, 119);
memcpy(expected, SCREEN, sizeof(expected));
/* Replacing the professor with the girl style must leave identical pixels. */
restore(PROF_X - 8, PROF_Y - 20, 17, 24);
styled_person(PROF_X, PROF_Y, 0, RGB(29, 30, 27), RGB(20, 21, 19),
FACING_DOWN, GIRL_STYLE);
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
current_room = OUTSIDE;
assert(test_pixels[0] == 0xbeef);
assert(test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
render_scene(108, 103);
@@ -177,6 +197,7 @@ int main(void)
check_buffered_walking();
check_route_travel();
check_mellon_visit();
check_beach_travel();
check_starter_gift();
check_following_and_battle();
check_wild_encounters();
@@ -184,6 +205,10 @@ int main(void)
check_background_cache();
check_sprite_rows();
check_movement_clock_and_speed();
check_music();
check_catching();
check_fishing();
check_partner_selection();
assert(test_pixels[0] == 0xbeef);
assert(test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
puts("Ball gift/inventory/save migration, wild encounters, battles, following, and map checks passed");
+68 -1
View File
@@ -15,7 +15,7 @@ void check_buffered_walking(void)
mark_dirty(240, 160, 4, 4);
assert(pending_pixels() == 0);
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
for (int room = OUTSIDE; room <= BEACH; ++room) {
current_room = (enum Room)room;
player_facing = FACING_DOWN;
int x, y;
@@ -219,3 +219,70 @@ void check_mellon_visit(void)
current_room = OUTSIDE;
player_facing = FACING_DOWN;
}
void check_beach_travel(void)
{
static u16 expected[WIDTH * HEIGHT], visible[WIDTH * HEIGHT];
current_room = MELLON_GARDEN;
partner_owned = 1;
assert(reachable(31, 113, 108, 131));
int x = 80, y = 131;
assert(!use_map_exit(&x, &y, DOWN));
x = 108;
assert(!use_map_exit(&x, &y, UP));
for (int trip = 0; trip < 5; ++trip) {
x = 108;
y = 129;
assert(walk_movement(DOWN, &x, &y, 1) == WALK_MAP_CHANGED);
assert(current_room == BEACH && x == 108 && y == 60);
assert(can_walk(x, y) && player_facing == FACING_DOWN);
assert(follower_x == x && follower_y == y);
assert(!use_map_exit(&x, &y, DOWN));
assert(!near_npc(RANGER_X, RANGER_Y) && !near_door(177, 83));
assert(!in_tall_grass(48, 70));
assert(!check_grass_encounter(80, 80, 81, 80));
assert(!can_walk(55, 85)); /* Umbrella. */
assert(!can_walk(28, 60) && !can_walk(210, 60)); /* Palms. */
assert(reachable(x, y, 178, 97));
assert(reachable(x, y, 30, 99));
assert(reachable(x, y, 108, 47));
for (int col = 17; col <= 222; ++col)
assert(!can_walk(col, beach_shoreline(col) - 4));
assert(!can_walk(108, 115) && !can_walk(108, 140));
render_scene(x, y);
copy_pending_rows(visible);
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
write_preview("build/beach-preview.ppm");
const int positions[][2] = {{108, 47}, {178, 97}, {30, 99}, {90, 82}};
for (unsigned i = 0; i < sizeof(positions) / sizeof(positions[0]); ++i) {
int nx = positions[i][0], ny = positions[i][1];
assert(can_walk(nx, ny));
render_scene(nx, ny);
memcpy(expected, SCREEN, sizeof(expected));
render_scene(x, y);
restore(x - 8, y - 20, 17, 24);
actors(nx, ny, 0);
location_status(nx, ny);
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
}
x = 108;
y = beach_shoreline(x) - 6;
assert(walk_movement(DOWN, &x, &y, MAX_MOVEMENT_TICKS) == WALK_NORMAL);
assert(y == beach_shoreline(x) - 5); /* Even catch-up frames cannot enter the sea. */
reset_position(&x, &y);
assert(current_room == BEACH && x == 108 && y == 60);
assert(follower_x == x && follower_y == y);
y = 48;
assert(walk_movement(UP, &x, &y, 1) == WALK_MAP_CHANGED);
assert(current_room == MELLON_GARDEN && x == 108 && y == 125);
assert(player_facing == FACING_UP && follower_x == x && follower_y == y);
assert(!use_map_exit(&x, &y, UP));
assert(reachable(x, y, 177, 83)); /* Professor's door remains accessible. */
assert(reachable(x, y, 17, 113)); /* Town exit remains accessible. */
}
current_room = OUTSIDE;
partner_owned = follower_ready = 0;
player_facing = FACING_DOWN;
puts("Beach: garden connection, return path, shore collisions, following, and redraw checks passed");
}
+1 -1
View File
@@ -98,7 +98,7 @@ void check_movement_clock_and_speed(void)
static u16 snapshot[WIDTH * HEIGHT];
const unsigned directions[] = {RIGHT, DOWN, LEFT, UP};
const int tick_counts[] = {1, 2, 1, 3, 0};
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
for (int room = OUTSIDE; room <= BEACH; ++room) {
current_room = (enum Room)room;
reset_position(&x, &y);
if (current_room == OUTSIDE) { x = 40; y = 125; }
+4 -3
View File
@@ -10,7 +10,7 @@ void check_background_cache(void)
restore(240, 160, 4, 4);
assert(!background_valid && scenery_samples == 0 && pending_pixels() == 0);
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
for (int room = OUTSIDE; room <= BEACH; ++room) {
current_room = (enum Room)room;
door_open = 0;
unsigned before = scenery_samples;
@@ -87,7 +87,7 @@ void check_background_cache(void)
assert(SCREEN[y * WIDTH + x] == expected);
}
assert(test_pixels[0] == 0xbeef && test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
puts("Background cache: 5 maps match reference; warm restores use 0 scenery evaluations (was 408 each)");
puts("Background cache: 6 maps match reference; warm restores use 0 scenery evaluations (was 408 each)");
}
/* Reference implementation of the previous per-pixel rectangle renderer. */
@@ -116,8 +116,9 @@ void check_sprite_rows(void)
static const char *const zero_art[] = {"0A..B1..", "..1.....", "........"};
const struct { const char *const *art; int width, rows; } images[] = {
{person_art, 16, 20}, {person_back_art, 16, 20}, {person_side_art, 16, 20},
{girl_art, 16, 20}, {girl_back_art, 16, 20}, {girl_side_art, 16, 20},
{creature_art, 16, 16}, {fernfox_art, 24, 24}, {emberwing_art, 24, 24},
{pebblit_art, 24, 24}, {zero_art, 8, 3}
{pebblit_art, 24, 24}, {tidefin_art, 24, 24}, {zero_art, 8, 3}
};
const int positions[][2] = {
{70, 60}, {-8, 40}, {232, 40}, {80, -12}, {80, 155},
+6 -6
View File
@@ -42,7 +42,7 @@ void check_starter_gift(void)
assert(advance_conversation(0) == 1);
assert(advance_conversation(1) == -1);
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
for (int i = 9; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
for (int i = SAVE_RECORD_SIZE; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
/* Ownership survives map changes, position reset, and loading SRAM. */
x = 120;
@@ -68,7 +68,7 @@ void check_starter_gift(void)
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
/* Reject damaged, incomplete, or unknown-version save records. */
for (int byte = 0; byte < 9; ++byte) {
for (int byte = 0; byte < SAVE_RECORD_SIZE; ++byte) {
memcpy(test_save, saved, sizeof(saved));
test_save[byte] ^= 1;
load_progress();
@@ -132,7 +132,7 @@ void check_ball_gift(void)
restore(DIALOGUE_X, DIALOGUE_Y, DIALOGUE_W, DIALOGUE_H);
actors(99, 97, 0);
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
assert(test_save[4] == 2);
assert(test_save[4] == 5);
unsigned char saved[sizeof(test_save)];
memcpy(saved, test_save, sizeof(saved));
for (int visit = 0; visit < 10; ++visit) {
@@ -146,7 +146,7 @@ void check_ball_gift(void)
assert(partner_owned && balls_given && ball_count == 5);
draw_team();
write_preview("build/poke-balls-preview.ppm");
for (int i = 9; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
for (int i = SAVE_RECORD_SIZE; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
int x = 108, y = 47;
assert(use_map_exit(&x, &y, UP));
assert(ball_count == 5 && balls_given);
@@ -165,7 +165,7 @@ void check_ball_gift(void)
load_progress();
assert(partner_owned && balls_given && ball_count == 5);
memcpy(saved, test_save, sizeof(saved));
for (int byte = 0; byte < 9; ++byte) {
for (int byte = 0; byte < SAVE_RECORD_SIZE; ++byte) {
memcpy(test_save, saved, sizeof(saved));
test_save[byte] ^= 1;
load_progress();
@@ -173,7 +173,7 @@ void check_ball_gift(void)
}
memcpy(test_save, saved, sizeof(saved));
test_save[6] = 100;
test_save[7] = (unsigned char)(0xa5 ^ 2 ^ test_save[5] ^ test_save[6]);
test_save[13] ^= (unsigned char)(5 ^ 100); /* Keep checksum valid; count itself is invalid. */
load_progress();
assert(!partner_owned && !balls_given && ball_count == 0);
for (int page = 0; page < DIALOGUE_PAGES; ++page)
+5
View File
@@ -15,6 +15,7 @@ void copy_pending_rows(u16 *visible);
void check_buffered_walking(void);
void check_route_travel(void);
void check_mellon_visit(void);
void check_beach_travel(void);
void check_starter_gift(void);
void check_ball_gift(void);
void check_following_and_battle(void);
@@ -22,5 +23,9 @@ void check_wild_encounters(void);
void check_background_cache(void);
void check_sprite_rows(void);
void check_movement_clock_and_speed(void);
void check_music(void);
void check_catching(void);
void check_fishing(void);
void check_partner_selection(void);
#endif