I think I've got my head around what ECS does and am slowly reshaping the engine to use it better.
This commit is contained in:
parent
da04c5ec54
commit
e42647d727
5 changed files with 93 additions and 76 deletions
46
systems.cpp
Normal file
46
systems.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include "systems.hpp"
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue