Quan el jugador moria podia quedarse engantxat rebotant en les vores
So aleatori en els rebots del jugador al morir
This commit is contained in:
@@ -174,10 +174,14 @@ void Player::move()
|
||||
case PlayerState::DYING:
|
||||
{
|
||||
// Si el cadaver abandona el area de juego por los laterales lo hace rebotar
|
||||
if ((player_sprite_->getPosX() < play_area_.x) || (player_sprite_->getPosX() + WIDTH_ > play_area_.w))
|
||||
const int x = player_sprite_->getPosX();
|
||||
const int min_x = play_area_.x;
|
||||
const int max_x = play_area_.x + play_area_.w - WIDTH_;
|
||||
if ((x < min_x) || (x > max_x))
|
||||
{
|
||||
player_sprite_->setPosX(std::clamp(x, min_x, max_x));
|
||||
player_sprite_->setVelX(-player_sprite_->getVelX());
|
||||
JA_PlaySound(Resource::get()->getSound("bubble4.wav"));
|
||||
playRandomBubbleSound();
|
||||
}
|
||||
|
||||
// Si el cadaver toca el suelo cambia el estado
|
||||
@@ -191,7 +195,7 @@ void Player::move()
|
||||
pos_y_ = default_pos_y_;
|
||||
player_sprite_->clear();
|
||||
shiftSprite();
|
||||
JA_PlaySound(Resource::get()->getSound("bubble4.wav"));
|
||||
playRandomBubbleSound();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -199,7 +203,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);
|
||||
JA_PlaySound(Resource::get()->getSound("bubble4.wav"));
|
||||
playRandomBubbleSound();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -755,4 +759,11 @@ void Player::shiftSprite()
|
||||
player_sprite_->setPosX(pos_x_);
|
||||
player_sprite_->setPosY(pos_y_);
|
||||
power_sprite_->setPosX(getPosX() - power_up_desp_x_);
|
||||
}
|
||||
|
||||
// Hace sonar un ruido al azar
|
||||
void Player::playRandomBubbleSound()
|
||||
{
|
||||
const std::vector<std::string> sounds = {"bubble1.wav", "bubble2.wav", "bubble3.wav", "bubble4.wav"};
|
||||
JA_PlaySound(Resource::get()->getSound(sounds.at(rand() % sounds.size())));
|
||||
}
|
||||
Reference in New Issue
Block a user