From 08ba88ec0531ab3d1c24264ed5cc843506568729 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 4 Apr 2026 12:44:45 +0200 Subject: [PATCH] mes granera --- CLAUDE.md | 42 +++++++++++-------- CMakeLists.txt | 37 +++++++++------- source/{ => core}/jail_audio.cpp | 4 +- source/{jail_audio.h => core/jail_audio.hpp} | 0 source/{ => core}/jdraw8.cpp | 8 ++-- source/{jdraw8.h => core/jdraw8.hpp} | 0 source/{ => core}/jfile.cpp | 2 +- source/{jfile.h => core/jfile.hpp} | 0 source/{ => core}/jgame.cpp | 2 +- source/{jgame.h => core/jgame.hpp} | 0 source/{ => core}/jinput.cpp | 4 +- source/{jinput.h => core/jinput.hpp} | 0 source/{ => core}/jshader.cpp | 2 +- source/{jshader.h => core/jshader.hpp} | 0 source/{ => external}/gif.h | 0 source/{ => external}/stb_vorbis.h | 0 source/{ => game}/bola.cpp | 4 +- source/{bola.h => game/bola.hpp} | 6 +-- source/{ => game}/engendro.cpp | 4 +- source/{engendro.h => game/engendro.hpp} | 2 +- source/{ => game}/info.cpp | 2 +- source/{info.h => game/info.hpp} | 0 source/{ => game}/mapa.cpp | 6 +-- source/{mapa.h => game/mapa.hpp} | 6 +-- source/{ => game}/marcador.cpp | 2 +- source/{marcador.h => game/marcador.hpp} | 6 +-- source/{ => game}/modulegame.cpp | 12 +++--- source/{modulegame.h => game/modulegame.hpp} | 12 +++--- source/{ => game}/modulesequence.cpp | 12 +++--- .../modulesequence.hpp} | 2 +- source/{ => game}/momia.cpp | 4 +- source/{momia.h => game/momia.hpp} | 8 ++-- source/{ => game}/prota.cpp | 6 +-- source/{prota.h => game/prota.hpp} | 4 +- source/{ => game}/sprite.cpp | 2 +- source/{sprite.h => game/sprite.hpp} | 2 +- source/main.cpp | 16 +++---- 37 files changed, 115 insertions(+), 104 deletions(-) rename source/{ => core}/jail_audio.cpp (99%) rename source/{jail_audio.h => core/jail_audio.hpp} (100%) rename source/{ => core}/jdraw8.cpp (95%) rename source/{jdraw8.h => core/jdraw8.hpp} (100%) rename source/{ => core}/jfile.cpp (99%) rename source/{jfile.h => core/jfile.hpp} (100%) rename source/{ => core}/jgame.cpp (90%) rename source/{jgame.h => core/jgame.hpp} (100%) rename source/{ => core}/jinput.cpp (90%) rename source/{jinput.h => core/jinput.hpp} (100%) rename source/{ => core}/jshader.cpp (99%) rename source/{jshader.h => core/jshader.hpp} (100%) rename source/{ => external}/gif.h (100%) rename source/{ => external}/stb_vorbis.h (100%) rename source/{ => game}/bola.cpp (93%) rename source/{bola.h => game/bola.hpp} (63%) rename source/{ => game}/engendro.cpp (92%) rename source/{engendro.h => game/engendro.hpp} (78%) rename source/{ => game}/info.cpp (87%) rename source/{info.h => game/info.hpp} (100%) rename source/{ => game}/mapa.cpp (95%) rename source/{mapa.h => game/mapa.hpp} (85%) rename source/{ => game}/marcador.cpp (94%) rename source/{marcador.h => game/marcador.hpp} (68%) rename source/{ => game}/modulegame.cpp (92%) rename source/{modulegame.h => game/modulegame.hpp} (58%) rename source/{ => game}/modulesequence.cpp (96%) rename source/{modulesequence.h => game/modulesequence.hpp} (83%) rename source/{ => game}/momia.cpp (95%) rename source/{momia.h => game/momia.hpp} (68%) rename source/{ => game}/prota.cpp (94%) rename source/{prota.h => game/prota.hpp} (69%) rename source/{ => game}/sprite.cpp (93%) rename source/{sprite.h => game/sprite.hpp} (86%) diff --git a/CLAUDE.md b/CLAUDE.md index f442da5..53fa2f4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -28,26 +28,31 @@ The executable is output to the project root. The `data/` folder contains runtim All engine modules are flat C-style APIs (no classes), prefixed by subsystem: -- **JG** (`source/jgame`) — Game loop timing: init/finalize, fixed-timestep update via `JG_ShouldUpdate()` -- **JD8** (`source/jdraw8`) — 8-bit paletted software renderer. 320x200 screen buffer (`JD8_Surface` = `Uint8*`), palette-indexed blitting with color-key transparency, fade effects. `JD8_Flip()` converts the indexed buffer to ARGB, uploads to SDL texture, and renders through the CRT shader -- **JA** (`source/jail_audio`) — Custom audio mixing using SDL3 audio streams directly (OGG via stb_vorbis, WAV). Manages music and sound channels independently -- **JI** (`source/jinput`) — Input: keyboard state polling, key debouncing, cheat code detection -- **JF** (`source/jfile`) — File I/O: supports loading from filesystem folder or a packed resource file (`.jrf`). Currently uses folder mode (`data/`) -- **shader** (`source/jshader`) — OpenGL post-processing shader (CRT effect) applied to the back buffer +- **JG** (`source/core/jgame`) — Game loop timing: init/finalize, fixed-timestep update via `JG_ShouldUpdate()` +- **JD8** (`source/core/jdraw8`) — 8-bit paletted software renderer. 320x200 screen buffer (`JD8_Surface` = `Uint8*`), palette-indexed blitting with color-key transparency, fade effects. `JD8_Flip()` converts the indexed buffer to ARGB, uploads to SDL texture, and renders through the CRT shader +- **JA** (`source/core/jail_audio`) — Custom audio mixing using SDL3 audio streams directly (OGG via stb_vorbis, WAV). Manages music and sound channels independently +- **JI** (`source/core/jinput`) — Input: keyboard state polling, key debouncing, cheat code detection +- **JF** (`source/core/jfile`) — File I/O: supports loading from filesystem folder or a packed resource file (`.jrf`). Currently uses folder mode (`data/`) +- **shader** (`source/core/jshader`) — OpenGL post-processing shader (CRT effect) applied to the back buffer -### Game Modules +### Game Modules (`source/game/`) -- **ModuleSequence** (`modulesequence.cpp/h`) — Non-gameplay screens: intro, menu, slides, banners, credits, death screen. State machine entry point (state=1) -- **ModuleGame** (`modulegame.cpp/h`) — Core gameplay loop. Owns and orchestrates all game objects. State=0 -- **Sprite** (`sprite.cpp/h`) — Base class for animated entities (frame/animation data via `Entitat`) -- **Prota** (`prota.cpp/h`) — Player character ("Sam"), extends Sprite -- **Mapa** (`mapa.cpp/h`) — Level map with tomb grid (16 tombs), items (treasure, keys, pharaoh, mummy, scroll, diamond), door logic -- **Momia** (`momia.cpp/h`) — Enemy: mummies -- **Bola** (`bola.cpp/h`) — Enemy: projectile ball -- **Marcador** (`marcador.cpp/h`) — HUD/scoreboard -- **info** (`info.cpp/h`) — Global game state namespace (room number, pyramid, money, diamonds, lives, etc.) +- **ModuleSequence** — Non-gameplay screens: intro, menu, slides, banners, credits, death screen. State machine entry point (state=1) +- **ModuleGame** — Core gameplay loop. Owns and orchestrates all game objects. State=0 +- **Sprite** — Base class for animated entities (frame/animation data via `Entitat`) +- **Prota** — Player character ("Sam"), extends Sprite +- **Mapa** — Level map with tomb grid (16 tombs), items (treasure, keys, pharaoh, mummy, scroll, diamond), door logic +- **Momia** — Enemy: mummies +- **Bola** — Enemy: projectile ball +- **Marcador** — HUD/scoreboard +- **info** — Global game state namespace (room number, pyramid, money, diamonds, lives, etc.) -### Main Loop (`main.cpp`) +### External Libraries (`source/external/`) + +- `gif.h` — Header-only GIF decoder +- `stb_vorbis.h` — stb single-header OGG decoder + +### Main Loop (`source/main.cpp`) A state machine alternates between `ModuleSequence` (state 1) and `ModuleGame` (state 0). Each module's `Go()` returns the next state (-1 to quit). Modules are allocated/freed each transition. @@ -57,4 +62,5 @@ A state machine alternates between `ModuleSequence` (state 1) and `ModuleGame` ( - Graphics loaded from GIF files, palettes extracted from GIF headers - Music files are numbered OGG files (`00000001.ogg` etc.) - `trick.ini` presence enables the secret character -- The `gif.h` is a header-only GIF decoder; `stb_vorbis.h` is the stb single-header OGG decoder +- Includes use absolute paths from `source/` (e.g., `#include "core/jgame.hpp"`, `#include "game/info.hpp"`) +- Headers use `.hpp` extension; external third-party headers in `source/external/` keep `.h` diff --git a/CMakeLists.txt b/CMakeLists.txt index d88ff1f..6be66a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,23 +12,28 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # --- LISTA EXPLÍCITA DE FUENTES --- set(APP_SOURCES + # Core - Motor "Jail" + source/core/jail_audio.cpp + source/core/jdraw8.cpp + source/core/jfile.cpp + source/core/jgame.cpp + source/core/jinput.cpp + source/core/jshader.cpp + + # Game + source/game/bola.cpp + source/game/engendro.cpp + source/game/info.cpp + source/game/mapa.cpp + source/game/marcador.cpp + source/game/modulegame.cpp + source/game/modulesequence.cpp + source/game/momia.cpp + source/game/prota.cpp + source/game/sprite.cpp + + # Main source/main.cpp - source/bola.cpp - source/engendro.cpp - source/info.cpp - source/jail_audio.cpp - source/jdraw8.cpp - source/jfile.cpp - source/jgame.cpp - source/jinput.cpp - source/jshader.cpp - source/mapa.cpp - source/marcador.cpp - source/modulegame.cpp - source/modulesequence.cpp - source/momia.cpp - source/prota.cpp - source/sprite.cpp ) # Configuración de SDL3 diff --git a/source/jail_audio.cpp b/source/core/jail_audio.cpp similarity index 99% rename from source/jail_audio.cpp rename to source/core/jail_audio.cpp index 3b523b8..9d3a7b3 100644 --- a/source/jail_audio.cpp +++ b/source/core/jail_audio.cpp @@ -1,6 +1,6 @@ #ifndef JA_USESDLMIXER -#include "jail_audio.h" -#include "stb_vorbis.h" +#include "core/jail_audio.hpp" +#include "external/stb_vorbis.h" #include #include diff --git a/source/jail_audio.h b/source/core/jail_audio.hpp similarity index 100% rename from source/jail_audio.h rename to source/core/jail_audio.hpp diff --git a/source/jdraw8.cpp b/source/core/jdraw8.cpp similarity index 95% rename from source/jdraw8.cpp rename to source/core/jdraw8.cpp index 7b9e0bd..f2590db 100644 --- a/source/jdraw8.cpp +++ b/source/core/jdraw8.cpp @@ -1,8 +1,8 @@ -#include "jdraw8.h" -#include "jfile.h" +#include "core/jdraw8.hpp" +#include "core/jfile.hpp" #include -#include "gif.h" -#include "jshader.h" +#include "external/gif.h" +#include "core/jshader.hpp" #define SCREEN_WIDTH 960 #define SCREEN_HEIGHT 720 diff --git a/source/jdraw8.h b/source/core/jdraw8.hpp similarity index 100% rename from source/jdraw8.h rename to source/core/jdraw8.hpp diff --git a/source/jfile.cpp b/source/core/jfile.cpp similarity index 99% rename from source/jfile.cpp rename to source/core/jfile.cpp index 24e936f..7b1cc46 100644 --- a/source/jfile.cpp +++ b/source/core/jfile.cpp @@ -2,7 +2,7 @@ #include #include #include -#include "jfile.h" +#include "core/jfile.hpp" #include #include #include diff --git a/source/jfile.h b/source/core/jfile.hpp similarity index 100% rename from source/jfile.h rename to source/core/jfile.hpp diff --git a/source/jgame.cpp b/source/core/jgame.cpp similarity index 90% rename from source/jgame.cpp rename to source/core/jgame.cpp index b53ef60..1b8132e 100644 --- a/source/jgame.cpp +++ b/source/core/jgame.cpp @@ -1,4 +1,4 @@ -#include "jgame.h" +#include "core/jgame.hpp" bool eixir = false; Uint32 updateTicks = 0; diff --git a/source/jgame.h b/source/core/jgame.hpp similarity index 100% rename from source/jgame.h rename to source/core/jgame.hpp diff --git a/source/jinput.cpp b/source/core/jinput.cpp similarity index 90% rename from source/jinput.cpp rename to source/core/jinput.cpp index 3becd0a..0784fc0 100644 --- a/source/jinput.cpp +++ b/source/core/jinput.cpp @@ -1,5 +1,5 @@ -#include "jinput.h" -#include "jgame.h" +#include "core/jinput.hpp" +#include "core/jgame.hpp" #include const bool *keystates;// = SDL_GetKeyboardState( NULL ); diff --git a/source/jinput.h b/source/core/jinput.hpp similarity index 100% rename from source/jinput.h rename to source/core/jinput.hpp diff --git a/source/jshader.cpp b/source/core/jshader.cpp similarity index 99% rename from source/jshader.cpp rename to source/core/jshader.cpp index 36e240a..f0a4ee6 100644 --- a/source/jshader.cpp +++ b/source/core/jshader.cpp @@ -1,4 +1,4 @@ -#include "jshader.h" +#include "core/jshader.hpp" #include diff --git a/source/jshader.h b/source/core/jshader.hpp similarity index 100% rename from source/jshader.h rename to source/core/jshader.hpp diff --git a/source/gif.h b/source/external/gif.h similarity index 100% rename from source/gif.h rename to source/external/gif.h diff --git a/source/stb_vorbis.h b/source/external/stb_vorbis.h similarity index 100% rename from source/stb_vorbis.h rename to source/external/stb_vorbis.h diff --git a/source/bola.cpp b/source/game/bola.cpp similarity index 93% rename from source/bola.cpp rename to source/game/bola.cpp index 75dbaef..81527c6 100644 --- a/source/bola.cpp +++ b/source/game/bola.cpp @@ -1,5 +1,5 @@ -#include "bola.h" -#include "jgame.h" +#include "game/bola.hpp" +#include "core/jgame.hpp" #include Bola::Bola( JD8_Surface gfx, Prota* sam ) : Sprite( gfx ) { diff --git a/source/bola.h b/source/game/bola.hpp similarity index 63% rename from source/bola.h rename to source/game/bola.hpp index 601a2e8..abb519e 100644 --- a/source/bola.h +++ b/source/game/bola.hpp @@ -1,8 +1,8 @@ #pragma once -#include "sprite.h" -#include "prota.h" -#include "info.h" +#include "game/sprite.hpp" +#include "game/prota.hpp" +#include "game/info.hpp" class Bola : public Sprite { diff --git a/source/engendro.cpp b/source/game/engendro.cpp similarity index 92% rename from source/engendro.cpp rename to source/game/engendro.cpp index 89e473b..8875fc5 100644 --- a/source/engendro.cpp +++ b/source/game/engendro.cpp @@ -1,5 +1,5 @@ -#include "engendro.h" -#include "jgame.h" +#include "game/engendro.hpp" +#include "core/jgame.hpp" #include Engendro::Engendro( JD8_Surface gfx, Uint16 x, Uint16 y ) : Sprite( gfx ) { diff --git a/source/engendro.h b/source/game/engendro.hpp similarity index 78% rename from source/engendro.h rename to source/game/engendro.hpp index 525deae..4f670ef 100644 --- a/source/engendro.h +++ b/source/game/engendro.hpp @@ -1,6 +1,6 @@ #pragma once -#include "sprite.h" +#include "game/sprite.hpp" class Engendro : public Sprite { diff --git a/source/info.cpp b/source/game/info.cpp similarity index 87% rename from source/info.cpp rename to source/game/info.cpp index 9ad305b..aee3589 100644 --- a/source/info.cpp +++ b/source/game/info.cpp @@ -1,4 +1,4 @@ -#include "info.h" +#include "game/info.hpp" namespace info { diff --git a/source/info.h b/source/game/info.hpp similarity index 100% rename from source/info.h rename to source/game/info.hpp diff --git a/source/mapa.cpp b/source/game/mapa.cpp similarity index 95% rename from source/mapa.cpp rename to source/game/mapa.cpp index 0b5722a..937bac6 100644 --- a/source/mapa.cpp +++ b/source/game/mapa.cpp @@ -1,7 +1,7 @@ -#include "mapa.h" +#include "game/mapa.hpp" -#include "jgame.h" -#include "jinput.h" +#include "core/jgame.hpp" +#include "core/jinput.hpp" #include Mapa::Mapa( JD8_Surface gfx, Prota* sam ) { diff --git a/source/mapa.h b/source/game/mapa.hpp similarity index 85% rename from source/mapa.h rename to source/game/mapa.hpp index e5ee2e4..0e725ad 100644 --- a/source/mapa.h +++ b/source/game/mapa.hpp @@ -1,9 +1,9 @@ #pragma once -#include "jdraw8.h" +#include "core/jdraw8.hpp" -#include "info.h" -#include "prota.h" +#include "game/info.hpp" +#include "game/prota.hpp" #define CONTE_RES 0 #define CONTE_TRESOR 1 diff --git a/source/marcador.cpp b/source/game/marcador.cpp similarity index 94% rename from source/marcador.cpp rename to source/game/marcador.cpp index d24f3af..94f026d 100644 --- a/source/marcador.cpp +++ b/source/game/marcador.cpp @@ -1,4 +1,4 @@ -#include "marcador.h" +#include "game/marcador.hpp" Marcador::Marcador( JD8_Surface gfx, Prota* sam ) { diff --git a/source/marcador.h b/source/game/marcador.hpp similarity index 68% rename from source/marcador.h rename to source/game/marcador.hpp index f0d0481..bf889b4 100644 --- a/source/marcador.h +++ b/source/game/marcador.hpp @@ -1,8 +1,8 @@ #pragma once -#include "jdraw8.h" -#include "info.h" -#include "prota.h" +#include "core/jdraw8.hpp" +#include "game/info.hpp" +#include "game/prota.hpp" class Marcador { diff --git a/source/modulegame.cpp b/source/game/modulegame.cpp similarity index 92% rename from source/modulegame.cpp rename to source/game/modulegame.cpp index 793c575..19ce8c2 100644 --- a/source/modulegame.cpp +++ b/source/game/modulegame.cpp @@ -1,10 +1,10 @@ -#include "modulegame.h" +#include "game/modulegame.hpp" -#include "jgame.h" -#include "jdraw8.h" -#include "jail_audio.h" -#include "jinput.h" -#include "jfile.h" +#include "core/jgame.hpp" +#include "core/jdraw8.hpp" +#include "core/jail_audio.hpp" +#include "core/jinput.hpp" +#include "core/jfile.hpp" ModuleGame::ModuleGame() { diff --git a/source/modulegame.h b/source/game/modulegame.hpp similarity index 58% rename from source/modulegame.h rename to source/game/modulegame.hpp index 087ad95..293b3ad 100644 --- a/source/modulegame.h +++ b/source/game/modulegame.hpp @@ -1,11 +1,11 @@ #pragma once -#include "info.h" -#include "mapa.h" -#include "prota.h" -#include "marcador.h" -#include "momia.h" -#include "bola.h" +#include "game/info.hpp" +#include "game/mapa.hpp" +#include "game/prota.hpp" +#include "game/marcador.hpp" +#include "game/momia.hpp" +#include "game/bola.hpp" class ModuleGame { diff --git a/source/modulesequence.cpp b/source/game/modulesequence.cpp similarity index 96% rename from source/modulesequence.cpp rename to source/game/modulesequence.cpp index 4b0ea42..136d06f 100644 --- a/source/modulesequence.cpp +++ b/source/game/modulesequence.cpp @@ -1,10 +1,10 @@ -#include "modulesequence.h" +#include "game/modulesequence.hpp" -#include "jgame.h" -#include "jdraw8.h" -#include "jinput.h" -#include "jfile.h" -#include "jail_audio.h" +#include "core/jgame.hpp" +#include "core/jdraw8.hpp" +#include "core/jinput.hpp" +#include "core/jfile.hpp" +#include "core/jail_audio.hpp" #include #include diff --git a/source/modulesequence.h b/source/game/modulesequence.hpp similarity index 83% rename from source/modulesequence.h rename to source/game/modulesequence.hpp index a7fe94b..2bbe625 100644 --- a/source/modulesequence.h +++ b/source/game/modulesequence.hpp @@ -1,6 +1,6 @@ #pragma once -#include "info.h" +#include "game/info.hpp" class ModuleSequence { diff --git a/source/momia.cpp b/source/game/momia.cpp similarity index 95% rename from source/momia.cpp rename to source/game/momia.cpp index 3bd5201..062d949 100644 --- a/source/momia.cpp +++ b/source/game/momia.cpp @@ -1,5 +1,5 @@ -#include "momia.h" -#include "jgame.h" +#include "game/momia.hpp" +#include "core/jgame.hpp" #include Momia::Momia( JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam ) : Sprite( gfx ) { diff --git a/source/momia.h b/source/game/momia.hpp similarity index 68% rename from source/momia.h rename to source/game/momia.hpp index 670dd90..e06a8de 100644 --- a/source/momia.h +++ b/source/game/momia.hpp @@ -1,9 +1,9 @@ #pragma once -#include "sprite.h" -#include "prota.h" -#include "engendro.h" -#include "info.h" +#include "game/sprite.hpp" +#include "game/prota.hpp" +#include "game/engendro.hpp" +#include "game/info.hpp" class Momia : public Sprite { diff --git a/source/prota.cpp b/source/game/prota.cpp similarity index 94% rename from source/prota.cpp rename to source/game/prota.cpp index 75d34cd..043461f 100644 --- a/source/prota.cpp +++ b/source/game/prota.cpp @@ -1,6 +1,6 @@ -#include "prota.h" -#include "jgame.h" -#include "jinput.h" +#include "game/prota.hpp" +#include "core/jgame.hpp" +#include "core/jinput.hpp" #include Prota::Prota( JD8_Surface gfx ) : Sprite( gfx ) { diff --git a/source/prota.h b/source/game/prota.hpp similarity index 69% rename from source/prota.h rename to source/game/prota.hpp index af89e17..71143b7 100644 --- a/source/prota.h +++ b/source/game/prota.hpp @@ -1,7 +1,7 @@ #pragma once -#include "sprite.h" -#include "info.h" +#include "game/sprite.hpp" +#include "game/info.hpp" class Prota : public Sprite { diff --git a/source/sprite.cpp b/source/game/sprite.cpp similarity index 93% rename from source/sprite.cpp rename to source/game/sprite.cpp index 1e3ceb5..52fa448 100644 --- a/source/sprite.cpp +++ b/source/game/sprite.cpp @@ -1,4 +1,4 @@ -#include "sprite.h" +#include "game/sprite.hpp" #include Sprite::Sprite( JD8_Surface gfx ) { diff --git a/source/sprite.h b/source/game/sprite.hpp similarity index 86% rename from source/sprite.h rename to source/game/sprite.hpp index dd4f777..da930d2 100644 --- a/source/sprite.h +++ b/source/game/sprite.hpp @@ -1,6 +1,6 @@ #pragma once -#include "jdraw8.h" +#include "core/jdraw8.hpp" struct Frame { Uint16 x; diff --git a/source/main.cpp b/source/main.cpp index 0f2f717..dfd8645 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,11 +1,11 @@ -#include "jgame.h" -#include "jdraw8.h" -#include "jail_audio.h" -#include "jfile.h" -#include "info.h" -#include "modulegame.h" -#include "modulesequence.h" -#include "time.h" +#include "core/jgame.hpp" +#include "core/jdraw8.hpp" +#include "core/jail_audio.hpp" +#include "core/jfile.hpp" +#include "game/info.hpp" +#include "game/modulegame.hpp" +#include "game/modulesequence.hpp" +#include #include /*