Noves animacions per a deixar de disparar

This commit is contained in:
2024-10-31 23:32:11 +01:00
parent 30dfa4c545
commit c6e2368e82
6 changed files with 97 additions and 46 deletions

View File

@@ -23,29 +23,64 @@ frames=8,9,10,11
[/animation] [/animation]
[animation] [animation]
name=stand-sideshoot name=walk-sideshoot-cooldown
speed=5 speed=5
loop=0 loop=0
frames=12,13,14,15 frames=12,13,14,15
[/animation] [/animation]
[animation] [animation]
name=walk-centershoot name=stand-sideshoot
speed=5 speed=5
loop=0 loop=0
frames=16,17,18,19 frames=16,17,18,19
[/animation] [/animation]
[animation] [animation]
name=stand-centershoot name=stand-sideshoot-cooldown
speed=5
loop=0
frames=15
[/animation]
[animation]
name=walk-centershoot
speed=5 speed=5
loop=0 loop=0
frames=20,21,22,23 frames=20,21,22,23
[/animation] [/animation]
[animation]
name=walk-centershoot-cooldown
speed=5
loop=0
frames=24,25,26,27
[/animation]
[animation]
name=stand-centershoot
speed=5
loop=0
frames=28,29,30,31
[/animation]
[animation]
name=stand-centershoot-cooldown
speed=5
loop=0
frames=27
[/animation]
[animation] [animation]
name=death name=death
speed=10 speed=10
loop=0 loop=0
frames=24,25,26,27 frames=32,33,34,35
[/animation]
[animation]
name=celeb
speed=10
loop=-1
frames=36,36,36,36,36,36,37,38,39,40,40,40,40,40,40,39,39,39,40,40,40,39,39,39,38,37,36,36,36
[/animation] [/animation]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@@ -1710,32 +1710,24 @@ void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player)
handleFireInputs(player, autofire, controllerIndex); // Verifica y maneja todas las posibles entradas de disparo. handleFireInputs(player, autofire, controllerIndex); // Verifica y maneja todas las posibles entradas de disparo.
} }
// Procesa las entradas de disparo del jugador, permitiendo disparos automáticos // Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
// si está habilitado. void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controllerIndex)
void Game::handleFireInputs(const std::shared_ptr<Player> &player,
bool autofire, int controllerIndex)
{ {
if (input_->checkInput(InputType::FIRE_CENTER, autofire, if (input_->checkInput(InputType::FIRE_CENTER, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
options.controller[controllerIndex].device_type,
options.controller[controllerIndex].index))
{ {
handleFireInput(player, BulletType::UP); handleFireInput(player, BulletType::UP);
#ifdef RECORDING #ifdef RECORDING
demo_.keys.fire = 1; demo_.keys.fire = 1;
#endif #endif
} }
else if (input_->checkInput(InputType::FIRE_LEFT, autofire, else if (input_->checkInput(InputType::FIRE_LEFT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
options.controller[controllerIndex].device_type,
options.controller[controllerIndex].index))
{ {
handleFireInput(player, BulletType::LEFT); handleFireInput(player, BulletType::LEFT);
#ifdef RECORDING #ifdef RECORDING
demo_.keys.fire_left = 1; demo_.keys.fire_left = 1;
#endif #endif
} }
else if (input_->checkInput(InputType::FIRE_RIGHT, autofire, else if (input_->checkInput(InputType::FIRE_RIGHT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
options.controller[controllerIndex].device_type,
options.controller[controllerIndex].index))
{ {
handleFireInput(player, BulletType::RIGHT); handleFireInput(player, BulletType::RIGHT);
#ifdef RECORDING #ifdef RECORDING
@@ -1744,29 +1736,19 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player,
} }
} }
// Maneja la continuación del jugador cuando no está jugando, permitiendo que // Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
// continúe si se pulsa el botón de inicio.
void Game::handlePlayerContinue(const std::shared_ptr<Player> &player) void Game::handlePlayerContinue(const std::shared_ptr<Player> &player)
{ {
const auto controllerIndex = player->getController(); const auto controllerIndex = player->getController();
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
options.controller[controllerIndex].device_type,
options.controller[controllerIndex].index))
{ {
player->setStatusPlaying(PlayerStatus::PLAYING); player->setStatusPlaying(PlayerStatus::PLAYING);
} }
// Disminuye el contador de continuación si se presiona cualquier botón de // Disminuye el contador de continuación si se presiona cualquier botón de disparo.
// disparo. if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index) ||
if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index) ||
options.controller[controllerIndex].device_type, input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
options.controller[controllerIndex].index) ||
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT,
options.controller[controllerIndex].device_type,
options.controller[controllerIndex].index) ||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT,
options.controller[controllerIndex].device_type,
options.controller[controllerIndex].index))
{ {
player->decContinueCounter(); player->decContinueCounter();
} }

View File

@@ -239,9 +239,11 @@ void Player::setAnimation()
// Crea cadenas de texto para componer el nombre de la animación // Crea cadenas de texto para componer el nombre de la animación
const std::string a_walking = status_walking_ == PlayerStatus::WALKING_STOP ? "stand" : "walk"; const std::string a_walking = status_walking_ == PlayerStatus::WALKING_STOP ? "stand" : "walk";
const std::string a_firing = status_firing_ == PlayerStatus::FIRING_UP ? "centershoot" : "sideshoot"; const std::string a_firing = status_firing_ == PlayerStatus::FIRING_UP ? "centershoot" : "sideshoot";
const std::string a_cooling = status_firing_ == PlayerStatus::COOLING_UP ? "centershoot" : "sideshoot";
const SDL_RendererFlip flip_walk = status_walking_ == PlayerStatus::WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE; const SDL_RendererFlip flip_walk = status_walking_ == PlayerStatus::WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
const SDL_RendererFlip flip_fire = status_firing_ == PlayerStatus::FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE; const SDL_RendererFlip flip_fire = status_firing_ == PlayerStatus::FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
const SDL_RendererFlip flip_cooling = status_firing_ == PlayerStatus::COOLING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
// Establece la animación a partir de las cadenas // Establece la animación a partir de las cadenas
if (isPlaying() || isEnteringNameGameCompleted() || isGameCompleted()) if (isPlaying() || isEnteringNameGameCompleted() || isGameCompleted())
@@ -251,12 +253,17 @@ void Player::setAnimation()
player_sprite_->setCurrentAnimation(a_walking); player_sprite_->setCurrentAnimation(a_walking);
player_sprite_->setFlip(flip_walk); player_sprite_->setFlip(flip_walk);
} }
else if (isCooling())
{ // Acaba de disparar
player_sprite_->setCurrentAnimation(a_walking + "-" + a_cooling + "-cooldown");
player_sprite_->setFlip(flip_cooling);
}
else else
{ // Está disparando { // Está disparando
player_sprite_->setCurrentAnimation(a_walking + "-" + a_firing); player_sprite_->setCurrentAnimation(a_walking + "-" + a_firing);
// Si dispara de lado, invierte el sprite segun hacia donde dispara // Si dispara de lado, invierte el sprite segun hacia donde dispara
// Si dispara recto, invierte el sprite segun hacia donde camina // Si dispara recto, invierte el sprite segun hacia donde camina
a_firing == "centershoot" ? player_sprite_->setFlip(flip_walk) : player_sprite_->setFlip(flip_fire); player_sprite_->setFlip(a_firing == "centershoot" ? flip_walk : flip_fire);
} }
} }
else else
@@ -292,15 +299,36 @@ void Player::updateCooldown()
{ {
if (cooldown_ > 0) if (cooldown_ > 0)
{ {
cooldown_--; cooldown_ -= power_up_ ? 2 : 1;
if (power_up_)
{
cooldown_--;
}
} }
else else
{ {
setFiringStatus(PlayerStatus::FIRING_NONE); if (!isCooling())
{
cooling_status_counter_ = 40;
switch (status_firing_)
{
case PlayerStatus::FIRING_LEFT:
status_firing_ = PlayerStatus::COOLING_LEFT;
break;
case PlayerStatus::FIRING_RIGHT:
status_firing_ = PlayerStatus::COOLING_RIGHT;
break;
case PlayerStatus::FIRING_UP:
status_firing_ = PlayerStatus::COOLING_UP;
break;
default:
break;
}
}
else if (cooling_status_counter_ > 0)
{
--cooling_status_counter_;
}
else
{
setFiringStatus(PlayerStatus::FIRING_NONE);
}
} }
} }
@@ -695,4 +723,6 @@ void Player::shiftSprite()
player_sprite_->setPosX(pos_x_); player_sprite_->setPosX(pos_x_);
player_sprite_->setPosY(pos_y_); player_sprite_->setPosY(pos_y_);
power_sprite_->setPosX(getPosX() - power_up_desp_x_); power_sprite_->setPosX(getPosX() - power_up_desp_x_);
} }
bool Player::isCooling() { return status_firing_ == PlayerStatus::COOLING_LEFT || status_firing_ == PlayerStatus::COOLING_UP || status_firing_ == PlayerStatus::COOLING_RIGHT; }

