new: el jugador explota els globos per contacte si estos estan parats
This commit is contained in:
@@ -274,4 +274,4 @@ void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &so
|
||||
void AnimatedSprite::setAnimationSpeed(size_t value)
|
||||
{
|
||||
animations_[current_animation_].speed = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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> &player)
|
||||
std::shared_ptr<Balloon> Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &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
|
||||
|
||||
@@ -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> &player); // Comprueba la colisión entre el jugador y los globos activos
|
||||
std::shared_ptr<Balloon> checkPlayerBalloonCollision(std::shared_ptr<Player> &player); // Comprueba la colisión entre el jugador y los globos activos
|
||||
void checkPlayerItemCollision(std::shared_ptr<Player> &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
|
||||
|
||||
Reference in New Issue
Block a user