54 lines
1.8 KiB
C++
54 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <memory> // Para shared_ptr
|
|
#include <string> // Para string
|
|
|
|
class AnimatedSprite;
|
|
|
|
class MovingPlatform {
|
|
public:
|
|
struct Data {
|
|
std::string animation_path; // Ruta al fichero con la animación
|
|
float x{0.0F}; // Posición inicial en el eje X
|
|
float y{0.0F}; // Posición inicial en el eje Y
|
|
float vx{0.0F}; // Velocidad en el eje X
|
|
float vy{0.0F}; // Velocidad en el eje Y
|
|
int x1{0}; // Límite izquierdo de la ruta en el eje X
|
|
int x2{0}; // Límite derecho de la ruta en el eje X
|
|
int y1{0}; // Límite superior de la ruta en el eje Y
|
|
int y2{0}; // Límite inferior de la ruta en el eje Y
|
|
int frame{0}; // Frame inicial para la animación
|
|
};
|
|
|
|
explicit MovingPlatform(const Data& data);
|
|
~MovingPlatform() = default;
|
|
|
|
void update(float delta_time);
|
|
void render();
|
|
#ifdef _DEBUG
|
|
void updateAnimation(float delta_time);
|
|
void resetToInitialPosition(const Data& data);
|
|
#endif
|
|
|
|
auto getRect() -> SDL_FRect;
|
|
auto getCollider() -> SDL_FRect&;
|
|
|
|
// Desplazamiento real del último frame (para transportar al jugador)
|
|
[[nodiscard]] auto getLastDX() const -> float { return last_dx_; }
|
|
[[nodiscard]] auto getLastDY() const -> float { return last_dy_; }
|
|
|
|
private:
|
|
void checkPath(); // Comprueba los límites del recorrido
|
|
|
|
std::shared_ptr<AnimatedSprite> sprite_;
|
|
SDL_FRect collider_{};
|
|
int x1_{0};
|
|
int x2_{0};
|
|
int y1_{0};
|
|
int y2_{0};
|
|
float last_dx_{0.0F}; // Desplazamiento horizontal del último frame
|
|
float last_dy_{0.0F}; // Desplazamiento vertical del último frame
|
|
};
|