revisat moving i animated sprite
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
- [ ] Convertir a timers basados en deltaTime
|
- [ ] Convertir a timers basados en deltaTime
|
||||||
- [ ] Eliminar variables como `counter_`, `frame_counter_`, etc.
|
- [ ] Eliminar variables como `counter_`, `frame_counter_`, etc.
|
||||||
- [ ] Patrón: `if (counter-- <= 0)` → `if (timer >= DURATION_MS)`
|
- [ ] Patrón: `if (counter-- <= 0)` → `if (timer >= DURATION_MS)`
|
||||||
|
- [ ] **IMPORTANTE**: Todos los contadores han de ser crecientes, de cero hasta llegar a la constante que define su tope
|
||||||
|
|
||||||
### 2. Revisar Inicializaciones de Aceleraciones MovingSprite
|
### 2. Revisar Inicializaciones de Aceleraciones MovingSprite
|
||||||
- [ ] Buscar todas las llamadas a `setAccelX()`, `setAccelY()`
|
- [ ] Buscar todas las llamadas a `setAccelX()`, `setAccelY()`
|
||||||
@@ -28,8 +29,16 @@
|
|||||||
- [ ] Buscar `1000.0f / 60.0f` hardcodeado
|
- [ ] Buscar `1000.0f / 60.0f` hardcodeado
|
||||||
- [ ] Buscar `16.67f` hardcodeado
|
- [ ] Buscar `16.67f` hardcodeado
|
||||||
- [ ] Buscar comentarios con "frame" o "60fps"
|
- [ ] Buscar comentarios con "frame" o "60fps"
|
||||||
|
- [ ] Localizar magic numbers y convertirlos a constantes con nombres descriptivos
|
||||||
|
- [ ] **IMPORTANTE**: Modificar speed en ficheros .ani - está en frames, hay que pasarlo a milisegundos (multiplicar speed por 1000/60 = 16.67)
|
||||||
|
|
||||||
### 5. Archivos Prioritarios a Revisar
|
### 5. Cambio de Unidades de Tiempo en sections/*
|
||||||
|
- [ ] Cambiar el cálculo de deltatime en source/sections/* para que devuelva segundos (float) en lugar de milisegundos
|
||||||
|
- [ ] Cambiar velocidades de pixeles/ms a pixeles/segundos para evitar valores absurdamente pequeños
|
||||||
|
- [ ] Cambiar aceleraciones de pixeles/ms² a pixeles/segundos²
|
||||||
|
- [ ] Actualizar todas las constantes de tiempo en archivos de sections
|
||||||
|
|
||||||
|
### 6. Archivos Prioritarios a Revisar
|
||||||
- [ ] **player.cpp** - puede tener aceleraciones
|
- [ ] **player.cpp** - puede tener aceleraciones
|
||||||
- [ ] **balloon.cpp** - contadores de estado
|
- [ ] **balloon.cpp** - contadores de estado
|
||||||
- [ ] **stage.cpp** - timers de nivel
|
- [ ] **stage.cpp** - timers de nivel
|
||||||
@@ -37,7 +46,7 @@
|
|||||||
- [ ] **tabe.cpp** - movimiento del protagonista
|
- [ ] **tabe.cpp** - movimiento del protagonista
|
||||||
- [ ] **sections/*.cpp** - transiciones y efectos
|
- [ ] **sections/*.cpp** - transiciones y efectos
|
||||||
|
|
||||||
### 6. Validación Final
|
### 7. Validación Final
|
||||||
- [ ] Compilar sin warnings
|
- [ ] Compilar sin warnings
|
||||||
- [ ] Probar gameplay normal
|
- [ ] Probar gameplay normal
|
||||||
- [ ] Probar modo demo
|
- [ ] Probar modo demo
|
||||||
@@ -57,7 +66,9 @@ rg "60\.0|16\.67|1000\.0.*60"
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Notas
|
## Notas
|
||||||
- Mantener consistencia: velocidades en `pixels/ms`, aceleraciones en `pixels/ms²`
|
- **Para archivos sections/***: velocidades en `pixels/segundos`, aceleraciones en `pixels/segundos²`
|
||||||
|
- **Para resto del código**: mantener velocidades en `pixels/ms`, aceleraciones en `pixels/ms²`
|
||||||
|
- Todos los contadores deben ser crecientes (0 → constante_tope)
|
||||||
- Documentar las conversiones en comentarios
|
- Documentar las conversiones en comentarios
|
||||||
- Crear constantes para valores repetidos
|
- Crear constantes para valores repetidos
|
||||||
- Evitar números mágicos
|
- Evitar números mágicos
|
||||||
@@ -92,15 +92,12 @@ void AnimatedSprite::animate(float deltaTime) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convertir speed (frames) a tiempo: speed frames = speed * (1000ms/60fps) milisegundos
|
|
||||||
float frameTime = static_cast<float>(animations_[current_animation_].speed) * (1000.0f / 60.0f);
|
|
||||||
|
|
||||||
// Acumular tiempo transcurrido
|
// Acumular tiempo transcurrido
|
||||||
animations_[current_animation_].time_accumulator += deltaTime;
|
animations_[current_animation_].time_accumulator += deltaTime;
|
||||||
|
|
||||||
// Verificar si es momento de cambiar frame
|
// Verificar si es momento de cambiar frame
|
||||||
if (animations_[current_animation_].time_accumulator >= frameTime) {
|
if (animations_[current_animation_].time_accumulator >= animations_[current_animation_].speed) {
|
||||||
animations_[current_animation_].time_accumulator -= frameTime;
|
animations_[current_animation_].time_accumulator -= animations_[current_animation_].speed;
|
||||||
animations_[current_animation_].current_frame++;
|
animations_[current_animation_].current_frame++;
|
||||||
|
|
||||||
// Si alcanza el final de la animación
|
// Si alcanza el final de la animación
|
||||||
@@ -132,12 +129,10 @@ void AnimatedSprite::setCurrentAnimation(const std::string& name, bool reset) {
|
|||||||
current_animation_ = NEW_ANIMATION;
|
current_animation_ = NEW_ANIMATION;
|
||||||
if (reset) {
|
if (reset) {
|
||||||
animations_[current_animation_].current_frame = 0;
|
animations_[current_animation_].current_frame = 0;
|
||||||
animations_[current_animation_].counter = 0;
|
|
||||||
animations_[current_animation_].time_accumulator = 0.0f;
|
animations_[current_animation_].time_accumulator = 0.0f;
|
||||||
animations_[current_animation_].completed = false;
|
animations_[current_animation_].completed = false;
|
||||||
} else {
|
} else {
|
||||||
animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size() - 1);
|
animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size() - 1);
|
||||||
animations_[current_animation_].counter = animations_[OLD_ANIMATION].counter;
|
|
||||||
animations_[current_animation_].time_accumulator = animations_[OLD_ANIMATION].time_accumulator;
|
animations_[current_animation_].time_accumulator = animations_[OLD_ANIMATION].time_accumulator;
|
||||||
animations_[current_animation_].completed = animations_[OLD_ANIMATION].completed;
|
animations_[current_animation_].completed = animations_[OLD_ANIMATION].completed;
|
||||||
}
|
}
|
||||||
@@ -153,12 +148,10 @@ void AnimatedSprite::setCurrentAnimation(int index, bool reset) {
|
|||||||
current_animation_ = NEW_ANIMATION;
|
current_animation_ = NEW_ANIMATION;
|
||||||
if (reset) {
|
if (reset) {
|
||||||
animations_[current_animation_].current_frame = 0;
|
animations_[current_animation_].current_frame = 0;
|
||||||
animations_[current_animation_].counter = 0;
|
|
||||||
animations_[current_animation_].time_accumulator = 0.0f;
|
animations_[current_animation_].time_accumulator = 0.0f;
|
||||||
animations_[current_animation_].completed = false;
|
animations_[current_animation_].completed = false;
|
||||||
} else {
|
} else {
|
||||||
animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size());
|
animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size());
|
||||||
animations_[current_animation_].counter = animations_[OLD_ANIMATION].counter;
|
|
||||||
animations_[current_animation_].time_accumulator = animations_[OLD_ANIMATION].time_accumulator;
|
animations_[current_animation_].time_accumulator = animations_[OLD_ANIMATION].time_accumulator;
|
||||||
animations_[current_animation_].completed = animations_[OLD_ANIMATION].completed;
|
animations_[current_animation_].completed = animations_[OLD_ANIMATION].completed;
|
||||||
}
|
}
|
||||||
@@ -175,7 +168,6 @@ void AnimatedSprite::update(float deltaTime) {
|
|||||||
// Reinicia la animación
|
// Reinicia la animación
|
||||||
void AnimatedSprite::resetAnimation() {
|
void AnimatedSprite::resetAnimation() {
|
||||||
animations_[current_animation_].current_frame = 0;
|
animations_[current_animation_].current_frame = 0;
|
||||||
animations_[current_animation_].counter = 0;
|
|
||||||
animations_[current_animation_].time_accumulator = 0.0f;
|
animations_[current_animation_].time_accumulator = 0.0f;
|
||||||
animations_[current_animation_].completed = false;
|
animations_[current_animation_].completed = false;
|
||||||
animations_[current_animation_].paused = false;
|
animations_[current_animation_].paused = false;
|
||||||
|
|||||||
@@ -17,15 +17,14 @@ class Texture;
|
|||||||
|
|
||||||
// --- Estructuras ---
|
// --- Estructuras ---
|
||||||
struct Animation {
|
struct Animation {
|
||||||
static constexpr int DEFAULT_SPEED = 5;
|
static constexpr float DEFAULT_SPEED = 80.0F;
|
||||||
|
|
||||||
std::string name; // Nombre de la animación
|
std::string name; // Nombre de la animación
|
||||||
std::vector<SDL_FRect> frames; // Frames que componen la animación
|
std::vector<SDL_FRect> frames; // Frames que componen la animación
|
||||||
int speed{DEFAULT_SPEED}; // Velocidad de reproducción (frame-based)
|
float speed{DEFAULT_SPEED}; // Velocidad de reproducción (ms entre frames)
|
||||||
int loop{0}; // Frame de vuelta al terminar (-1 para no repetir)
|
int loop{0}; // Frame de vuelta al terminar (-1 para no repetir)
|
||||||
bool completed{false}; // Indica si la animación ha finalizado
|
bool completed{false}; // Indica si la animación ha finalizado
|
||||||
size_t current_frame{0}; // Frame actual en reproducción
|
size_t current_frame{0}; // Frame actual en reproducción
|
||||||
int counter{0}; // Contador para la animación (frame-based)
|
|
||||||
float time_accumulator{0.0f}; // Acumulador de tiempo para animaciones time-based
|
float time_accumulator{0.0f}; // Acumulador de tiempo para animaciones time-based
|
||||||
bool paused{false}; // La animación no avanza
|
bool paused{false}; // La animación no avanza
|
||||||
|
|
||||||
|
|||||||
@@ -81,16 +81,13 @@ void MovingSprite::render() {
|
|||||||
// Establece la rotacion (time-based)
|
// Establece la rotacion (time-based)
|
||||||
void MovingSprite::rotate(float deltaTime) {
|
void MovingSprite::rotate(float deltaTime) {
|
||||||
if (rotate_.enabled) {
|
if (rotate_.enabled) {
|
||||||
// DeltaTime puro: velocidad de rotación debe estar en unidades/ms
|
rotate_.angle += rotate_.amount * deltaTime;
|
||||||
float rotationFrameTime = static_cast<float>(rotate_.speed) * (1000.0f / 60.0f);
|
|
||||||
rotate_.angle += rotate_.amount * (deltaTime / rotationFrameTime);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activa o desactiva el efecto de rotación
|
// Activa o desactiva el efecto de rotación
|
||||||
void MovingSprite::setRotate(bool enable) {
|
void MovingSprite::setRotate(bool enable) {
|
||||||
rotate_.enabled = enable;
|
rotate_.enabled = enable;
|
||||||
rotate_.counter = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la posición y_ el tamaño del objeto
|
// Establece la posición y_ el tamaño del objeto
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class MovingSprite : public Sprite {
|
|||||||
// --- Estructuras ---
|
// --- Estructuras ---
|
||||||
struct Rotate {
|
struct Rotate {
|
||||||
bool enabled{false}; // Indica si ha de rotar
|
bool enabled{false}; // Indica si ha de rotar
|
||||||
int counter{0}; // Contador
|
|
||||||
int speed{1}; // Velocidad de giro
|
int speed{1}; // Velocidad de giro
|
||||||
double angle{0.0}; // Ángulo para dibujarlo
|
double angle{0.0}; // Ángulo para dibujarlo
|
||||||
float amount{0.0F}; // Cantidad de grados a girar en cada iteración
|
float amount{0.0F}; // Cantidad de grados a girar en cada iteración
|
||||||
|
|||||||
Reference in New Issue
Block a user