2017-09-26 15:49:11 +02:00
|
|
|
//
|
|
|
|
// Created by Adrian on 2017-09-25.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "Tilemap.h"
|
|
|
|
|
|
|
|
Entity::Entity(Tilemap *map, vec2i pos) {
|
|
|
|
this->map = map;
|
|
|
|
position = pos;
|
|
|
|
collision = false;
|
|
|
|
sprite_id = '?';
|
|
|
|
}
|
|
|
|
|
|
|
|
vec2i Entity::get_position() {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Entity::move(vec2i dpos) {
|
|
|
|
return move(dpos.x, dpos.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Entity::move(int dx, int dy) {
|
2017-10-18 12:22:28 +02:00
|
|
|
vec2i newpos = position + vec2i(dx, dy);
|
2017-12-30 00:08:09 +01:00
|
|
|
if (!collision || !map->is_blocked(newpos.x, newpos.y)) {
|
2017-09-26 15:49:11 +02:00
|
|
|
position = newpos;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entity::set_position(vec2i pos) {
|
|
|
|
position = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tilemap *Entity::get_map() {
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Entity::has_collision() {
|
|
|
|
return collision;
|
|
|
|
}
|