Player: afegides animacions per al estat WAITING
Player: si tires a jugar desde el estat WAITING passes al ENTERING_SCREEN i despres sempre tens inmunitat, fins i tot la primera volta (al començar el joc) falta: arregñar el z-order per al estat WAITING
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
// Constructor
|
||||
Tabe::Tabe()
|
||||
: sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("tabe.png"), Resource::get()->getAnimation("tabe.ani"))),
|
||||
timer_(TabeTimer(2.5F, 4.0F)) {}
|
||||
timer_(Timer(2.5F, 4.0F)) {}
|
||||
|
||||
// Actualiza la lógica
|
||||
void Tabe::update() {
|
||||
@@ -49,23 +49,23 @@ void Tabe::move() {
|
||||
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 TabeDirection::TO_THE_LEFT: {
|
||||
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_ == TabeDirection::TO_THE_RIGHT) {
|
||||
setRandomFlyPath(TabeDirection::TO_THE_LEFT, 80);
|
||||
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 TabeDirection::TO_THE_RIGHT: {
|
||||
case Direction::TO_THE_RIGHT: {
|
||||
if (x_ > MAX_X) {
|
||||
disable();
|
||||
}
|
||||
if (x_ < param.game.game_area.rect.x && direction_ == TabeDirection::TO_THE_LEFT) {
|
||||
setRandomFlyPath(TabeDirection::TO_THE_RIGHT, 80);
|
||||
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;
|
||||
@@ -80,19 +80,19 @@ void Tabe::move() {
|
||||
--waiting_counter_;
|
||||
} else {
|
||||
constexpr int CHOICES = 4;
|
||||
const std::array<TabeDirection, CHOICES> LEFT = {
|
||||
TabeDirection::TO_THE_LEFT,
|
||||
TabeDirection::TO_THE_LEFT,
|
||||
TabeDirection::TO_THE_LEFT,
|
||||
TabeDirection::TO_THE_RIGHT};
|
||||
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<TabeDirection, CHOICES> RIGHT = {
|
||||
TabeDirection::TO_THE_LEFT,
|
||||
TabeDirection::TO_THE_RIGHT,
|
||||
TabeDirection::TO_THE_RIGHT,
|
||||
TabeDirection::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 TabeDirection DIRECTION = destiny_ == TabeDirection::TO_THE_LEFT
|
||||
const Direction DIRECTION = destiny_ == Direction::TO_THE_LEFT
|
||||
? LEFT[rand() % CHOICES]
|
||||
: RIGHT[rand() % CHOICES];
|
||||
|
||||
@@ -113,10 +113,10 @@ void Tabe::enable() {
|
||||
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;
|
||||
destiny_ = direction_ = rand() % 2 == 0 ? Direction::TO_THE_LEFT : Direction::TO_THE_RIGHT;
|
||||
|
||||
// Establece la posición inicial
|
||||
x_ = (direction_ == TabeDirection::TO_THE_LEFT) ? param.game.game_area.rect.x + param.game.game_area.rect.w : param.game.game_area.rect.x - WIDTH;
|
||||
x_ = (direction_ == Direction::TO_THE_LEFT) ? param.game.game_area.rect.x + param.game.game_area.rect.w : param.game.game_area.rect.x - WIDTH;
|
||||
|
||||
// Crea una ruta de vuelo
|
||||
setRandomFlyPath(direction_, 60);
|
||||
@@ -125,7 +125,7 @@ void Tabe::enable() {
|
||||
}
|
||||
|
||||
// Establece un vuelo aleatorio
|
||||
void Tabe::setRandomFlyPath(TabeDirection direction, int lenght) {
|
||||
void Tabe::setRandomFlyPath(Direction direction, int lenght) {
|
||||
direction_ = direction;
|
||||
fly_distance_ = lenght;
|
||||
waiting_counter_ = 5 + rand() % 15;
|
||||
@@ -134,14 +134,14 @@ void Tabe::setRandomFlyPath(TabeDirection direction, int lenght) {
|
||||
constexpr float SPEED = 2.0F;
|
||||
|
||||
switch (direction) {
|
||||
case TabeDirection::TO_THE_LEFT: {
|
||||
case Direction::TO_THE_LEFT: {
|
||||
speed_ = -1.0F * SPEED;
|
||||
accel_ = -1.0F * (1 + rand() % 10) / 30.0F;
|
||||
sprite_->setFlip(SDL_FLIP_NONE);
|
||||
break;
|
||||
}
|
||||
|
||||
case TabeDirection::TO_THE_RIGHT: {
|
||||
case Direction::TO_THE_RIGHT: {
|
||||
speed_ = SPEED;
|
||||
accel_ = (1 + rand() % 10) / 30.0F;
|
||||
sprite_->setFlip(SDL_FLIP_HORIZONTAL);
|
||||
@@ -154,16 +154,16 @@ void Tabe::setRandomFlyPath(TabeDirection direction, int lenght) {
|
||||
}
|
||||
|
||||
// Establece el estado
|
||||
void Tabe::setState(TabeState state) {
|
||||
void Tabe::setState(State state) {
|
||||
if (enabled_) {
|
||||
state_ = state;
|
||||
|
||||
switch (state) {
|
||||
case TabeState::FLY:
|
||||
case State::FLY:
|
||||
sprite_->setCurrentAnimation("fly");
|
||||
break;
|
||||
|
||||
case TabeState::HIT:
|
||||
case State::HIT:
|
||||
sprite_->setCurrentAnimation("hit");
|
||||
hit_counter_ = 5;
|
||||
++number_of_hits_;
|
||||
@@ -177,10 +177,10 @@ void Tabe::setState(TabeState state) {
|
||||
|
||||
// Actualiza el estado
|
||||
void Tabe::updateState() {
|
||||
if (state_ == TabeState::HIT) {
|
||||
if (state_ == State::HIT) {
|
||||
--hit_counter_;
|
||||
if (hit_counter_ == 0) {
|
||||
setState(TabeState::FLY);
|
||||
setState(State::FLY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user