diff --git a/collider.cpp b/collider.cpp index 262dfd2..f8154e2 100644 --- a/collider.cpp +++ b/collider.cpp @@ -22,6 +22,10 @@ bool spatial_map::occupied(Point at) const { return table.contains(at); } +Entity spatial_map::get(Point at) const { + return table.at(at); +} + /* * Avoid doing work by using the dy,dx and confirming that * at.x or at.y is > 0. If either is 0 then there can't be diff --git a/collider.hpp b/collider.hpp index bbc5dee..622d97a 100644 --- a/collider.hpp +++ b/collider.hpp @@ -22,6 +22,7 @@ class spatial_map { void move(Point from, Point to, DinkyECS::Entity ent); void remove(Point pos); bool occupied(Point pos) const; + DinkyECS::Entity get(Point at) const; FoundEntities neighbors(Point position, bool diag=false) const; private: diff --git a/main.cpp b/main.cpp index 500ef2a..7577ce7 100644 --- a/main.cpp +++ b/main.cpp @@ -33,7 +33,7 @@ void configure_world(DinkyECS::World &world, Map &game_map) { world.set(player.entity, {100, 10}); world.set(player.entity, {config.PLAYER_TILE}); world.set(player.entity, {5}); - world.set(player.entity, {150}); + world.set(player.entity, {50}); auto enemy = world.entity(); world.set(enemy, {game_map.place_entity(1)}); @@ -46,11 +46,18 @@ void configure_world(DinkyECS::World &world, Map &game_map) { world.set(enemy2, {0,0}); world.set(enemy2, {20, 10}); world.set(enemy2, {"*"}); + world.set(enemy2, {100}); auto gold = world.entity(); world.set(gold, {game_map.place_entity(3)}); world.set(gold, {100}); world.set(gold, {"$"}); + + + auto wall_torch = world.entity(); + world.set(wall_torch, {game_map.place_entity(4)}); + world.set(wall_torch, {200}); + world.set(wall_torch, {"!"}); } const int GAME_MAP_X = 40; diff --git a/status.txt b/status.txt index f878184..9efe357 100644 --- a/status.txt +++ b/status.txt @@ -1,8 +1,11 @@ TODAY'S GOAL: - -TODO: * Neighbors needs a rewrite * Neighbors algo isn't using greater parameter +* Refine the lighting to support multiple lights. +* Think up an enemy system. +* Revisit map generation. + +TODO: * Write a method for renderer that can translate coordinates. * Can std::any be defaulted to a noop in the events? * Save file isn't saving gold. diff --git a/systems.cpp b/systems.cpp index 41b28b5..8328032 100644 --- a/systems.cpp +++ b/systems.cpp @@ -20,23 +20,49 @@ const int LIGHT_MIN = 20; const int LIGHT_MAX = 160; void System::lighting(DinkyECS::World &world, Map &game_map, Player &player) { - const auto& player_light = world.get(player.entity); - auto &paths = game_map.paths(); + using std::min, std::max, std::clamp; + auto &lighting = game_map.lighting(); std::vector has_light; - for(size_t x = 0; x < game_map.width(); ++x) { - for(size_t y = 0; y < game_map.height(); ++y) { - int dnum = paths[y][x]; - int light = std::clamp(255 - (dnum * player_light.strength), LIGHT_MIN, LIGHT_MAX); - lighting[y][x] = light; - - if(light > LIGHT_MIN) { - has_light.push_back({x,y}); - } + for(auto &row : lighting) { + for(size_t i = 0; i < row.size(); i++) { + row[i] = LIGHT_MIN; } } + world.query([&](const auto &ent, auto &position, auto &lightsource) { + game_map.set_target(position.location); + }); + + game_map.make_paths(); + auto &paths = game_map.paths(); + + world.query([&](const auto &ent, auto &position, auto &lightsource) { + game_map.clear_target(position.location); + int strength = 255 - lightsource.strength; + + size_t dist = size_t((float(lightsource.strength) / 255.0) * 3) + 1; + + size_t min_x = max(position.location.x, dist) - dist; + size_t max_x = min(position.location.x + dist, game_map.width() - 1); + size_t min_y = max(position.location.y, dist) - dist; + size_t max_y = min(position.location.y + dist, game_map.height() - 1); + + for(size_t x = min_x; x <= max_x; ++x) { + for(size_t y = min_y; y <= max_y; ++y) { + int dnum = paths[y][x]; + int light = std::clamp(255 - (strength * dnum), LIGHT_MIN, LIGHT_MAX); + if(lighting[y][x] < light) { + lighting[y][x] = light; + + if(light > LIGHT_MIN) { + has_light.push_back({x, y}); + } + } + } + } + }); const int UNPATH = game_map.limit();