Implementar cambio de sprite dinámico con hot-swap (Tecla N)

Sistema de múltiples texturas:
- Carga ball.png (10x10) y ball_small.png (6x6) al inicio
- Variable current_ball_size_ obtiene tamaño desde texture->getWidth()
- Eliminar constante BALL_SIZE hardcoded

Cambio de tamaño con ajuste de posiciones:
- updateBallSizes() ajusta pos según gravedad y superficie
- DOWN: mueve Y hacia abajo si crece
- UP: mueve Y hacia arriba si crece
- LEFT/RIGHT: mueve X correspondiente
- Solo ajusta pelotas en superficie (isOnSurface())

Ball class actualizada:
- Constructor recibe ball_size como parámetro
- updateSize(new_size): actualiza hitbox y sprite
- setTexture(texture): cambia textura del sprite
- setPosition() usa setRotoBallScreenPosition()

Sprite class:
- Añadido setTexture() inline para hot-swap

Tecla N:
- Cicla entre texturas disponibles
- Actualiza todas las pelotas sin reiniciar física
- Texto informativo "SPRITE: NORMAL" / "SPRITE: SMALL"

Fix bug initBalls():
- Ahora usa current_ball_size_ en constructor
- Pelotas nuevas tienen tamaño correcto según textura activa

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-04 08:08:00 +02:00
parent 6bb814e61c
commit dcd05e502f
6 changed files with 133 additions and 12 deletions

View File

@@ -32,7 +32,7 @@ class Ball {
public:
// Constructor
Ball(float x, float vx, float vy, Color color, std::shared_ptr<Texture> texture, int screen_width, int screen_height, GravityDirection gravity_dir = GravityDirection::DOWN, float mass_factor = 1.0f);
Ball(float x, float vx, float vy, Color color, std::shared_ptr<Texture> texture, int screen_width, int screen_height, int ball_size, GravityDirection gravity_dir = GravityDirection::DOWN, float mass_factor = 1.0f);
// Destructor
~Ball() = default;
@@ -78,6 +78,10 @@ class Ball {
Color getColor() const { return color_; }
void setColor(const Color& color) { color_ = color; }
// Sistema de cambio de sprite dinámico
void updateSize(int new_size); // Actualizar tamaño de hitbox
void setTexture(std::shared_ptr<Texture> texture); // Cambiar textura del sprite
// Funciones para modo RotoBall
void setRotoBallPosition3D(float x, float y, float z);
void setRotoBallTarget2D(float x, float y);