revisat tabe.cpp, item.cpp i game.cpp

This commit is contained in:
2025-09-24 09:37:23 +02:00
parent 6a223b68ba
commit 2977869ab5
7 changed files with 96 additions and 93 deletions

View File

@@ -67,16 +67,16 @@ void Item::alignTo(int x) {
void Item::render() {
if (enabled_) {
// Muestra normalmente hasta los últimos ~3.3 segundos (200 frames)
constexpr float BLINK_START_MS = LIFETIME_DURATION_MS - (200.0f * (1000.0f / 60.0f));
// Muestra normalmente hasta los últimos ~3.3 segundos
constexpr float BLINK_START_S = LIFETIME_DURATION_S - 3.33f;
if (lifetime_timer_ < BLINK_START_MS) {
if (lifetime_timer_ < BLINK_START_S) {
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;
// Efecto de parpadeo en los últimos segundos (cada ~0.33 segundos)
constexpr float BLINK_INTERVAL_S = 0.33f;
const float phase = fmod(lifetime_timer_, BLINK_INTERVAL_S);
const float half_interval = BLINK_INTERVAL_S / 2.0f;
if (phase < half_interval) {
sprite_->render();
@@ -88,11 +88,11 @@ void Item::render() {
void Item::move(float deltaTime) {
floor_collision_ = false;
// Calcula la nueva posición usando deltaTime puro (velocidad en pixels/ms)
// Calcula la nueva posición usando deltaTime (velocidad en pixels/segundo)
pos_x_ += vel_x_ * deltaTime;
pos_y_ += vel_y_ * deltaTime;
// Aplica las aceleraciones a la velocidad usando deltaTime puro (aceleración en pixels/ms²)
// Aplica las aceleraciones a la velocidad usando deltaTime (aceleración en pixels/segundo²)
vel_x_ += accel_x_ * deltaTime;
vel_y_ += accel_y_ * deltaTime;
@@ -162,7 +162,7 @@ void Item::update(float deltaTime) {
void Item::updateTimeToLive(float deltaTime) {
lifetime_timer_ += deltaTime;
if (lifetime_timer_ >= LIFETIME_DURATION_MS) {
if (lifetime_timer_ >= LIFETIME_DURATION_S) {
disable();
}
}