From 91b26631c63dbe7003d1fbb507f3bbbaeb500624 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 22 Sep 2025 12:14:09 +0200 Subject: [PATCH] magic numbers: bullet.cpp --- DELTATIME_MIGRATION_PLAN.md | 8 ++++---- source/bullet.cpp | 8 +++----- source/bullet.h | 6 +++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/DELTATIME_MIGRATION_PLAN.md b/DELTATIME_MIGRATION_PLAN.md index 72eba49..8f6100a 100644 --- a/DELTATIME_MIGRATION_PLAN.md +++ b/DELTATIME_MIGRATION_PLAN.md @@ -49,10 +49,10 @@ pos_x_ += vel_x_ * (deltaTime / FRAME_TIME_MS); // donde FRAME_TIME_MS = 16.67f - [ ] 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) +- [x] **balloon.cpp**: Migrar velocidades x/y y contadores ✅ +- [x] **balloon_manager.cpp**: Migrar balloon_deploy_counter_ ✅ +- [x] **bullet.cpp**: Migrar velocidades de bala ✅ (VEL_Y: -3.0F→-0.18F, VEL_X: ±2.0F→±0.12F) +- [x] **item.cpp**: Migrar física de ítems ✅ (vel_x: ±1.0F→±0.06F, vel_y: -4.0F→-0.24F, accel_y: 0.2F→0.012F) - [ ] **moving_sprite.cpp**: Migrar sistema base de movimiento - [ ] **tabe.cpp**: Migrar movimiento y efectos - [ ] **credits.cpp**: Migrar contadores de timing diff --git a/source/bullet.cpp b/source/bullet.cpp index 2b907e2..8770a1c 100644 --- a/source/bullet.cpp +++ b/source/bullet.cpp @@ -68,16 +68,14 @@ auto Bullet::update(float deltaTime) -> BulletMoveStatus { // Implementación del movimiento usando BulletMoveStatus (time-based) auto Bullet::move(float deltaTime) -> BulletMoveStatus { - // Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps) - float frameFactor = deltaTime / (1000.0f / 60.0f); - - pos_x_ += vel_x_ * frameFactor; + // DeltaTime puro: velocidad (pixels/ms) * tiempo (ms) + pos_x_ += vel_x_ * deltaTime; if (pos_x_ < param.game.play_area.rect.x - WIDTH || pos_x_ > param.game.play_area.rect.w) { disable(); return BulletMoveStatus::OUT; } - pos_y_ += VEL_Y * frameFactor; + pos_y_ += VEL_Y * deltaTime; if (pos_y_ < param.game.play_area.rect.y - HEIGHT) { disable(); return BulletMoveStatus::OUT; diff --git a/source/bullet.h b/source/bullet.h index a3be095..c5bdc9d 100644 --- a/source/bullet.h +++ b/source/bullet.h @@ -45,9 +45,9 @@ class Bullet { private: // --- Constantes --- - static constexpr float VEL_Y = -3.0F; // Velocidad vertical - static constexpr float VEL_X_LEFT = -2.0F; // Velocidad izquierda - static constexpr float VEL_X_RIGHT = 2.0F; // Velocidad derecha + static constexpr float VEL_Y = -0.18F; // Velocidad vertical (pixels/ms) + static constexpr float VEL_X_LEFT = -0.12F; // Velocidad izquierda (pixels/ms) + static constexpr float VEL_X_RIGHT = 0.12F; // Velocidad derecha (pixels/ms) static constexpr float VEL_X_CENTER = 0.0F; // Velocidad central // --- Objetos y punteros ---