From d4a0189dc83e3a21a397144384bea3985e9fefd2 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 19 Sep 2025 14:15:44 +0200 Subject: [PATCH] arreglant balloon.cpp per a deltaTime pur --- DELTATIME_MIGRATION_PLAN.md | 81 ++++++++++ config/formations.txt | 308 ++++++++++++++++++------------------ config/param_320x240.txt | 18 +-- config/param_320x256.txt | 18 +-- source/balloon.cpp | 45 ++---- source/balloon.h | 15 +- source/balloon_formations.h | 2 +- source/balloon_manager.cpp | 35 ++-- source/balloon_manager.h | 6 +- source/defaults.h | 9 +- source/sections/game.cpp | 10 +- 11 files changed, 307 insertions(+), 240 deletions(-) create mode 100644 DELTATIME_MIGRATION_PLAN.md diff --git a/DELTATIME_MIGRATION_PLAN.md b/DELTATIME_MIGRATION_PLAN.md new file mode 100644 index 0000000..72eba49 --- /dev/null +++ b/DELTATIME_MIGRATION_PLAN.md @@ -0,0 +1,81 @@ +# Plan de Migración DeltaTime - Eliminación de frameFactor + +## Problema Identificado +Se están usando `frameFactor` conversions en 7 archivos, lo que indica una migración incompleta a deltaTime. +El patrón `float frameFactor = deltaTime / (1000.0f / 60.0f)` simula frames de 60fps en lugar de usar tiempo real. + +## Archivos Afectados y Estado +1. **balloon.cpp** - 9 ocurrencias en métodos: moveX(), moveY(), updateState(), updateCreation() +2. **balloon_manager.cpp** - 2 ocurrencias en updateBalloonDeployment() +3. **bullet.cpp** - 3 ocurrencias en move() +4. **item.cpp** - 6 ocurrencias en move() +5. **moving_sprite.cpp** - 5 ocurrencias en move() +6. **tabe.cpp** - 5 ocurrencias en update() y updateHitEffect() +7. **credits.cpp** - 3 ocurrencias en update() y handleFadeOut() + +## Estrategia de Migración + +### Opción A: Velocidades ya en pixels/segundo +Si las velocidades están definidas en pixels/segundo: +```cpp +// ANTES (incorrecto) +float frameFactor = deltaTime / (1000.0f / 60.0f); +pos_x_ += vel_x_ * frameFactor; + +// DESPUÉS (correcto) +pos_x_ += vel_x_ * (deltaTime / 1000.0f); // deltaTime en ms -> segundos +``` + +### Opción B: Velocidades en pixels/frame (legacy) +Si las velocidades están en pixels/frame (sistema legacy): +```cpp +// ANTES (incorrecto con deltaTime) +float frameFactor = deltaTime / (1000.0f / 60.0f); +pos_x_ += vel_x_ * frameFactor; + +// OPCIÓN 1: Convertir velocidades a pixels/segundo +static constexpr float VEL_X_PER_SECOND = VEL_X_PER_FRAME * 60.0f; +pos_x_ += VEL_X_PER_SECOND * (deltaTime / 1000.0f); + +// OPCIÓN 2: Mantener frame-factor pero mejorar claridad +pos_x_ += vel_x_ * (deltaTime / FRAME_TIME_MS); // donde FRAME_TIME_MS = 16.67f +``` + +## Plan de Ejecución + +### Fase 1: Análisis de Velocidades +- [ ] Revisar definiciones de velocidades en cada clase +- [ ] Determinar si están en pixels/frame o pixels/segundo +- [ ] Identificar constantes que necesitan conversión + +### Fase 2: Migración por Archivo +- [ ] **balloon.cpp**: Migrar velocidades x/y y contadores +- [ ] **balloon_manager.cpp**: Migrar balloon_deploy_counter_ +- [ ] **bullet.cpp**: Migrar velocidades de bala +- [ ] **item.cpp**: Migrar física de ítems (ya parcialmente hecho) +- [ ] **moving_sprite.cpp**: Migrar sistema base de movimiento +- [ ] **tabe.cpp**: Migrar movimiento y efectos +- [ ] **credits.cpp**: Migrar contadores de timing + +### Fase 3: Verificación +- [ ] Compilar y probar cada archivo migrado +- [ ] Verificar que el comportamiento se mantiene consistente +- [ ] Eliminar todas las referencias a frameFactor +- [ ] Actualizar comentarios para reflejar unidades correctas + +## Criterios de Éxito +1. ✅ Cero ocurrencias de "frameFactor" en el código +2. ✅ Todas las velocidades claramente documentadas (pixels/segundo vs pixels/frame) +3. ✅ Comportamiento del juego idéntico al anterior +4. ✅ Código más limpio y mantenible + +## Notas Importantes +- El frameFactor actual simula 60fps: `deltaTime / 16.67ms` +- Esto significa que las velocidades actuales están en "pixels per 16.67ms" +- Para verdadero deltaTime, necesitamos convertir a "pixels per second" o usar factor de frame explícito +- Mantener constantes claras para evitar números mágicos + +## Estado: En Progreso +- Análisis iniciado +- Plan documentado +- Próximo paso: Análisis de velocidades en cada archivo \ No newline at end of file diff --git a/config/formations.txt b/config/formations.txt index 70f0b82..9727911 100644 --- a/config/formations.txt +++ b/config/formations.txt @@ -18,148 +18,148 @@ X3_75, 0, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0 formation: 2 # Cuatro enemigos BALLOON1 uno detrás del otro. A la izquierda y hacia el centro -X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 30 -X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 20 -X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 10 +X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 500 +X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 334 +X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 167 X1_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0 formation: 3 # Cuatro enemigos BALLOON1 uno detrás del otro. A la derecha y hacia el centro -X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 30 -X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 20 -X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 10 +X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 500 +X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 334 +X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 167 X1_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0 formation: 4 -# Tres enemigos BALLOON2. 0, 25, 50. Hacia la derecha -X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20 -X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10 +# Tres enemigos BALLOON2. 0, 417, 834. Hacia la derecha +X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 334 +X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 167 X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0 formation: 5 -# Tres enemigos BALLOON2. 50, 75, 100. Hacia la izquierda -X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20 -X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10 +# Tres enemigos BALLOON2. 50, 75, 1667. Hacia la izquierda +X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 334 +X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 167 X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0 formation: 6 # Tres enemigos BALLOON2. 0, 0, 0. Hacia la derecha -X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20 -X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10 +X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 334 +X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 167 X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0 formation: 7 -# Tres enemigos BALLOON2. 100, 100, 100. Hacia la izquierda -X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20 -X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10 +# Tres enemigos BALLOON2. 100, 1667, 1667. Hacia la izquierda +X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 334 +X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 167 X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0 formation: 8 # Seis enemigos BALLOON0. 0, 0, 0, 0, 0, 0. Hacia la derecha -X0_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 50 -X0_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 40 -X0_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 30 -X0_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 20 -X0_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 10 +X0_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 834 +X0_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 667 +X0_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 500 +X0_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 334 +X0_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 167 X0_0, 5, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0 formation: 9 -# Seis enemigos BALLOON0. 100, 100, 100, 100, 100, 100. Hacia la izquierda -X0_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 50 -X0_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 40 -X0_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 30 -X0_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 20 -X0_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 10 +# Seis enemigos BALLOON0. 100, 1667, 1667, 1667, 1667, 1667. Hacia la izquierda +X0_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 834 +X0_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 667 +X0_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 500 +X0_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 334 +X0_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 167 X0_100, -5, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0 formation: 10 # Tres enemigos BALLOON3 seguidos desde la izquierda. Hacia la derecha -X3_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 30 -X3_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 15 +X3_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 500 +X3_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 250 X3_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0 formation: 11 # Tres enemigos BALLOON3 seguidos desde la derecha. Hacia la izquierda -X3_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 30 -X3_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 15 +X3_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 500 +X3_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 250 X3_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0 formation: 12 # Seis enemigos BALLOON1 uno detrás del otro. A la izquierda y hacia el centro -X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 50 -X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 40 -X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 30 -X1_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 20 -X1_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 10 +X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 834 +X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 667 +X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 500 +X1_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 334 +X1_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 167 X1_0, 5, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0 formation: 13 # Seis enemigos BALLOON1 uno detrás del otro. A la derecha y hacia el centro -X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 50 -X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 40 -X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 30 -X1_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 20 -X1_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 10 +X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 834 +X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 667 +X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 500 +X1_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 334 +X1_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 167 X1_100, -5, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0 formation: 14 # Cinco enemigos BALLOON2. Hacia la derecha. Separados -X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 40 -X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 30 -X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20 -X2_0, 6, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10 +X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 667 +X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 500 +X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 334 +X2_0, 6, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 167 X2_0, 8, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0 formation: 15 # Cinco enemigos BALLOON2. Hacia la izquierda. Separados -X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 40 -X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 30 -X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20 -X2_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10 +X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 667 +X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 500 +X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 334 +X2_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 167 X2_100, -8, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0 formation: 16 # Cinco enemigos BALLOON2. Hacia la derecha. Juntos -X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 40 -X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 30 -X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20 -X2_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10 +X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 667 +X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 500 +X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 334 +X2_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 167 X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0 formation: 17 # Cinco enemigos BALLOON2. Hacia la izquierda. Juntos -X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 40 -X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 30 -X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20 -X2_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10 +X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 667 +X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 500 +X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 334 +X2_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 167 X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0 formation: 18 # Doce enemigos BALLOON0. Hacia la derecha. Juntos -X0_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 110 -X0_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 100 -X0_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 90 -X0_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 80 +X0_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1834 +X0_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1667 +X0_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 25000 +X0_0, 50, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1334 X0_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 70 -X0_0, 5, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 60 -X0_0, 6, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 50 +X0_0, 83, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1000 +X0_0, 100, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 830 X0_0, 7, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 40 -X0_0, 8, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 30 -X0_0, 9, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 20 -X0_0, 10, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 10 +X0_0, 8, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 500 +X0_0, 150, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 20 +X0_0, 167, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 10 X0_0, 11, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0 formation: 19 # Doce enemigos BALLOON0. Hacia la izquierda. Juntos -X0_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 110 -X0_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 100 -X0_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 90 -X0_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 80 +X0_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1834 +X0_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1667 +X0_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 25000 +X0_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1334 X0_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 70 -X0_100, -5, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 60 -X0_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 50 +X0_100, -5, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1000 +X0_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 830 X0_100, -7, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 40 -X0_100, -8, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 30 +X0_100, -8, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 500 X0_100, -9, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 20 X0_100, -10, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 10 X0_100, -11, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0 @@ -173,105 +173,105 @@ X3_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0 formation: 21 # Diez enemigos BALLOON1 uno detrás del otro. Izquierda/derecha. Simétricos -X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 12 -X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 9 -X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 6 -X1_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 3 +X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 200 +X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 150 +X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 100 +X1_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 50 X1_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0 -X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 12 -X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 9 -X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 6 -X1_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 3 +X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 200 +X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 150 +X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 100 +X1_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 50 X1_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0 formation: 22 # Diez enemigos BALLOON2. Hacia la derecha/izquierda. Separados. Simétricos -X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 40 -X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 30 -X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20 -X2_0, 6, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10 +X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 667 +X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 500 +X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 334 +X2_0, 6, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 167 X2_0, 8, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0 -X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 40 -X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 30 -X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20 -X2_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10 +X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 667 +X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 500 +X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 334 +X2_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 167 X2_100, -8, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0 formation: 23 # Diez enemigos BALLOON2. Hacia la derecha. Juntos. Simétricos -X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 40 -X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 30 -X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20 -X2_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10 +X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 667 +X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 500 +X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 334 +X2_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 167 X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0 -X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 40 -X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 30 -X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20 -X2_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10 +X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 667 +X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 500 +X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 334 +X2_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 167 X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0 formation: 24 # Treinta enemigos BALLOON0. Del centro hacia los extremos. Juntos. Simétricos X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 5 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 10 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 15 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 20 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 25 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 30 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 35 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 40 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 45 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 50 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 55 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 60 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 65 -X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 70 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 83 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 167 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 250 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 334 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 417 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 500 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 584 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 667 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 750 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 834 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 917 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 16700 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 16784 +X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1167 X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 5 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 10 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 15 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 20 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 25 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 30 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 35 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 40 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 45 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 50 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 55 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 60 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 65 -X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 70 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 83 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 167 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 250 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 334 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 417 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 500 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 584 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 667 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 750 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 834 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 917 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 16700 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 16784 +X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1167 formation: 25 # Treinta enemigos BALLOON0. Del centro hacia adentro. Juntos. Simétricos -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 70 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 65 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 60 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 55 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 50 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 45 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 40 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 35 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 30 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 25 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 20 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 15 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 10 -X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 5 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1167 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 16784 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 16700 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 917 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 834 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 750 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 667 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 584 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 500 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 417 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 334 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 250 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 167 +X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 83 X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 70 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 65 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 60 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 55 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 50 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 45 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 40 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 35 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 30 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 25 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 20 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 15 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 10 -X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 5 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1167 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 16784 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 16700 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 917 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 834 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 750 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 667 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 584 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 500 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 417 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 334 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 250 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 167 +X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 83 X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0 diff --git a/config/param_320x240.txt b/config/param_320x240.txt index a95d6ee..6aba433 100644 --- a/config/param_320x240.txt +++ b/config/param_320x240.txt @@ -48,15 +48,15 @@ title.bg_color 41526F # Color de fondo en la sección titulo # --- BACKGROUND --- background.attenuate_color FFFFFF00 # Color de atenuación del fondo (RGBA hexadecimal) -# --- BALLOONS --- -balloon.settings[0].vel 2.75f # Velocidad inicial del globo 1 -balloon.settings[0].grav 0.09f # Gravedad aplicada al globo 1 -balloon.settings[1].vel 3.70f # Velocidad inicial del globo 2 -balloon.settings[1].grav 0.10f # Gravedad aplicada al globo 2 -balloon.settings[2].vel 4.70f # Velocidad inicial del globo 3 -balloon.settings[2].grav 0.10f # Gravedad aplicada al globo 3 -balloon.settings[3].vel 5.45f # Velocidad inicial del globo 4 -balloon.settings[3].grav 0.10f # Gravedad aplicada al globo 4 +# --- BALLOONS --- (deltaTime puro: vel en pixels/ms, grav en pixels/ms²) +balloon.settings[0].vel 0.165f # Velocidad inicial del globo 1 (pixels/ms) +balloon.settings[0].grav 0.00032f # Gravedad aplicada al globo 1 (pixels/ms²) +balloon.settings[1].vel 0.222f # Velocidad inicial del globo 2 (pixels/ms) +balloon.settings[1].grav 0.00036f # Gravedad aplicada al globo 2 (pixels/ms²) +balloon.settings[2].vel 0.282f # Velocidad inicial del globo 3 (pixels/ms) +balloon.settings[2].grav 0.00036f # Gravedad aplicada al globo 3 (pixels/ms²) +balloon.settings[3].vel 0.327f # Velocidad inicial del globo 4 (pixels/ms) +balloon.settings[3].grav 0.00036f # Gravedad aplicada al globo 4 (pixels/ms²) balloon.color[0] blue # Color de creación del globo normal balloon.color[1] orange # Color del globo normal diff --git a/config/param_320x256.txt b/config/param_320x256.txt index 8fd457b..fd470d3 100644 --- a/config/param_320x256.txt +++ b/config/param_320x256.txt @@ -48,15 +48,15 @@ title.bg_color 41526F # Color de fondo en la sección titulo # --- BACKGROUND --- background.attenuate_color FFFFFF00 # Color de atenuación del fondo (RGBA hexadecimal) -# --- BALLOONS --- -balloon.settings[0].vel 2.75f # Velocidad inicial del globo 1 -balloon.settings[0].grav 0.09f # Gravedad aplicada al globo 1 -balloon.settings[1].vel 3.70f # Velocidad inicial del globo 2 -balloon.settings[1].grav 0.10f # Gravedad aplicada al globo 2 -balloon.settings[2].vel 4.70f # Velocidad inicial del globo 3 -balloon.settings[2].grav 0.10f # Gravedad aplicada al globo 3 -balloon.settings[3].vel 5.45f # Velocidad inicial del globo 4 -balloon.settings[3].grav 0.10f # Gravedad aplicada al globo 4 +# --- BALLOONS --- (deltaTime puro: vel en pixels/ms, grav en pixels/ms²) +balloon.settings[0].vel 0.165f # Velocidad inicial del globo 1 (pixels/ms) +balloon.settings[0].grav 0.00032f # Gravedad aplicada al globo 1 (pixels/ms²) +balloon.settings[1].vel 0.222f # Velocidad inicial del globo 2 (pixels/ms) +balloon.settings[1].grav 0.00036f # Gravedad aplicada al globo 2 (pixels/ms²) +balloon.settings[2].vel 0.282f # Velocidad inicial del globo 3 (pixels/ms) +balloon.settings[2].grav 0.00036f # Gravedad aplicada al globo 3 (pixels/ms²) +balloon.settings[3].vel 0.327f # Velocidad inicial del globo 4 (pixels/ms) +balloon.settings[3].grav 0.00036f # Gravedad aplicada al globo 4 (pixels/ms²) balloon.color[0] blue # Color de creación del globo normal balloon.color[1] orange # Color del globo normal diff --git a/source/balloon.cpp b/source/balloon.cpp index 9651520..6350da2 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -23,7 +23,7 @@ Balloon::Balloon(const Config& config) creation_counter_ini_(config.creation_counter), type_(config.type), size_(config.size), - speed_(config.speed), + game_tempo_(config.game_tempo), play_area_(config.play_area), sound_(config.sound) { switch (type_) { @@ -147,9 +147,8 @@ void Balloon::move(float deltaTime) { } void Balloon::handleHorizontalMovement(float deltaTime) { - // Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps) - float frameFactor = deltaTime / (1000.0f / 60.0f); - x_ += vx_ * speed_ * frameFactor; + // DeltaTime puro: velocidad (pixels/ms) * tempo * tiempo (ms) + x_ += vx_ * game_tempo_ * deltaTime; const int CLIP = 2; const float MIN_X = play_area_.x - CLIP; @@ -161,9 +160,8 @@ void Balloon::handleHorizontalMovement(float deltaTime) { } void Balloon::handleVerticalMovement(float deltaTime) { - // Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps) - float frameFactor = deltaTime / (1000.0f / 60.0f); - y_ += vy_ * speed_ * frameFactor; + // DeltaTime puro: velocidad (pixels/ms) * tempo * tiempo (ms) + y_ += vy_ * game_tempo_ * deltaTime; if (shouldCheckTopCollision()) { handleTopCollision(); @@ -219,15 +217,8 @@ void Balloon::handleBottomCollision() { } void Balloon::applyGravity(float deltaTime) { - // Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps) - float frameFactor = deltaTime / (1000.0f / 60.0f); - - travel_y_ += speed_ * frameFactor; - - if (travel_y_ >= 1.0F) { - travel_y_ -= 1.0F; - vy_ += gravity_; - } + // DeltaTime puro: aceleración (pixels/ms²) * tempo * tiempo (ms) + vy_ += gravity_ * game_tempo_ * deltaTime; } void Balloon::playBouncingSound() { @@ -250,9 +241,8 @@ void Balloon::update(float deltaTime) { shiftSprite(); shiftColliders(); sprite_->update(deltaTime); - // Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps) - float frameFactor = deltaTime / (1000.0f / 60.0f); - counter_ += frameFactor; + // Contador interno con deltaTime puro + counter_ += deltaTime; } // Actualiza los estados del globo (time-based) @@ -264,17 +254,14 @@ void Balloon::updateState(float deltaTime) { setInvulnerable(true); if (creation_counter_ > 0) { - // Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps) - float frameFactor = deltaTime / (1000.0f / 60.0f); - // Desplaza lentamente el globo hacia abajo y hacia un lado - // Cada 10 frames (aproximadamente cada 166ms a 60fps) - movement_accumulator_ += frameFactor; + // Cada 166ms (equivalente a 10 frames a 60fps) + movement_accumulator_ += deltaTime; - if (movement_accumulator_ >= 10.0f) { - movement_accumulator_ -= 10.0f; + if (movement_accumulator_ >= 166.0f) { + movement_accumulator_ -= 166.0f; y_++; - x_ += vx_; + x_ += vx_ * 10.0f; // Movimiento equivalente a 10 frames de velocidad horizontal // Comprueba no se salga por los laterales const int MIN_X = play_area_.x; @@ -282,11 +269,11 @@ void Balloon::updateState(float deltaTime) { if (x_ < MIN_X || x_ > MAX_X) { // Corrige y cambia el sentido de la velocidad - x_ -= vx_; + x_ -= vx_ * 10.0f; vx_ = -vx_; } } - creation_counter_ -= frameFactor; + creation_counter_ -= deltaTime; if (creation_counter_ < 0) creation_counter_ = 0; } diff --git a/source/balloon.h b/source/balloon.h index 213446d..2673399 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -36,10 +36,12 @@ class Balloon { "balloon_pop2.wav", "balloon_pop3.wav"}; - static constexpr float VELX_POSITIVE = 0.7F; - static constexpr float VELX_NEGATIVE = -0.7F; + // Velocidades horizontales en pixels/ms (convertidas desde 0.7 pixels/frame a 60fps) + static constexpr float VELX_POSITIVE = 0.7F / (1000.0F / 60.0F); // ~0.042 pixels/ms + static constexpr float VELX_NEGATIVE = -0.7F / (1000.0F / 60.0F); // ~-0.042 pixels/ms - static constexpr std::array SPEED = {0.60F, 0.70F, 0.80F, 0.90F, 1.00F}; + // Multiplicadores de tempo del juego (sin cambios, son puros multiplicadores) + static constexpr std::array GAME_TEMPO = {0.60F, 0.70F, 0.80F, 0.90F, 1.00F}; static constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10; static constexpr int POWERBALL_COUNTER = 8; @@ -74,7 +76,7 @@ class Balloon { Type type = Type::BALLOON; Size size = Size::EXTRALARGE; float vel_x = VELX_POSITIVE; - float speed = SPEED.at(0); + float game_tempo = GAME_TEMPO.at(0); Uint16 creation_counter = 0; SDL_FRect play_area = {.x = 0.0F, .y = 0.0F, .w = 0.0F, .h = 0.0F}; std::shared_ptr texture = nullptr; @@ -120,7 +122,7 @@ class Balloon { // --- Setters --- void setVelY(float vel_y) { vy_ = vel_y; } - void setSpeed(float speed) { speed_ = speed; } + void setGameTempo(float tempo) { game_tempo_ = tempo; } void setInvulnerable(bool value) { invulnerable_ = value; } void setBouncingSound(bool value) { sound_.bouncing_enabled = value; } void setPoppingSound(bool value) { sound_.poping_enabled = value; } @@ -263,8 +265,7 @@ class Balloon { Size size_; // Tamaño de globo Uint8 menace_; // Amenaza que genera el globo Uint32 counter_ = 0; // Contador interno - float travel_y_ = 1.0F; // Distancia a recorrer en Y antes de aplicar gravedad - float speed_; // Velocidad del globo + float game_tempo_; // Multiplicador de tempo del juego float movement_accumulator_ = 0.0f; // Acumulador para movimiento durante creación (deltaTime) Uint8 power_; // Poder que alberga el globo SDL_FRect play_area_; // Zona de movimiento del globo diff --git a/source/balloon_formations.h b/source/balloon_formations.h index 76b5d89..10f52ac 100644 --- a/source/balloon_formations.h +++ b/source/balloon_formations.h @@ -82,7 +82,7 @@ class BalloonFormations { private: // --- Constantes --- static constexpr int BALLOON_SPAWN_HEIGHT = 208; // Altura desde el suelo en la que aparecen los globos - static constexpr int DEFAULT_CREATION_TIME = 200; // Tiempo base de creación de los globos para las formaciones + static constexpr int DEFAULT_CREATION_TIME = 3334; // Tiempo base de creación de los globos en ms (200 frames × 16.67ms) // --- Variables --- std::vector formations_; // Vector con todas las formaciones disponibles diff --git a/source/balloon_manager.cpp b/source/balloon_manager.cpp index 5259708..2562815 100644 --- a/source/balloon_manager.cpp +++ b/source/balloon_manager.cpp @@ -82,11 +82,11 @@ void BalloonManager::render() { // Crea una formación de globos void BalloonManager::deployRandomFormation(int stage) { // Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última - if (balloon_deploy_counter_ == 0) { + if (balloon_deploy_counter_ >= DEFAULT_BALLOON_DEPLOY_COUNTER) { // En este punto se decide entre crear una powerball o una formación enemiga if ((rand() % 100 < 15) && (canPowerBallBeCreated())) { createPowerBall(); // Crea una powerball - balloon_deploy_counter_ = 10; // Da un poco de margen para que se creen mas globos + balloon_deploy_counter_ = -167; // Resetea con pequeño retraso (10 frames = 167ms negativos) } else { // Decrementa el contador de despliegues de globos necesarios para la siguiente PowerBall if (power_ball_counter_ > 0) { @@ -113,13 +113,13 @@ void BalloonManager::deployRandomFormation(int stage) { .type = balloon.type, .size = balloon.size, .vel_x = balloon.vel_x, - .speed = balloon_speed_, + .game_tempo = balloon_speed_, .creation_counter = static_cast(creation_time_enabled_ ? balloon.creation_counter : 0)}; createBalloon(config); } // Reinicia el contador para el próximo despliegue - balloon_deploy_counter_ = DEFAULT_BALLOON_DEPLOY_COUNTER; + balloon_deploy_counter_ = 0; } } } @@ -134,7 +134,7 @@ void BalloonManager::deployFormation(int formation_id) { .type = balloon.type, .size = balloon.size, .vel_x = balloon.vel_x, - .speed = balloon_speed_, + .game_tempo = balloon_speed_, .creation_counter = balloon.creation_counter}; createBalloon(config); } @@ -150,7 +150,7 @@ void BalloonManager::deployFormation(int formation_id, float y) { .type = balloon.type, .size = balloon.size, .vel_x = balloon.vel_x, - .speed = balloon_speed_, + .game_tempo = balloon_speed_, .creation_counter = balloon.creation_counter}; createBalloon(config); } @@ -164,12 +164,8 @@ void BalloonManager::freeBalloons() { // Actualiza la variable enemyDeployCounter (time-based) void BalloonManager::updateBalloonDeployCounter(float deltaTime) { - if (balloon_deploy_counter_ > 0) { - // Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps) - float frameFactor = deltaTime / (1000.0f / 60.0f); - balloon_deploy_counter_ -= frameFactor; - if (balloon_deploy_counter_ < 0) balloon_deploy_counter_ = 0; - } + // DeltaTime puro - contador incrementa hasta llegar al umbral + balloon_deploy_counter_ += deltaTime; } // Indica si se puede crear una powerball @@ -214,14 +210,15 @@ void BalloonManager::createChildBalloon(const std::shared_ptr &balloon, .y = balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2), .size = static_cast(static_cast(balloon->getSize()) - 1), .vel_x = direction == "LEFT" ? Balloon::VELX_NEGATIVE : Balloon::VELX_POSITIVE, - .speed = balloon_speed_, + .game_tempo = balloon_speed_, .creation_counter = 0}; // Crea el globo auto b = createBalloon(config); - // Establece parametros - b->setVelY(b->getType() == Balloon::Type::BALLOON ? -2.50F : Balloon::VELX_NEGATIVE * 2.0F); + // Establece parametros (deltaTime puro - valores ya en pixels/ms) + constexpr float VEL_Y_BALLOON_PER_MS = -0.15F; // -2.50F convertido a pixels/ms + b->setVelY(b->getType() == Balloon::Type::BALLOON ? VEL_Y_BALLOON_PER_MS : Balloon::VELX_NEGATIVE * 2.0F); // Herencia de estados if (balloon->isStopped()) { b->stop(); } @@ -248,7 +245,7 @@ void BalloonManager::createPowerBall() { .type = Balloon::Type::POWERBALL, .size = Balloon::Size::EXTRALARGE, .vel_x = VEL_X.at(LUCK), - .speed = balloon_speed_, + .game_tempo = balloon_speed_, .creation_counter = 0, .play_area = play_area_, .texture = balloon_textures_.at(4), @@ -270,7 +267,7 @@ void BalloonManager::createPowerBall() { void BalloonManager::setBalloonSpeed(float speed) { balloon_speed_ = speed; for (auto &balloon : balloons_) { - balloon->setSpeed(speed); + balloon->setGameTempo(speed); } } @@ -283,7 +280,7 @@ auto BalloonManager::popBalloon(const std::shared_ptr &balloon) -> int balloon->pop(true); score = destroyAllBalloons(); power_ball_enabled_ = false; - balloon_deploy_counter_ = 20; + balloon_deploy_counter_ = -334; // Resetea con retraso (20 frames = 334ms negativos) } else { score = balloon->getScore(); if (balloon->getSize() != Balloon::Size::SMALL) { @@ -339,7 +336,7 @@ auto BalloonManager::destroyAllBalloons() -> int { score += destroyBalloon(balloon); } - balloon_deploy_counter_ = 300; + balloon_deploy_counter_ = -5000; // Resetea con retraso grande (300 frames = 5000ms negativos) Screen::get()->flash(Colors::FLASH, 3); Screen::get()->shake(); diff --git a/source/balloon_manager.h b/source/balloon_manager.h index 2731d12..41ccc6a 100644 --- a/source/balloon_manager.h +++ b/source/balloon_manager.h @@ -82,7 +82,7 @@ class BalloonManager { private: // --- Constantes --- - static const int DEFAULT_BALLOON_DEPLOY_COUNTER = 300; + static const int DEFAULT_BALLOON_DEPLOY_COUNTER = 5000; // 300 frames × 16.67ms = 5000ms // --- Objetos y punteros --- Balloons balloons_; // Vector con los globos activos @@ -96,8 +96,8 @@ class BalloonManager { // --- Variables de estado --- SDL_FRect play_area_ = param.game.play_area.rect; - float balloon_speed_ = Balloon::SPEED.at(0); - float default_balloon_speed_ = Balloon::SPEED.at(0); + float balloon_speed_ = Balloon::GAME_TEMPO.at(0); + float default_balloon_speed_ = Balloon::GAME_TEMPO.at(0); float balloon_deploy_counter_ = 0; int power_ball_counter_ = 0; int last_balloon_deploy_ = 0; diff --git a/source/defaults.h b/source/defaults.h index 9f1c5df..883069e 100644 --- a/source/defaults.h +++ b/source/defaults.h @@ -80,11 +80,12 @@ struct BalloonSettings { grav(g) {} }; +// Valores para deltaTime puro: vel en pixels/ms, grav en pixels/ms² (aceleración) constexpr std::array SETTINGS = {{ - BalloonSettings(2.75F, 0.09F), // Globo 0 - BalloonSettings(3.70F, 0.10F), // Globo 1 - BalloonSettings(4.70F, 0.10F), // Globo 2 - BalloonSettings(5.45F, 0.10F) // Globo 3 + BalloonSettings(2.75F / 16.67F, 0.09F / (16.67F * 16.67F)), // Globo 0: vel=0.165 pixels/ms, grav=0.00032 pixels/ms² + BalloonSettings(3.70F / 16.67F, 0.10F / (16.67F * 16.67F)), // Globo 1: vel=0.222 pixels/ms, grav=0.00036 pixels/ms² + BalloonSettings(4.70F / 16.67F, 0.10F / (16.67F * 16.67F)), // Globo 2: vel=0.282 pixels/ms, grav=0.00036 pixels/ms² + BalloonSettings(5.45F / 16.67F, 0.10F / (16.67F * 16.67F)) // Globo 3: vel=0.327 pixels/ms, grav=0.00036 pixels/ms² }}; constexpr std::array COLORS = { diff --git a/source/sections/game.cpp b/source/sections/game.cpp index 3c4555e..40ca07f 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -1546,21 +1546,21 @@ void Game::initDifficultyVars() { // Variables relacionadas con la dificultad switch (difficulty_) { case Difficulty::Code::EASY: { - balloon_manager_->setDefaultBalloonSpeed(Balloon::SPEED.at(0)); + balloon_manager_->setDefaultBalloonSpeed(Balloon::GAME_TEMPO.at(0)); difficulty_score_multiplier_ = 0.5F; scoreboard_->setColor(param.scoreboard.easy_color); break; } case Difficulty::Code::NORMAL: { - balloon_manager_->setDefaultBalloonSpeed(Balloon::SPEED.at(0)); + balloon_manager_->setDefaultBalloonSpeed(Balloon::GAME_TEMPO.at(0)); difficulty_score_multiplier_ = 1.0F; scoreboard_->setColor(param.scoreboard.normal_color); break; } case Difficulty::Code::HARD: { - balloon_manager_->setDefaultBalloonSpeed(Balloon::SPEED.at(4)); + balloon_manager_->setDefaultBalloonSpeed(Balloon::GAME_TEMPO.at(4)); difficulty_score_multiplier_ = 1.5F; scoreboard_->setColor(param.scoreboard.hard_color); break; @@ -1813,9 +1813,9 @@ void Game::checkAndUpdateBalloonSpeed() { for (size_t i = 0; i < std::size(THRESHOLDS); ++i) { // Si la velocidad actual del globo es la correspondiente al umbral "i" y el porcentaje de progreso ha superado ese umbral - if (balloon_manager_->getBalloonSpeed() == Balloon::SPEED.at(i) && PERCENT > THRESHOLDS.at(i)) { + if (balloon_manager_->getBalloonSpeed() == Balloon::GAME_TEMPO.at(i) && PERCENT > THRESHOLDS.at(i)) { // Sube la velocidad al siguiente nivel (i + 1) - balloon_manager_->setBalloonSpeed(Balloon::SPEED.at(i + 1)); + balloon_manager_->setBalloonSpeed(Balloon::GAME_TEMPO.at(i + 1)); return; } }