Lighting now works, now to get multiple lights.
This commit is contained in:
parent
4ceacecfda
commit
6174df5ec7
4 changed files with 36 additions and 13 deletions
2
main.cpp
2
main.cpp
|
@ -33,7 +33,7 @@ void configure_world(DinkyECS::World &world, Map &game_map) {
|
||||||
world.set<Combat>(player.entity, {100, 10});
|
world.set<Combat>(player.entity, {100, 10});
|
||||||
world.set<Tile>(player.entity, {config.PLAYER_TILE});
|
world.set<Tile>(player.entity, {config.PLAYER_TILE});
|
||||||
world.set<Inventory>(player.entity, {5});
|
world.set<Inventory>(player.entity, {5});
|
||||||
world.set<LightSource>(player.entity, {200});
|
world.set<LightSource>(player.entity, {150});
|
||||||
|
|
||||||
auto enemy = world.entity();
|
auto enemy = world.entity();
|
||||||
world.set<Position>(enemy, {game_map.place_entity(1)});
|
world.set<Position>(enemy, {game_map.place_entity(1)});
|
||||||
|
|
4
map.cpp
4
map.cpp
|
@ -192,9 +192,9 @@ bool Map::neighbors(Point &out, bool greater) {
|
||||||
// BUG: sometimes cur is in a wall so finding neighbors fails
|
// BUG: sometimes cur is in a wall so finding neighbors fails
|
||||||
for(size_t i = 0; i < dirs.size(); ++i) {
|
for(size_t i = 0; i < dirs.size(); ++i) {
|
||||||
Point dir = dirs[i];
|
Point dir = dirs[i];
|
||||||
int target = inmap(dir.x, dir.y) ? $paths[dir.y][dir.x] : 1000;
|
int target = inmap(dir.x, dir.y) ? $paths[dir.y][dir.x] : $limit;
|
||||||
|
|
||||||
if(target == 1000) continue; // skip unpathable stuff
|
if(target == $limit) continue; // skip unpathable stuff
|
||||||
|
|
||||||
int diff = cur - target;
|
int diff = cur - target;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
TODAY'S GOAL:
|
TODAY'S GOAL:
|
||||||
|
|
||||||
* Use d-map to create a mapping of light strength and use that to alter the value of colors in the map.
|
|
||||||
* Make it possible to visualize the d-map when I need to.
|
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
* Neighbors needs a rewrite
|
* Neighbors needs a rewrite
|
||||||
* Neighbors algo isn't using greater parameter
|
* Neighbors algo isn't using greater parameter
|
||||||
* Look in system.cpp::draw_map for notes on a Lighting system.
|
|
||||||
* Write a method for renderer that can translate coordinates.
|
* Write a method for renderer that can translate coordinates.
|
||||||
* Can std::any be defaulted to a noop in the events?
|
* Can std::any be defaulted to a noop in the events?
|
||||||
* Save file isn't saving gold.
|
* Save file isn't saving gold.
|
||||||
|
|
39
systems.cpp
39
systems.cpp
|
@ -16,17 +16,39 @@ using namespace fmt;
|
||||||
using namespace components;
|
using namespace components;
|
||||||
using ftxui::Color;
|
using ftxui::Color;
|
||||||
|
|
||||||
|
const int LIGHT_MIN = 20;
|
||||||
|
const int LIGHT_MAX = 160;
|
||||||
|
|
||||||
void System::lighting(DinkyECS::World &world, Map &game_map, Player &player) {
|
void System::lighting(DinkyECS::World &world, Map &game_map, Player &player) {
|
||||||
const auto& player_light = world.get<LightSource>(player.entity);
|
const auto& player_light = world.get<LightSource>(player.entity);
|
||||||
auto &paths = game_map.paths();
|
auto &paths = game_map.paths();
|
||||||
auto &lighting = game_map.lighting();
|
auto &lighting = game_map.lighting();
|
||||||
const int LIGHT_MIN = 10;
|
std::vector<Point> has_light;
|
||||||
const int LIGHT_MAX = 110;
|
|
||||||
|
|
||||||
for(size_t x = 0; x < game_map.width(); ++x) {
|
for(size_t x = 0; x < game_map.width(); ++x) {
|
||||||
for(size_t y = 0; y < game_map.height(); ++y) {
|
for(size_t y = 0; y < game_map.height(); ++y) {
|
||||||
int dnum = paths[y][x];
|
int dnum = paths[y][x];
|
||||||
lighting[y][x] = std::clamp(255 - (dnum * player_light.strength), LIGHT_MIN, LIGHT_MAX);
|
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});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const int UNPATH = game_map.limit();
|
||||||
|
|
||||||
|
for(auto point : has_light) {
|
||||||
|
for(int i = -1; i <= 1; i++) {
|
||||||
|
for(int j = -1; j <= 1; j++) {
|
||||||
|
if(!game_map.inmap(point.x+i, point.y+j)) continue;
|
||||||
|
|
||||||
|
if(paths[point.y+j][point.x+i] == UNPATH) {
|
||||||
|
lighting[point.y+j][point.x+i] = LIGHT_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,9 +205,14 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canv
|
||||||
int light_value = lighting[start.y+y][start.x+x];
|
int light_value = lighting[start.y+y][start.x+x];
|
||||||
|
|
||||||
if(tile == config.WALL_TILE) {
|
if(tile == config.WALL_TILE) {
|
||||||
canvas.DrawText(x * 2, y * 4, config.WALL_TILE, [](auto &pixel) {
|
canvas.DrawText(x * 2, y * 4, config.WALL_TILE, [light_value](auto &pixel) {
|
||||||
pixel.foreground_color = Color::HSV(230, 20, 10);
|
if(light_value > LIGHT_MIN) {
|
||||||
pixel.background_color = Color::HSV(230, 20, 30);
|
pixel.foreground_color = Color::HSV(230, 20, 10);
|
||||||
|
pixel.background_color = Color::HSV(230, 20, light_value / 2);
|
||||||
|
} else {
|
||||||
|
pixel.foreground_color = Color::HSV(230, 20, 20);
|
||||||
|
pixel.background_color = Color::HSV(230, 20, 30);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else if(DEBUG_MAP) {
|
} else if(DEBUG_MAP) {
|
||||||
int dnum = paths[start.y+y][start.x+x];
|
int dnum = paths[start.y+y][start.x+x];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue