main
parent
da04c5ec54
commit
e42647d727
@ -0,0 +1,28 @@ |
||||
#pragma once |
||||
#include "dinkyecs.hpp" |
||||
|
||||
struct Player { |
||||
DinkyECS::Entity entity; |
||||
}; |
||||
|
||||
struct Position { |
||||
Point location; |
||||
}; |
||||
|
||||
struct Motion { |
||||
int dx; |
||||
int dy; |
||||
}; |
||||
|
||||
struct Combat { |
||||
int hp; |
||||
int damage; |
||||
}; |
||||
|
||||
struct Treasure { |
||||
int amount; |
||||
}; |
||||
|
||||
struct Tile { |
||||
std::string chr = "!"; |
||||
}; |
@ -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); |
||||
}); |
||||
} |
@ -0,0 +1,12 @@ |
||||
#pragma once |
||||
#include "dinkyecs.hpp" |
||||
#include "map.hpp" |
||||
#include "components.hpp" |
||||
#include <ftxui/dom/canvas.hpp> |
||||
|
||||
namespace System { |
||||
void motion(DinkyECS::World &world, Map &game_map); |
||||
void combat(DinkyECS::World &world, Player &player); |
||||
void draw_entities(DinkyECS::World &world, ftxui::Canvas &canvas); |
||||
void enemy_pathing(DinkyECS::World &world, Map &game_map, Player &player); |
||||
} |
Loading…
Reference in new issue