fix: SHAPE mode - regenerar figuras automáticamente al cambiar escenario
PROBLEMA RESUELTO: En modo SHAPE (figuras 3D), al cambiar el número de pelotas (teclas 1-8), las nuevas pelotas aparecían en pantalla pero NO formaban la figura hasta pulsar de nuevo la tecla de figura (Q/W/E/R/T). CAUSA RAÍZ: 1. changeScenario() creaba pelotas nuevas en centro de pantalla 2. generateShape() generaba puntos target de la figura 3. PERO las pelotas nuevas no tenían shape_attraction_active=true 4. Sin atracción activa, las pelotas no se movían hacia sus targets CAMBIOS IMPLEMENTADOS: 1. Ball class (ball.h/ball.cpp): - Constructor ahora acepta parámetro Y explícito - Eliminado hardcodeo Y=0.0f en inicialización de pos_ 2. SceneManager (scene_manager.cpp): - PHYSICS mode: Y = 0.0f (parte superior, comportamiento original) - SHAPE mode: Y = screen_height_/2.0f (centro vertical) ✅ - BOIDS mode: Y = rand() (posición Y aleatoria) - Ball constructor llamado con parámetro Y según modo 3. Engine (engine.cpp:514-521): - Tras generateShape(), activar enableShapeAttraction(true) en todas las pelotas nuevas - Garantiza que las pelotas converjan inmediatamente hacia figura RESULTADO: ✅ Cambiar escenario (1-8) en modo SHAPE regenera automáticamente la figura ✅ No requiere pulsar tecla de figura de nuevo ✅ Transición suave e inmediata hacia nueva configuración ARCHIVOS MODIFICADOS: - source/ball.h: Constructor acepta parámetro Y - source/ball.cpp: Usar Y en lugar de hardcode 0.0f - source/scene/scene_manager.cpp: Inicializar Y según SimulationMode - source/engine.cpp: Activar shape attraction tras changeScenario() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -45,7 +45,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) {
|
||||
|
||||
// Crear las bolas según el escenario
|
||||
for (int i = 0; i < BALL_COUNT_SCENARIOS[scenario_id]; ++i) {
|
||||
float X, VX, VY;
|
||||
float X, Y, VX, VY;
|
||||
|
||||
// Inicialización según SimulationMode (RULES.md líneas 23-26)
|
||||
switch (mode) {
|
||||
@@ -55,6 +55,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) {
|
||||
const int margin = static_cast<int>(screen_width_ * BALL_SPAWN_MARGIN);
|
||||
const int spawn_zone_width = screen_width_ - (2 * margin);
|
||||
X = (rand() % spawn_zone_width) + margin;
|
||||
Y = 0.0f; // Parte superior
|
||||
VX = (((rand() % 20) + 10) * 0.1f) * SIGN;
|
||||
VY = ((rand() % 60) - 30) * 0.1f;
|
||||
break;
|
||||
@@ -63,6 +64,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) {
|
||||
case SimulationMode::SHAPE: {
|
||||
// SHAPE: Centro de pantalla, sin velocidad inicial
|
||||
X = screen_width_ / 2.0f;
|
||||
Y = screen_height_ / 2.0f; // Centro vertical
|
||||
VX = 0.0f;
|
||||
VY = 0.0f;
|
||||
break;
|
||||
@@ -73,6 +75,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) {
|
||||
const int SIGN_X = ((rand() % 2) * 2) - 1;
|
||||
const int SIGN_Y = ((rand() % 2) * 2) - 1;
|
||||
X = static_cast<float>(rand() % screen_width_);
|
||||
Y = static_cast<float>(rand() % screen_height_); // Posición Y aleatoria
|
||||
VX = (((rand() % 40) + 10) * 0.1f) * SIGN_X; // 1.0 - 5.0 px/frame
|
||||
VY = (((rand() % 40) + 10) * 0.1f) * SIGN_Y;
|
||||
break;
|
||||
@@ -84,6 +87,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) {
|
||||
const int margin = static_cast<int>(screen_width_ * BALL_SPAWN_MARGIN);
|
||||
const int spawn_zone_width = screen_width_ - (2 * margin);
|
||||
X = (rand() % spawn_zone_width) + margin;
|
||||
Y = 0.0f; // Parte superior
|
||||
VX = (((rand() % 20) + 10) * 0.1f) * SIGN;
|
||||
VY = ((rand() % 60) - 30) * 0.1f;
|
||||
break;
|
||||
@@ -97,7 +101,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) {
|
||||
float mass_factor = GRAVITY_MASS_MIN + (rand() % 1000) / 1000.0f * (GRAVITY_MASS_MAX - GRAVITY_MASS_MIN);
|
||||
|
||||
balls_.emplace_back(std::make_unique<Ball>(
|
||||
X, VX, VY, COLOR, texture_,
|
||||
X, Y, VX, VY, COLOR, texture_,
|
||||
screen_width_, screen_height_, current_ball_size_,
|
||||
current_gravity_, mass_factor
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user