From a4c13f7fc9eac463e143e2254c55f6f3bc8d6b75 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 9 Feb 2025 14:57:19 -0500 Subject: [PATCH] Maps are back and have color now. TileCell needs a rework. --- assets/config.json | 4 ++-- components.hpp | 6 ------ raycaster.cpp | 4 +++- systems.cpp | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/assets/config.json b/assets/config.json index 65d2360..f08cc4d 100644 --- a/assets/config.json +++ b/assets/config.json @@ -14,8 +14,8 @@ "player": { }, "worldgen": { - "enemy_probability": 50, + "enemy_probability": 20, "empty_room_probability": 10, - "device_probability": 10 + "device_probability": 20 } } diff --git a/components.hpp b/components.hpp index a0f7730..bbc3b1d 100644 --- a/components.hpp +++ b/components.hpp @@ -28,12 +28,6 @@ namespace components { std::string chr; std::array foreground; std::array background; - uint8_t fg_h = 200; - uint8_t fg_s = 20; - uint8_t fg_v = 200; - uint8_t bg_h = 100; - uint8_t bg_s = 20; - uint8_t bg_v = 0; }; struct GameConfig { diff --git a/raycaster.cpp b/raycaster.cpp index 346691f..aaeb5b6 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -123,6 +123,8 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { if(drawEndY >= $height) drawEndY = $height - 1; int texX = int(textureWidth * (drawStartX - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / textureWidth; + int texRenderWidth = texX_end - texX; + if(texRenderWidth <= 0) continue; float x = float(drawStartX + RAY_VIEW_X); float y = float(drawStartY + RAY_VIEW_Y); @@ -133,7 +135,7 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { int texY = ((d * textureHeight) / spriteHeight) / textureHeight; sf_sprite->setScale({sprite_w, sprite_h}); - $anim.step(*sf_sprite, texX, texY, texX_end - texX, textureHeight); + $anim.step(*sf_sprite, texX, texY, texRenderWidth, textureHeight); sf_sprite->setPosition({x, y}); $brightness.setUniform("offsetFactor", sf::Glsl::Vec2{0.0f, 0.0f}); diff --git a/systems.cpp b/systems.cpp index 1ea796c..c9c37db 100644 --- a/systems.cpp +++ b/systems.cpp @@ -242,7 +242,7 @@ void System::draw_entities(DinkyECS::World &world, Map &map, const Matrix &light // the 2 and 4 are from ftxui::Canvas since it does a kind of "subpixel" drawing canvas.DrawText(loc.x*2, loc.y*4, tile.chr, [tile, light_value, cell](auto &pixel) { - pixel.foreground_color = Color::HSV(tile.fg_h, tile.fg_s, tile.fg_v * light_value); + pixel.foreground_color = Color::HSV(tile.foreground[0], tile.foreground[1], tile.foreground[2] * light_value); pixel.background_color = Color::HSV(cell.bg_h, cell.bg_s, cell.bg_v * light_value); }); }