afegida Player::computeAnimation() i soluciona algunes animacions incorrectes que havia
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
#include "scoreboard.h" // Para Scoreboard
|
||||
#include "stage.h" // Para power_can_be_added
|
||||
#include "texture.h" // Para Texture
|
||||
#ifdef _DEBUG
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
Player::Player(const Config &config)
|
||||
@@ -389,6 +392,60 @@ void Player::render() {
|
||||
}
|
||||
}
|
||||
|
||||
// Calcula la animacion de moverse y disparar del jugador
|
||||
auto Player::computeAnimation() const -> std::pair<std::string, SDL_FlipMode> {
|
||||
const std::string baseAnim = (walking_state_ == State::WALKING_STOP) ? "stand" : "walk";
|
||||
std::string animName;
|
||||
SDL_FlipMode flipMode = SDL_FLIP_NONE;
|
||||
|
||||
switch (firing_state_) {
|
||||
case State::FIRING_NONE:
|
||||
animName = baseAnim;
|
||||
flipMode = (walking_state_ == State::WALKING_RIGHT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
break;
|
||||
|
||||
case State::FIRING_UP:
|
||||
animName = baseAnim + "-fire-center";
|
||||
flipMode = (walking_state_ == State::WALKING_RIGHT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
break;
|
||||
|
||||
case State::FIRING_LEFT:
|
||||
case State::FIRING_RIGHT:
|
||||
animName = baseAnim + "-fire-side";
|
||||
flipMode = (firing_state_ == State::FIRING_RIGHT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
break;
|
||||
|
||||
case State::RECOILING_UP:
|
||||
animName = baseAnim + "-recoil-center";
|
||||
flipMode = (walking_state_ == State::WALKING_RIGHT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
break;
|
||||
|
||||
case State::RECOILING_LEFT:
|
||||
case State::RECOILING_RIGHT:
|
||||
animName = baseAnim + "-recoil-side";
|
||||
flipMode = (firing_state_ == State::RECOILING_RIGHT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
break;
|
||||
|
||||
case State::COOLING_UP:
|
||||
animName = baseAnim + "-cool-center";
|
||||
flipMode = (walking_state_ == State::WALKING_RIGHT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
break;
|
||||
|
||||
case State::COOLING_LEFT:
|
||||
case State::COOLING_RIGHT:
|
||||
animName = baseAnim + "-cool-side";
|
||||
flipMode = (firing_state_ == State::COOLING_RIGHT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
break;
|
||||
|
||||
default:
|
||||
animName = baseAnim;
|
||||
flipMode = (walking_state_ == State::WALKING_RIGHT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
return {animName, flipMode};
|
||||
}
|
||||
|
||||
// Establece la animación correspondiente al estado
|
||||
void Player::setAnimation() {
|
||||
switch (playing_state_) {
|
||||
@@ -398,64 +455,36 @@ void Player::setAnimation() {
|
||||
case State::LEAVING_SCREEN:
|
||||
case State::TITLE_ANIMATION:
|
||||
case State::CREDITS: {
|
||||
// Crea cadenas de texto para componer el nombre de la animación
|
||||
const std::string WALK_ANIMATION = walking_state_ == State::WALKING_STOP ? "stand" : "walk";
|
||||
const std::string FIRE_ANIMATION = firing_state_ == State::FIRING_UP ? "-fire-center" : "-fire-side";
|
||||
const std::string RECOIL_ANIMATION = firing_state_ == State::RECOILING_UP ? "-recoil-center" : "-recoil-side";
|
||||
const std::string COOL_ANIMATION = firing_state_ == State::COOLING_UP ? "-cool-center" : "-cool-side";
|
||||
|
||||
const SDL_FlipMode FLIP_WALK = walking_state_ == State::WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_FlipMode FLIP_FIRE = firing_state_ == State::FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_FlipMode FLIP_RECOIL = firing_state_ == State::RECOILING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_FlipMode FLIP_COOL = firing_state_ == State::COOLING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
|
||||
// Establece la animación a partir de las cadenas
|
||||
if (firing_state_ == State::FIRING_NONE) {
|
||||
// No esta disparando
|
||||
player_sprite_->setCurrentAnimation(WALK_ANIMATION, false);
|
||||
player_sprite_->setFlip(FLIP_WALK);
|
||||
} else if (isRecoiling()) {
|
||||
// Retroceso
|
||||
player_sprite_->setCurrentAnimation(WALK_ANIMATION + RECOIL_ANIMATION, false);
|
||||
player_sprite_->setFlip(FLIP_RECOIL);
|
||||
} else if (isCooling()) {
|
||||
// Acaba de disparar
|
||||
player_sprite_->setCurrentAnimation(WALK_ANIMATION + COOL_ANIMATION, false);
|
||||
player_sprite_->setFlip(FLIP_COOL);
|
||||
} else {
|
||||
// Está disparando
|
||||
player_sprite_->setCurrentAnimation(WALK_ANIMATION + FIRE_ANIMATION, false);
|
||||
// Si dispara de lado, invierte el sprite segun hacia donde dispara
|
||||
// Si dispara recto, invierte el sprite segun hacia donde camina
|
||||
player_sprite_->setFlip(FIRE_ANIMATION == "-fire-center" ? FLIP_WALK : FLIP_FIRE);
|
||||
}
|
||||
auto [animName, flipMode] = computeAnimation();
|
||||
player_sprite_->setCurrentAnimation(animName, false);
|
||||
player_sprite_->setFlip(flipMode);
|
||||
break;
|
||||
}
|
||||
case State::WAITING: {
|
||||
|
||||
case State::WAITING:
|
||||
player_sprite_->setCurrentAnimation("hello");
|
||||
break;
|
||||
}
|
||||
|
||||
case State::ROLLING:
|
||||
case State::CONTINUE_TIME_OUT: {
|
||||
case State::CONTINUE_TIME_OUT:
|
||||
player_sprite_->setCurrentAnimation("rolling");
|
||||
break;
|
||||
}
|
||||
|
||||
case State::LYING_ON_THE_FLOOR_FOREVER:
|
||||
case State::ENTERING_NAME:
|
||||
case State::CONTINUE: {
|
||||
case State::CONTINUE:
|
||||
player_sprite_->setCurrentAnimation("dead");
|
||||
break;
|
||||
}
|
||||
case State::CELEBRATING: {
|
||||
|
||||
case State::CELEBRATING:
|
||||
player_sprite_->setCurrentAnimation("celebration");
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Actualiza las animaciones de los sprites
|
||||
player_sprite_->update(); // Hace avanzar las animaciones y mueve el cadaver del jugador
|
||||
player_sprite_->update();
|
||||
power_sprite_->update();
|
||||
}
|
||||
|
||||
|
||||
@@ -297,4 +297,5 @@ class Player {
|
||||
void updateWalkingStateForCredits(); // Actualiza el estado de caminata de algún personaje u elemento animado en los créditos
|
||||
void setInputBasedOnPlayerId(); // Asocia las entradas de control en función del identificador del jugador (teclas, mando, etc.)
|
||||
void updateStepCounter(); // Incrementa o ajusta el contador de pasos para animaciones o mecánicas relacionadas con movimiento
|
||||
auto computeAnimation() const -> std::pair<std::string, SDL_FlipMode>; // Calcula la animacion de moverse y disparar del jugador
|
||||
};
|
||||
Reference in New Issue
Block a user