polimorfise d'enemics

moving platforms
This commit is contained in:
2026-04-08 14:09:28 +02:00
parent 5e02854e7a
commit 73a520bf3c
20 changed files with 632 additions and 106 deletions

View File

@@ -0,0 +1,53 @@
#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
};