Creando subclases de actors

This commit is contained in:
2022-08-26 07:24:22 +02:00
parent 6b2901cebc
commit aea71599ff
3 changed files with 71 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
#include "actor_moving_platform.h"
#include <fstream>
#include <sstream>
// 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();
}