afegit AnimatedSprite::getCurrentAnimationFrame()

fix: player2.gif faltava el outline
noves veus i arreglo d'altres
style: fitxer de config
This commit is contained in:
2025-08-15 11:09:17 +02:00
parent a983269080
commit a7519fc372
13 changed files with 89 additions and 93 deletions

View File

@@ -52,7 +52,7 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const Animation
}
// Obtiene el índice de la animación a partir del nombre
auto AnimatedSprite::getIndex(const std::string& name) -> int {
auto AnimatedSprite::getAnimationIndex(const std::string& name) -> int {
auto iterator = animation_indices_.find(name);
if (iterator != animation_indices_.end()) {
// Si se encuentra la animación en el mapa, devuelve su índice
@@ -101,7 +101,7 @@ auto AnimatedSprite::animationIsCompleted() -> bool {
// Establece la animacion actual
void AnimatedSprite::setCurrentAnimation(const std::string& name, bool reset) {
const auto NEW_ANIMATION = getIndex(name);
const auto NEW_ANIMATION = getAnimationIndex(name);
if (current_animation_ != NEW_ANIMATION) {
const auto OLD_ANIMATION = current_animation_;
current_animation_ = NEW_ANIMATION;

View File

@@ -56,17 +56,18 @@ class AnimatedSprite : public MovingSprite {
void update() override; // Actualiza la animación
// --- Control de animaciones ---
void setCurrentAnimation(const std::string& name = "default", bool reset = true); // Establece la animación por nombre
void setCurrentAnimation(int index = 0, bool reset = true); // Establece la animación por índice
void resetAnimation(); // Reinicia la animación actual
void setAnimationSpeed(size_t value); // Establece la velocidad de la animación
auto getAnimationSpeed() const -> size_t { return animations_[current_animation_].speed; } // Obtiene la velocidad de la animación actual
void animtionPause() { animations_[current_animation_].paused = true; } // Detiene la animación
void animationResume() { animations_[current_animation_].paused = false; } // Reanuda la animación
void setCurrentAnimation(const std::string& name = "default", bool reset = true); // Establece la animación por nombre
void setCurrentAnimation(int index = 0, bool reset = true); // Establece la animación por índice
void resetAnimation(); // Reinicia la animación actual
void setAnimationSpeed(size_t value); // Establece la velocidad de la animación
auto getAnimationSpeed() const -> size_t { return animations_[current_animation_].speed; } // Obtiene la velocidad de la animación actual
void animtionPause() { animations_[current_animation_].paused = true; } // Detiene la animación
void animationResume() { animations_[current_animation_].paused = false; } // Reanuda la animación
auto getCurrentAnimationFrame() const -> size_t { return animations_[current_animation_].current_frame; } // Obtiene el numero de frame de la animación actual
// --- Consultas ---
auto animationIsCompleted() -> bool; // Comprueba si la animación ha terminado
auto getIndex(const std::string& name) -> int; // Obtiene el índice de una animación por nombre
auto animationIsCompleted() -> bool; // Comprueba si la animación ha terminado
auto getAnimationIndex(const std::string& name) -> int; // Obtiene el índice de una animación por nombre
protected:
// --- Datos de animación ---

View File

@@ -101,14 +101,11 @@ auto saveToFile() -> bool {
// Opciones de ventana
file << "## WINDOW\n";
file << "\n";
file << "window.zoom=" << window.zoom << "\n";
// Opciones de video
file << "## VIDEO\n";
file << "\n## VIDEO\n";
file << "## video.scale_mode [" << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_NEAREST) << ": nearest, " << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_LINEAR) << ": lineal]\n";
file << "\n";
file << "video.fullscreen=" << boolToString(video.fullscreen) << "\n";
file << "video.scale_mode=" << static_cast<int>(video.scale_mode) << "\n";
@@ -117,9 +114,8 @@ auto saveToFile() -> bool {
file << "video.shaders=" << boolToString(video.shaders) << "\n";
// Opciones de audio
file << "\n\n## AUDIO\n";
file << "\n## AUDIO\n";
file << "## volume [0 .. 100]\n";
file << "\n";
file << "audio.enabled=" << boolToString(audio.enabled) << "\n";
file << "audio.volume=" << audio.volume << "\n";
@@ -129,10 +125,9 @@ auto saveToFile() -> bool {
file << "audio.sound.volume=" << audio.sound.volume << "\n";
// Opciones del juego
file << "\n\n## GAME\n";
file << "\n## GAME\n";
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
file << "## game.difficulty [" << static_cast<int>(Difficulty::Code::EASY) << ": easy, " << static_cast<int>(Difficulty::Code::NORMAL) << ": normal, " << static_cast<int>(Difficulty::Code::HARD) << ": hard]\n";
file << "\n";
file << "game.language=" << static_cast<int>(settings.language) << "\n";
file << "game.difficulty=" << static_cast<int>(settings.difficulty) << "\n";
@@ -140,11 +135,11 @@ auto saveToFile() -> bool {
file << "game.shutdown_enabled=" << boolToString(settings.shutdown_enabled) << "\n";
// Opciones de mandos
file << "\n\n## CONTROLLERS\n";
file << "\n## CONTROLLERS\n";
gamepad_manager.saveToFile(file);
// Opciones de teclado
file << "\n\n## KEYBOARD\n";
file << "\n## KEYBOARD\n";
file << "keyboard.player=" << static_cast<int>(keyboard.player_id) << "\n";
// Cierra el fichero

View File

@@ -182,7 +182,7 @@ void Player::move() {
handleWaitingMovement();
break;
case State::RECOVER:
handleThankYouMovement();
handleRecoverMovement();
break;
default:
break;
@@ -201,11 +201,9 @@ void Player::handlePlayingMovement() {
shiftSprite();
}
void Player::handleThankYouMovement() {
// Si termina la animacion, cambia de estado
if (player_sprite_->animationIsCompleted()) {
setPlayingState(State::RESPAWNING);
}
void Player::handleRecoverMovement() {
if (player_sprite_->getCurrentAnimationFrame() == 10) { playSound("voice_brbrbr.wav"); }
if (player_sprite_->animationIsCompleted()) { setPlayingState(State::RESPAWNING); }
}
void Player::handleRollingMovement() {
@@ -641,10 +639,10 @@ void Player::setPlayingState(State state) {
switch (playing_state_) {
case State::RECOVER: {
playSound("voice_thankyou.wav");
break;
}
case State::RESPAWNING: {
playSound("voice_thankyou.wav");
setPlayingState(State::PLAYING);
setInvulnerable(true);
break;
@@ -708,7 +706,7 @@ void Player::setPlayingState(State state) {
case State::TITLE_ANIMATION: {
// Activa la animación de rodar
player_sprite_->setCurrentAnimation("walk");
playSound("voice_thankyou.wav");
playSound("voice_credit_thankyou.wav");
break;
}
case State::TITLE_HIDDEN: {
@@ -947,7 +945,6 @@ void Player::playSound(const std::string &name) const {
// Indica si se puede dibujar el objeto
auto Player::isRenderable() const -> bool {
// return !isGameOver() && !isTitleHidden();
return !isTitleHidden();
};
@@ -965,4 +962,9 @@ void Player::addScoreToScoreBoard() const {
}
manager->saveToFile(Asset::get()->get("score.bin"));
}
void Player::addCredit() {
++credits_used_;
playSound("credit.wav");
}

View File

@@ -184,8 +184,8 @@ class Player {
void setScoreBoardPanel(Scoreboard::Id panel) { scoreboard_panel_ = panel; }
void setScoreMultiplier(float value) { score_multiplier_ = value; }
void setWalkingState(State state) { walking_state_ = state; }
void addCredit() { ++credits_used_; }
void addCredit();
void setGamepad(std::shared_ptr<Input::Gamepad> gamepad) { gamepad_ = gamepad; }
[[nodiscard]] auto getGamepad() const -> std::shared_ptr<Input::Gamepad> { return gamepad_; }
void setUsesKeyboard(bool value) { uses_keyboard_ = value; }
@@ -281,7 +281,7 @@ class Player {
void transitionToCooling(); // Cambia el estado actual al de enfriamiento (por ejemplo, tras una ráfaga o sobrecalentamiento)
void completeCooling(); // Finaliza el proceso de enfriamiento y restablece el estado listo para disparar
void handlePlayingMovement(); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo
void handleThankYouMovement(); // Comprueba si ha acabado la animación
void handleRecoverMovement(); // Comprueba si ha acabado la animación
void handleRollingMovement(); // Actualiza la lógica de movimiento de "rodar" (posiblemente tras impacto o acción especial)
void handleRollingBoundaryCollision(); // Detecta y maneja colisiones del objeto rodante con los límites de la pantalla
void handleRollingGroundCollision(); // Gestiona la interacción del objeto rodante con el suelo (rebotes, frenado, etc.)

View File

@@ -598,8 +598,7 @@ void Resource::createTextTextures() {
{"game_text_powerup", Lang::getText("[GAME_TEXT] 4")},
{"game_text_one_hit", Lang::getText("[GAME_TEXT] 5")},
{"game_text_stop", Lang::getText("[GAME_TEXT] 6")},
{"game_text_1000000_points", Lang::getText("[GAME_TEXT] 8")},
{"game_text_thank_you", Lang::getText("[GAME_TEXT] THANK_YOU")}};
{"game_text_1000000_points", Lang::getText("[GAME_TEXT] 8")}};
auto text = getText("04b_25");
for (const auto &s : strings) {

View File

@@ -144,7 +144,6 @@ void Game::setResources() {
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_one_hit"));
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_stop"));
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_100000_points"));
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_thank_you"));
// Texturas - Items
item_textures_.clear();
@@ -1405,9 +1404,6 @@ void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) {
player->setPlayingState(Player::State::RECOVER);
player->addCredit();
sendPlayerToTheFront(player);
// Crea letrero de THANK_YOU
//const auto X = player->getPosX() + (player->getWidth() - game_text_textures_.at(7)->getWidth()) / 2;
//createItemText(X, game_text_textures_.at(7));
}
// Disminuye el contador de continuación si se presiona cualquier botón de disparo.