delta-time: balloon.cpp
delta-time: balloon_manager.cpp delta-time: credits.cpp
This commit is contained in:
@@ -135,7 +135,7 @@ void Balloon::render() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la posición y estados del globo
|
||||
// Actualiza la posición y estados del globo (frame-based)
|
||||
void Balloon::move() {
|
||||
if (isStopped()) {
|
||||
return;
|
||||
@@ -146,6 +146,17 @@ void Balloon::move() {
|
||||
applyGravity();
|
||||
}
|
||||
|
||||
// Actualiza la posición y estados del globo (time-based)
|
||||
void Balloon::move(float deltaTime) {
|
||||
if (isStopped()) {
|
||||
return;
|
||||
}
|
||||
|
||||
handleHorizontalMovement(deltaTime);
|
||||
handleVerticalMovement(deltaTime);
|
||||
applyGravity(deltaTime);
|
||||
}
|
||||
|
||||
void Balloon::handleHorizontalMovement() {
|
||||
x_ += vx_ * speed_;
|
||||
|
||||
@@ -158,6 +169,20 @@ void Balloon::handleHorizontalMovement() {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
const int CLIP = 2;
|
||||
const float MIN_X = play_area_.x - CLIP;
|
||||
const float MAX_X = play_area_.x + play_area_.w - w_ + CLIP;
|
||||
|
||||
if (isOutOfHorizontalBounds(MIN_X, MAX_X)) {
|
||||
handleHorizontalBounce(MIN_X, MAX_X);
|
||||
}
|
||||
}
|
||||
|
||||
void Balloon::handleVerticalMovement() {
|
||||
y_ += vy_ * speed_;
|
||||
|
||||
@@ -168,6 +193,18 @@ void Balloon::handleVerticalMovement() {
|
||||
handleBottomCollision();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (shouldCheckTopCollision()) {
|
||||
handleTopCollision();
|
||||
}
|
||||
|
||||
handleBottomCollision();
|
||||
}
|
||||
|
||||
auto Balloon::isOutOfHorizontalBounds(float min_x, float max_x) const -> bool {
|
||||
return x_ < min_x || x_ > max_x;
|
||||
}
|
||||
@@ -230,6 +267,18 @@ void Balloon::applyGravity() {
|
||||
}
|
||||
}
|
||||
|
||||
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_;
|
||||
}
|
||||
}
|
||||
|
||||
void Balloon::playBouncingSound() {
|
||||
if (sound_.enabled && sound_.bouncing_enabled) {
|
||||
Audio::get()->playSound(sound_.bouncing_file);
|
||||
@@ -242,7 +291,7 @@ void Balloon::playPoppingSound() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza al globo a su posicion, animación y controla los contadores
|
||||
// Actualiza al globo a su posicion, animación y controla los contadores (frame-based)
|
||||
void Balloon::update() {
|
||||
move();
|
||||
updateState();
|
||||
@@ -253,7 +302,20 @@ void Balloon::update() {
|
||||
++counter_;
|
||||
}
|
||||
|
||||
// Actualiza los estados del globo
|
||||
// Actualiza al globo a su posicion, animación y controla los contadores (time-based)
|
||||
void Balloon::update(float deltaTime) {
|
||||
move(deltaTime);
|
||||
updateState(deltaTime);
|
||||
updateBounceEffect();
|
||||
shiftSprite();
|
||||
shiftColliders();
|
||||
sprite_->update(deltaTime);
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
counter_ += frameFactor;
|
||||
}
|
||||
|
||||
// Actualiza los estados del globo (frame-based)
|
||||
void Balloon::updateState() {
|
||||
// Si se está creando
|
||||
if (isBeingCreated()) {
|
||||
@@ -263,7 +325,7 @@ void Balloon::updateState() {
|
||||
|
||||
if (creation_counter_ > 0) {
|
||||
// Desplaza lentamente el globo hacia abajo y hacia un lado
|
||||
if (creation_counter_ % 10 == 0) {
|
||||
if (static_cast<int>(creation_counter_) % 10 == 0) {
|
||||
y_++;
|
||||
x_ += vx_;
|
||||
|
||||
@@ -290,6 +352,51 @@ void Balloon::updateState() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los estados del globo (time-based)
|
||||
void Balloon::updateState(float deltaTime) {
|
||||
// Si se está creando
|
||||
if (isBeingCreated()) {
|
||||
// Actualiza el valor de las variables
|
||||
stop();
|
||||
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;
|
||||
|
||||
if (movement_accumulator_ >= 10.0f) {
|
||||
movement_accumulator_ -= 10.0f;
|
||||
y_++;
|
||||
x_ += vx_;
|
||||
|
||||
// Comprueba no se salga por los laterales
|
||||
const int MIN_X = play_area_.x;
|
||||
const int MAX_X = play_area_.w - w_;
|
||||
|
||||
if (x_ < MIN_X || x_ > MAX_X) {
|
||||
// Corrige y cambia el sentido de la velocidad
|
||||
x_ -= vx_;
|
||||
vx_ = -vx_;
|
||||
}
|
||||
}
|
||||
creation_counter_ -= frameFactor;
|
||||
if (creation_counter_ < 0) creation_counter_ = 0;
|
||||
}
|
||||
|
||||
else {
|
||||
// El contador ha llegado a cero
|
||||
being_created_ = false;
|
||||
start();
|
||||
setInvulnerable(false);
|
||||
setAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establece la animación correspondiente al estado
|
||||
void Balloon::setAnimation() {
|
||||
std::string creating_animation;
|
||||
|
||||
Reference in New Issue
Block a user