summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/main.cpp43
1 files changed, 40 insertions, 3 deletions
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:
62 62
63 std::vector<Tile> tiles; 63 std::vector<Tile> tiles;
64 std::vector<bool> lighting; 64 std::vector<bool> lighting;
65 std::vector<bool> oldLighting;
65 int lightedSpots = 0; 66 int lightedSpots = 0;
66}; 67};
67 68
@@ -141,7 +142,7 @@ void incrementIfSet(Map& map, int& count, int x, int y, int w, int h, Tile val =
141 } 142 }
142} 143}
143 144
144void tick(Map& map, int x1 = 0, int y1 = 0, int x2 = VIEW_WIDTH, int y2 = VIEW_HEIGHT) 145void tick(Map& map, int x1 = 0, int y1 = 0, int x2 = VIEW_WIDTH, int y2 = VIEW_HEIGHT, bool onlyDark = false)
145{ 146{
146 std::vector<Tile> temp(map.tiles); 147 std::vector<Tile> temp(map.tiles);
147 148
@@ -149,6 +150,11 @@ void tick(Map& map, int x1 = 0, int y1 = 0, int x2 = VIEW_WIDTH, int y2 = VIEW_H
149 { 150 {
150 for (int x = std::max(x1, 0); x < std::min(x2, VIEW_WIDTH); x++) 151 for (int x = std::max(x1, 0); x < std::min(x2, VIEW_WIDTH); x++)
151 { 152 {
153 if (onlyDark && map.lighting[x+y*VIEW_WIDTH])
154 {
155 continue;
156 }
157
152 if (map.tiles[x+y*VIEW_WIDTH] == Tile::Lamp) 158 if (map.tiles[x+y*VIEW_WIDTH] == Tile::Lamp)
153 { 159 {
154 continue; 160 continue;
@@ -203,6 +209,7 @@ void setIfValid(Map& map, int x, int y, Tile val)
203 209
204void recalculateLighting(Map& map, fov_settings_type* fov) 210void recalculateLighting(Map& map, fov_settings_type* fov)
205{ 211{
212 map.oldLighting = map.lighting;
206 map.lighting = std::vector<bool>(VIEW_WIDTH*VIEW_HEIGHT, false); 213 map.lighting = std::vector<bool>(VIEW_WIDTH*VIEW_HEIGHT, false);
207 map.lightedSpots = 0; 214 map.lightedSpots = 0;
208 215
@@ -240,12 +247,15 @@ void recalculateLighting(Map& map, fov_settings_type* fov)
240 fov_circle(fov, static_cast<void*>(&map), nullptr, x, y, 8); 247 fov_circle(fov, static_cast<void*>(&map), nullptr, x, y, 8);
241 } 248 }
242 249
243 if (map.tiles[x+VIEW_WIDTH*y] == Tile::Lamp) 250 if (map.tiles[x+VIEW_WIDTH*y] == Tile::Lamp ||
251 map.tiles[x+VIEW_WIDTH*y] == Tile::Dust)
244 { 252 {
245 map.lighting[x+VIEW_WIDTH*y] = true; 253 map.lighting[x+VIEW_WIDTH*y] = true;
246 } 254 }
247 } 255 }
248 } 256 }
257
258 map.lighting[player_x+VIEW_WIDTH*player_y] = true;
249} 259}
250 260
251void processKeys(Map& map) 261void processKeys(Map& map)
@@ -371,8 +381,11 @@ int main(int, char**)
371 SDL_Delay(30); 381 SDL_Delay(30);
372 } 382 }
373 383
384 int lamped = 0;
374 while (!lamps.empty()) 385 while (!lamps.empty())
375 { 386 {
387 lamped++;
388
376 int px, py; 389 int px, py;
377 std::tie(px, py) = lamps.front(); 390 std::tie(px, py) = lamps.front();
378 lamps.pop_front(); 391 lamps.pop_front();
@@ -409,7 +422,7 @@ int main(int, char**)
409 } 422 }
410 }); 423 });
411 424
412 fov_circle(dusty.get(), static_cast<void*>(&map), static_cast<void*>(&lamps), px, py, 8); 425 fov_circle(dusty.get(), static_cast<void*>(&map), static_cast<void*>(&lamps), px, py, 8*lamped);
413 426
414 render(ren.get(), map, false); 427 render(ren.get(), map, false);
415 SDL_Delay(50); 428 SDL_Delay(50);
@@ -444,6 +457,30 @@ int main(int, char**)
444 } 457 }
445 458
446 recalculateLighting(map, fov.get()); 459 recalculateLighting(map, fov.get());
460
461 if (presses > 0)
462 {
463 for (int y = 0; y < VIEW_HEIGHT; y++)
464 {
465 for (int x = 0; x < VIEW_WIDTH; x++)
466 {
467 if (!map.lighting[x+y*VIEW_WIDTH] && map.oldLighting[x+y*VIEW_WIDTH])
468 {
469 if (std::bernoulli_distribution(0.5)(rng))
470 {
471 map.tiles[x+y*VIEW_WIDTH] = Tile::Wall;
472 } else {
473 map.tiles[x+y*VIEW_WIDTH] = Tile::Floor;
474 }
475 }
476 }
477 }
478
479 tick(map, 0, 0, VIEW_WIDTH, VIEW_HEIGHT, true);
480 tick(map, 0, 0, VIEW_WIDTH, VIEW_HEIGHT, true);
481 tick(map, 0, 0, VIEW_WIDTH, VIEW_HEIGHT, true);
482 }
483
447 render(ren.get(), map, true); 484 render(ren.get(), map, true);
448 SDL_Delay(10); 485 SDL_Delay(10);
449 } 486 }