Nova animació per a la mort del personatge

Nova lògica al morir
This commit is contained in:
2024-11-17 08:43:24 +01:00
parent da74b8dfce
commit 47e468034f
5 changed files with 77 additions and 34 deletions

View File

@@ -72,12 +72,19 @@ frames=27
[/animation]
[animation]
name=death
name=dying
speed=10
loop=0
frames=32,33,34,35
[/animation]
[animation]
name=dead
speed=3
loop=0
frames=44,45,46,47,48,49,50,51
[/animation]
[animation]
name=celebration
speed=10

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@@ -350,7 +350,7 @@ void Game::updateCompletedState()
for (auto &player : players_)
if (player->isCelebrating())
{
player->setPlayingState(player->IsEligibleForHighScore() ? PlayerState::ENTERING_NAME_GAME_COMPLETED : PlayerState::GAME_COMPLETED);
player->setPlayingState(player->IsEligibleForHighScore() ? PlayerState::ENTERING_NAME_GAME_COMPLETED : PlayerState::LEAVING_SCREEN);
}
}
@@ -1166,7 +1166,7 @@ void Game::checkEvents()
}
case SDLK_8:
{
players_.at(0)->setPlayingState(PlayerState::GAME_COMPLETED);
players_.at(0)->setPlayingState(PlayerState::LEAVING_SCREEN);
}
default:
break;
@@ -1494,7 +1494,7 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
player->setInput(InputType::START);
addScoreToScoreBoard(player->getRecordName(), player->getScore());
const auto status = player->getPlayingState();
player->setPlayingState(status == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::GAME_COMPLETED);
player->setPlayingState(status == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN);
}
else
{
@@ -1518,7 +1518,7 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
player->setInput(InputType::START);
addScoreToScoreBoard(player->getRecordName(), player->getScore());
const auto status = player->getPlayingState();
player->setPlayingState(status == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::GAME_COMPLETED);
player->setPlayingState(status == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN);
}
}

View File

