- Añadir getter isStopped() en Ball para detectar pelotas quietas - Sistema de temporizador de 5 segundos que detecta cuando todas las pelotas están paradas - Auto-reinicio aleatorio cuando se cumple el tiempo de inactividad: * Escenario aleatorio usando test_.size() (1 a 100,000 pelotas) * Tema aleatorio usando sizeof(themes_) (5 temas disponibles) * Reset inteligente del temporizador si alguna pelota se mueve - Integración no intrusiva en update() del bucle principal - Usa infraestructura existente (SDL_GetTicks, initBalls, rand) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
63 lines
2.5 KiB
C++
63 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL_rect.h> // for SDL_FRect
|
|
|
|
#include <memory> // for shared_ptr, unique_ptr
|
|
|
|
#include "defines.h" // for Color
|
|
#include "external/sprite.h" // for Sprite
|
|
class Texture;
|
|
|
|
class Ball {
|
|
private:
|
|
std::unique_ptr<Sprite> sprite_; // Sprite para pintar la clase
|
|
SDL_FRect pos_; // Posición y tamaño de la pelota
|
|
float vx_, vy_; // Velocidad
|
|
float gravity_force_; // Gravedad base
|
|
float gravity_mass_factor_; // Factor de masa individual (0.7-1.3, afecta gravedad)
|
|
GravityDirection gravity_direction_; // Direcci\u00f3n de la gravedad
|
|
int screen_width_; // Ancho del terreno de juego
|
|
int screen_height_; // Alto del terreno de juego
|
|
Color color_; // Color de la pelota
|
|
bool on_surface_; // Indica si la pelota est\u00e1 en la superficie (suelo/techo/pared)
|
|
bool stopped_; // Indica si la pelota ha terminado de moverse;
|
|
float loss_; // Coeficiente de rebote. Pérdida de energía en cada rebote
|
|
|
|
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);
|
|
|
|
// Destructor
|
|
~Ball() = default;
|
|
|
|
// Actualiza la lógica de la clase
|
|
void update(float deltaTime);
|
|
|
|
// Pinta la clase
|
|
void render();
|
|
|
|
// Modifica la velocidad
|
|
void modVel(float vx, float vy);
|
|
|
|
// Cambia la gravedad
|
|
void switchGravity();
|
|
|
|
// Cambia la direcci\u00f3n de gravedad
|
|
void setGravityDirection(GravityDirection direction);
|
|
|
|
// Aplica un peque\u00f1o empuje lateral aleatorio
|
|
void applyRandomLateralPush();
|
|
|
|
// Getters para debug
|
|
float getVelocityY() const { return vy_; }
|
|
float getVelocityX() const { return vx_; }
|
|
float getGravityForce() const { return gravity_force_; }
|
|
float getLossCoefficient() const { return loss_; }
|
|
GravityDirection getGravityDirection() const { return gravity_direction_; }
|
|
bool isOnSurface() const { return on_surface_; }
|
|
bool isStopped() const { return stopped_; }
|
|
|
|
// Getters para batch rendering
|
|
SDL_FRect getPosition() const { return pos_; }
|
|
Color getColor() const { return color_; }
|
|
}; |