dungeon/src/Actor.cpp

49 lines
852 B
C++
Raw Normal View History

2017-09-17 13:43:13 +02:00
#include "Actor.h"
#include "Tilemap.h"
#include "BehaviourTree.h"
2017-09-24 00:15:28 +02:00
int idcounter = 0;
2017-09-17 13:43:13 +02:00
Actor::Actor(Tilemap * map, vec2i pos) {
2017-09-24 00:15:28 +02:00
id = idcounter++;
name = "Actor";
2017-09-17 13:43:13 +02:00
this->map = map;
position = pos;
2017-09-23 22:06:36 +02:00
bt = nullptr;
2017-09-17 13:43:13 +02:00
}
2017-09-21 22:44:05 +02:00
const vec2i Actor::get_position() {
2017-09-17 13:43:13 +02:00
return position;
}
bool Actor::Move(int dx, int dy) {
vec2i newpos = position + vec2i(dx, dy); //GoTo({0,0}, {dx,dy});
//dir = ParseDir(dx, dy);
if (!map->IsBlocked(newpos.x, newpos.y)) {
position = newpos;
return true;
}
return false;
}
2017-09-21 22:44:05 +02:00
void Actor::update() {
2017-09-17 13:43:13 +02:00
if (!alive) return;
2017-09-23 22:06:36 +02:00
if (bt != nullptr) {
2017-09-17 13:43:13 +02:00
bt->tick(this);
}
if (health < maxhealth) {
if (healcounter <= 0) {
health++;
healcounter = 4;
}
healcounter--;
}
if (health <= 0) {
Kill();
}
}
2017-09-23 22:06:36 +02:00
Actor::~Actor() = default;