View File

@@ -25,6 +25,10 @@ enum class PlayerStatus
FIRING_RIGHT, FIRING_RIGHT,
FIRING_NONE, FIRING_NONE,
COOLING_UP,
COOLING_LEFT,
COOLING_RIGHT,
PLAYING, PLAYING,
CONTINUE, CONTINUE,
WAITING, WAITING,
@@ -36,8 +40,6 @@ enum class PlayerStatus
GAME_COMPLETED, GAME_COMPLETED,
}; };
// Variables del jugador
// Clase Player // Clase Player
class Player class Player
{ {
@@ -63,7 +65,8 @@ private:
int default_pos_y_; // Posición inicial para el jugador int default_pos_y_; // Posición inicial para el jugador
float vel_x_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje X float vel_x_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje X
int vel_y_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje Y int vel_y_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje Y
int cooldown_ = 10; // Contador durante el cual no puede disparar int cooldown_ = 0; // Contador durante el cual no puede disparar
int cooling_status_counter_ = 0; // Contador para la animación del estado cooling
int score_ = 0; // Puntos del jugador int score_ = 0; // Puntos del jugador
float score_multiplier_ = 1.0f; // Multiplicador de puntos float score_multiplier_ = 1.0f; // Multiplicador de puntos
PlayerStatus status_walking_ = PlayerStatus::WALKING_STOP; // Estado del jugador al moverse PlayerStatus status_walking_ = PlayerStatus::WALKING_STOP; // Estado del jugador al moverse
@@ -78,8 +81,7 @@ private:
int power_up_desp_x_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador int power_up_desp_x_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
Circle collider_ = Circle(0, 0, 9); // Circulo de colisión del jugador Circle collider_ = Circle(0, 0, 9); // Circulo de colisión del jugador
int continue_counter_ = 10; // Contador para poder continuar int continue_counter_ = 10; // Contador para poder continuar
Uint32 continue_ticks_ = 0; // Variable para poder cambiar el contador de Uint32 continue_ticks_ = 0; // Variable para poder cambiar el contador de continue en función del tiempo
// continue en función del tiempo
int scoreboard_panel_ = 0; // Panel del marcador asociado al jugador int scoreboard_panel_ = 0; // Panel del marcador asociado al jugador
std::string name_; // Nombre del jugador std::string name_; // Nombre del jugador
std::string record_name_; // Nombre del jugador para la tabla de mejores puntuaciones std::string record_name_; // Nombre del jugador para la tabla de mejores puntuaciones
@@ -115,6 +117,8 @@ private:
// Cambia el modo del marcador // Cambia el modo del marcador
void setScoreboardMode(ScoreboardMode mode); void setScoreboardMode(ScoreboardMode mode);
bool isCooling();
public: public:
// Constructor // Constructor
Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations); Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations);