Implementando el enemy engine
This commit is contained in:
43
source/enemy_path.cpp
Normal file
43
source/enemy_path.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "enemy_path.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
// Constructor
|
||||
EnemyPath::EnemyPath(enemy_t enemy, SDL_Point p1, SDL_Point p2) : Enemy(enemy)
|
||||
{
|
||||
// Obten el resto de valores
|
||||
this->p1 = p1;
|
||||
this->p2 = p2;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
EnemyPath::~EnemyPath()
|
||||
{
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void EnemyPath::update()
|
||||
{
|
||||
sprite->update();
|
||||
sprite->animate();
|
||||
checkPath();
|
||||
collider = getRect();
|
||||
}
|
||||
|
||||
// Comprueba si ha llegado al limite del recorrido para darse media vuelta
|
||||
void EnemyPath::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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user