eliminats metodes frame-based obsolets
This commit is contained in:
@@ -86,36 +86,6 @@ auto AnimatedSprite::getAnimationIndex(const std::string& name) -> int {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Calcula el frame correspondiente a la animación (frame-based)
|
||||
void AnimatedSprite::animate() {
|
||||
if (animations_[current_animation_].speed == 0 || animations_[current_animation_].paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Calcula el frame actual a partir del contador
|
||||
animations_[current_animation_].current_frame = animations_[current_animation_].counter / animations_[current_animation_].speed;
|
||||
|
||||
// Si alcanza el final de la animación, reinicia el contador de la animación
|
||||
// en función de la variable loop y coloca el nuevo frame
|
||||
if (animations_[current_animation_].current_frame >= animations_[current_animation_].frames.size()) {
|
||||
if (animations_[current_animation_].loop == -1) { // Si no hay loop, deja el último frame
|
||||
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size();
|
||||
animations_[current_animation_].completed = true;
|
||||
} else { // Si hay loop, vuelve al frame indicado
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].current_frame = animations_[current_animation_].loop;
|
||||
}
|
||||
}
|
||||
// En caso contrario
|
||||
else {
|
||||
// Escoge el frame correspondiente de la animación
|
||||
updateSpriteClip();
|
||||
|
||||
// Incrementa el contador de la animacion
|
||||
animations_[current_animation_].counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Calcula el frame correspondiente a la animación (time-based)
|
||||
void AnimatedSprite::animate(float deltaTime) {
|
||||
if (animations_[current_animation_].speed == 0 || animations_[current_animation_].paused) {
|
||||
@@ -196,12 +166,6 @@ void AnimatedSprite::setCurrentAnimation(int index, bool reset) {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto (frame-based)
|
||||
void AnimatedSprite::update() {
|
||||
animate();
|
||||
MovingSprite::update();
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto (time-based)
|
||||
void AnimatedSprite::update(float deltaTime) {
|
||||
animate(deltaTime);
|
||||
|
||||
@@ -56,7 +56,6 @@ class AnimatedSprite : public MovingSprite {
|
||||
~AnimatedSprite() override = default;
|
||||
|
||||
// --- Métodos principales ---
|
||||
void update() override; // Actualiza la animación (frame-based)
|
||||
void update(float deltaTime); // Actualiza la animación (time-based)
|
||||
|
||||
// --- Control de animaciones ---
|
||||
@@ -80,7 +79,6 @@ class AnimatedSprite : public MovingSprite {
|
||||
int current_animation_ = 0; // Índice de la animación activa
|
||||
|
||||
// --- Métodos internos ---
|
||||
void animate(); // Calcula el frame correspondiente a la animación (frame-based)
|
||||
void animate(float deltaTime); // Calcula el frame correspondiente a la animación (time-based)
|
||||
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer& source); // Carga la animación desde un vector de cadenas
|
||||
void processConfigLine(const std::string& line, AnimationConfig& config); // Procesa una línea de configuración
|
||||
|
||||
@@ -125,13 +125,6 @@ void Background::initializeTextures() {
|
||||
SDL_SetTextureAlphaMod(color_texture_, alpha_color_texture_);
|
||||
}
|
||||
|
||||
// Actualiza la lógica del objeto
|
||||
// Actualiza la lógica del objeto (compatibilidad)
|
||||
void Background::update() {
|
||||
constexpr float FRAME_TIME_MS = 1000.0f / 60.0f; // 16.67ms por frame a 60 FPS
|
||||
update(FRAME_TIME_MS);
|
||||
}
|
||||
|
||||
// Actualiza la lógica del objeto
|
||||
void Background::update(float delta_time) {
|
||||
// Actualiza la progresión y calcula transiciones
|
||||
@@ -143,7 +136,7 @@ void Background::update(float delta_time) {
|
||||
updateAlphaColorTexture();
|
||||
|
||||
// Actualiza las nubes
|
||||
updateClouds();
|
||||
updateClouds(delta_time);
|
||||
|
||||
// Calcula el frame de la hierba
|
||||
grass_sprite_->setSpriteClip(0, (10 * (counter_ / 20 % 2)), 320, 10);
|
||||
@@ -321,12 +314,12 @@ void Background::updateCloudsSpeed() {
|
||||
}
|
||||
|
||||
// Actualiza las nubes
|
||||
void Background::updateClouds() {
|
||||
void Background::updateClouds(float deltaTime) {
|
||||
// Mueve las nubes
|
||||
top_clouds_sprite_a_->update();
|
||||
top_clouds_sprite_b_->update();
|
||||
bottom_clouds_sprite_a_->update();
|
||||
bottom_clouds_sprite_b_->update();
|
||||
top_clouds_sprite_a_->update(deltaTime);
|
||||
top_clouds_sprite_b_->update(deltaTime);
|
||||
bottom_clouds_sprite_a_->update(deltaTime);
|
||||
bottom_clouds_sprite_b_->update(deltaTime);
|
||||
|
||||
// Calcula el offset de las nubes
|
||||
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth()) {
|
||||
|
||||
@@ -31,7 +31,6 @@ class Background {
|
||||
~Background(); // Destructor
|
||||
|
||||
// --- Métodos principales ---
|
||||
void update(); // Actualiza la lógica del objeto (compatibilidad)
|
||||
void update(float delta_time); // Actualiza la lógica del objeto
|
||||
void render(); // Dibuja el objeto
|
||||
void reset(); // Reinicia la progresión
|
||||
@@ -130,7 +129,7 @@ class Background {
|
||||
void renderBottomClouds(); // Dibuja las nubes inferiores
|
||||
void fillCanvas(); // Compone todos los elementos en la textura
|
||||
void updateAlphaColorTexture(); // Actualiza el alpha de la textura de atenuación
|
||||
void updateClouds(); // Actualiza el movimiento de las nubes
|
||||
void updateClouds(float deltaTime); // Actualiza el movimiento de las nubes (time-based)
|
||||
void createSunPath(); // Precalcula el recorrido del sol
|
||||
void createMoonPath(); // Precalcula el recorrido de la luna
|
||||
};
|
||||
@@ -135,17 +135,6 @@ void Balloon::render() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la posición y estados del globo (frame-based)
|
||||
void Balloon::move() {
|
||||
if (isStopped()) {
|
||||
return;
|
||||
}
|
||||
|
||||
handleHorizontalMovement();
|
||||
handleVerticalMovement();
|
||||
applyGravity();
|
||||
}
|
||||
|
||||
// Actualiza la posición y estados del globo (time-based)
|
||||
void Balloon::move(float deltaTime) {
|
||||
if (isStopped()) {
|
||||
@@ -157,18 +146,6 @@ void Balloon::move(float deltaTime) {
|
||||
applyGravity(deltaTime);
|
||||
}
|
||||
|
||||
void Balloon::handleHorizontalMovement() {
|
||||
x_ += vx_ * speed_;
|
||||
|
||||
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::handleHorizontalMovement(float deltaTime) {
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
@@ -183,16 +160,6 @@ void Balloon::handleHorizontalMovement(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void Balloon::handleVerticalMovement() {
|
||||
y_ += vy_ * speed_;
|
||||
|
||||
if (shouldCheckTopCollision()) {
|
||||
handleTopCollision();
|
||||
}
|
||||
|
||||
handleBottomCollision();
|
||||
}
|
||||
|
||||
void Balloon::handleVerticalMovement(float deltaTime) {
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
@@ -251,22 +218,6 @@ void Balloon::handleBottomCollision() {
|
||||
}
|
||||
}
|
||||
|
||||
void Balloon::applyGravity() {
|
||||
/*
|
||||
Para aplicar la gravedad, el diseño original la aplicaba en cada iteración del bucle
|
||||
Al añadir el modificador de velocidad se reduce la distancia que recorre el objeto y por
|
||||
tanto recibe mas gravedad. Para solucionarlo se va a aplicar la gravedad cuando se haya
|
||||
recorrido una distancia igual a la velocidad en Y, que era el cálculo inicial
|
||||
*/
|
||||
|
||||
travel_y_ += speed_;
|
||||
|
||||
if (travel_y_ >= 1.0F) {
|
||||
travel_y_ -= 1.0F;
|
||||
vy_ += gravity_;
|
||||
}
|
||||
}
|
||||
|
||||
void Balloon::applyGravity(float deltaTime) {
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
@@ -291,17 +242,6 @@ void Balloon::playPoppingSound() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza al globo a su posicion, animación y controla los contadores (frame-based)
|
||||
void Balloon::update() {
|
||||
move();
|
||||
updateState();
|
||||
updateBounceEffect();
|
||||
shiftSprite();
|
||||
shiftColliders();
|
||||
sprite_->update();
|
||||
++counter_;
|
||||
}
|
||||
|
||||
// Actualiza al globo a su posicion, animación y controla los contadores (time-based)
|
||||
void Balloon::update(float deltaTime) {
|
||||
move(deltaTime);
|
||||
@@ -315,43 +255,6 @@ void Balloon::update(float deltaTime) {
|
||||
counter_ += frameFactor;
|
||||
}
|
||||
|
||||
// Actualiza los estados del globo (frame-based)
|
||||
void Balloon::updateState() {
|
||||
// Si se está creando
|
||||
if (isBeingCreated()) {
|
||||
// Actualiza el valor de las variables
|
||||
stop();
|
||||
setInvulnerable(true);
|
||||
|
||||
if (creation_counter_ > 0) {
|
||||
// Desplaza lentamente el globo hacia abajo y hacia un lado
|
||||
if (static_cast<int>(creation_counter_) % 10 == 0) {
|
||||
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_;
|
||||
}
|
||||
|
||||
else {
|
||||
// El contador ha llegado a cero
|
||||
being_created_ = false;
|
||||
start();
|
||||
setInvulnerable(false);
|
||||
setAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los estados del globo (time-based)
|
||||
void Balloon::updateState(float deltaTime) {
|
||||
// Si se está creando
|
||||
|
||||
@@ -89,9 +89,7 @@ class Balloon {
|
||||
// --- Métodos principales ---
|
||||
void alignTo(int x); // Centra el globo en la posición X
|
||||
void render(); // Pinta el globo en la pantalla
|
||||
void move(); // Actualiza la posición y estados del globo (frame-based)
|
||||
void move(float deltaTime); // Actualiza la posición y estados del globo (time-based)
|
||||
void update(); // Actualiza el globo (posición, animación, contadores) (frame-based)
|
||||
void update(float deltaTime); // Actualiza el globo (posición, animación, contadores) (time-based)
|
||||
void stop(); // Detiene el globo
|
||||
void start(); // Pone el globo en movimiento
|
||||
@@ -283,11 +281,8 @@ class Balloon {
|
||||
void playPoppingSound(); // Reproduce el sonido de reventar
|
||||
|
||||
// --- Movimiento y física ---
|
||||
void handleHorizontalMovement(); // Maneja el movimiento horizontal (frame-based)
|
||||
void handleHorizontalMovement(float deltaTime); // Maneja el movimiento horizontal (time-based)
|
||||
void handleVerticalMovement(); // Maneja el movimiento vertical (frame-based)
|
||||
void handleVerticalMovement(float deltaTime); // Maneja el movimiento vertical (time-based)
|
||||
void applyGravity(); // Aplica la gravedad al objeto (frame-based)
|
||||
void applyGravity(float deltaTime); // Aplica la gravedad al objeto (time-based)
|
||||
|
||||
// --- Rebote ---
|
||||
@@ -303,6 +298,5 @@ class Balloon {
|
||||
void handleBottomCollision(); // Maneja la colisión inferior
|
||||
|
||||
// --- Lógica de estado ---
|
||||
void updateState(); // Actualiza los estados del globo (frame-based)
|
||||
void updateState(float deltaTime); // Actualiza los estados del globo (time-based)
|
||||
};
|
||||
@@ -62,15 +62,6 @@ void BalloonManager::init() {
|
||||
explosions_->addTexture(3, explosions_textures_.at(3), explosions_animations_.at(3));
|
||||
}
|
||||
|
||||
// Actualiza (frame-based)
|
||||
void BalloonManager::update() {
|
||||
for (const auto &balloon : balloons_) {
|
||||
balloon->update();
|
||||
}
|
||||
updateBalloonDeployCounter();
|
||||
explosions_->update();
|
||||
}
|
||||
|
||||
// Actualiza (time-based)
|
||||
void BalloonManager::update(float deltaTime) {
|
||||
for (const auto &balloon : balloons_) {
|
||||
@@ -171,13 +162,6 @@ void BalloonManager::freeBalloons() {
|
||||
balloons_.erase(result.begin(), balloons_.end());
|
||||
}
|
||||
|
||||
// Actualiza la variable enemyDeployCounter (frame-based)
|
||||
void BalloonManager::updateBalloonDeployCounter() {
|
||||
if (balloon_deploy_counter_ > 0) {
|
||||
--balloon_deploy_counter_;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la variable enemyDeployCounter (time-based)
|
||||
void BalloonManager::updateBalloonDeployCounter(float deltaTime) {
|
||||
if (balloon_deploy_counter_ > 0) {
|
||||
|
||||
@@ -28,7 +28,6 @@ class BalloonManager {
|
||||
~BalloonManager() = default;
|
||||
|
||||
// --- Métodos principales ---
|
||||
void update(); // Actualiza el estado de los globos (frame-based)
|
||||
void update(float deltaTime); // Actualiza el estado de los globos (time-based)
|
||||
void render(); // Renderiza los globos en pantalla
|
||||
|
||||
@@ -50,7 +49,6 @@ class BalloonManager {
|
||||
void setBalloonSpeed(float speed); // Ajusta la velocidad de los globos
|
||||
void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; }; // Establece la velocidad base
|
||||
void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); }; // Restablece la velocidad de los globos
|
||||
void updateBalloonDeployCounter(); // Actualiza el contador de despliegue (frame-based)
|
||||
void updateBalloonDeployCounter(float deltaTime); // Actualiza el contador de despliegue (time-based)
|
||||
auto canPowerBallBeCreated() -> bool; // Indica si se puede crear una PowerBall
|
||||
auto calculateScreenPower() -> int; // Calcula el poder de los globos en pantalla
|
||||
|
||||
@@ -60,38 +60,12 @@ void Bullet::render() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado del objeto (frame-based)
|
||||
auto Bullet::update() -> BulletMoveStatus {
|
||||
sprite_->update();
|
||||
return move();
|
||||
}
|
||||
|
||||
// Actualiza el estado del objeto (time-based)
|
||||
auto Bullet::update(float deltaTime) -> BulletMoveStatus {
|
||||
sprite_->update(deltaTime);
|
||||
return move(deltaTime);
|
||||
}
|
||||
|
||||
// Implementación del movimiento usando BulletMoveStatus (frame-based)
|
||||
auto Bullet::move() -> BulletMoveStatus {
|
||||
pos_x_ += vel_x_;
|
||||
if (pos_x_ < param.game.play_area.rect.x - WIDTH || pos_x_ > param.game.play_area.rect.w) {
|
||||
disable();
|
||||
return BulletMoveStatus::OUT;
|
||||
}
|
||||
|
||||
pos_y_ += VEL_Y;
|
||||
if (pos_y_ < param.game.play_area.rect.y - HEIGHT) {
|
||||
disable();
|
||||
return BulletMoveStatus::OUT;
|
||||
}
|
||||
|
||||
shiftSprite();
|
||||
shiftColliders();
|
||||
|
||||
return BulletMoveStatus::OK;
|
||||
}
|
||||
|
||||
// Implementación del movimiento usando BulletMoveStatus (time-based)
|
||||
auto Bullet::move(float deltaTime) -> BulletMoveStatus {
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
|
||||
@@ -35,7 +35,6 @@ class Bullet {
|
||||
|
||||
// --- Métodos principales ---
|
||||
void render(); // Dibuja la bala en pantalla
|
||||
auto update() -> BulletMoveStatus; // Actualiza el estado del objeto (frame-based)
|
||||
auto update(float deltaTime) -> BulletMoveStatus; // Actualiza el estado del objeto (time-based)
|
||||
void disable(); // Desactiva la bala
|
||||
|
||||
@@ -65,7 +64,6 @@ class Bullet {
|
||||
// --- Métodos internos ---
|
||||
void shiftColliders(); // Ajusta el círculo de colisión
|
||||
void shiftSprite(); // Ajusta el sprite
|
||||
auto move() -> BulletMoveStatus; // Mueve la bala y devuelve su estado (frame-based)
|
||||
auto move(float deltaTime) -> BulletMoveStatus; // Mueve la bala y devuelve su estado (time-based)
|
||||
static auto calculateVelocity(BulletType bullet_type) -> float; // Calcula la velocidad horizontal de la bala
|
||||
static auto buildAnimationString(BulletType bullet_type, bool powered) -> std::string; // Construye el string de animación
|
||||
|
||||
@@ -6,16 +6,6 @@
|
||||
|
||||
class Texture; // lines 4-4
|
||||
|
||||
// Actualiza la lógica de la clase (frame-based)
|
||||
void Explosions::update() {
|
||||
for (auto &explosion : explosions_) {
|
||||
explosion->update();
|
||||
}
|
||||
|
||||
// Vacia el vector de elementos finalizados
|
||||
freeExplosions();
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase (time-based)
|
||||
void Explosions::update(float deltaTime) {
|
||||
for (auto &explosion : explosions_) {
|
||||
|
||||
@@ -29,7 +29,6 @@ class Explosions {
|
||||
~Explosions() = default; // Destructor por defecto
|
||||
|
||||
// --- Métodos principales ---
|
||||
void update(); // Actualiza la lógica de la clase (frame-based)
|
||||
void update(float deltaTime); // Actualiza la lógica de la clase (time-based)
|
||||
void render(); // Dibuja el objeto en pantalla
|
||||
|
||||
|
||||
@@ -113,13 +113,6 @@ void GameLogo::render() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase (frame-based)
|
||||
void GameLogo::update() {
|
||||
updateCoffeeCrisis();
|
||||
updateArcadeEdition();
|
||||
updatePostFinishedCounter();
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase (time-based)
|
||||
void GameLogo::update(float deltaTime) {
|
||||
updateCoffeeCrisis(deltaTime);
|
||||
@@ -127,22 +120,6 @@ void GameLogo::update(float deltaTime) {
|
||||
updatePostFinishedCounter(deltaTime);
|
||||
}
|
||||
|
||||
void GameLogo::updateCoffeeCrisis() {
|
||||
switch (coffee_crisis_status_) {
|
||||
case Status::MOVING:
|
||||
handleCoffeeCrisisMoving();
|
||||
break;
|
||||
case Status::SHAKING:
|
||||
handleCoffeeCrisisShaking();
|
||||
break;
|
||||
case Status::FINISHED:
|
||||
handleCoffeeCrisisFinished();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::updateCoffeeCrisis(float deltaTime) {
|
||||
switch (coffee_crisis_status_) {
|
||||
case Status::MOVING:
|
||||
@@ -159,19 +136,6 @@ void GameLogo::updateCoffeeCrisis(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::updateArcadeEdition() {
|
||||
switch (arcade_edition_status_) {
|
||||
case Status::MOVING:
|
||||
handleArcadeEditionMoving();
|
||||
break;
|
||||
case Status::SHAKING:
|
||||
handleArcadeEditionShaking();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::updateArcadeEdition(float deltaTime) {
|
||||
switch (arcade_edition_status_) {
|
||||
case Status::MOVING:
|
||||
@@ -185,16 +149,6 @@ void GameLogo::updateArcadeEdition(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisMoving() {
|
||||
coffee_sprite_->update();
|
||||
crisis_sprite_->update();
|
||||
|
||||
if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished()) {
|
||||
coffee_crisis_status_ = Status::SHAKING;
|
||||
playTitleEffects();
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisMoving(float deltaTime) {
|
||||
coffee_sprite_->update(deltaTime);
|
||||
crisis_sprite_->update(deltaTime);
|
||||
@@ -205,16 +159,6 @@ void GameLogo::handleCoffeeCrisisMoving(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisShaking() {
|
||||
if (shake_.remaining > 0) {
|
||||
processShakeEffect(coffee_sprite_.get(), crisis_sprite_.get());
|
||||
} else {
|
||||
finishCoffeeCrisisShaking();
|
||||
}
|
||||
|
||||
updateDustSprites();
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisShaking(float deltaTime) {
|
||||
if (shake_.remaining > 0) {
|
||||
processShakeEffect(coffee_sprite_.get(), crisis_sprite_.get(), deltaTime);
|
||||
@@ -225,23 +169,10 @@ void GameLogo::handleCoffeeCrisisShaking(float deltaTime) {
|
||||
updateDustSprites(deltaTime);
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisFinished() {
|
||||
updateDustSprites();
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisFinished(float deltaTime) {
|
||||
updateDustSprites(deltaTime);
|
||||
}
|
||||
|
||||
void GameLogo::handleArcadeEditionMoving() {
|
||||
zoom_ -= 0.1F * ZOOM_FACTOR;
|
||||
arcade_edition_sprite_->setZoom(zoom_);
|
||||
|
||||
if (zoom_ <= 1.0F) {
|
||||
finishArcadeEditionMoving();
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleArcadeEditionMoving(float deltaTime) {
|
||||
// Convertir 0.1F * ZOOM_FACTOR por frame a por milisegundo (asumiendo 60fps)
|
||||
zoom_ -= (0.1F * ZOOM_FACTOR) * deltaTime / (1000.0F / 60.0F);
|
||||
@@ -252,15 +183,6 @@ void GameLogo::handleArcadeEditionMoving(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleArcadeEditionShaking() {
|
||||
if (shake_.remaining > 0) {
|
||||
processArcadeEditionShake();
|
||||
} else {
|
||||
arcade_edition_sprite_->setX(shake_.origin);
|
||||
arcade_edition_status_ = Status::FINISHED;
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleArcadeEditionShaking(float deltaTime) {
|
||||
if (shake_.remaining > 0) {
|
||||
processArcadeEditionShake(deltaTime);
|
||||
@@ -301,17 +223,6 @@ void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* seco
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::processArcadeEditionShake() {
|
||||
if (shake_.counter > 0) {
|
||||
shake_.counter--;
|
||||
} else {
|
||||
shake_.counter = shake_.delay;
|
||||
const auto DISPLACEMENT = calculateShakeDisplacement();
|
||||
arcade_edition_sprite_->setX(shake_.origin + DISPLACEMENT);
|
||||
shake_.remaining--;
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::processArcadeEditionShake(float deltaTime) {
|
||||
// Convertir delay (frames) a tiempo: delay frames = delay * (1000ms/60fps)
|
||||
float delayTime = static_cast<float>(shake_.delay) * (1000.0f / 60.0f);
|
||||
@@ -351,24 +262,11 @@ void GameLogo::playTitleEffects() {
|
||||
Screen::get()->shake();
|
||||
}
|
||||
|
||||
void GameLogo::updateDustSprites() {
|
||||
dust_right_sprite_->update();
|
||||
dust_left_sprite_->update();
|
||||
}
|
||||
|
||||
void GameLogo::updateDustSprites(float deltaTime) {
|
||||
dust_right_sprite_->update(deltaTime);
|
||||
dust_left_sprite_->update(deltaTime);
|
||||
}
|
||||
|
||||
void GameLogo::updatePostFinishedCounter() {
|
||||
if (coffee_crisis_status_ == Status::FINISHED &&
|
||||
arcade_edition_status_ == Status::FINISHED &&
|
||||
post_finished_counter_ > 0) {
|
||||
--post_finished_counter_;
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::updatePostFinishedCounter(float deltaTime) {
|
||||
if (coffee_crisis_status_ == Status::FINISHED &&
|
||||
arcade_edition_status_ == Status::FINISHED &&
|
||||
|
||||
@@ -17,7 +17,6 @@ class GameLogo {
|
||||
|
||||
// --- Métodos principales ---
|
||||
void render(); // Pinta la clase en pantalla
|
||||
void update(); // Actualiza la lógica de la clase (frame-based)
|
||||
void update(float deltaTime); // Actualiza la lógica de la clase (time-based)
|
||||
void enable(); // Activa la clase
|
||||
|
||||
@@ -90,36 +89,26 @@ class GameLogo {
|
||||
[[nodiscard]] auto getInitialVerticalDesp() const -> int; // Calcula el desplazamiento vertical inicial
|
||||
|
||||
// --- Actualización de estados específicos ---
|
||||
void updateCoffeeCrisis(); // Actualiza el estado de "Coffee Crisis" (frame-based)
|
||||
void updateCoffeeCrisis(float deltaTime); // Actualiza el estado de "Coffee Crisis" (time-based)
|
||||
void updateArcadeEdition(); // Actualiza el estado de "Arcade Edition" (frame-based)
|
||||
void updateArcadeEdition(float deltaTime); // Actualiza el estado de "Arcade Edition" (time-based)
|
||||
void updatePostFinishedCounter(); // Actualiza el contador tras finalizar una animación (frame-based)
|
||||
void updatePostFinishedCounter(float deltaTime); // Actualiza el contador tras finalizar una animación (time-based)
|
||||
|
||||
// --- Efectos visuales: movimiento y sacudidas ---
|
||||
void handleCoffeeCrisisMoving(); // Maneja el movimiento de "Coffee Crisis" (frame-based)
|
||||
void handleCoffeeCrisisMoving(float deltaTime); // Maneja el movimiento de "Coffee Crisis" (time-based)
|
||||
void handleCoffeeCrisisShaking(); // Maneja la sacudida de "Coffee Crisis" (frame-based)
|
||||
void handleCoffeeCrisisShaking(float deltaTime); // Maneja la sacudida de "Coffee Crisis" (time-based)
|
||||
void handleArcadeEditionMoving(); // Maneja el movimiento de "Arcade Edition" (frame-based)
|
||||
void handleArcadeEditionMoving(float deltaTime); // Maneja el movimiento de "Arcade Edition" (time-based)
|
||||
void handleArcadeEditionShaking(); // Maneja la sacudida de "Arcade Edition" (frame-based)
|
||||
void handleArcadeEditionShaking(float deltaTime); // Maneja la sacudida de "Arcade Edition" (time-based)
|
||||
void processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite = nullptr); // Procesa el efecto de sacudida en sprites (frame-based)
|
||||
void processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite, float deltaTime); // Procesa el efecto de sacudida en sprites (time-based)
|
||||
void processArcadeEditionShake(); // Procesa la sacudida específica de "Arcade Edition" (frame-based)
|
||||
void processArcadeEditionShake(float deltaTime); // Procesa la sacudida específica de "Arcade Edition" (time-based)
|
||||
[[nodiscard]] auto calculateShakeDisplacement() const -> int; // Calcula el desplazamiento de la sacudida
|
||||
|
||||
// --- Gestión de finalización de efectos ---
|
||||
void handleCoffeeCrisisFinished(); // Maneja el final de la animación "Coffee Crisis" (frame-based)
|
||||
void handleCoffeeCrisisFinished(float deltaTime); // Maneja el final de la animación "Coffee Crisis" (time-based)
|
||||
void finishCoffeeCrisisShaking(); // Finaliza la sacudida de "Coffee Crisis"
|
||||
void finishArcadeEditionMoving(); // Finaliza el movimiento de "Arcade Edition"
|
||||
|
||||
// --- Utilidades ---
|
||||
static void playTitleEffects(); // Reproduce efectos visuales/sonoros del título
|
||||
void updateDustSprites(); // Actualiza los sprites de polvo (frame-based)
|
||||
void updateDustSprites(float deltaTime); // Actualiza los sprites de polvo (time-based)
|
||||
};
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,16 +29,17 @@ class Item {
|
||||
// --- Constantes ---
|
||||
static constexpr int COFFEE_MACHINE_WIDTH = 30; // Anchura de la máquina de café
|
||||
static constexpr int COFFEE_MACHINE_HEIGHT = 39; // Altura de la máquina de café
|
||||
static constexpr float LIFETIME_DURATION_MS = 10000.0f; // Duración de vida del ítem (600 frames a 60fps)
|
||||
|
||||
// --- Constructor y destructor ---
|
||||
Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::shared_ptr<Texture> &texture, const std::vector<std::string> &animation); // Constructor principal
|
||||
~Item() = default; // Destructor
|
||||
|
||||
// --- Métodos principales ---
|
||||
void alignTo(int x); // Centra el objeto en la posición X indicada
|
||||
void render(); // Renderiza el objeto en pantalla
|
||||
void disable(); // Desactiva el objeto
|
||||
void update(); // Actualiza la posición, animación y contadores
|
||||
void alignTo(int x); // Centra el objeto en la posición X indicada
|
||||
void render(); // Renderiza el objeto en pantalla
|
||||
void disable(); // Desactiva el objeto
|
||||
void update(float deltaTime); // Actualiza la posición, animación y contadores (time-based)
|
||||
|
||||
// --- Getters ---
|
||||
[[nodiscard]] auto getPosX() const -> float { return pos_x_; } // Obtiene la posición X
|
||||
@@ -66,14 +67,14 @@ class Item {
|
||||
float accel_y_; // Aceleración en el eje Y
|
||||
int width_; // Ancho del objeto
|
||||
int height_; // Alto del objeto
|
||||
Uint16 time_to_live_ = 600; // Tiempo que el objeto está presente
|
||||
float lifetime_timer_ = 0.0f; // Acumulador de tiempo de vida del ítem (milisegundos)
|
||||
bool floor_collision_ = false; // Indica si el objeto colisiona con el suelo
|
||||
bool enabled_ = true; // Indica si el objeto está habilitado
|
||||
|
||||
// --- Métodos internos ---
|
||||
void shiftColliders(); // Alinea el círculo de colisión con la posición del objeto
|
||||
void shiftSprite(); // Coloca el sprite en la posición del objeto
|
||||
void move(); // Actualiza la posición y estados del objeto
|
||||
void updateTimeToLive(); // Actualiza el contador de tiempo de vida
|
||||
void move(float deltaTime); // Actualiza la posición y estados del objeto (time-based)
|
||||
void updateTimeToLive(float deltaTime); // Actualiza el contador de tiempo de vida (time-based)
|
||||
static auto getCoffeeMachineSpawn(int player_x, int item_width, int area_width, int margin = 2) -> int; // Calcula la zona de aparición de la máquina de café
|
||||
};
|
||||
|
||||
@@ -53,18 +53,6 @@ void MovingSprite::stop() {
|
||||
flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
||||
}
|
||||
|
||||
// Mueve el sprite (frame-based)
|
||||
void MovingSprite::move() {
|
||||
x_ += vx_;
|
||||
y_ += vy_;
|
||||
|
||||
vx_ += ax_;
|
||||
vy_ += ay_;
|
||||
|
||||
pos_.x = static_cast<int>(x_);
|
||||
pos_.y = static_cast<int>(y_);
|
||||
}
|
||||
|
||||
// Mueve el sprite (time-based)
|
||||
void MovingSprite::move(float deltaTime) {
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
@@ -80,12 +68,6 @@ void MovingSprite::move(float deltaTime) {
|
||||
pos_.y = static_cast<int>(y_);
|
||||
}
|
||||
|
||||
// Actualiza las variables internas del objeto (frame-based)
|
||||
void MovingSprite::update() {
|
||||
move();
|
||||
rotate();
|
||||
}
|
||||
|
||||
// Actualiza las variables internas del objeto (time-based)
|
||||
void MovingSprite::update(float deltaTime) {
|
||||
move(deltaTime);
|
||||
@@ -97,17 +79,6 @@ void MovingSprite::render() {
|
||||
getTexture()->render(pos_.x, pos_.y, &sprite_clip_, horizontal_zoom_, vertical_zoom_, rotate_.angle, &rotate_.center, flip_);
|
||||
}
|
||||
|
||||
// Establece la rotacion (frame-based)
|
||||
void MovingSprite::rotate() {
|
||||
if (rotate_.enabled) {
|
||||
++rotate_.counter;
|
||||
if (rotate_.counter % rotate_.speed == 0) {
|
||||
updateAngle();
|
||||
rotate_.counter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establece la rotacion (time-based)
|
||||
void MovingSprite::rotate(float deltaTime) {
|
||||
if (rotate_.enabled) {
|
||||
|
||||
@@ -29,7 +29,6 @@ class MovingSprite : public Sprite {
|
||||
~MovingSprite() override = default;
|
||||
|
||||
// --- Métodos principales ---
|
||||
virtual void update(); // Actualiza las variables internas del objeto (frame-based)
|
||||
virtual void update(float deltaTime); // Actualiza las variables internas del objeto (time-based)
|
||||
void clear() override; // Reinicia todas las variables a cero
|
||||
void stop(); // Elimina el movimiento del sprite
|
||||
@@ -80,8 +79,6 @@ class MovingSprite : public Sprite {
|
||||
|
||||
// --- Métodos internos ---
|
||||
void updateAngle() { rotate_.angle += rotate_.amount; } // Incrementa el valor del ángulo
|
||||
void move(); // Mueve el sprite según velocidad y aceleración (frame-based)
|
||||
void move(float deltaTime); // Mueve el sprite según velocidad y aceleración (time-based)
|
||||
void rotate(); // Rota el sprite según los parámetros de rotación (frame-based)
|
||||
void rotate(float deltaTime); // Rota el sprite según los parámetros de rotación (time-based)
|
||||
};
|
||||
@@ -149,41 +149,6 @@ void Player::setInputEnteringName(Input::Action action) {
|
||||
name_entry_idle_time_accumulator_ = 0.0f;
|
||||
}
|
||||
|
||||
// Mueve el jugador a la posición y animación que le corresponde
|
||||
void Player::move() {
|
||||
switch (playing_state_) {
|
||||
case State::PLAYING:
|
||||
handlePlayingMovement();
|
||||
break;
|
||||
case State::ROLLING:
|
||||
handleRollingMovement();
|
||||
break;
|
||||
case State::TITLE_ANIMATION:
|
||||
handleTitleAnimation();
|
||||
break;
|
||||
case State::CONTINUE_TIME_OUT:
|
||||
handleContinueTimeOut();
|
||||
break;
|
||||
case State::LEAVING_SCREEN:
|
||||
handleLeavingScreen();
|
||||
break;
|
||||
case State::ENTERING_SCREEN:
|
||||
handleEnteringScreen();
|
||||
break;
|
||||
case State::CREDITS:
|
||||
handleCreditsMovement();
|
||||
break;
|
||||
case State::WAITING:
|
||||
handleWaitingMovement();
|
||||
break;
|
||||
case State::RECOVER:
|
||||
handleRecoverMovement();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 1: Sistema de movimiento time-based
|
||||
void Player::move(float deltaTime) {
|
||||
switch (playing_state_) {
|
||||
@@ -191,28 +156,28 @@ void Player::move(float deltaTime) {
|
||||
handlePlayingMovement(deltaTime);
|
||||
break;
|
||||
case State::ROLLING:
|
||||
handleRollingMovement(); // Usa MovingSprite que ya soporta deltaTime
|
||||
handleRollingMovement();
|
||||
break;
|
||||
case State::TITLE_ANIMATION:
|
||||
handleTitleAnimation(); // Sin cambios - usa solo animaciones
|
||||
handleTitleAnimation();
|
||||
break;
|
||||
case State::CONTINUE_TIME_OUT:
|
||||
handleContinueTimeOut(); // Sin cambios - usa MovingSprite que ya soporta deltaTime
|
||||
handleContinueTimeOut();
|
||||
break;
|
||||
case State::LEAVING_SCREEN:
|
||||
handleLeavingScreen(); // Sin cambios - usa MovingSprite que ya soporta deltaTime
|
||||
handleLeavingScreen();
|
||||
break;
|
||||
case State::ENTERING_SCREEN:
|
||||
handleEnteringScreen(); // Sin cambios - usa MovingSprite que ya soporta deltaTime
|
||||
handleEnteringScreen();
|
||||
break;
|
||||
case State::CREDITS:
|
||||
handleCreditsMovement(deltaTime); // Fase 4: Sistema de créditos time-based
|
||||
handleCreditsMovement(deltaTime);
|
||||
break;
|
||||
case State::WAITING:
|
||||
handleWaitingMovement(deltaTime); // Fase 4: Sistema de waiting time-based
|
||||
handleWaitingMovement(deltaTime);
|
||||
break;
|
||||
case State::RECOVER:
|
||||
handleRecoverMovement(); // Sin cambios - usa AnimatedSprite que ya soporta deltaTime
|
||||
handleRecoverMovement();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -548,47 +513,6 @@ auto Player::computeAnimation() const -> std::pair<std::string, SDL_FlipMode> {
|
||||
return {anim_name, flip_mode};
|
||||
}
|
||||
|
||||
// Establece la animación correspondiente al estado (frame-based)
|
||||
void Player::setAnimation() {
|
||||
switch (playing_state_) {
|
||||
case State::PLAYING:
|
||||
case State::ENTERING_NAME_GAME_COMPLETED:
|
||||
case State::ENTERING_SCREEN:
|
||||
case State::LEAVING_SCREEN:
|
||||
case State::TITLE_ANIMATION:
|
||||
case State::CREDITS: {
|
||||
auto [animName, flipMode] = computeAnimation();
|
||||
player_sprite_->setCurrentAnimation(animName, false);
|
||||
player_sprite_->setFlip(flipMode);
|
||||
break;
|
||||
}
|
||||
case State::RECOVER:
|
||||
player_sprite_->setCurrentAnimation("recover");
|
||||
break;
|
||||
case State::WAITING:
|
||||
case State::GAME_OVER:
|
||||
player_sprite_->setCurrentAnimation("hello");
|
||||
break;
|
||||
case State::ROLLING:
|
||||
case State::CONTINUE_TIME_OUT:
|
||||
player_sprite_->setCurrentAnimation("rolling");
|
||||
break;
|
||||
case State::LYING_ON_THE_FLOOR_FOREVER:
|
||||
case State::ENTERING_NAME:
|
||||
case State::CONTINUE:
|
||||
player_sprite_->setCurrentAnimation("dizzy");
|
||||
break;
|
||||
case State::CELEBRATING:
|
||||
player_sprite_->setCurrentAnimation("celebration");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
player_sprite_->update();
|
||||
power_sprite_->update();
|
||||
}
|
||||
|
||||
// Fase 1: Establece la animación correspondiente al estado (time-based)
|
||||
void Player::setAnimation(float deltaTime) {
|
||||
switch (playing_state_) {
|
||||
|
||||
@@ -118,9 +118,7 @@ class Player {
|
||||
void setInputEnteringName(Input::Action action); // Procesa entrada al introducir nombre
|
||||
|
||||
// --- Movimiento y animación ---
|
||||
void move(); // Mueve el jugador (frame-based)
|
||||
void move(float deltaTime); // Mueve el jugador (time-based)
|
||||
void setAnimation(); // Establece la animación según el estado (frame-based)
|
||||
void setAnimation(float deltaTime); // Establece la animación según el estado (time-based)
|
||||
|
||||
// --- Texturas y animaciones ---
|
||||
|
||||
@@ -316,12 +316,12 @@ void Game::updateGameStateGameOver(float deltaTime) {
|
||||
fade_out_->update();
|
||||
updatePlayers(deltaTime);
|
||||
updateScoreboard();
|
||||
updateBackground();
|
||||
balloon_manager_->update();
|
||||
tabe_->update();
|
||||
updateBullets();
|
||||
updateItems();
|
||||
updateSmartSprites();
|
||||
updateBackground(deltaTime);
|
||||
balloon_manager_->update(deltaTime);
|
||||
tabe_->update(deltaTime);
|
||||
updateBullets(deltaTime);
|
||||
updateItems(deltaTime);
|
||||
updateSmartSprites(deltaTime);
|
||||
updatePathSprites();
|
||||
updateTimeStopped(deltaTime);
|
||||
checkBulletCollision();
|
||||
@@ -363,12 +363,12 @@ void Game::updateGameStateGameOver(float deltaTime) {
|
||||
void Game::updateGameStateCompleted(float deltaTime) {
|
||||
updatePlayers(deltaTime);
|
||||
updateScoreboard();
|
||||
updateBackground();
|
||||
balloon_manager_->update();
|
||||
tabe_->update();
|
||||
updateBullets();
|
||||
updateItems();
|
||||
updateSmartSprites();
|
||||
updateBackground(deltaTime);
|
||||
balloon_manager_->update(deltaTime);
|
||||
tabe_->update(deltaTime);
|
||||
updateBullets(deltaTime);
|
||||
updateItems(deltaTime);
|
||||
updateSmartSprites(deltaTime);
|
||||
updatePathSprites();
|
||||
cleanVectors();
|
||||
|
||||
@@ -597,9 +597,9 @@ void Game::handleBalloonDestruction(std::shared_ptr<Balloon> balloon, const std:
|
||||
}
|
||||
|
||||
// Mueve las balas activas
|
||||
void Game::updateBullets() {
|
||||
void Game::updateBullets(float deltaTime) {
|
||||
for (auto &bullet : bullets_) {
|
||||
if (bullet->update() == BulletMoveStatus::OUT) {
|
||||
if (bullet->update(deltaTime) == BulletMoveStatus::OUT) {
|
||||
getPlayer(bullet->getOwner())->decScoreMultiplier();
|
||||
}
|
||||
}
|
||||
@@ -629,10 +629,10 @@ void Game::freeBullets() {
|
||||
}
|
||||
|
||||
// Actualiza los items
|
||||
void Game::updateItems() {
|
||||
void Game::updateItems(float deltaTime) {
|
||||
for (auto &item : items_) {
|
||||
if (item->isEnabled()) {
|
||||
item->update();
|
||||
item->update(deltaTime);
|
||||
if (item->isOnFloor()) {
|
||||
playSound("title.wav");
|
||||
screen_->shake(1, 2, 4);
|
||||
@@ -799,9 +799,9 @@ void Game::throwCoffee(int x, int y) {
|
||||
}
|
||||
|
||||
// Actualiza los SmartSprites
|
||||
void Game::updateSmartSprites() {
|
||||
void Game::updateSmartSprites(float deltaTime) {
|
||||
for (auto &sprite : smart_sprites_) {
|
||||
sprite->update();
|
||||
sprite->update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -924,7 +924,7 @@ void Game::updateGameStates(float deltaTime) {
|
||||
if (!pause_manager_->isPaused()) {
|
||||
switch (state_) {
|
||||
case State::FADE_IN:
|
||||
updateGameStateFadeIn();
|
||||
updateGameStateFadeIn(deltaTime);
|
||||
break;
|
||||
case State::ENTERING_PLAYER:
|
||||
updateGameStateEnteringPlayer(deltaTime);
|
||||
@@ -948,8 +948,8 @@ void Game::updateGameStates(float deltaTime) {
|
||||
}
|
||||
|
||||
// Actualiza el fondo
|
||||
void Game::updateBackground() {
|
||||
background_->update();
|
||||
void Game::updateBackground(float deltaTime) {
|
||||
background_->update(deltaTime);
|
||||
}
|
||||
|
||||
// Dibuja los elementos de la zona de juego en su textura
|
||||
@@ -1699,10 +1699,10 @@ void Game::updateRecording() {
|
||||
#endif
|
||||
|
||||
// Actualiza las variables durante dicho estado
|
||||
void Game::updateGameStateFadeIn() {
|
||||
void Game::updateGameStateFadeIn(float deltaTime) {
|
||||
fade_in_->update();
|
||||
updateScoreboard();
|
||||
updateBackground();
|
||||
updateBackground(deltaTime);
|
||||
if (fade_in_->hasEnded()) {
|
||||
setState(State::ENTERING_PLAYER);
|
||||
balloon_manager_->createTwoBigBalloons();
|
||||
@@ -1712,10 +1712,10 @@ void Game::updateGameStateFadeIn() {
|
||||
|
||||
// Actualiza las variables durante dicho estado
|
||||
void Game::updateGameStateEnteringPlayer(float deltaTime) {
|
||||
balloon_manager_->update();
|
||||
balloon_manager_->update(deltaTime);
|
||||
updatePlayers(deltaTime);
|
||||
updateScoreboard();
|
||||
updateBackground();
|
||||
updateBackground(deltaTime);
|
||||
for (const auto &player : players_) {
|
||||
if (player->isPlaying()) {
|
||||
setState(State::SHOWING_GET_READY_MESSAGE);
|
||||
@@ -1741,19 +1741,19 @@ void Game::updateGameStateShowingGetReadyMessage(float deltaTime) {
|
||||
void Game::updateGameStatePlaying(float deltaTime) {
|
||||
#ifdef _DEBUG
|
||||
if (auto_pop_balloons_) {
|
||||
stage_manager_->addPower(5);
|
||||
stage_manager_->addPower(1);
|
||||
}
|
||||
#endif
|
||||
updatePlayers(deltaTime);
|
||||
checkPlayersStatusPlaying();
|
||||
updateScoreboard();
|
||||
updateBackground();
|
||||
balloon_manager_->update();
|
||||
tabe_->update();
|
||||
updateBullets();
|
||||
updateItems();
|
||||
updateBackground(deltaTime);
|
||||
balloon_manager_->update(deltaTime);
|
||||
tabe_->update(deltaTime);
|
||||
updateBullets(deltaTime);
|
||||
updateItems(deltaTime);
|
||||
updateStage();
|
||||
updateSmartSprites();
|
||||
updateSmartSprites(deltaTime);
|
||||
updatePathSprites();
|
||||
updateTimeStopped(deltaTime);
|
||||
updateHelper();
|
||||
|
||||
@@ -180,7 +180,7 @@ class Game {
|
||||
|
||||
// --- Gestión de estados del juego ---
|
||||
void updateGameStates(float deltaTime); // Actualiza todos los estados del juego
|
||||
void updateGameStateFadeIn(); // Gestiona el estado de transición de entrada
|
||||
void updateGameStateFadeIn(float deltaTime); // Gestiona el estado de transición de entrada (time-based)
|
||||
void updateGameStateEnteringPlayer(float deltaTime); // Gestiona el estado de entrada de jugador
|
||||
void updateGameStateShowingGetReadyMessage(float deltaTime); // Gestiona el estado de mensaje "preparado"
|
||||
void updateGameStatePlaying(float deltaTime); // Gestiona el estado de juego activo
|
||||
@@ -226,7 +226,7 @@ class Game {
|
||||
void demoHandlePlayerInput(const std::shared_ptr<Player> &player, int index); // Procesa entrada de jugador en demo
|
||||
|
||||
// --- Sistema de balas y proyectiles ---
|
||||
void updateBullets(); // Actualiza posición y estado de todas las balas
|
||||
void updateBullets(float deltaTime); // Actualiza posición y estado de todas las balas (time-based)
|
||||
void renderBullets(); // Renderiza todas las balas activas
|
||||
void createBullet(int x, int y, BulletType kind, bool powered_up, Player::Id owner); // Crea una nueva bala
|
||||
void checkBulletCollision(); // Verifica colisiones de todas las balas
|
||||
@@ -238,7 +238,7 @@ class Game {
|
||||
void processBalloonHit(const std::shared_ptr<Bullet> &bullet, const std::shared_ptr<Balloon> &balloon); // Procesa impacto en globo
|
||||
|
||||
// --- Sistema de ítems y power-ups ---
|
||||
void updateItems(); // Actualiza posición y estado de todos los ítems
|
||||
void updateItems(float deltaTime); // Actualiza posición y estado de todos los ítems
|
||||
void renderItems(); // Renderiza todos los ítems activos
|
||||
auto dropItem() -> ItemType; // Determina aleatoriamente qué ítem soltar
|
||||
void createItem(ItemType type, float x, float y); // Crea un nuevo ítem en posición específica
|
||||
@@ -257,7 +257,7 @@ class Game {
|
||||
void handleItemDrop(const std::shared_ptr<Balloon> &balloon, const std::shared_ptr<Player> &player); // Gestiona caída de ítem desde globo
|
||||
|
||||
// --- Sprites inteligentes (smartsprites) ---
|
||||
void updateSmartSprites(); // Actualiza todos los sprites con lógica propia
|
||||
void updateSmartSprites(float deltaTime); // Actualiza todos los sprites con lógica propia (time-based)
|
||||
void renderSmartSprites(); // Renderiza todos los sprites inteligentes
|
||||
void freeSmartSprites(); // Libera memoria de sprites inteligentes
|
||||
|
||||
@@ -296,7 +296,7 @@ class Game {
|
||||
|
||||
// --- Recursos y renderizado ---
|
||||
void setResources(); // Asigna texturas y animaciones a los objetos
|
||||
void updateBackground(); // Actualiza elementos del fondo
|
||||
void updateBackground(float deltaTime); // Actualiza elementos del fondo (time-based)
|
||||
void fillCanvas(); // Renderiza elementos del área de juego en su textura
|
||||
void updateHelper(); // Actualiza variables auxiliares de renderizado
|
||||
|
||||
|
||||
@@ -2,15 +2,6 @@
|
||||
|
||||
#include "moving_sprite.h" // Para MovingSprite
|
||||
|
||||
// Actualiza la posición y comprueba si ha llegado a su destino (frame-based)
|
||||
void SmartSprite::update() {
|
||||
if (enabled_) {
|
||||
MovingSprite::update();
|
||||
checkMove();
|
||||
checkFinished();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la posición y comprueba si ha llegado a su destino (time-based)
|
||||
void SmartSprite::update(float deltaTime) {
|
||||
if (enabled_) {
|
||||
|
||||
@@ -16,7 +16,6 @@ class SmartSprite : public AnimatedSprite {
|
||||
~SmartSprite() override = default;
|
||||
|
||||
// --- Métodos principales ---
|
||||
void update() override; // Actualiza la posición y comprueba si ha llegado a su destino (frame-based)
|
||||
void update(float deltaTime) override; // Actualiza la posición y comprueba si ha llegado a su destino (time-based)
|
||||
void render() override; // Dibuja el sprite
|
||||
|
||||
|
||||
@@ -17,20 +17,6 @@ Tabe::Tabe()
|
||||
: sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("tabe.png"), Resource::get()->getAnimation("tabe.ani"))),
|
||||
timer_(Timer(param.tabe.min_spawn_time, param.tabe.max_spawn_time)) {}
|
||||
|
||||
// Actualiza la lógica (frame-based)
|
||||
void Tabe::update() {
|
||||
if (enabled_ && !timer_.is_paused) {
|
||||
sprite_->update();
|
||||
move();
|
||||
updateState();
|
||||
}
|
||||
|
||||
timer_.update();
|
||||
if (timer_.shouldSpawn()) {
|
||||
enable();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la lógica (time-based)
|
||||
void Tabe::update(float deltaTime) {
|
||||
if (enabled_ && !timer_.is_paused) {
|
||||
@@ -52,71 +38,6 @@ void Tabe::render() {
|
||||
}
|
||||
}
|
||||
|
||||
// Mueve el objeto (frame-based)
|
||||
void Tabe::move() {
|
||||
const int X = static_cast<int>(x_);
|
||||
speed_ += accel_;
|
||||
x_ += speed_;
|
||||
fly_distance_ -= std::abs(X - static_cast<int>(x_));
|
||||
|
||||
// Comprueba si sale por los bordes
|
||||
const float MIN_X = param.game.game_area.rect.x - WIDTH;
|
||||
const float MAX_X = param.game.game_area.rect.x + param.game.game_area.rect.w;
|
||||
switch (destiny_) {
|
||||
case Direction::TO_THE_LEFT: {
|
||||
if (x_ < MIN_X) {
|
||||
disable();
|
||||
}
|
||||
if (x_ > param.game.game_area.rect.x + param.game.game_area.rect.w - WIDTH && direction_ == Direction::TO_THE_RIGHT) {
|
||||
setRandomFlyPath(Direction::TO_THE_LEFT, 80);
|
||||
x_ = param.game.game_area.rect.x + param.game.game_area.rect.w - WIDTH;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Direction::TO_THE_RIGHT: {
|
||||
if (x_ > MAX_X) {
|
||||
disable();
|
||||
}
|
||||
if (x_ < param.game.game_area.rect.x && direction_ == Direction::TO_THE_LEFT) {
|
||||
setRandomFlyPath(Direction::TO_THE_RIGHT, 80);
|
||||
x_ = param.game.game_area.rect.x;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (fly_distance_ <= 0) {
|
||||
if (waiting_counter_ > 0) {
|
||||
accel_ = speed_ = 0.0F;
|
||||
--waiting_counter_;
|
||||
} else {
|
||||
constexpr int CHOICES = 4;
|
||||
const std::array<Direction, CHOICES> LEFT = {
|
||||
Direction::TO_THE_LEFT,
|
||||
Direction::TO_THE_LEFT,
|
||||
Direction::TO_THE_LEFT,
|
||||
Direction::TO_THE_RIGHT};
|
||||
|
||||
const std::array<Direction, CHOICES> RIGHT = {
|
||||
Direction::TO_THE_LEFT,
|
||||
Direction::TO_THE_RIGHT,
|
||||
Direction::TO_THE_RIGHT,
|
||||
Direction::TO_THE_RIGHT};
|
||||
|
||||
const Direction DIRECTION = destiny_ == Direction::TO_THE_LEFT
|
||||
? LEFT[rand() % CHOICES]
|
||||
: RIGHT[rand() % CHOICES];
|
||||
|
||||
setRandomFlyPath(DIRECTION, 20 + (rand() % 40));
|
||||
}
|
||||
}
|
||||
|
||||
shiftSprite();
|
||||
}
|
||||
|
||||
// Mueve el objeto (time-based)
|
||||
void Tabe::move(float deltaTime) {
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
@@ -258,16 +179,6 @@ void Tabe::setState(State state) {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado (frame-based)
|
||||
void Tabe::updateState() {
|
||||
if (state_ == State::HIT) {
|
||||
--hit_counter_;
|
||||
if (hit_counter_ <= 0) {
|
||||
setState(State::FLY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado (time-based)
|
||||
void Tabe::updateState(float deltaTime) {
|
||||
if (state_ == State::HIT) {
|
||||
|
||||
@@ -26,7 +26,6 @@ class Tabe {
|
||||
~Tabe() = default;
|
||||
|
||||
// --- Métodos principales ---
|
||||
void update(); // Actualiza la lógica (frame-based)
|
||||
void update(float deltaTime); // Actualiza la lógica (time-based)
|
||||
void render(); // Dibuja el objeto
|
||||
void enable(); // Habilita el objeto
|
||||
@@ -142,11 +141,9 @@ class Tabe {
|
||||
Timer timer_; // Temporizador para gestionar la aparición
|
||||
|
||||
// --- Métodos internos ---
|
||||
void move(); // Mueve el objeto (frame-based)
|
||||
void move(float deltaTime); // Mueve el objeto (time-based)
|
||||
void shiftSprite() { sprite_->setPos(x_, y_); } // Actualiza la posición del sprite
|
||||
void setRandomFlyPath(Direction direction, int length); // Establece un vuelo aleatorio
|
||||
void updateState(); // Actualiza el estado (frame-based)
|
||||
void updateState(float deltaTime); // Actualiza el estado (time-based)
|
||||
void updateTimer(); // Actualiza el temporizador
|
||||
void disable(); // Deshabilita el objeto
|
||||
|
||||
Reference in New Issue
Block a user