Dungeon

Dungeon title screen on the Mini Arcade

A three-floor generated adventure

Dungeon combines procedural world generation, room artwork, exploration, traps, treasure, shops, turn-based combat, player progression, persistent saves and an automatic AI player.

This overview follows the current firmware structure. The linked detail pages contain expandable diagrams and protected reference listings for every Dungeon C module.

From the main loop to the screen

  1. Select Dungeon

    main.c detects SCREEN_DUNGEON and calls startDungeon().

  2. Handle controls

    dungeonAction() receives primary, map, status and context actions. dungeonAIControl() handles AI speed changes.

  3. Advance the active state

    updateDungeon() handles joystick movement, AI decisions, image decoding and timed state work.

  4. Draw the current screen

    drawDungeon() selects the start menu, room, map, status, reward, shop, combat, completion or history presentation.

  5. Leave Dungeon

    stopDungeon() commits played time and ends the active session when the menu changes.

Controls entering the module

ControlDungeon inputTypical role
JoystickX/Y offsetsMove through rooms or change the selected choice.
A or KPrimary actionConfirm a menu, combat, shop or progression choice.
BMap actionOpen or change the map view where the current state permits it.
CStatus actionOpen the status, inventory and progress pages.
DContext actionUse the state-specific extra action.
EAI speed actionCycle the automatic player's speed.

State machine

The core module keeps presentation and input handling explicit with fourteen states:

Start menu
AI start
Creating
Room
Notice
Reward
Trap result
Locked door
Level bonus
Shop
Combat
Combat result
Complete
History

Room movement can lead to a trap, locked door, encounter, reward, stair/shop interaction or completion. Each result returns through an explicit state rather than an inferred runtime path.

Exploration and events

  1. Choose a valid exit

    The current cell's exit mask and the destination bounds determine whether movement is possible.

  2. Load destination artwork

    dungeon_tiles.c resolves the generated cell type, exits and variant into a tile image path.

  3. Persist the move

    The player position, move count, explored map and play time are updated and saved.

  4. Resolve the room

    Traps, locked encounters, enemies, keys and treasure select the next state.

  5. Return to exploration

    After the result screen, the module restores the room view or advances floors through linked stairs.

Automatic player

The AI searches the generated world for useful destinations, queues a route through neighbouring cells, chooses unexplored rooms or an uncollected key, handles shops and selects combat actions. The coloured arrows in the captures expose its chosen route, while E cycles the speed.

Module architecture

The Dungeon implementation contains 11 C modules and 199 functions, split by responsibility. Open a filename for its function diagrams and complete protected reference listing.

ModuleFunctionsResponsibility
dungeon.c70Owns the game state machine, player movement, room events, AI route selection, controls, screen updates and drawing.
dungeon_combat.c7Creates encounters and resolves attacks, escape attempts, enemy turns and health-potion use.
dungeon_config.c3Holds the tunable generation, reward, progression and combat rules used by the other Dungeon modules.
dungeon_explored.c20Tracks which map cells have been visited and persists the exploration record with validation and checksums.
dungeon_files.c2Initialises the Dungeon resource folder and installs required files when they are missing.
dungeon_generator.c24Builds the three procedural floors, rooms, passages, stairs, events and treasures, then validates the result.
dungeon_history.c23Stores, sorts and validates completed runs for the Dungeon high-score and history screens.
dungeon_map.c2Owns and initialises the in-memory DungeonWorld structure shared by generation, play and storage.
dungeon_player.c22Owns player statistics, saved progress, experience requirements, levelling choices and validation.
dungeon_storage.c18Loads and saves generated worlds, serialises positions and cells, validates checksums and deletes run data.
dungeon_tiles.c8Converts generated cell shapes and variants into artwork paths and validates the required tile files.

Screen tour

Reference-source notice

The source pages are documentation snapshots rather than build-ready downloads. Each complete listing starts with the JD credit and a deliberate #error line.