Implementar sistema de masa/peso individual por pelota

 Nueva característica:
- Cada pelota tiene un factor de masa único que afecta la gravedad
- Simula pelotas de diferente peso/densidad para física más realista

🔧 Implementación:
- GRAVITY_MASS_MIN = 0.7f (pelotas ligeras - 70% gravedad)
- GRAVITY_MASS_MAX = 1.3f (pelotas pesadas - 130% gravedad)
- Factor aleatorio generado por pelota en initBalls()
- Gravedad efectiva = gravity_force × mass_factor × deltaTime

📊 Comportamiento:
- Pelotas ligeras (0.7): Caen 30% más lento, efecto "flotante"
- Pelotas pesadas (1.3): Caen 30% más rápido, más "densas"
- Variabilidad continua entre 0.7-1.3 para cada pelota

🎯 Resultado visual:
- FIN del problema: "todas llegan al mismo tiempo"
- Ahora las pelotas llegan escalonadas al cambiar gravedad
- Física más realista y visualmente interesante

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-18 17:52:31 +02:00
parent e15c1f5349
commit a798811d23
4 changed files with 18 additions and 8 deletions

View File

@@ -22,7 +22,7 @@ float generateLateralLoss() {
}
// Constructor
Ball::Ball(float x, float vx, float vy, Color color, std::shared_ptr<Texture> texture, GravityDirection gravity_dir)
Ball::Ball(float x, float vx, float vy, Color color, std::shared_ptr<Texture> texture, GravityDirection gravity_dir, float mass_factor)
: sprite_(std::make_unique<Sprite>(texture)),
pos_({x, 0.0f, BALL_SIZE, BALL_SIZE}) {
// Convertir velocidades de píxeles/frame a píxeles/segundo (multiplicar por 60)
@@ -34,6 +34,7 @@ Ball::Ball(float x, float vx, float vy, Color color, std::shared_ptr<Texture> te
color_ = color;
// Convertir gravedad de píxeles/frame² a píxeles/segundo² (multiplicar por 60²)
gravity_force_ = GRAVITY_FORCE * 60.0f * 60.0f;
gravity_mass_factor_ = mass_factor; // Factor de masa individual para esta pelota
gravity_direction_ = gravity_dir;
on_surface_ = false;
stopped_ = false;
@@ -49,18 +50,20 @@ void Ball::update(float deltaTime) {
// Aplica la gravedad según la dirección (píxeles/segundo²)
if (!on_surface_) {
// Aplicar gravedad multiplicada por factor de masa individual
float effective_gravity = gravity_force_ * gravity_mass_factor_ * deltaTime;
switch (gravity_direction_) {
case GravityDirection::DOWN:
vy_ += gravity_force_ * deltaTime;
vy_ += effective_gravity;
break;
case GravityDirection::UP:
vy_ -= gravity_force_ * deltaTime;
vy_ -= effective_gravity;
break;
case GravityDirection::LEFT:
vx_ -= gravity_force_ * deltaTime;
vx_ -= effective_gravity;
break;
case GravityDirection::RIGHT:
vx_ += gravity_force_ * deltaTime;
vx_ += effective_gravity;
break;
}
}