@@ -29,6 +29,7 @@ Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vect
power_sprite_->setPosY(y - (power_sprite_->getHeight() - player_sprite_->getHeight()));
// Inicializa variables
pos_x_ = default_pos_x_;
init();
}
@@ -36,7 +37,6 @@ Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vect
void Player::init()
{
// Inicializa variables de estado
pos_x_ = default_pos_x_;
pos_y_ = default_pos_y_;
walking_state_ = PlayerState::WALKING_STOP;
firing_state_ = PlayerState::FIRING_NONE;
@@ -175,14 +175,22 @@ void Player::move()
{
// Si el cadaver abandona el area de juego por los laterales lo hace rebotar
if ((player_sprite_->getPosX() < param.game.play_area.rect.x) || (player_sprite_->getPosX() + WIDTH_ > play_area_.w))
{
player_sprite_->setVelX(-player_sprite_->getVelX());
}
// Si el cadaver abandona el area de juego por abajo
if (player_sprite_->getPosY() > param.game.play_area.rect.h)
// Si el cadaver toca el suelo cambia el estado
if (player_sprite_->getPosY() > param.game.play_area.rect.h - HEIGHT_)
{
setPlayingState(PlayerState::DIED);
pos_x_ = player_sprite_->getPosX();
pos_y_ = default_pos_y_;
player_sprite_->clear();
shiftSprite();
}
break;
}
case PlayerState::GAME_COMPLETED:
case PlayerState::LEAVING_SCREEN:
{
switch (id_)
{
@@ -214,28 +222,38 @@ void Player::move()
void Player::render()
{
if (power_up_ && isPlaying())
{
if (power_up_counter_ > (POWERUP_COUNTER_ / 4) || power_up_counter_ % 20 > 4)
{
power_sprite_->render();
}
}
if (isRenderable())
{
player_sprite_->render();
}
}
// Establece la animación correspondiente al estado
void Player::setAnimation()
{
// Crea cadenas de texto para componer el nombre de la animación
const std::string a_walking = walking_state_ == PlayerState::WALKING_STOP ? "stand" : "walk";
const std::string a_firing = firing_state_ == PlayerState::FIRING_UP ? "centershoot" : "sideshoot";
const std::string a_cooling = firing_state_ == PlayerState::COOLING_UP ? "centershoot" : "sideshoot";
const SDL_RendererFlip flip_walk = walking_state_ == PlayerState::WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
const SDL_RendererFlip flip_fire = firing_state_ == PlayerState::FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
const SDL_RendererFlip flip_cooling = firing_state_ == PlayerState::COOLING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
// Establece la animación a partir de las cadenas
if (isPlaying() || isEnteringNameGameCompleted() || isGameCompleted())
switch (playing_state_)
{
case PlayerState::PLAYING:
case PlayerState::ENTERING_NAME_GAME_COMPLETED:
case PlayerState::LEAVING_SCREEN:
{
// Crea cadenas de texto para componer el nombre de la animación
const std::string a_walking = walking_state_ == PlayerState::WALKING_STOP ? "stand" : "walk";
const std::string a_firing = firing_state_ == PlayerState::FIRING_UP ? "centershoot" : "sideshoot";
const std::string a_cooling = firing_state_ == PlayerState::COOLING_UP ? "centershoot" : "sideshoot";
const SDL_RendererFlip flip_walk = walking_state_ == PlayerState::WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
const SDL_RendererFlip flip_fire = firing_state_ == PlayerState::FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
const SDL_RendererFlip flip_cooling = firing_state_ == PlayerState::COOLING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
// Establece la animación a partir de las cadenas
if (firing_state_ == PlayerState::FIRING_NONE)
{ // No esta disparando
player_sprite_->setCurrentAnimation(a_walking);
@@ -253,14 +271,27 @@ void Player::setAnimation()
// Si dispara recto, invierte el sprite segun hacia donde camina
player_sprite_->setFlip(a_firing == "centershoot" ? flip_walk : flip_fire);
}
break;
}
else if (isDying() || hasDied())
case PlayerState::DYING:
{
player_sprite_->setCurrentAnimation("death");
player_sprite_->setCurrentAnimation("dying");
break;
}
else if (isCelebrating())
case PlayerState::DIED:
case PlayerState::ENTERING_NAME:
case PlayerState::CONTINUE:
{
player_sprite_->setCurrentAnimation("dead");
break;
}
case PlayerState::CELEBRATING:
{
player_sprite_->setCurrentAnimation("celebration");
break;
}
default:
break;
}
// Actualiza las animaciones de los sprites
@@ -423,7 +454,7 @@ void Player::setPlayingState(PlayerState state)
setScoreboardMode(ScoreboardMode::ENTER_NAME);
break;
}
case PlayerState::GAME_COMPLETED:
case PlayerState::LEAVING_SCREEN:
{
setScoreboardMode(ScoreboardMode::GAME_COMPLETED);
break;
@@ -575,7 +606,7 @@ void Player::decEnterNameCounter()
if (playing_state_ == PlayerState::ENTERING_NAME)
setPlayingState(PlayerState::CONTINUE);
else
setPlayingState(PlayerState::GAME_COMPLETED);
setPlayingState(PlayerState::LEAVING_SCREEN);
}
}

View File

@@ -39,7 +39,7 @@ enum class PlayerState
GAME_OVER, // No está jugando y no puede entrar a jugar
CELEBRATING, // Poniendo pose de victoria
ENTERING_NAME_GAME_COMPLETED, // Poniendo nombre en el tramo final del juego
GAME_COMPLETED, // Moviendose fuera de la pantalla
LEAVING_SCREEN, // Moviendose fuera de la pantalla
};
// Clase Player
@@ -115,7 +115,7 @@ private:
// Cambia el modo del marcador
void setScoreboardMode(ScoreboardMode mode);
bool isRenderable() const { return isPlaying() || isDying() || isCelebrating() || isEnteringNameGameCompleted() || isGameCompleted(); }
bool isRenderable() const { return !isWaiting() && !isGameOver(); }
public:
// Constructor
@@ -187,22 +187,25 @@ public:
// Obtiene la posición que se está editando del nombre del jugador para la tabla de mejores puntuaciones
int getRecordNamePos() const;
bool canFire() const { return cooldown_ > 0 ? false : true; }
// Comprobación de playing_state
bool hasDied() const { return playing_state_ == PlayerState::DIED; }
bool hasExtraHit() const { return extra_hit_; }
bool isCelebrating() const { return playing_state_ == PlayerState::CELEBRATING; }
bool isContinue() const { return playing_state_ == PlayerState::CONTINUE; }
bool isCooling() { return firing_state_ == PlayerState::COOLING_LEFT || firing_state_ == PlayerState::COOLING_UP || firing_state_ == PlayerState::COOLING_RIGHT; }
bool isDying() const { return playing_state_ == PlayerState::DYING; }
bool IsEligibleForHighScore() { return score_ > options.game.hi_score_table.back().score; }
bool isEnteringName() const { return playing_state_ == PlayerState::ENTERING_NAME; }
bool isEnteringNameGameCompleted() const { return playing_state_ == PlayerState::ENTERING_NAME_GAME_COMPLETED; }
bool isGameCompleted() const { return playing_state_ == PlayerState::GAME_COMPLETED; }
bool isLeavingScreen() const { return playing_state_ == PlayerState::LEAVING_SCREEN; }
bool isGameOver() const { return playing_state_ == PlayerState::GAME_OVER; }
bool isInvulnerable() const { return invulnerable_; }
bool isPlaying() const { return playing_state_ == PlayerState::PLAYING; }
bool isPowerUp() const { return power_up_; }
bool isWaiting() const { return playing_state_ == PlayerState::WAITING; }
// Getters
bool canFire() const { return cooldown_ > 0 ? false : true; }
bool hasExtraHit() const { return extra_hit_; }
bool isCooling() { return firing_state_ == PlayerState::COOLING_LEFT || firing_state_ == PlayerState::COOLING_UP || firing_state_ == PlayerState::COOLING_RIGHT; }
bool IsEligibleForHighScore() { return score_ > options.game.hi_score_table.back().score; }
bool isInvulnerable() const { return invulnerable_; }
bool isPowerUp() const { return power_up_; }
Circle &getCollider() { return collider_; }
float getScoreMultiplier() const { return score_multiplier_; }
int getCoffees() const { return coffees_; }
@@ -220,6 +223,8 @@ public:
int getWidth() const { return WIDTH_; }
PlayerState getPlayingState() const { return playing_state_; }
std::string getName() const { return name_; }
// Setters
void setController(int index) { controller_index_ = index; }
void setFireCooldown(int time) { cooldown_ = time; }
void setFiringState(PlayerState state) { firing_state_ = state; }