HeadlinesBriefing favicon HeadlinesBriefing.com

C64 BASIC Dungeon Crawler: Goblin AI & Memory Bugs

Hacker News •
×

Part eight of the C64 BASIC tutorial series adds redefinable keys, chasing goblins, d20 combat, and a critical memory bug fix. Previously, goblins were static decorations; now they track player position using parallel arrays (GX, GY, GH) and pursue actively. Combat uses a d20 roll plus strength modifier.

The article details Commodore BASIC's variable-name traps: only the first two letters matter (so PLAYERHEALTH and PLAYERX collide), and names containing keywords like GO in GOLD cause tokenization errors. The fix uses unique two-letter prefixes (QK, AK, OK, PK, FK) for key mappings.

Key redefinition replaces literal QAOP checks with variable comparisons. The routine uses GET in a tight loop (waiting for a keystroke) rather than INPUT, allowing any key including cursor keys. A confirmation step prevents accidental mis-mapping.

The memory bug silently corrupted the custom character set when goblin arrays expanded into protected RAM. The author calls this the "most useful lesson" in the part. Code is editable in the RGC online IDE with no downloads required.