From 3d26a3022c92887ade878e6fabdc880224dc367b Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 14 Jul 2025 14:08:08 +0200 Subject: [PATCH] new: el jugador explota els globos per contacte si estos estan parats --- source/animated_sprite.cpp | 2 +- source/animated_sprite.h | 9 +++++---- source/player.cpp | 7 ++++++- source/sections/game.cpp | 32 ++++++++++++++++++++++---------- source/sections/game.h | 3 ++- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/source/animated_sprite.cpp b/source/animated_sprite.cpp index 8a41ac1..b35e7a2 100644 --- a/source/animated_sprite.cpp +++ b/source/animated_sprite.cpp @@ -274,4 +274,4 @@ void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &so void AnimatedSprite::setAnimationSpeed(size_t value) { animations_[current_animation_].speed = value; -} \ No newline at end of file +} diff --git a/source/animated_sprite.h b/source/animated_sprite.h index 5054b9d..3d54418 100644 --- a/source/animated_sprite.h +++ b/source/animated_sprite.h @@ -45,10 +45,11 @@ public: void update() override; // Actualiza la animación // --- Control de animaciones --- - void setCurrentAnimation(const std::string &name = "default", bool reset = true); // Establece la animación por nombre - void setCurrentAnimation(int index = 0, bool reset = true); // Establece la animación por índice - void resetAnimation(); // Reinicia la animación actual - void setAnimationSpeed(size_t value); // Establece la velocidad de la animación + void setCurrentAnimation(const std::string &name = "default", bool reset = true); // Establece la animación por nombre + void setCurrentAnimation(int index = 0, bool reset = true); // Establece la animación por índice + void resetAnimation(); // Reinicia la animación actual + void setAnimationSpeed(size_t value); // Establece la velocidad de la animación + size_t getAnimationSpeed() const { return animations_[current_animation_].speed; } // Obtiene la velocidad de la animación actual // --- Consultas --- bool animationIsCompleted(); // Comprueba si la animación ha terminado diff --git a/source/player.cpp b/source/player.cpp index 1941afe..5b28530 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -195,7 +195,7 @@ void Player::move() { if (player_sprite_->getVelY() < 2.0f) { - // Si la velocidad de rebote es baja, termina de rebotar y cambia de estado + // Si la velocidad de rebote es baja, lo detiene y cambia de estado const auto nextPlayerStatus = IsEligibleForHighScore() ? PlayerState::ENTERING_NAME : PlayerState::CONTINUE; demo_ ? setPlayingState(PlayerState::LYING_ON_THE_FLOOR_FOREVER) : setPlayingState(nextPlayerStatus); pos_x_ = player_sprite_->getPosX(); @@ -210,6 +210,7 @@ void Player::move() player_sprite_->setPosY(play_area_.h - HEIGHT_); player_sprite_->setVelY(player_sprite_->getVelY() * -0.5f); player_sprite_->setVelX(player_sprite_->getVelX() * 0.75f); + player_sprite_->setAnimationSpeed(player_sprite_->getAnimationSpeed() * 2); playSound("jump.wav"); } } @@ -627,6 +628,8 @@ void Player::setPlayingState(PlayerState state) case PlayerState::ROLLING: { // Activa la animación de rodar + player_sprite_->setCurrentAnimation("rolling"); + player_sprite_->setAnimationSpeed(4); player_sprite_->setAccelY(0.2f); player_sprite_->setVelY(-6.6f); (rand() % 2 == 0) ? player_sprite_->setVelX(3.3f) : player_sprite_->setVelX(-3.3f); @@ -635,6 +638,8 @@ void Player::setPlayingState(PlayerState state) case PlayerState::TITLE_ANIMATION: { // Activa la animación de rodar + player_sprite_->setCurrentAnimation("rolling"); + player_sprite_->setAnimationSpeed(5); player_sprite_->setAccelY(0.2f); player_sprite_->setVelY(-6.6f); playSound("voice_thankyou.wav"); diff --git a/source/sections/game.cpp b/source/sections/game.cpp index 66a259f..a1b109d 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -210,14 +210,26 @@ void Game::updatePlayers() if (player->isPlaying()) { // Comprueba la colisión entre el jugador y los globos - if (checkPlayerBalloonCollision(player)) - { - handlePlayerCollision(player); + auto balloon = checkPlayerBalloonCollision(player); - if (demo_.enabled && allPlayersAreNotPlaying()) + // Si hay colisión + if (balloon) + { + // Si el globo está parado y el temporizador activo, lo explota + if (balloon->isStopped() && time_stopped_counter_ > 0) { - fade_out_->setType(FadeType::RANDOM_SQUARE); - fade_out_->activate(); + balloon_manager_->popBalloon(balloon); + } + // En caso contrario, el jugador ha sido golpeado por un globo activo + else + { + handlePlayerCollision(player); + + if (demo_.enabled && allPlayersAreNotPlaying()) + { + fade_out_->setType(FadeType::RANDOM_SQUARE); + fade_out_->activate(); + } } } @@ -443,20 +455,20 @@ void Game::destroyAllItems() } // Comprueba la colisión entre el jugador y los globos activos -bool Game::checkPlayerBalloonCollision(std::shared_ptr &player) +std::shared_ptr Game::checkPlayerBalloonCollision(std::shared_ptr &player) { for (auto &balloon : balloon_manager_->getBalloons()) { - if (!balloon->isStopped() && !balloon->isInvulnerable() && !balloon->isPowerBall()) + if (!balloon->isInvulnerable() && !balloon->isPowerBall()) { if (checkCollision(player->getCollider(), balloon->getCollider())) { - return true; + return balloon; // Devuelve el globo con el que se ha producido la colisión } } } - return false; + return nullptr; // No se ha producido ninguna colisión } // Comprueba la colisión entre el jugador y los items diff --git a/source/sections/game.h b/source/sections/game.h index 5fcde3f..91a20a5 100644 --- a/source/sections/game.h +++ b/source/sections/game.h @@ -14,6 +14,7 @@ class Audio; class Asset; class Background; +class Balloon; class BalloonManager; class Tabe; class Bullet; @@ -174,7 +175,7 @@ private: void updateStage(); // Comprueba si hay cambio de fase y actualiza las variables void updateGameStateGameOver(); // Actualiza el estado de fin de la partida void destroyAllItems(); // Destruye todos los items - bool checkPlayerBalloonCollision(std::shared_ptr &player); // Comprueba la colisión entre el jugador y los globos activos + std::shared_ptr checkPlayerBalloonCollision(std::shared_ptr &player); // Comprueba la colisión entre el jugador y los globos activos void checkPlayerItemCollision(std::shared_ptr &player); // Comprueba la colisión entre el jugador y los items void checkBulletCollision(); // Comprueba y procesa la colisión de las balas void updateBullets(); // Mueve las balas activas