|
|
|
@ -13,9 +13,9 @@ using namespace fmt; |
|
|
|
|
using namespace Components; |
|
|
|
|
using ftxui::Color; |
|
|
|
|
|
|
|
|
|
#define HEARING_DISTANCE 8 |
|
|
|
|
|
|
|
|
|
void System::enemy_pathing(DinkyECS::World &world, Map &game_map, Player &player) { |
|
|
|
|
// TODO: this will be on each enemy not a global thing
|
|
|
|
|
const auto &config = world.get_the<EnemyConfig>(); |
|
|
|
|
const auto &player_position = world.get<Position>(player.entity); |
|
|
|
|
game_map.set_target(player_position.location); |
|
|
|
|
game_map.make_paths(); |
|
|
|
@ -23,7 +23,7 @@ void System::enemy_pathing(DinkyECS::World &world, Map &game_map, Player &player |
|
|
|
|
world.query<Position, Motion>([&](const auto &ent, auto &position, auto &motion) { |
|
|
|
|
if(ent != player.entity) { |
|
|
|
|
Point out = position.location; // copy
|
|
|
|
|
if(game_map.distance(out) < HEARING_DISTANCE) { |
|
|
|
|
if(game_map.distance(out) < config.HEARING_DISTANCE) { |
|
|
|
|
game_map.neighbors(out, false); |
|
|
|
|
motion = { int(out.x - position.location.x), int(out.y - position.location.y)}; |
|
|
|
|
} |
|
|
|
@ -133,6 +133,7 @@ void System::draw_entities(DinkyECS::World &world, Map &game_map, ftxui::Canvas |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canvas, size_t view_x, size_t view_y) { |
|
|
|
|
const auto& config = world.get_the<MapConfig>(); |
|
|
|
|
const auto& player = world.get_the<Player>(); |
|
|
|
|
const auto& player_position = world.get<Position>(player.entity); |
|
|
|
|
Point start = game_map.center_camera(player_position.location, view_x, view_y); |
|
|
|
@ -143,9 +144,9 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canv |
|
|
|
|
|
|
|
|
|
for(size_t x = 0; x < end_x; ++x) { |
|
|
|
|
for(size_t y = 0; y < end_y; ++y) { |
|
|
|
|
string tile = walls[start.y+y][start.x+x] == 1 ? WALL_TILE : FLOOR_TILE; |
|
|
|
|
string tile = walls[start.y+y][start.x+x] == 1 ? config.WALL_TILE : config.FLOOR_TILE; |
|
|
|
|
// the 2 and 4 are from ftxui::Canvas since it does a kind of "subpixel" drawing
|
|
|
|
|
if(tile == WALL_TILE) { |
|
|
|
|
if(tile == config.WALL_TILE) { |
|
|
|
|
canvas.DrawText(x * 2, y * 4, tile, Color::RGB(70, 70, 70)); |
|
|
|
|
} else { |
|
|
|
|
canvas.DrawText(x * 2, y * 4, tile, Color::RGB(20, 20, 20)); |
|
|
|
|