|
|
|
#include "systems.hpp"
|
|
|
|
|
|
|
|
using namespace Components;
|
|
|
|
|
|
|
|
void System::enemy_pathing(DinkyECS::World &world, Map &game_map, Player &player) {
|
|
|
|
// move enemies system
|
|
|
|
world.system<Position, Motion>([&](const auto &ent, auto &position, auto &motion) {
|
|
|
|
if(ent != player.entity) {
|
|
|
|
Point out = position.location;
|
|
|
|
game_map.neighbors(out, false);
|
|
|
|
motion = { int(out.x - position.location.x), int(out.y - position.location.y)};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void System::motion(DinkyECS::World &world, Map &game_map) {
|
|
|
|
world.system<Position, Motion>([&](const auto &ent, auto &position, auto &motion) {
|
|
|
|
Point move_to = {
|
|
|
|
position.location.x + motion.dx,
|
|
|
|
position.location.y + motion.dy
|
|
|
|
};
|
|
|
|
motion = {0,0}; // clear it after getting it
|
|
|
|
|
|
|
|
if(game_map.inmap(move_to.x, move_to.y) && !game_map.iswall(move_to.x,move_to.y)) {
|
|
|
|
game_map.clear_target(position.location);
|
|
|
|
position.location = move_to;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void System::combat(DinkyECS::World &world, Player &player) {
|
|
|
|
const auto& player_position = world.component<Position>(player.entity);
|
|
|
|
|
|
|
|
world.system<Position, Combat>([&](const auto &ent, auto &pos, auto &combat) {
|
|
|
|
if(ent != player.entity && pos.location.x == player_position.location.x &&
|
|
|
|
pos.location.y == player_position.location.y) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void System::draw_entities(DinkyECS::World &world, ftxui::Canvas &canvas) {
|
|
|
|
world.system<Position, Tile>([&](const auto &ent, auto &pos, auto &tile) {
|
|
|
|
canvas.DrawText(pos.location.x*2, pos.location.y*4, tile.chr);
|
|
|
|
});
|
|
|
|
}
|