From 62f986719da4ae2c675e9e79ce61f9e204156dfc Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 25 Nov 2024 02:38:24 -0500 Subject: [PATCH] Quick hack to test finding a better light. If you find the gold you get a better light. --- components.hpp | 4 ++++ main.cpp | 1 + systems.cpp | 6 ++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/components.hpp b/components.hpp index fdd5b29..be39110 100644 --- a/components.hpp +++ b/components.hpp @@ -48,4 +48,8 @@ namespace components { struct EnemyConfig { int HEARING_DISTANCE; }; + + struct LightSource { + int strength = 100; + }; } diff --git a/main.cpp b/main.cpp index bd8f93b..452796b 100644 --- a/main.cpp +++ b/main.cpp @@ -33,6 +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, {200}); auto enemy = world.entity(); world.set(enemy, {game_map.place_entity(1)}); diff --git a/systems.cpp b/systems.cpp index 9e6116b..ae05f09 100644 --- a/systems.cpp +++ b/systems.cpp @@ -117,9 +117,11 @@ void System::collision(DinkyECS::World &world, Player &player) { auto loot = world.get(entity); auto &loot_pos = world.get(entity); auto &inventory = world.get(player.entity); + auto &light = world.get(player.entity); world.send(Events::GUI::LOOT, entity, loot); inventory.gold += loot.amount; + light.strength = 100; collider.remove(loot_pos.location); } else { println("UNKNOWN COLLISION TYPE {}", entity); @@ -145,6 +147,7 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canv const auto& config = world.get_the(); const auto& player = world.get_the(); const auto& player_position = world.get(player.entity); + const auto& player_light = world.get(player.entity); Point start = game_map.center_camera(player_position.location, view_x, view_y); auto &walls = game_map.walls(); auto &paths = game_map.paths(); @@ -161,11 +164,10 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canv // it gets brighter. const int LIGHT_MIN = 10; const int LIGHT_MAX = 110; - int light_strength = 100; // lower is stronger Point light_at{start.x+x, start.y+y}; int dnum = paths[light_at.y][light_at.x]; - int light_value = std::clamp(255 - (dnum * light_strength), LIGHT_MIN, LIGHT_MAX); + int light_value = std::clamp(255 - (dnum * player_light.strength), LIGHT_MIN, LIGHT_MAX); // "WALL_TILE": "\u2591", // "WALL_TILE": "\ua5b8",