pasaeta loca de clang-format (despres m'arrepentiré pero bueno)
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_FRect
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para basic_string, string, hash
|
||||
#include <unordered_map> // Para unordered_map
|
||||
#include <vector> // Para vector
|
||||
#include <SDL3/SDL.h> // Para SDL_FRect
|
||||
#include <stddef.h> // Para size_t
|
||||
|
||||
#include "moving_sprite.h" // Para MovingSprite
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para basic_string, string, hash
|
||||
#include <unordered_map> // Para unordered_map
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "moving_sprite.h" // Para MovingSprite
|
||||
|
||||
// Declaración adelantada
|
||||
class Texture;
|
||||
|
||||
// Estructura de Animación
|
||||
struct Animation
|
||||
{
|
||||
std::string name; // Nombre de la animación
|
||||
std::vector<SDL_FRect> frames; // Frames que componen la animación
|
||||
int speed; // Velocidad de reproducción
|
||||
int loop; // Frame de vuelta al terminar (-1 para no repetir)
|
||||
bool completed; // Indica si la animación ha finalizado
|
||||
size_t current_frame; // Frame actual en reproducción
|
||||
int counter; // Contador para la animación
|
||||
struct Animation {
|
||||
std::string name; // Nombre de la animación
|
||||
std::vector<SDL_FRect> frames; // Frames que componen la animación
|
||||
int speed; // Velocidad de reproducción
|
||||
int loop; // Frame de vuelta al terminar (-1 para no repetir)
|
||||
bool completed; // Indica si la animación ha finalizado
|
||||
size_t current_frame; // Frame actual en reproducción
|
||||
int counter; // Contador para la animación
|
||||
|
||||
Animation() : name(std::string()), speed(5), loop(0), completed(false), current_frame(0), counter(0) {}
|
||||
};
|
||||
@@ -33,9 +33,8 @@ using AnimationsFileBuffer = std::vector<std::string>;
|
||||
AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path);
|
||||
|
||||
// Clase AnimatedSprite: Sprite animado que hereda de MovingSprite
|
||||
class AnimatedSprite : public MovingSprite
|
||||
{
|
||||
public:
|
||||
class AnimatedSprite : public MovingSprite {
|
||||
public:
|
||||
// --- Constructores y destructor ---
|
||||
AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
|
||||
AnimatedSprite(std::shared_ptr<Texture> texture, const AnimationsFileBuffer &animations);
|
||||
@@ -43,28 +42,28 @@ public:
|
||||
virtual ~AnimatedSprite() override = default;
|
||||
|
||||
// --- Métodos principales ---
|
||||
void update() override; // Actualiza la animación
|
||||
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
|
||||
size_t getAnimationSpeed() const { return animations_[current_animation_].speed; } // Obtiene la velocidad de la animación actual
|
||||
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
|
||||
size_t getAnimationSpeed() const { return animations_[current_animation_].speed; } // Obtiene la velocidad de la animación actual
|
||||
|
||||
// --- Consultas ---
|
||||
bool animationIsCompleted(); // Comprueba si la animación ha terminado
|
||||
int getIndex(const std::string &name); // Obtiene el índice de una animación por nombre
|
||||
bool animationIsCompleted(); // Comprueba si la animación ha terminado
|
||||
int getIndex(const std::string &name); // Obtiene el índice de una animación por nombre
|
||||
|
||||
protected:
|
||||
protected:
|
||||
// --- Datos de animación ---
|
||||
std::vector<Animation> animations_; // Vector de animaciones disponibles
|
||||
int current_animation_ = 0; // Índice de la animación activa
|
||||
std::vector<Animation> animations_; // Vector de animaciones disponibles
|
||||
int current_animation_ = 0; // Índice de la animación activa
|
||||
|
||||
// --- Mapa para búsqueda rápida de animaciones por nombre ---
|
||||
std::unordered_map<std::string, int> animation_indices_;
|
||||
|
||||
// --- Métodos internos ---
|
||||
void animate(); // Calcula el frame actual de la animación
|
||||
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source); // Carga animaciones desde un buffer
|
||||
void animate(); // Calcula el frame actual de la animación
|
||||
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source); // Carga animaciones desde un buffer
|
||||
};
|
||||
Reference in New Issue
Block a user