eliminats metodes frame-based obsolets
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "item.h"
|
||||
|
||||
#include <algorithm> // Para clamp
|
||||
#include <cmath> // Para fmod
|
||||
#include <cstdlib> // Para rand
|
||||
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
@@ -66,24 +67,36 @@ void Item::alignTo(int x) {
|
||||
|
||||
void Item::render() {
|
||||
if (enabled_) {
|
||||
if (time_to_live_ > 200) {
|
||||
sprite_->render();
|
||||
} else if (time_to_live_ % 20 > 10) {
|
||||
// Muestra normalmente hasta los últimos ~3.3 segundos (200 frames)
|
||||
constexpr float BLINK_START_MS = LIFETIME_DURATION_MS - (200.0f * (1000.0f / 60.0f));
|
||||
|
||||
if (lifetime_timer_ < BLINK_START_MS) {
|
||||
sprite_->render();
|
||||
} else {
|
||||
// Efecto de parpadeo en los últimos segundos (cada ~333ms o 20 frames)
|
||||
constexpr float BLINK_INTERVAL_MS = 20.0f * (1000.0f / 60.0f);
|
||||
const float phase = fmod(lifetime_timer_, BLINK_INTERVAL_MS);
|
||||
const float half_interval = BLINK_INTERVAL_MS / 2.0f;
|
||||
|
||||
if (phase < half_interval) {
|
||||
sprite_->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Item::move() {
|
||||
void Item::move(float deltaTime) {
|
||||
// Convertir deltaTime a factor de frame para compatibilidad (asumiendo 60fps)
|
||||
const float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
floor_collision_ = false;
|
||||
|
||||
// Calcula la nueva posición
|
||||
pos_x_ += vel_x_;
|
||||
pos_y_ += vel_y_;
|
||||
// Calcula la nueva posición (time-based)
|
||||
pos_x_ += vel_x_ * frameFactor;
|
||||
pos_y_ += vel_y_ * frameFactor;
|
||||
|
||||
// Aplica las aceleraciones a la velocidad
|
||||
vel_x_ += accel_x_;
|
||||
vel_y_ += accel_y_;
|
||||
// Aplica las aceleraciones a la velocidad (time-based)
|
||||
vel_x_ += accel_x_ * frameFactor;
|
||||
vel_y_ += accel_y_ * frameFactor;
|
||||
|
||||
// Comprueba los laterales de la zona de juego
|
||||
const float MIN_X = param.game.play_area.rect.x;
|
||||
@@ -143,16 +156,15 @@ void Item::move() {
|
||||
|
||||
void Item::disable() { enabled_ = false; }
|
||||
|
||||
void Item::update() {
|
||||
move();
|
||||
sprite_->update();
|
||||
updateTimeToLive();
|
||||
void Item::update(float deltaTime) {
|
||||
move(deltaTime);
|
||||
sprite_->update(deltaTime);
|
||||
updateTimeToLive(deltaTime);
|
||||
}
|
||||
|
||||
void Item::updateTimeToLive() {
|
||||
if (time_to_live_ > 0) {
|
||||
time_to_live_--;
|
||||
} else {
|
||||
void Item::updateTimeToLive(float deltaTime) {
|
||||
lifetime_timer_ += deltaTime;
|
||||
if (lifetime_timer_ >= LIFETIME_DURATION_MS) {
|
||||
disable();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user