revisat credits.cpp, player.cpp, balloon.cpp i balloon_manager.cpp

This commit is contained in:
2025-09-23 13:42:09 +02:00
parent 6c8f231b34
commit 159528adc9
34 changed files with 184 additions and 326 deletions

View File

@@ -29,7 +29,7 @@ Balloon::Balloon(const Config& config)
switch (type_) {
case Type::BALLOON: {
vy_ = 0;
max_vy_ = 3.0F;
max_vy_ = 3.0F * 60.0F; // Convert from frames to seconds (180 pixels/s)
const int INDEX = static_cast<int>(size_);
gravity_ = param.balloon.settings.at(INDEX).grav;
@@ -65,7 +65,7 @@ Balloon::Balloon(const Config& config)
power_ = score_ = menace_ = 0;
vy_ = 0;
max_vy_ = 3.0F;
max_vy_ = 3.0F * 60.0F; // Convert from frames to seconds (180 pixels/s)
gravity_ = param.balloon.settings.at(INDEX).grav;
default_vy_ = param.balloon.settings.at(INDEX).vel;
@@ -153,7 +153,7 @@ void Balloon::move(float deltaTime) {
}
void Balloon::handleHorizontalMovement(float deltaTime) {
// DeltaTime puro: velocidad (pixels/ms) * tempo * tiempo (ms)
// DeltaTime en segundos: velocidad (pixels/s) * tempo * tiempo (s)
x_ += vx_ * game_tempo_ * deltaTime;
const int CLIP = 2;
@@ -166,7 +166,7 @@ void Balloon::handleHorizontalMovement(float deltaTime) {
}
void Balloon::handleVerticalMovement(float deltaTime) {
// DeltaTime puro: velocidad (pixels/ms) * tempo * tiempo (ms)
// DeltaTime en segundos: velocidad (pixels/s) * tempo * tiempo (s)
y_ += vy_ * game_tempo_ * deltaTime;
if (shouldCheckTopCollision()) {
@@ -223,7 +223,7 @@ void Balloon::handleBottomCollision() {
}
void Balloon::applyGravity(float deltaTime) {
// DeltaTime puro: aceleración (pixels/ms²) * tempo * tiempo (ms)
// DeltaTime en segundos: aceleración (pixels/s²) * tempo * tiempo (s)
vy_ += gravity_ * game_tempo_ * deltaTime;
}
@@ -247,7 +247,7 @@ void Balloon::update(float deltaTime) {
shiftSprite();
shiftColliders();
sprite_->update(deltaTime);
// Contador interno con deltaTime puro
// Contador interno con deltaTime en segundos
counter_ += deltaTime;
}
@@ -261,13 +261,14 @@ void Balloon::updateState(float deltaTime) {
if (creation_counter_ > 0) {
// Desplaza lentamente el globo hacia abajo y hacia un lado
// Cada 166ms (equivalente a 10 frames a 60fps)
// Cada 10/60 segundos (equivalente a 10 frames a 60fps)
movement_accumulator_ += deltaTime;
if (movement_accumulator_ >= 166.0f) {
movement_accumulator_ -= 166.0f;
constexpr float MOVEMENT_INTERVAL_S = 10.0f / 60.0f; // 10 frames = ~0.167s
if (movement_accumulator_ >= MOVEMENT_INTERVAL_S) {
movement_accumulator_ -= MOVEMENT_INTERVAL_S;
y_++;
x_ += vx_ * 10.0f; // Movimiento equivalente a 10 frames de velocidad horizontal
x_ += vx_ * MOVEMENT_INTERVAL_S; // Movimiento equivalente a 10 frames de velocidad horizontal
// Comprueba no se salga por los laterales
const int MIN_X = play_area_.x;
@@ -275,7 +276,7 @@ void Balloon::updateState(float deltaTime) {
if (x_ < MIN_X || x_ > MAX_X) {
// Corrige y cambia el sentido de la velocidad
x_ -= vx_ * 10.0f;
x_ -= vx_ * MOVEMENT_INTERVAL_S;
vx_ = -vx_;
}
}