diff --git a/assets/map_tiles.json b/assets/map_tiles.json index 5106a93..545e8ed 100644 --- a/assets/map_tiles.json +++ b/assets/map_tiles.json @@ -8,121 +8,121 @@ { "centered": false, "display": 35, - "x": 64, + "x": 32, "y": 0 }, { "centered": false, "display": 10398, - "x": 128, + "x": 64, "y": 0 }, { "centered": false, "display": 35, - "x": 192, + "x": 96, "y": 0 }, { "centered": false, "display": 35, - "x": 256, + "x": 128, "y": 0 }, { "centered": false, "display": 8820, - "x": 320, + "x": 160, "y": 0 }, { "centered": false, "display": 9608, - "x": 384, + "x": 192, "y": 0 }, { "centered": false, "display": 35, - "x": 448, + "x": 224, "y": 0 }, { "centered": true, "display": 1003, - "x": 512, + "x": 256, "y": 0 }, { "centered": true, "display": 3848, - "x": 576, + "x": 288, "y": 0 }, { "centered": true, "display": 85, "x": 0, - "y": 64 + "y": 32 }, { "centered": true, "display": 8687, - "x": 64, - "y": 64 + "x": 32, + "y": 32 }, { "centered": true, "display": 10949, - "x": 128, - "y": 64 + "x": 64, + "y": 32 }, { "centered": true, "display": 8793, - "x": 192, - "y": 64 + "x": 96, + "y": 32 }, { "centered": true, "display": 95, - "x": 256, - "y": 64 + "x": 128, + "y": 32 }, { "centered": true, "display": 1898, - "x": 320, - "y": 64 + "x": 160, + "y": 32 }, { "centered": true, "display": 2189, - "x": 384, - "y": 64 + "x": 192, + "y": 32 }, { "centered": true, "display": 2189, - "x": 448, - "y": 64 + "x": 224, + "y": 32 }, { "centered": true, "display": 42603, - "x": 512, - "y": 64 + "x": 256, + "y": 32 }, { "centered": true, "display": 2220, - "x": 576, - "y": 64 + "x": 288, + "y": 32 }, { "centered": true, "display": 1218, "x": 0, - "y": 128 + "y": 64 } ] diff --git a/assets/map_tiles.png b/assets/map_tiles.png index dcf893e..fc25b4a 100644 Binary files a/assets/map_tiles.png and b/assets/map_tiles.png differ diff --git a/assets/tiles.json b/assets/tiles.json index 05fda6d..d6b1694 100644 --- a/assets/tiles.json +++ b/assets/tiles.json @@ -6,7 +6,6 @@ "ceiling": "ceiling_black", "light": 0, "foreground": [40, 40, 40], - "background": [10, 10, 10], "id": 0 }, "wall_plain": { @@ -23,8 +22,8 @@ "collision": true, "display": 8820, "light": 20, - "foreground": [150, 255, 150], - "background": [10, 10, 10], + "foreground": [100, 150, 100], + "background": [100, 100, 100], "id": 2 }, "ceiling_black": { @@ -32,8 +31,7 @@ "collision": false, "display": 35, "light": 0, - "foreground": [150, 150, 150], - "background": [10, 10, 10], + "foreground": [100, 100, 100], "id": 4 }, "lava_floor": { @@ -42,7 +40,7 @@ "display": 35, "ceiling": "ceiling_black", "light": 20, - "foreground": [255, 0, 0], + "foreground": [200, 100, 100], "background": [10, 10, 10], "id": 5 }, @@ -52,8 +50,7 @@ "display": 35, "ceiling": "ceiling_blue_light", "light": 40, - "foreground": [150, 150, 150], - "background": [10, 10, 10], + "foreground": [40, 40, 40], "id": 6 }, "ceiling_blue_light": { @@ -61,8 +58,7 @@ "collision": false, "display": 35, "light": 0, - "foreground": [150, 150, 150], - "background": [10, 10, 10], + "foreground": [100, 100, 100], "id": 7 }, "wood_wall": { @@ -70,8 +66,8 @@ "collision": false, "display": 35, "light": 0, - "foreground": [250, 250, 150], - "background": [10, 10, 10], + "foreground": [70, 70, 70], + "background": [100, 100, 100], "id": 8 } } diff --git a/tests/map.cpp b/tests/map.cpp index 750f7d0..47f1ea0 100644 --- a/tests/map.cpp +++ b/tests/map.cpp @@ -80,6 +80,13 @@ TEST_CASE("dijkstra algo test", "[map]") { } } +sf::Sprite render_sprite(std::unordered_map& sprite_coord, sf::Vector2i size, wchar_t display, sf::Texture& map_sprites) { + auto coords = sprite_coord.at(display); + sf::IntRect square{coords, {size.x, size.y}}; + sf::Sprite sprite{map_sprites, square}; + return sprite; +} + TEST_CASE("map image test", "[map-sprite]") { components::init(); @@ -89,7 +96,7 @@ TEST_CASE("map image test", "[map-sprite]") { auto &walls = level.map->tiles(); auto &tile_set = textures::get_map_tile_set(); - sf::Vector2i size{64,64}; + sf::Vector2i size{32,32}; matrix::dump("TILES?", walls); std::unordered_map sprite_coord; @@ -109,29 +116,31 @@ TEST_CASE("map image test", "[map-sprite]") { (unsigned int)matrix::height(walls) * size.y}; sf::RenderTexture render{dim}; - render.clear({50,50,50,255}); + render.clear({0,0,0,0}); sf::Texture map_sprites{"./assets/map_tiles.png"}; + sf::Texture paper{"./assets/ui/full_screen_paper.png"}; + sf::Sprite paper_sprite{paper}; + paper_sprite.scale({1.5f, 1.5f}); + paper_sprite.setPosition({-30.0f, -30.0f}); + render.draw(paper_sprite); for(matrix::each_row it{walls}; it.next();) { size_t tid = walls[it.y][it.x]; wchar_t display = tile_set[tid]; REQUIRE(sprite_coord.contains(display)); - auto coords = sprite_coord.at(display); - sf::IntRect square{coords, {size.x, size.y}}; - sf::Sprite sprite{map_sprites, square}; - // sprite.setColor({150,150,150,255}); + auto sprite = render_sprite(sprite_coord, size, display, map_sprites); sprite.setPosition({float(it.x * size.x), float(it.y * size.y)}); + sprite.setColor({255, 255, 255, 200}); render.draw(sprite); } - level.world->query([&](auto, auto &pos, auto &entity_glyph) { REQUIRE(sprite_coord.contains(entity_glyph.display)); - auto coords = sprite_coord.at(entity_glyph.display); - sf::IntRect square{coords, {size.x, size.y}}; - sf::Sprite sprite{map_sprites, square}; + + auto sprite = render_sprite(sprite_coord, size, entity_glyph.display, map_sprites); + sprite.setColor({255,150,150,255}); sprite.setPosition({float(pos.location.x * size.x), float(pos.location.y * size.y)}); render.draw(sprite); diff --git a/tools/icongen.cpp b/tools/icongen.cpp index 1bc62cc..7188328 100644 --- a/tools/icongen.cpp +++ b/tools/icongen.cpp @@ -12,7 +12,7 @@ namespace fs = std::filesystem; constexpr const int TILE_COUNT=10; constexpr const sf::Color DEFAULT_COLOR{255, 255, 255, 255}; -constexpr const size_t DEFAULT_DIM=64; +constexpr const size_t DEFAULT_DIM=32; using namespace shiterator; @@ -26,6 +26,7 @@ struct MapConfig { MapGrid map = make(TILE_COUNT, TILE_COUNT); BoolGrid centered = make(TILE_COUNT, TILE_COUNT); std::unordered_map colors; + std::unordered_map backgrounds; each_row_t it{map}; }; @@ -86,6 +87,7 @@ struct MapTileBuilder { $render->setSmooth(false); sf::Vector2f cell_pos{0.0f,0.0f}; + sf::RectangleShape background({(float)$size.x, (float)$size.y}); for(each_row_t it{config.map}; it.next();) { // a 0 slot means we're done @@ -112,6 +114,9 @@ struct MapTileBuilder { dbc::check($size.x - t_size.x >= 0, "font too big on x"); dbc::check($size.y - t_size.y >= 0, "font too big on y"); + // draw the background first + background.setFillColor(config.backgrounds[display_char]); + if(is_centered) { sf::Vector2f center{ float(($size.x - t_size.x) / 2), @@ -123,10 +128,12 @@ struct MapTileBuilder { sf::Vector2f scale{float($size.x) / float(t_size.x), float($size.y) / float(t_size.y)}; sprite.setScale(scale); sprite.setPosition(cell_pos); + background.setPosition(cell_pos); } sprite.setColor(config.colors[display_char]); + $render->draw(background); $render->draw(sprite); } @@ -170,9 +177,18 @@ void load_config(MapConfig& config, bool is_centered, std::string path, std::fun sf::Color fg{fg_color[0], fg_color[1], fg_color[2]}; config.colors.insert_or_assign(display, fg); } else { - sf::Color fg{255, 100, 100}; - config.colors.insert_or_assign(display, fg); + config.colors.insert_or_assign(display, DEFAULT_COLOR); + } + + if(val.contains("background")) { + auto bg_color = val["background"]; + sf::Color bg{bg_color[0], bg_color[1], bg_color[2]}; + config.backgrounds.insert_or_assign(display, bg); + } else { + sf::Color bg{0, 0, 0, 0}; + config.backgrounds.insert_or_assign(display, bg); } + } }