El malo nou ja suca cosetes, falta ajustar un poc els paràmetres

This commit is contained in:
2025-01-25 17:41:45 +01:00
parent 2b3cc719ba
commit e60938cb19
12 changed files with 153 additions and 49 deletions

View File

@@ -18,6 +18,7 @@ void Tabe::update()
{
sprite_->update();
move();
updateState();
}
}
@@ -100,7 +101,8 @@ void Tabe::enable()
if (!enabled_)
{
enabled_ = true;
y_ = 20.0f;
has_bonus_ = true;
y_ = param.game.game_area.rect.y + 20.0f;
// Establece una dirección aleatoria
destiny_ = direction_ = rand() % 2 == 0 ? TabeDirection::TO_THE_LEFT : TabeDirection::TO_THE_RIGHT;
@@ -145,4 +147,52 @@ void Tabe::setRandomFlyPath(TabeDirection direction, int lenght)
default:
break;
}
}
}
// Establece el estado
void Tabe::setState(TabeState state)
{
if (enabled_)
{
state_ = state;
switch (state)
{
case TabeState::FLY:
sprite_->setCurrentAnimation("fly");
break;
case TabeState::HIT:
sprite_->setCurrentAnimation("hit");
hit_counter = 5;
break;
default:
break;
}
}
}
// Actualiza el estado
void Tabe::updateState()
{
if (state_ == TabeState::HIT)
{
--hit_counter;
if (hit_counter == 0)
{
setState(TabeState::FLY);
}
}
}
// Intenta obtener el bonus
bool Tabe::tryToGetBonus()
{
if (has_bonus_ && rand() % 10 == 0)
{
has_bonus_ = false;
return true;
}
return false;
}