diff --git a/data/gfx/player/player.ani b/data/gfx/player/player.ani index 7f4f078..3ed8cfa 100644 --- a/data/gfx/player/player.ani +++ b/data/gfx/player/player.ani @@ -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=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=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] \ No newline at end of file diff --git a/data/gfx/player/player1.gif b/data/gfx/player/player1.gif index 33d5c8a..4808eb4 100644 Binary files a/data/gfx/player/player1.gif and b/data/gfx/player/player1.gif differ diff --git a/data/gfx/player/player2.gif b/data/gfx/player/player2.gif index 670d3d1..f83198f 100644 Binary files a/data/gfx/player/player2.gif and b/data/gfx/player/player2.gif differ diff --git a/source/game.cpp b/source/game.cpp index 7320a3f..4e08cd1 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1710,32 +1710,24 @@ void Game::handleNormalPlayerInput(const std::shared_ptr &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, - 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, 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, } } -// 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) { 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(); } diff --git a/source/player.cpp b/source/player.cpp index ce3e829..93b961e 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -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,15 +299,36 @@ void Player::updateCooldown() { if (cooldown_ > 0) { - cooldown_--; - if (power_up_) - { - cooldown_--; - } + cooldown_ -= power_up_ ? 2 : 1; } 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_->setPosY(pos_y_); power_sprite_->setPosX(getPosX() - power_up_desp_x_); -} \ No newline at end of file +} + +bool Player::isCooling() { return status_firing_ == PlayerStatus::COOLING_LEFT || status_firing_ == PlayerStatus::COOLING_UP || status_firing_ == PlayerStatus::COOLING_RIGHT; } \ No newline at end of file diff --git a/source/player.h b/source/player.h index 5317c28..a0496f5 100644 --- a/source/player.h +++ b/source/player.h @@ -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> texture, const std::vector> &animations);