diff --git a/assets/ceiling_moss_brick_blue_light-256.png b/assets/ceiling_moss_brick_blue_light-256.png index 0784e07..90abd19 100644 Binary files a/assets/ceiling_moss_brick_blue_light-256.png and b/assets/ceiling_moss_brick_blue_light-256.png differ diff --git a/assets/enemies.json b/assets/enemies.json index 884eb36..33700f7 100644 --- a/assets/enemies.json +++ b/assets/enemies.json @@ -8,7 +8,7 @@ }, {"_type": "Combat", "hp": 200, "max_hp": 200, "damage": 10, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, - {"_type": "LightSource", "strength": 45, "radius": 2.0} + {"_type": "LightSource", "strength": 35, "radius": 2.0} ] }, "GOLD_SAVIOR": { diff --git a/assets/large_stone_floor-256.png b/assets/large_stone_floor-256.png index 06a0e02..db35a09 100644 Binary files a/assets/large_stone_floor-256.png and b/assets/large_stone_floor-256.png differ diff --git a/assets/tiles.json b/assets/tiles.json index 6e4188c..18df268 100644 --- a/assets/tiles.json +++ b/assets/tiles.json @@ -4,30 +4,35 @@ "collision": false, "display": 10398, "ceiling": "ceiling_plain", + "light": 0, "id": 0 }, "wall_plain": { "texture": "assets/wall_texture_test-256.png", "collision": true, "display": 9608, + "light": 0, "id": 1 }, "wall_moss": { "texture": "assets/glowing_moss_wall-256.png", "collision": true, "display": 8820, + "light": 20, "id": 2 }, "wall_vines": { "texture": "assets/wall_with_vines-256.png", "collision": true, "display": 35, + "light": 0, "id": 3 }, "ceiling_plain": { "texture": "assets/ceiling_test-256.png", "collision": false, "display": 35, + "light": 0, "id": 4 }, "lava_floor": { @@ -35,6 +40,7 @@ "collision": false, "display": 35, "ceiling": "ceiling_plain", + "light": 20, "id": 5 }, "large_stone_floor": { @@ -42,12 +48,14 @@ "collision": false, "display": 35, "ceiling": "ceiling_moss_brick_blue_light", + "light": 40, "id": 6 }, "ceiling_moss_brick_blue_light": { "texture": "assets/ceiling_moss_brick_blue_light-256.png", "collision": false, "display": 35, + "light": 0, "id": 7 } } diff --git a/gui/fsm.cpp b/gui/fsm.cpp index b404974..6138c32 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -318,6 +318,7 @@ namespace gui { break; case KEY::P: sound::mute(false); + if(!sound::playing("ambient_1")) sound::play("ambient_1", true); $debug_ui.debug(); shaders::reload(); dbc::log("save map!"); diff --git a/levelmanager.cpp b/levelmanager.cpp index ea405f7..7b43864 100644 --- a/levelmanager.cpp +++ b/levelmanager.cpp @@ -99,8 +99,7 @@ size_t LevelManager::create_level(shared_ptr prev_world) { auto player = world->get_the(); $levels.emplace_back(index, player.entity, map, world, - make_shared(map->width(), map->height()), - collider); + make_shared(map->tiles()), collider); dbc::check(index == $levels.size() - 1, "Level index is not the same as $levels.size() - 1, off by one error"); return index; diff --git a/lights.cpp b/lights.cpp index a2dd2cb..4867473 100644 --- a/lights.cpp +++ b/lights.cpp @@ -1,10 +1,27 @@ #include "lights.hpp" #include "constants.hpp" +#include "textures.hpp" #include using std::vector; namespace lighting { + + LightRender::LightRender(Matrix& tiles) : + $width(matrix::width(tiles)), + $height(matrix::height(tiles)), + $lightmap(matrix::make($width, $height)), + $ambient(matrix::make($width, $height)), + $paths($width, $height) + { + auto& tile_ambient = textures::get_ambient_light(); + + for(matrix::each_cell it{tiles}; it.next();) { + size_t tile_id = tiles[it.y][it.x]; + $ambient[it.y][it.x] = MIN + tile_ambient[tile_id]; + } + } + void LightRender::render_square_light(LightSource source, Point at, PointList &has_light) { for(matrix::box it{$lightmap, at.x, at.y, (size_t)floor(source.radius)}; it.next();) { if($paths.$paths[it.y][it.x] != WALL_PATH_LIMIT) { @@ -44,7 +61,7 @@ namespace lighting { } void LightRender::reset_light() { - matrix::assign($lightmap, lighting::MIN); + $lightmap = $ambient; } void LightRender::clear_light_target(const Point &at) { diff --git a/lights.hpp b/lights.hpp index df7fb1f..a4e4298 100644 --- a/lights.hpp +++ b/lights.hpp @@ -19,14 +19,10 @@ namespace lighting { size_t $width; size_t $height; Matrix $lightmap; + Matrix $ambient; Pathing $paths; - LightRender(size_t width, size_t height) : - $width(width), - $height(height), - $lightmap(height, matrix::Row(width, 0)), - $paths(width, height) - {} + LightRender(Matrix& walls); void reset_light(); void set_light_target(const Point &at, int value=0); diff --git a/tests/lighting.cpp b/tests/lighting.cpp index ffe2f92..8789d26 100644 --- a/tests/lighting.cpp +++ b/tests/lighting.cpp @@ -22,7 +22,7 @@ TEST_CASE("lighting a map works", "[lighting]") { LightSource source1{6, 1.0}; LightSource source2{4,3}; - LightRender lr(map.width(), map.height()); + LightRender lr(map.walls()); lr.reset_light(); diff --git a/textures.cpp b/textures.cpp index 6be20d7..a91d886 100644 --- a/textures.cpp +++ b/textures.cpp @@ -29,13 +29,18 @@ namespace textures { } } + inline void resize_shit(size_t size) { + TMGR.surfaces.resize(size); + TMGR.ceilings.resize(size); + TMGR.map_tile_set.resize(size); + TMGR.ambient_light.resize(size); + } + void load_tiles() { Config assets("assets/tiles.json"); auto &tiles = assets.json(); - TMGR.surfaces.resize(tiles.size()); - TMGR.ceilings.resize(tiles.size()); - TMGR.map_tile_set.resize(tiles.size()); + resize_shit(tiles.size()); for(auto &el : tiles.items()) { auto &config = el.value(); @@ -43,12 +48,11 @@ namespace textures { size_t surface_i = config["id"]; if(surface_i >= tiles.size()) { - TMGR.surfaces.resize(surface_i + 1); - TMGR.ceilings.resize(surface_i + 1); - TMGR.map_tile_set.resize(surface_i + 1); + resize_shit(surface_i + 1); } TMGR.map_tile_set[surface_i] = config["display"]; + TMGR.ambient_light[surface_i] = config["light"]; TMGR.surfaces[surface_i] = load_image(texture_fname); // NOTE: ceilings defaults to 0 which is floor texture so only need to update @@ -93,6 +97,10 @@ namespace textures { return texture; } + std::vector& get_ambient_light() { + return TMGR.ambient_light; + } + std::vector& get_map_tile_set() { return TMGR.map_tile_set; } diff --git a/textures.hpp b/textures.hpp index 2e64ad3..56fa46f 100644 --- a/textures.hpp +++ b/textures.hpp @@ -18,6 +18,7 @@ namespace textures { std::vector surfaces; std::vector ceilings; std::vector map_tile_set; + std::vector ambient_light; std::unordered_map sprite_textures; }; @@ -27,6 +28,7 @@ namespace textures { sf::Image load_image(const std::string& filename); + std::vector& get_ambient_light(); std::vector& get_map_tile_set(); const uint32_t* get_surface(size_t num);