Files
coffee_crisis_arcade_edition/source/path_sprite.h
2025-03-25 14:13:58 +01:00

83 lines
2.3 KiB
C++

#pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Point
#include <functional> // Para function
#include <memory> // Para shared_ptr
#include <vector> // Para vector
#include "sprite.h" // Para Sprite
class Texture; // lines 8-8
enum class PathType
{
VERTICAL,
HORIZONTAL,
};
enum class PathCentered
{
ON_X,
ON_Y,
NONE,
};
// Estructuras
struct Path
{
std::vector<SDL_Point> spots; // Puntos por los que se desplazará el sprite
int waiting_counter; // Tiempo de espera una vez en el destino
bool on_destination = false; // Indica si ha llegado al destino
bool finished = false; // Indica si ha terminado de esperarse
int counter = 0; // Contador interno
// Constructor
Path(const std::vector<SDL_Point> &spots_init, int waiting_counter_init)
: spots(spots_init), waiting_counter(waiting_counter_init) {}
};
// Devuelve un vector con los puntos que conforman la ruta
std::vector<SDL_Point> createPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction);
// Clase PathSprite
class PathSprite : public Sprite
{
private:
// Variables
bool enabled_ = false; // Indica si el objeto está habilitado
bool has_finished_ = false; // Indica si el objeto ha finalizado el recorrido
int current_path_ = 0; // Path que se está recorriendo actualmente
std::vector<Path> paths_; // Caminos a recorrer por el sprite
// Coloca el sprite en los diferentes puntos del recorrido
void moveThroughCurrentPath();
// Cambia de recorrido o finaliza
void goToNextPathOrDie();
public:
// Constructor
explicit PathSprite(std::shared_ptr<Texture> texture)
: Sprite(texture) {}
// Destructor
~PathSprite() override = default;
// Actualiza la posición del sprite
void update();
// Muestra el sprite por pantalla
void render() override;
// Añade un recorrido
void addPath(Path path, bool centered = false);
void addPath(std::vector<SDL_Point> spots, int waiting_counter = 0);
void addPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction, int waiting_counter = 0);
// Habilita el objeto
void enable();
// Indica si ha terminado todos los recorridos
bool hasFinished();
// Getters
int getCurrentPath() const { return current_path_; }
};