diff --git a/Makefile b/Makefile index a3f6721..ece7c1d 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ clean: meson compile --clean -C builddir debug_test: build - gdb --nx -x .gdbinit --ex run --ex bt --ex q --args builddir/runtests -e "[lighting]" + gdb --nx -x .gdbinit --ex run --ex bt --ex q --args builddir/runtests -e win_installer: powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp' diff --git a/assets/bosses.json b/assets/bosses.json index 2d18cdb..f82834b 100644 --- a/assets/bosses.json +++ b/assets/bosses.json @@ -2,8 +2,8 @@ "RAT_KING": { "components": [ {"_type": "BossFight", - "background": "boss_fight_background", - "stage": null, + "background": "test_background", + "floor": "test_floor", "weapon_sound": "Sword_Hit_2" }, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, @@ -16,15 +16,15 @@ "scale": 0.2, "stationary": false }, - {"_type": "Sprite", "name": "rat_king_boss", "width": 720, "height": 720, "scale": 0.8, "stationary": false}, + {"_type": "Sprite", "name": "test_boss", "width": 720, "height": 720, "scale": 0.8, "stationary": false}, {"_type": "Sound", "attack": "Marmot_Scream_1", "death": "Creature_Death_1"} ] }, "DEVILS_FINGERS": { "components": [ {"_type": "BossFight", - "background": "devils_fingers_background", - "stage": "devils_fingers_stage", + "background": "test_background", + "floor": "test_floor", "weapon_sound": "Sword_Hit_2" }, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, @@ -38,7 +38,7 @@ "stationary": true }, {"_type": "Sprite", - "name": "devils_fingers_sprite", + "name": "test_boss", "width": 720, "height": 720, "scale": 1.0 diff --git a/assets/bossfights/test_background.png b/assets/bossfights/test_background.png new file mode 100644 index 0000000..3af780a Binary files /dev/null and b/assets/bossfights/test_background.png differ diff --git a/assets/bossfights/test_boss.png b/assets/bossfights/test_boss.png new file mode 100644 index 0000000..d8b0bf9 Binary files /dev/null and b/assets/bossfights/test_boss.png differ diff --git a/assets/bossfights/test_floor.png b/assets/bossfights/test_floor.png new file mode 100644 index 0000000..c6f46d9 Binary files /dev/null and b/assets/bossfights/test_floor.png differ diff --git a/assets/bossfights/test_player.png b/assets/bossfights/test_player.png new file mode 100644 index 0000000..32aafad Binary files /dev/null and b/assets/bossfights/test_player.png differ diff --git a/assets/bossfights/test_thirds.png b/assets/bossfights/test_thirds.png new file mode 100644 index 0000000..2b49ed3 Binary files /dev/null and b/assets/bossfights/test_thirds.png differ diff --git a/assets/config.json b/assets/config.json index b2da914..65e5afe 100644 --- a/assets/config.json +++ b/assets/config.json @@ -243,7 +243,32 @@ "peasant_girl_rear_view": {"path": "assets/sprites/peasant_girl_rear_view_01.png", "frame_width": 400, - "frame_height": 543 + "frame_height": 540 + }, + "test_background": + {"path": "assets/bossfights/test_background.png", + "frame_width": 1920, + "frame_height": 1080 + }, + "test_boss": + {"path": "assets/bossfights/test_boss.png", + "frame_width": 498, + "frame_height": 832 + }, + "test_floor": + {"path": "assets/bossfights/test_floor.png", + "frame_width": 1920, + "frame_height": 1080 + }, + "test_player": + {"path": "assets/bossfights/test_player.png", + "frame_width": 208, + "frame_height": 434 + }, + "test_thirds": + {"path": "assets/bossfights/test_thirds.png", + "frame_width": 1656, + "frame_height": 1080 } }, "worldgen": { diff --git a/assets/sprites/peasant_girl_rear_view_01.png b/assets/sprites/peasant_girl_rear_view_01.png new file mode 100644 index 0000000..a447cbc Binary files /dev/null and b/assets/sprites/peasant_girl_rear_view_01.png differ diff --git a/boss/ui.cpp b/boss/ui.cpp index cb1954e..cdb9a4e 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -2,30 +2,58 @@ #include "constants.hpp" namespace boss { - UI::UI(shared_ptr world, Entity boss_id) - : $world(world), $boss_id(boss_id) + using namespace guecs; + + UI::UI(shared_ptr world, Entity boss_id) : + $world(world), + $boss_id(boss_id), + $boss_sprite(textures::get_sprite("test_boss")), + $player_sprite(textures::get_sprite("test_player")), + $floor_sprite(textures::get_sprite("test_floor")) { } void UI::init() { $gui.position(SCREEN_WIDTH-BOSS_VIEW_WIDTH,0, BOSS_VIEW_WIDTH, SCREEN_HEIGHT); + $gui.set($gui.MAIN, {$gui.$parser, THEME.DARK_MID}); + auto& background = $gui.get($gui.MAIN); + background.set_sprite("test_background", true); + $gui.layout( - "[a1|b1|c1|d1|e1|f1]" + "[a1|boss1|boss2|boss3|e1|f1]" "[a2|b2|c2|d2|e2|f2]" - "[a3|b3|c3|d3|e3|f3]" + "[floor2|b3|c3|d3|e3|f3]" "[a4|b4|c4|d4|e4|f4]" - "[a5|b5|c5|d5|e5|f5]" + "[floor1|player1|player2|player3|e5|f5]" "[a6|b6|c6|d6|e6|f6]" ); + + + position_sprite($boss_sprite, "boss2", 0.4, true); + position_sprite($player_sprite, "player1", 0.5, true); + position_sprite($floor_sprite, "floor2", 1.0, false); + $gui.init(); } + void UI::position_sprite(textures::SpriteTexture& st, const std::string& name, float scale, bool at_mid) { + auto& cell = $gui.cell_for(name); + float x = float(at_mid ? cell.mid_x : cell.x); + float y = float(at_mid ? cell.mid_y : cell.y); + + st.sprite->setPosition({x, y}); + st.sprite->setScale({scale, scale}); + } + void UI::render(sf::RenderWindow& window) { $gui.render(window); - $gui.debug_layout(window); + window.draw(*$floor_sprite.sprite); + window.draw(*$boss_sprite.sprite); + window.draw(*$player_sprite.sprite); + // $gui.debug_layout(window); } - bool UI::mouse(float x, float y, guecs::Modifiers mods) { + bool UI::mouse(float x, float y, Modifiers mods) { return $gui.mouse(x, y, mods); } diff --git a/boss/ui.hpp b/boss/ui.hpp index 7dff84e..c03d281 100644 --- a/boss/ui.hpp +++ b/boss/ui.hpp @@ -3,14 +3,19 @@ #include #include #include +#include "textures.hpp" namespace boss { using std::shared_ptr; using namespace DinkyECS; + using namespace textures; struct UI { shared_ptr $world = nullptr; Entity $boss_id = NONE; + SpriteTexture $boss_sprite; + SpriteTexture $player_sprite; + SpriteTexture $floor_sprite; guecs::UI $gui; UI(shared_ptr world, Entity boss_id); @@ -18,6 +23,7 @@ namespace boss { void init(); void render(sf::RenderWindow& window); bool mouse(float x, float y, guecs::Modifiers mods); + void position_sprite(SpriteTexture& st, const std::string& name, float scale, bool at_mid=false); bool boss_dead(); }; } diff --git a/components.hpp b/components.hpp index 1585645..b8eb454 100644 --- a/components.hpp +++ b/components.hpp @@ -78,7 +78,7 @@ namespace components { struct BossFight { std::string background; - std::optional stage; + std::optional floor; std::string weapon_sound; }; @@ -147,7 +147,7 @@ namespace components { using ComponentMap = std::unordered_map; ENROLL_COMPONENT(Tile, display, foreground, background); - ENROLL_COMPONENT(BossFight, background, stage, weapon_sound); + ENROLL_COMPONENT(BossFight, background, floor, weapon_sound); ENROLL_COMPONENT(Sprite, name, width, height, scale); ENROLL_COMPONENT(Curative, hp); ENROLL_COMPONENT(LightSource, strength, radius); diff --git a/tests/components.cpp b/tests/components.cpp index 3106c4f..32bbbc4 100644 --- a/tests/components.cpp +++ b/tests/components.cpp @@ -38,7 +38,7 @@ TEST_CASE("make sure json_mods works", "[components]") { if(comp_data["_type"] == "BossFight") { auto comp = components::convert(comp_data); // the boss fight for the rat king doesn't have a stage so false=optional - REQUIRE(comp.stage == std::nullopt); + REQUIRE(comp.floor != std::nullopt); } } @@ -51,11 +51,11 @@ TEST_CASE("make sure json_mods works", "[components]") { components::configure_entity(world, rat_king, config["RAT_KING"]["components"]); auto boss = world.get(rat_king); - REQUIRE(boss.stage == std::nullopt); + REQUIRE(boss.floor != std::nullopt); // now load the other one for the other way optional is used auto devils_fingers = world.entity(); components::configure_entity(world, devils_fingers, config["DEVILS_FINGERS"]["components"]); auto boss2 = world.get(devils_fingers); - REQUIRE(boss2.stage != std::nullopt); + REQUIRE(boss2.floor != std::nullopt); }