diff --git a/source/actor.h b/source/actor.h index b419120..b474f7c 100644 --- a/source/actor.h +++ b/source/actor.h @@ -27,7 +27,7 @@ struct actor_t // Clase Actor class Actor { -private: +protected: SDL_Renderer *renderer; // El renderizador de la ventana Asset *asset; // Objeto con la ruta a todos los ficheros de recursos LTexture *texture; // Textura con los graficos del enemigo diff --git a/source/actor_moving_platform.cpp b/source/actor_moving_platform.cpp new file mode 100644 index 0000000..dd9358e --- /dev/null +++ b/source/actor_moving_platform.cpp @@ -0,0 +1,39 @@ +#include "actor_moving_platform.h" +#include +#include + +// Constructor +ActorMovingPlatform::ActorMovingPlatform() +{ +} + +// Destructor +ActorMovingPlatform::~ActorMovingPlatform() +{ +} + +// Comprueba si ha llegado al limite del recorrido para darse media vuelta +void ActorMovingPlatform::checkPath() +{ + // Comprueba los límites horizontales + if (sprite->getPosX() > p2.x || sprite->getPosX() < p1.x) + { + sprite->setVelX(sprite->getVelX() * (-1)); + sprite->flip(); + } + + // Comprueba los límites verticales + if (sprite->getPosY() > p2.y || sprite->getPosY() < p1.y) + { + sprite->setVelY(sprite->getVelY() * (-1)); + sprite->flip(); + } +} + +// Actualiza las variables del objeto +void ActorMovingPlatform::update() +{ + checkPath(); + sprite->update(); + sprite->animate(); +} \ No newline at end of file diff --git a/source/actor_moving_platform.h b/source/actor_moving_platform.h new file mode 100644 index 0000000..997f68b --- /dev/null +++ b/source/actor_moving_platform.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include "actor.h" +#include + +#ifndef ACTOR_MOVING_PLATFORM_H +#define ACTOR_MOVING_PLATFORM_H + +// Clase Actor +class ActorMovingPlatform : public Actor +{ +private: + SDL_Point p1; // Punto 1 (inicial) de la ruta + SDL_Point p2; // Punto 2 (final) de la ruta + + // Comprueba si ha llegado al limite del recorrido para darse media vuelta + void checkPath(); + +public: + // Constructor + ActorMovingPlatform(); + + // Destructor + ~ActorMovingPlatform(); + + // Actualiza las variables del objeto + void update(); +}; + +#endif