Create GBA adventure with walkable map and NPC dialogue

This commit is contained in:
Rory Rogers committed 2026-10-26 00:37:22 +00:00
commit b4017d5c1a
10 files changed
+623

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
/* Test game rules on the Mac without touching GBA screen registers. */
#include <assert.h>
#include <stdio.h>
#define main gba_main
#include "../source/main.c"
#undef main
int main(void)
{
assert(can_walk(108, 103));
assert(!can_walk(30, 60)); /* Pond. */
assert(!can_walk(175, 60)); /* House. */
assert(!can_walk(0, 100)); /* Map edge. */
assert(!can_walk(NPC_X, NPC_Y));
assert(!can_walk(NPC_X - 12, NPC_Y));
assert(!can_walk(NPC_X, NPC_Y + 8));
assert(can_walk(NPC_X - 13, NPC_Y));
assert(can_walk(NPC_X + 13, NPC_Y));
assert(can_walk(NPC_X, NPC_Y + 9));
assert(can_walk(NPC_X, NPC_Y - 9));
assert(!near_npc(108, 103));
assert(near_npc(NPC_X - 13, NPC_Y));
assert(near_npc(NPC_X + 13, NPC_Y));
assert(near_npc(NPC_X, NPC_Y + 9));
assert(near_npc(NPC_X, NPC_Y - 9));
assert(near_npc(NPC_X - 24, NPC_Y - 20));
assert(!near_npc(NPC_X - 25, NPC_Y));
assert(!near_npc(NPC_X, NPC_Y + 21));
assert(!near_npc(182, 103)); /* The creature does not trigger Mila. */
assert(DIALOGUE_PAGES == 2);
assert(next_dialogue_page(0) == 1);
assert(next_dialogue_page(1) == -1);
for (int page = 0; page < DIALOGUE_PAGES; ++page) {
for (int line = 0; line < 2; ++line) {
int length = 0;
for (const char *p = dialogue[page][line]; *p; ++p) {
assert(*p == ' ' || (*p >= 'A' && *p <= 'Z'));
++length;
}
assert(length <= 52); /* Text stays inside its box. */
}
}
puts("NPC collision, talk distance, dialogue pages, and text checks passed");
return 0;
}
+58
View File
@@ -0,0 +1,58 @@
import importlib.util
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location("rom_header", ROOT / "tools/rom_header.py")
header = importlib.util.module_from_spec(spec)
spec.loader.exec_module(header)
class HeaderTests(unittest.TestCase):
def setUp(self):
self.rom = bytearray((ROOT / "game.gba").read_bytes())
def test_built_rom_is_valid(self):
self.assertEqual(len(header.LOGO), 156)
header.verify(self.rom)
def test_bad_logo_is_rejected(self):
self.rom[4] ^= 1
with self.assertRaisesRegex(ValueError, "hardware header"):
header.verify(self.rom)
def test_bad_checksum_is_rejected(self):
self.rom[160] ^= 1
with self.assertRaisesRegex(ValueError, "checksum"):
header.verify(self.rom)
def test_bad_entry_is_rejected(self):
self.rom[:4] = bytes.fromhex("ffffffea")
with self.assertRaisesRegex(ValueError, "Entry branch"):
header.verify(self.rom)
def test_small_rom_is_rejected(self):
with self.assertRaisesRegex(ValueError, "size"):
header.verify(b"short")
def test_header_writer_and_padding(self):
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / "test.gba"
raw = bytearray(256)
raw[:4] = bytes.fromhex("2e0000ea") # Branch to offset 192.
path.write_bytes(raw)
subprocess.run(
[sys.executable, str(ROOT / "tools/rom_header.py"), str(path)],
check=True, capture_output=True, text=True,
)
result = path.read_bytes()
self.assertEqual(len(result), 32768)
self.assertEqual(result[160:172], b"FIRSTQUEST\0\0")
header.verify(result)
if __name__ == "__main__":
unittest.main()