commit de merda pa llevar la branch
This commit is contained in:
@@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
#include "moving_sprite.h"
|
#include "moving_sprite.h"
|
||||||
|
|
||||||
// Declaraciones adelantadas
|
// Declaración adelantada
|
||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
// === Estructura de Animación ===
|
// Estructura de Animación
|
||||||
struct Animation
|
struct Animation
|
||||||
{
|
{
|
||||||
std::string name; // Nombre de la animación
|
std::string name; // Nombre de la animación
|
||||||
@@ -24,41 +24,40 @@ struct Animation
|
|||||||
Animation() : name(std::string()), speed(5), loop(0), completed(false), current_frame(0), counter(0) {}
|
Animation() : name(std::string()), speed(5), loop(0), completed(false), current_frame(0), counter(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// === Alias de Tipos ===
|
// Alias de tipo para buffer de animaciones
|
||||||
using AnimationsFileBuffer = std::vector<std::string>;
|
using AnimationsFileBuffer = std::vector<std::string>;
|
||||||
|
|
||||||
// === Funciones Globales ===
|
// Carga las animaciones desde un fichero en un vector de strings
|
||||||
// Carga las animaciones desde un fichero en un vector
|
|
||||||
AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path);
|
AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path);
|
||||||
|
|
||||||
|
// Clase AnimatedSprite: Sprite animado que hereda de MovingSprite
|
||||||
class AnimatedSprite : public MovingSprite
|
class AnimatedSprite : public MovingSprite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Constructores
|
// --- Constructores y destructor ---
|
||||||
AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
|
AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
|
||||||
AnimatedSprite(std::shared_ptr<Texture> texture, const AnimationsFileBuffer &animations);
|
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) {}
|
||||||
|
|
||||||
virtual ~AnimatedSprite() override = default;
|
virtual ~AnimatedSprite() override = default;
|
||||||
|
|
||||||
// === Actualización ===
|
// --- Métodos principales ---
|
||||||
void update() override; // Actualiza la animación
|
void update() override; // Actualiza la animación
|
||||||
|
|
||||||
// === Control de Animaciones ===
|
// --- Control de animaciones ---
|
||||||
void setCurrentAnimation(const std::string &name = "default"); // Establecer por nombre
|
void setCurrentAnimation(const std::string &name = "default"); // Establece la animación por nombre
|
||||||
void setCurrentAnimation(int index = 0); // Establecer por índice
|
void setCurrentAnimation(int index = 0); // Establece la animación por índice
|
||||||
void resetAnimation(); // Reiniciar la animación
|
void resetAnimation(); // Reinicia la animación actual
|
||||||
|
|
||||||
// === Consultas ===
|
// --- Consultas ---
|
||||||
bool animationIsCompleted(); // Comprobar si ha terminado
|
bool animationIsCompleted(); // Comprueba si la animación ha terminado
|
||||||
int getIndex(const std::string &name); // Obtener índice por nombre
|
int getIndex(const std::string &name); // Obtiene el índice de una animación por nombre
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// === Datos de Animación ===
|
// --- Datos de animación ---
|
||||||
std::vector<Animation> animations_; // Vector de animaciones disponibles
|
std::vector<Animation> animations_; // Vector de animaciones disponibles
|
||||||
int current_animation_ = 0; // Índice de la animación activa
|
int current_animation_ = 0; // Índice de la animación activa
|
||||||
|
|
||||||
// === Métodos Internos ===
|
// --- Métodos internos ---
|
||||||
void animate(); // Calcular el frame actual de la animación
|
void animate(); // Calcula el frame actual de la animación
|
||||||
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source); // Cargar desde buffer
|
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source); // Carga animaciones desde un buffer
|
||||||
};
|
};
|
||||||
@@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
// === Enumeraciones ===
|
// Tipos de recursos gestionados por Asset
|
||||||
enum class AssetType : int
|
enum class AssetType : int
|
||||||
{
|
{
|
||||||
BITMAP,
|
BITMAP,
|
||||||
@@ -20,30 +19,37 @@ enum class AssetType : int
|
|||||||
MAX_ASSET_TYPE,
|
MAX_ASSET_TYPE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Clase Asset: gestor de recursos (singleton)
|
||||||
class Asset
|
class Asset
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// === Singleton ===
|
// Obtención de la instancia única (Meyers Singleton)
|
||||||
static Asset &get() // Obtención de la instancia única (Meyers Singleton)
|
static Asset &get()
|
||||||
{
|
{
|
||||||
static Asset instance;
|
static Asset instance;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Inicialización ===
|
// Inicializa el gestor de recursos con la ruta del ejecutable
|
||||||
void init(const std::string &executable_path)
|
void init(const std::string &executable_path)
|
||||||
{
|
{
|
||||||
executable_path_ = getPath(executable_path);
|
executable_path_ = getPath(executable_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Gestión de Recursos ===
|
// Añade un recurso a la lista
|
||||||
void add(const std::string &file, AssetType type, bool required = true, bool absolute = false); // Añadir recurso
|
void add(const std::string &file, AssetType type, bool required = true, bool absolute = false);
|
||||||
std::string get(const std::string &text) const; // Obtener ruta completa
|
|
||||||
bool check() const; // Verificar existencia
|
// Obtiene la ruta completa de un recurso a partir de su nombre
|
||||||
std::vector<std::string> getListByType(AssetType type) const; // Lista por tipo
|
std::string get(const std::string &text) const;
|
||||||
|
|
||||||
|
// Verifica la existencia de todos los recursos requeridos
|
||||||
|
bool check() const;
|
||||||
|
|
||||||
|
// Devuelve una lista de archivos de un tipo concreto
|
||||||
|
std::vector<std::string> getListByType(AssetType type) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// === Estructura Interna ===
|
// Estructura interna para almacenar información de cada recurso
|
||||||
struct AssetItem
|
struct AssetItem
|
||||||
{
|
{
|
||||||
std::string file; // Ruta del fichero desde la raíz del directorio
|
std::string file; // Ruta del fichero desde la raíz del directorio
|
||||||
@@ -54,18 +60,18 @@ private:
|
|||||||
: file(filePath), type(assetType), required(isRequired) {}
|
: file(filePath), type(assetType), required(isRequired) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// === Variables Internas ===
|
// Variables internas
|
||||||
int longest_name_ = 0; // Longitud del nombre más largo
|
int longest_name_ = 0; // Longitud del nombre más largo
|
||||||
std::vector<AssetItem> file_list_; // Lista con todas las rutas
|
std::vector<AssetItem> file_list_; // Lista con todas las rutas de recursos
|
||||||
std::string executable_path_; // Ruta del ejecutable
|
std::string executable_path_; // Ruta del ejecutable
|
||||||
|
|
||||||
// === Métodos Internos ===
|
// Métodos internos
|
||||||
bool checkFile(const std::string &path) const; // Verificar si archivo existe
|
bool checkFile(const std::string &path) const; // Verifica si un archivo existe
|
||||||
std::string getTypeName(AssetType type) const; // Obtener nombre textual del tipo
|
std::string getTypeName(AssetType type) const; // Devuelve el nombre textual del tipo de recurso
|
||||||
|
|
||||||
// === Patrón Singleton ===
|
// Patrón Singleton: constructor y destructor privados, sin copia ni asignación
|
||||||
Asset() = default; // Constructor privado
|
Asset() = default;
|
||||||
~Asset() = default; // Destructor privado
|
~Asset() = default;
|
||||||
Asset(const Asset &) = delete; // Evitar copia
|
Asset(const Asset &) = delete;
|
||||||
Asset &operator=(const Asset &) = delete; // Evitar asignación
|
Asset &operator=(const Asset &) = delete;
|
||||||
};
|
};
|
||||||
@@ -2,23 +2,23 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "audio.h"
|
// Clase Audio: gestor de audio (singleton)
|
||||||
|
|
||||||
class Audio
|
class Audio
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// === Singleton ===
|
// === Singleton ===
|
||||||
static Audio &get() // Obtención de la instancia única (Meyers Singleton)
|
// Obtención de la instancia única (Meyers Singleton)
|
||||||
|
static Audio &get()
|
||||||
{
|
{
|
||||||
static Audio instance;
|
static Audio instance;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Control de Música ===
|
// === Control de Música ===
|
||||||
void playMusic(const std::string &name, int loop = -1); // Reproducir en bucle
|
void playMusic(const std::string &name, int loop = -1); // Reproducir música en bucle
|
||||||
void pauseMusic(); // Pausar reproducción
|
void pauseMusic(); // Pausar reproducción de música
|
||||||
void stopMusic(); // Detener completamente
|
void stopMusic(); // Detener completamente la música
|
||||||
void fadeOutMusic(int milliseconds); // Fundido de salida
|
void fadeOutMusic(int milliseconds); // Fundido de salida de la música
|
||||||
|
|
||||||
// === Control de Sonidos ===
|
// === Control de Sonidos ===
|
||||||
void playSound(const std::string &name); // Reproducir sonido puntual
|
void playSound(const std::string &name); // Reproducir sonido puntual
|
||||||
@@ -27,20 +27,20 @@ public:
|
|||||||
// === Configuración General ===
|
// === Configuración General ===
|
||||||
void enable() { enabled_ = true; } // Habilitar audio
|
void enable() { enabled_ = true; } // Habilitar audio
|
||||||
void disable() { enabled_ = false; } // Deshabilitar audio
|
void disable() { enabled_ = false; } // Deshabilitar audio
|
||||||
void enable(bool value) { enabled_ = value; } // Establecer estado
|
void enable(bool value) { enabled_ = value; } // Establecer estado general
|
||||||
void toggleEnabled() { enabled_ = !enabled_; } // Alternar estado
|
void toggleEnabled() { enabled_ = !enabled_; } // Alternar estado general
|
||||||
|
|
||||||
// === Configuración de Sonidos ===
|
// === Configuración de Sonidos ===
|
||||||
void enableSound() { sound_enabled_ = true; } // Habilitar sonidos
|
void enableSound() { sound_enabled_ = true; } // Habilitar sonidos
|
||||||
void disableSound() { sound_enabled_ = false; } // Deshabilitar sonidos
|
void disableSound() { sound_enabled_ = false; } // Deshabilitar sonidos
|
||||||
void enableSound(bool value) { sound_enabled_ = value; } // Establecer estado
|
void enableSound(bool value) { sound_enabled_ = value; } // Establecer estado de sonidos
|
||||||
void toggleSound() { sound_enabled_ = !sound_enabled_; } // Alternar estado
|
void toggleSound() { sound_enabled_ = !sound_enabled_; } // Alternar estado de sonidos
|
||||||
|
|
||||||
// === Configuración de Música ===
|
// === Configuración de Música ===
|
||||||
void enableMusic() { music_enabled_ = true; } // Habilitar música
|
void enableMusic() { music_enabled_ = true; } // Habilitar música
|
||||||
void disableMusic() { music_enabled_ = false; } // Deshabilitar música
|
void disableMusic() { music_enabled_ = false; } // Deshabilitar música
|
||||||
void enableMusic(bool value) { music_enabled_ = value; } // Establecer estado
|
void enableMusic(bool value) { music_enabled_ = value; } // Establecer estado de música
|
||||||
void toggleMusic() { music_enabled_ = !music_enabled_; } // Alternar estado
|
void toggleMusic() { music_enabled_ = !music_enabled_; } // Alternar estado de música
|
||||||
|
|
||||||
// === Control de Volumen ===
|
// === Control de Volumen ===
|
||||||
void setSoundVolume(int volume); // Ajustar volumen de efectos
|
void setSoundVolume(int volume); // Ajustar volumen de efectos
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <memory> // Para unique_ptr, shared_ptr
|
#include <memory> // Para unique_ptr, shared_ptr
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include "utils.h" // Para Color
|
#include "utils.h" // Para Color
|
||||||
|
|
||||||
class MovingSprite;
|
class MovingSprite;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Texture;
|
class Texture;
|
||||||
@@ -23,6 +24,7 @@ class Texture;
|
|||||||
- setColor(Color color) -> Aplica un color de atenuación
|
- setColor(Color color) -> Aplica un color de atenuación
|
||||||
- setAlpha(int alpha) -> Ajusta la transparencia de la capa de atenuación
|
- setAlpha(int alpha) -> Ajusta la transparencia de la capa de atenuación
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Background
|
class Background
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user