Light works with multiple sources and strengths, walls are faked out but I think I may keep that to make it easier to play.

main
Zed A. Shaw 1 week ago
parent 6174df5ec7
commit 0e8a2e520a
  1. 4
      collider.cpp
  2. 1
      collider.hpp
  3. 9
      main.cpp
  4. 7
      status.txt
  5. 48
      systems.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

@ -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:

@ -33,7 +33,7 @@ void configure_world(DinkyECS::World &world, Map &game_map) {
world.set<Combat>(player.entity, {100, 10});
world.set<Tile>(player.entity, {config.PLAYER_TILE});
world.set<Inventory>(player.entity, {5});
world.set<LightSource>(player.entity, {150});
world.set<LightSource>(player.entity, {50});
auto enemy = world.entity();
world.set<Position>(enemy, {game_map.place_entity(1)});
@ -46,11 +46,18 @@ void configure_world(DinkyECS::World &world, Map &game_map) {
world.set<Motion>(enemy2, {0,0});
world.set<Combat>(enemy2, {20, 10});
world.set<Tile>(enemy2, {"*"});
world.set<LightSource>(enemy2, {100});
auto gold = world.entity();
world.set<Position>(gold, {game_map.place_entity(3)});
world.set<Loot>(gold, {100});
world.set<Tile>(gold, {"$"});
auto wall_torch = world.entity();
world.set<Position>(wall_torch, {game_map.place_entity(4)});
world.set<LightSource>(wall_torch, {200});
world.set<Tile>(wall_torch, {"!"});
}
const int GAME_MAP_X = 40;

@ -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.

@ -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<LightSource>(player.entity);
auto &paths = game_map.paths();
using std::min, std::max, std::clamp;
auto &lighting = game_map.lighting();
std::vector<Point> 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<Position, LightSource>([&](const auto &ent, auto &position, auto &lightsource) {
game_map.set_target(position.location);
});
game_map.make_paths();
auto &paths = game_map.paths();
world.query<Position, LightSource>([&](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();

Loading…
Cancel
Save