arreglant balloon.cpp per a deltaTime pur
This commit is contained in:
@@ -23,7 +23,7 @@ Balloon::Balloon(const Config& config)
|
||||
creation_counter_ini_(config.creation_counter),
|
||||
type_(config.type),
|
||||
size_(config.size),
|
||||
speed_(config.speed),
|
||||
game_tempo_(config.game_tempo),
|
||||
play_area_(config.play_area),
|
||||
sound_(config.sound) {
|
||||
switch (type_) {
|
||||
@@ -147,9 +147,8 @@ void Balloon::move(float deltaTime) {
|
||||
}
|
||||
|
||||
void Balloon::handleHorizontalMovement(float deltaTime) {
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
x_ += vx_ * speed_ * frameFactor;
|
||||
// DeltaTime puro: velocidad (pixels/ms) * tempo * tiempo (ms)
|
||||
x_ += vx_ * game_tempo_ * deltaTime;
|
||||
|
||||
const int CLIP = 2;
|
||||
const float MIN_X = play_area_.x - CLIP;
|
||||
@@ -161,9 +160,8 @@ void Balloon::handleHorizontalMovement(float deltaTime) {
|
||||
}
|
||||
|
||||
void Balloon::handleVerticalMovement(float deltaTime) {
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
y_ += vy_ * speed_ * frameFactor;
|
||||
// DeltaTime puro: velocidad (pixels/ms) * tempo * tiempo (ms)
|
||||
y_ += vy_ * game_tempo_ * deltaTime;
|
||||
|
||||
if (shouldCheckTopCollision()) {
|
||||
handleTopCollision();
|
||||
@@ -219,15 +217,8 @@ void Balloon::handleBottomCollision() {
|
||||
}
|
||||
|
||||
void Balloon::applyGravity(float deltaTime) {
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
|
||||
travel_y_ += speed_ * frameFactor;
|
||||
|
||||
if (travel_y_ >= 1.0F) {
|
||||
travel_y_ -= 1.0F;
|
||||
vy_ += gravity_;
|
||||
}
|
||||
// DeltaTime puro: aceleración (pixels/ms²) * tempo * tiempo (ms)
|
||||
vy_ += gravity_ * game_tempo_ * deltaTime;
|
||||
}
|
||||
|
||||
void Balloon::playBouncingSound() {
|
||||
@@ -250,9 +241,8 @@ void Balloon::update(float deltaTime) {
|
||||
shiftSprite();
|
||||
shiftColliders();
|
||||
sprite_->update(deltaTime);
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
counter_ += frameFactor;
|
||||
// Contador interno con deltaTime puro
|
||||
counter_ += deltaTime;
|
||||
}
|
||||
|
||||
// Actualiza los estados del globo (time-based)
|
||||
@@ -264,17 +254,14 @@ void Balloon::updateState(float deltaTime) {
|
||||
setInvulnerable(true);
|
||||
|
||||
if (creation_counter_ > 0) {
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
|
||||
// Desplaza lentamente el globo hacia abajo y hacia un lado
|
||||
// Cada 10 frames (aproximadamente cada 166ms a 60fps)
|
||||
movement_accumulator_ += frameFactor;
|
||||
// Cada 166ms (equivalente a 10 frames a 60fps)
|
||||
movement_accumulator_ += deltaTime;
|
||||
|
||||
if (movement_accumulator_ >= 10.0f) {
|
||||
movement_accumulator_ -= 10.0f;
|
||||
if (movement_accumulator_ >= 166.0f) {
|
||||
movement_accumulator_ -= 166.0f;
|
||||
y_++;
|
||||
x_ += vx_;
|
||||
x_ += vx_ * 10.0f; // Movimiento equivalente a 10 frames de velocidad horizontal
|
||||
|
||||
// Comprueba no se salga por los laterales
|
||||
const int MIN_X = play_area_.x;
|
||||
@@ -282,11 +269,11 @@ void Balloon::updateState(float deltaTime) {
|
||||
|
||||
if (x_ < MIN_X || x_ > MAX_X) {
|
||||
// Corrige y cambia el sentido de la velocidad
|
||||
x_ -= vx_;
|
||||
x_ -= vx_ * 10.0f;
|
||||
vx_ = -vx_;
|
||||
}
|
||||
}
|
||||
creation_counter_ -= frameFactor;
|
||||
creation_counter_ -= deltaTime;
|
||||
if (creation_counter_ < 0) creation_counter_ = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user