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]
name=stand-sideshoot
name=walk-sideshoot-cooldown
speed=5
loop=0
frames=12,13,14,15
[/animation]
[animation]
name=walk-centershoot
name=stand-sideshoot
speed=5
loop=0
frames=16,17,18,19
[/animation]
[animation]
name=stand-centershoot
name=stand-sideshoot-cooldown
speed=5
loop=0
frames=15
[/animation]
[animation]
name=walk-centershoot
speed=5
loop=0
frames=20,21,22,23
[/animation]
[animation]
name=death
speed=10
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]
name=death
speed=10
loop=0
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]

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

View File

@@ -239,9 +239,11 @@ void Player::setAnimation()
// 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_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_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
if (isPlaying() || isEnteringNameGameCompleted() || isGameCompleted())
@@ -251,12 +253,17 @@ void Player::setAnimation()
player_sprite_->setCurrentAnimation(a_walking);
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
{ // Está disparando
player_sprite_->setCurrentAnimation(a_walking + "-" + a_firing);
// Si dispara de lado, invierte el sprite segun hacia donde dispara
// 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
@@ -292,17 +299,38 @@ void Player::updateCooldown()
{
if (cooldown_ > 0)
{
cooldown_--;
if (power_up_)
{
cooldown_--;
cooldown_ -= power_up_ ? 2 : 1;
}
else
{
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);
}
}
}
// Actualiza al jugador a su posicion, animación y controla los contadores
void Player::update()
@@ -696,3 +724,5 @@ void Player::shiftSprite()
player_sprite_->setPosY(pos_y_);
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_NONE,
COOLING_UP,
COOLING_LEFT,
COOLING_RIGHT,
PLAYING,
CONTINUE,
WAITING,
@@ -36,8 +40,6 @@ enum class PlayerStatus
GAME_COMPLETED,
};
// Variables del jugador
// Clase Player
class Player
{
@@ -63,7 +65,8 @@ private:
int default_pos_y_; // Posición inicial para el jugador
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 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
float score_multiplier_ = 1.0f; // Multiplicador de puntos
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
Circle collider_ = Circle(0, 0, 9); // Circulo de colisión del jugador
int continue_counter_ = 10; // Contador para poder continuar
Uint32 continue_ticks_ = 0; // Variable para poder cambiar el contador de
// continue en función del tiempo
Uint32 continue_ticks_ = 0; // Variable para poder cambiar el contador de continue en función del tiempo
int scoreboard_panel_ = 0; // Panel del marcador asociado al jugador
std::string name_; // Nombre del jugador
std::string record_name_; // Nombre del jugador para la tabla de mejores puntuaciones
@@ -115,6 +117,8 @@ private:
// Cambia el modo del marcador
void setScoreboardMode(ScoreboardMode mode);
bool isCooling();
public:
// 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);