46 lines
1.9 KiB
C++
46 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <memory> // Para shared_ptr
|
|
|
|
#include "animated_sprite.h" // Para AnimatedSprite
|
|
|
|
class Texture;
|
|
|
|
// Clase SmartSprite: Sprite animado que se mueve hacia un destino y puede deshabilitarse automáticamente
|
|
class SmartSprite : public AnimatedSprite
|
|
{
|
|
public:
|
|
// --- Constructor y destructor ---
|
|
explicit SmartSprite(std::shared_ptr<Texture> texture)
|
|
: AnimatedSprite(texture) {}
|
|
~SmartSprite() override = default;
|
|
|
|
// --- Métodos principales ---
|
|
void update() override; // Actualiza la posición y comprueba si ha llegado a su destino
|
|
void render() override; // Dibuja el sprite
|
|
|
|
// --- Getters ---
|
|
int getDestX() const { return dest_x_; } // Obtiene la posición de destino en X
|
|
int getDestY() const { return dest_y_; } // Obtiene la posición de destino en Y
|
|
bool isOnDestination() const { return on_destination_; } // Indica si está en el destino
|
|
bool hasFinished() const { return finished_; } // Indica si ya ha terminado
|
|
|
|
// --- Setters ---
|
|
void setFinishedCounter(int value) { finished_counter_ = value; } // Establece el contador para deshabilitarlo
|
|
void setDestX(int x) { dest_x_ = x; } // Establece la posición de destino en X
|
|
void setDestY(int y) { dest_y_ = y; } // Establece la posición de destino en Y
|
|
void setEnabled(bool value) { enabled_ = value; } // Habilita o deshabilita el objeto
|
|
|
|
private:
|
|
// --- Variables internas ---
|
|
bool on_destination_ = false; // Indica si está en el destino
|
|
int dest_x_ = 0; // Posición de destino en el eje X
|
|
int dest_y_ = 0; // Posición de destino en el eje Y
|
|
int finished_counter_ = 0; // Contador para deshabilitarlo
|
|
bool finished_ = false; // Indica si ya ha terminado
|
|
bool enabled_ = false; // Indica si el objeto está habilitado
|
|
|
|
// --- Métodos internos ---
|
|
void checkFinished(); // Comprueba si ha terminado
|
|
void checkMove(); // Comprueba el movimiento
|
|
}; |