Project Structure
Una Aventura Inesperada is a Nintendo DS puzzle game written in C using devkitPro. The project follows a simple flat structure with all source files in a single directory.File Organization
Each graphic asset has two files: a
.h header file with metadata and a .s assembly file containing the actual bitmap data.Code Organization
The game is structured around a singlemain.c file (~/workspace/source/source/main.c:1) containing all game logic.
Key Components
Hardware Initialization
The game initializes Nintendo DS hardware including:
- VRAM configuration for dual screens
- Background graphics layers
- Tile and map memory allocation
- Color palette setup (RGB15 format)
Key Data Structures
PuntoPantalla
Defines touchscreen button boundaries (~/workspace/source/source/main.c:76):
PosicionEnemigo
Tracks enemy state and position (~/workspace/source/source/main.c:82):
Main Game Loop Architecture
State Management
The game uses boolean flags to manage state:Movement System
Player movement is constrained by:- Available moves (
movimientosJugador) - Map boundaries (32x24 tile grid)
- Collision detection with walls, enemies, and boxes
Memory Management
VRAM Organization
The game uses two VRAM banks:- VRAM_A: Main screen framebuffer (256x192x2 bytes)
- VRAM_C: Sub screen background tiles and maps
Tile Memory Layout
Tiles are loaded sequentially into VRAM using DMA:Each 8x8 tile occupies 64 bytes in memory. Tile indices are calculated as
(offset / 64).Map Memory
The game uses a 32x24 tile map (768 tiles total):position = row * 32 + column
Function Overview
Core Functions
| Function | Purpose | Location |
|---|---|---|
main() | Entry point, hardware init, main loop | main.c:157 |
ConfigurarInterrupciones() | Sets up interrupt handlers | main.c:242 |
InicializarTeselas() | Loads all tile graphics | main.c:1065 |
GenerarNivel() | Renders level from map data | main.c:792 |
CrearMenu() | Displays main menu | main.c:871 |
CrearDialogo() | Shows question dialogs | main.c:939 |
Movement Functions
| Function | Purpose | Location |
|---|---|---|
TeclasJugador() | Handles player input | main.c:271 |
MoverEnemigo() | Moves or eliminates enemies | main.c:518 |
MoverObstaculo() | Pushes movable boxes | main.c:605 |
ComprobarSuelo() | Returns original floor tile | main.c:446 |
ElegirFondoJugador() | Selects player sprite with background | main.c:464 |
Game Logic Functions
| Function | Purpose | Location |
|---|---|---|
ConsultarSistemaDialogo() | Manages level progression | main.c:658 |
ActualizarBarraMovimientos() | Updates stamina bar | main.c:853 |
ActualizarAnimacion() | Cycles sprite animations | main.c:981 |
HabilitarBotonesDialogo() | Re-enables dialog buttons | main.c:780 |
The game uses a 2x2 tile grid for all sprites (player, enemies, NPCs, boxes), allowing for 16x16 pixel graphics.