Skip to content

Add Runner game: complete platformer with physics, obstacles, and HUD - #2

Merged
chispofish merged 2 commits into
mainfrom
claude/happy-curie-ntymcn
Nov 1, 2026
Merged

chispofish merged 2 commits into
mainfrom
claude/happy-curie-ntymcn

Conversation

@chispofish

Copy link
Copy Markdown
Owner

Summary

Implements a complete horizontal runner game ("Runner") built on top of the BasicGameEngine motor. The game features a player character that must jump over obstacles while the world accelerates, with score tracking and game-over mechanics.

Key Changes

  • Texture System (R1): Added Textura.* for BMP loading with SDL2 (no SDL_image dependency), supporting color-key transparency and alpha channels. Includes safe error handling with UltimoError() reporting.

  • Player Physics & Animation (R2): Implemented Jugador.* with:

    • Semi-implicit Euler integration for gravity and jumping
    • Three states: Running, Jumping (ascending), Falling (descending)
    • Sprite sheet animation cycling through 6 frames (4 running + jump + fall)
    • Collision box that excludes transparent sprite margins
  • Obstacles & Collision (R3.1-R3.2): Created Obstaculos.* with:

    • GestorObstaculos: generates obstacles at random intervals, moves them left at constant velocity, destroys them when off-screen
    • Deterministic RNG (seeded) for reproducible test sequences
    • Memory-efficient vector reuse (no allocations in steady state)
    • Exact AABB collision detection (touching edges ≠ collision, 1 pixel overlap = collision)
  • Game Logic (R3): Added Partida.* to manage:

    • Game state (Playing / GameOver)
    • Score calculation (distance / 10)
    • World velocity acceleration over time
    • Collision detection and game-over triggering
    • Reinitiation with best-score tracking
  • HUD (R3.3): Implemented Hud.* for rendering:

    • Current score, best score, and velocity display
    • Game-over screen with restart instructions
    • Initial controls hint (fades after ~1.3 seconds)
  • Main Game Loop: Added runner.cpp integrating all modules into the motor's Actualizar(dt) and Pintar() hooks, with keyboard input handling (SPACE/UP for jump).

  • Asset Generation: Included tools/generar_avatar.py to procedurally generate the 6-frame sprite sheet (no external image files needed).

  • Build System: Updated CMakeLists.txt to compile Runner for both native and Emscripten targets, with asset preloading for web.

  • Comprehensive QA: Added two test suites:

    • tests/test_jugador.cpp: 4 tests covering texture loading, transparency, physics, and animation
    • tests/test_partida.cpp: 3 tests for obstacle generation/destruction, collision accuracy, and HUD stability

Notable Implementation Details

  • Physics uses fixed 60 Hz timestep with semi-implicit Euler for stability
  • Collision boxes are tighter than visual sprites to avoid false positives on transparent margins
  • Obstacle generation is deterministic (seeded RNG) for reproducible gameplay and testing
  • Memory is pre-allocated and reused; no dynamic allocations during gameplay
  • Tests run headless (SDL_VIDEODRIVER=dummy) without a window
  • Web version uses Emscripten's virtual filesystem to preload assets

https://claude.ai/code/session_01XDoHNiNLnABtsZ7Z5gjs93

…ugador: fisica y animacion) con pruebas QA

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDoHNiNLnABtsZ7Z5gjs93
…o web de assets

- Obstaculos/GestorObstaculos: aparicion aleatoria (con semilla) por la derecha, destruccion al salir
- Partida: puntuacion por distancia, velocidad creciente, GameOver y reinicio
- Hud: puntos, mejor, velocidad y mensajes con Dibujante::Texto
- CMake: runner nativo y web (index.html) con --preload-file assets@/assets; demo 'juego' solo nativo
- CI: publica y verifica index.data (Test 3.4)
- Jugador: caja de colision ajustada al area visible del sprite
- Tests QA 3.1-3.3 (tests/test_partida.cpp)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDoHNiNLnABtsZ7Z5gjs93
@chispofish
chispofish merged commit ef183ca into main Nov 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants