#include "actor_moving_platform.h" #include #include // Constructor ActorMovingPlatform::ActorMovingPlatform(actor_t actor, SDL_Point p1, SDL_Point p2) : Actor(actor) { this->p1 = p1; this->p2 = p2; } // 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)); } // Comprueba los límites verticales if (sprite->getPosY() > p2.y || sprite->getPosY() < p1.y) { sprite->setVelY(sprite->getVelY() * (-1)); } } // Actualiza las variables del objeto void ActorMovingPlatform::update() { checkPath(); sprite->update(); sprite->animate(); }