dungeon/src/Entity.cpp

38 lines
678 B
C++
Raw Normal View History

2017-09-26 15:49:11 +02:00
//
// Created by Adrian on 2017-09-25.
//
#include "Entity.h"
#include "Tilemap.h"
2018-01-09 21:59:05 +01:00
Entity::Entity(vec2i pos) {
2017-09-26 15:49:11 +02:00
position = pos;
collision = false;
sprite_id = '?';
}
vec2i Entity::get_position() {
return position;
}
2018-01-09 21:59:05 +01:00
bool Entity::move(vec2i dpos, Tilemap* map) {
return move(dpos.x, dpos.y, map);
2017-09-26 15:49:11 +02:00
}
2018-01-09 21:59:05 +01:00
bool Entity::move(int dx, int dy, Tilemap* map) {
vec2i newpos = position + vec2i(dx, dy);
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;
}
bool Entity::has_collision() {
return collision;
}