From 39c7e5062ed85cd59f88bc3431e4a72f7d6936ab Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 24 May 2018 15:55:31 -0400 Subject: caverns shift in the dark after moving, any tile that just became dark will randomly become a wall or a floor. then, all of the dark tiles will be ticked three times. this is to cause a sense of being lost by having the caverns shift around you where you can't see. the radius of dust scattering after a lamp drops/pops increases with the number of pops that have occured due to that drop. this allows chain reactions of popping lamps to occur. both dust and the player are now considered illuminated (in addition to being light sources). --- src/main.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 7be82d1..28c89cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,6 +62,7 @@ public: std::vector tiles; std::vector lighting; + std::vector oldLighting; int lightedSpots = 0; }; @@ -141,7 +142,7 @@ void incrementIfSet(Map& map, int& count, int x, int y, int w, int h, Tile val = } } -void tick(Map& map, int x1 = 0, int y1 = 0, int x2 = VIEW_WIDTH, int y2 = VIEW_HEIGHT) +void tick(Map& map, int x1 = 0, int y1 = 0, int x2 = VIEW_WIDTH, int y2 = VIEW_HEIGHT, bool onlyDark = false) { std::vector temp(map.tiles); @@ -149,6 +150,11 @@ void tick(Map& map, int x1 = 0, int y1 = 0, int x2 = VIEW_WIDTH, int y2 = VIEW_H { for (int x = std::max(x1, 0); x < std::min(x2, VIEW_WIDTH); x++) { + if (onlyDark && map.lighting[x+y*VIEW_WIDTH]) + { + continue; + } + if (map.tiles[x+y*VIEW_WIDTH] == Tile::Lamp) { continue; @@ -203,6 +209,7 @@ void setIfValid(Map& map, int x, int y, Tile val) void recalculateLighting(Map& map, fov_settings_type* fov) { + map.oldLighting = map.lighting; map.lighting = std::vector(VIEW_WIDTH*VIEW_HEIGHT, false); map.lightedSpots = 0; @@ -240,12 +247,15 @@ void recalculateLighting(Map& map, fov_settings_type* fov) fov_circle(fov, static_cast(&map), nullptr, x, y, 8); } - if (map.tiles[x+VIEW_WIDTH*y] == Tile::Lamp) + if (map.tiles[x+VIEW_WIDTH*y] == Tile::Lamp || + map.tiles[x+VIEW_WIDTH*y] == Tile::Dust) { map.lighting[x+VIEW_WIDTH*y] = true; } } } + + map.lighting[player_x+VIEW_WIDTH*player_y] = true; } void processKeys(Map& map) @@ -371,8 +381,11 @@ int main(int, char**) SDL_Delay(30); } + int lamped = 0; while (!lamps.empty()) { + lamped++; + int px, py; std::tie(px, py) = lamps.front(); lamps.pop_front(); @@ -409,7 +422,7 @@ int main(int, char**) } }); - fov_circle(dusty.get(), static_cast(&map), static_cast(&lamps), px, py, 8); + fov_circle(dusty.get(), static_cast(&map), static_cast(&lamps), px, py, 8*lamped); render(ren.get(), map, false); SDL_Delay(50); @@ -444,6 +457,30 @@ int main(int, char**) } recalculateLighting(map, fov.get()); + + if (presses > 0) + { + for (int y = 0; y < VIEW_HEIGHT; y++) + { + for (int x = 0; x < VIEW_WIDTH; x++) + { + if (!map.lighting[x+y*VIEW_WIDTH] && map.oldLighting[x+y*VIEW_WIDTH]) + { + if (std::bernoulli_distribution(0.5)(rng)) + { + map.tiles[x+y*VIEW_WIDTH] = Tile::Wall; + } else { + map.tiles[x+y*VIEW_WIDTH] = Tile::Floor; + } + } + } + } + + tick(map, 0, 0, VIEW_WIDTH, VIEW_HEIGHT, true); + tick(map, 0, 0, VIEW_WIDTH, VIEW_HEIGHT, true); + tick(map, 0, 0, VIEW_WIDTH, VIEW_HEIGHT, true); + } + render(ren.get(), map, true); SDL_Delay(10); } -- cgit 1.4.1