revisió de capçaleres

This commit is contained in:
2025-05-29 09:58:23 +02:00
parent 677e4d465d
commit 0fc8224ef8
45 changed files with 1870 additions and 2684 deletions

View File

@@ -1,18 +1,22 @@
#pragma once
#include <SDL3/SDL_rect.h> // Para SDL_FRect
#include <memory> // Para shared_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "moving_sprite.h" // Para MovingSprite
#include <SDL3/SDL_rect.h>
#include <memory>
#include <string>
#include <vector>
#include "moving_sprite.h"
// Declaraciones adelantadas
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 al que vuelve la animación al terminar (-1 para no repetir)
int loop; // Frame de vuelta al terminar (-1 para no repetir)
bool completed; // Indica si la animación ha finalizado
int current_frame; // Frame actual en reproducción
int counter; // Contador para la animación
@@ -20,39 +24,41 @@ struct Animation
Animation() : name(std::string()), speed(5), loop(0), completed(false), current_frame(0), counter(0) {}
};
// === Alias de Tipos ===
using AnimationsFileBuffer = std::vector<std::string>;
// === Funciones Globales ===
// Carga las animaciones desde un fichero en un vector
AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path);
class AnimatedSprite : public MovingSprite
{
public:
// Constructor
// Constructores
AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
AnimatedSprite(std::shared_ptr<Texture> texture, const AnimationsFileBuffer &animations);
explicit AnimatedSprite(std::shared_ptr<Texture> texture)
: MovingSprite(texture) {}
explicit AnimatedSprite(std::shared_ptr<Texture> texture) : MovingSprite(texture) {}
// Destructor
virtual ~AnimatedSprite() override = default;
// Actualización del objeto
void update() override; // Actualiza la animación
bool animationIsCompleted(); // Comprueba si la animación ha terminado
int getIndex(const std::string &name); // Obtiene el índice de una animación según su nombre
// === Actualización ===
void update() override; // Actualiza la animación
// Manipulación de animaciones
void setCurrentAnimation(const std::string &name = "default"); // Establece animación por nombre
void setCurrentAnimation(int index = 0); // Establece animación por índice
void resetAnimation(); // Reinicia la animación
// === Control de Animaciones ===
void setCurrentAnimation(const std::string &name = "default"); // Establecer por nombre
void setCurrentAnimation(int index = 0); // Establecer por índice
void resetAnimation(); // Reiniciar la animación
// === Consultas ===
bool animationIsCompleted(); // Comprobar si ha terminado
int getIndex(const std::string &name); // Obtener índice por nombre
protected:
// Almacenamiento de animaciones
// === Datos de Animación ===
std::vector<Animation> animations_; // Vector de animaciones disponibles
int current_animation_ = 0; // Índice de la animación activa
// Procesos internos
void animate(); // Calcula el frame actual de la animación
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source); // Carga animaciones desde un buffer
};
// === Métodos Internos ===
void animate(); // Calcular el frame actual de la animación
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source); // Cargar desde buffer
};