diff --git a/assets/animations.json b/assets/animations.json index 9540dd0..5cdbc6e 100644 --- a/assets/animations.json +++ b/assets/animations.json @@ -111,12 +111,22 @@ }, "test_boss": { "_type": "Animation", - "easing": 3, + "easing": 1, "ease_rate": 0.5, "scale": 0.4, "simple": true, "frames": 1, "speed": 0.02, "stationary": true + }, + "rat_king_boss": { + "_type": "Animation", + "easing": 1, + "ease_rate": 0.5, + "scale": 0.4, + "simple": false, + "frames": 2, + "speed": 0.02, + "stationary": true } } diff --git a/assets/bosses.json b/assets/bosses.json index ade597e..c6f8ff0 100644 --- a/assets/bosses.json +++ b/assets/bosses.json @@ -2,23 +2,23 @@ "RAT_KING": { "components": [ {"_type": "BossFight", - "background": "test_background", - "floor": "test_floor", - "floor_pos": "floor2", + "background": "boss_fight_background", + "floor": "devils_fingers_background", + "floor_pos": "floor1", "player": { - "sprite": "test_player", + "sprite": "peasant_girl_rear_view", "start_pos": "player2", "scale": 0.5, "mid_cell": false }, "boss": { - "start_pos": "boss3", + "start_pos": "boss2", "scale": 0.7, "mid_cell": true } }, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, - {"_type": "Sprite", "name": "test_boss", "width": 720, "height": 720, "scale": 0.8, "stationary": false}, + {"_type": "Sprite", "name": "rat_king_boss", "width": 720, "height": 720, "scale": 0.8, "stationary": false}, {"_type": "Sound", "attack": "Marmot_Scream_1", "death": "Creature_Death_1"} ] } diff --git a/boss/fight.cpp b/boss/fight.cpp index 654982c..a2e44ef 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -88,9 +88,6 @@ namespace boss { boss::System::combat(attack_id); state(State::PLAYER_TURN); } break; - case TICK: - $ui.play_animations(); - break; default: break; // skip it @@ -107,15 +104,12 @@ namespace boss { break; case ATTACK: { $ui.status(L"BOSS TURN"); - $ui.move_boss(run % 10 < 5 ? "boss1" : "boss3"); + $ui.move_boss(run % 10 < 5 ? "boss1" : "boss2"); $ui.$boss_anim.play(); int attack_id = std::any_cast(data); boss::System::combat(attack_id); state(State::BOSS_TURN); } break; - case TICK: - $ui.play_animations(); - break; default: // skip it break; @@ -134,5 +128,6 @@ namespace boss { void Fight::render(sf::RenderWindow& window) { $ui.render(window); + $ui.play_animations(window); } } diff --git a/boss/ui.cpp b/boss/ui.cpp index 892ec69..2c29472 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -2,6 +2,8 @@ #include "constants.hpp" #include "components.hpp" #include "animation.hpp" +#include +#include namespace boss { using namespace guecs; @@ -16,7 +18,9 @@ namespace boss { $boss_sprite = textures::get_sprite(sprite.name); // floor is std::optional - $floor_sprite = textures::get_sprite(*$scene.floor); + if($scene.floor) { + $floor_sprite = textures::get_sprite(*$scene.floor); + } $player_sprite = textures::get_sprite($scene.player["sprite"]); @@ -41,7 +45,10 @@ namespace boss { move_boss($scene.boss["start_pos"]); move_player($scene.player["start_pos"]); - position_sprite($floor_sprite, $scene.floor_pos, 1.0, false); + + if($scene.floor) { + position_sprite($floor_sprite, $scene.floor_pos, 1.0, false); + } $arena.init(); @@ -78,7 +85,10 @@ namespace boss { $combat_ui.render(window); $arena.render(window); - window.draw(*$floor_sprite.sprite); + if($floor_sprite.sprite) { + window.draw(*$floor_sprite.sprite); + } + window.draw(*$boss_sprite.sprite); window.draw(*$player_sprite.sprite); @@ -106,9 +116,14 @@ namespace boss { position_sprite($player_sprite, cell_name, $scene.player["scale"], $scene.player["mid_cell"]); } - void UI::play_animations() { - if($boss_anim.playing) { + void UI::play_animations(sf::RenderWindow& window) { + using namespace std::chrono_literals; + + while($boss_anim.playing) { animation::apply($boss_anim, *$boss_sprite.sprite, $boss_pos); + render(window); + window.display(); + std::this_thread::sleep_for(16ms); } } } diff --git a/boss/ui.hpp b/boss/ui.hpp index f701f58..5423329 100644 --- a/boss/ui.hpp +++ b/boss/ui.hpp @@ -34,6 +34,6 @@ namespace boss { void status(const std::wstring& msg); void move_boss(const std::string& cell_name); void move_player(const std::string& cell_name); - void play_animations(); + void play_animations(sf::RenderWindow& window); }; }