diff --git a/boss/fight.cpp b/boss/fight.cpp index d90b40b..7d75147 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -129,14 +129,14 @@ namespace boss { std::string player_move = Random::uniform(0, 1) == 0 ? "player1" : "player3"; $ui.move_actor("player", player_move); if(result.player_did > 0) $ui.animate_actor("player"); - $ui.damage("boss", result.player_did); + $ui.damage("player", result.player_did); } break; case BattleHostState::not_host: { std::string boss_move = Random::uniform(0, 1) == 0 ? "boss5" : "boss6"; $ui.move_actor("boss", boss_move); if(result.enemy_did > 0) $ui.animate_actor("boss"); - $ui.damage("player", result.enemy_did); + $ui.damage("boss", result.enemy_did); } break; case BattleHostState::out_of_ap: break; diff --git a/boss/ui.cpp b/boss/ui.cpp index ea26c91..9889665 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -109,11 +109,10 @@ namespace boss { } void UI::damage(const std::string& actor, int amount) { - // BUG: the $arena should really do this - if(amount == 0) { - $arena.attach_text(actor, "MISS!"); - } else { - $arena.attach_text(actor, "HIT!"); + $arena.attach_text(actor, fmt::format("{}", amount)); + + if(amount > 0) { + $arena.apply_effect(actor, "flame"); } } diff --git a/scene.cpp b/scene.cpp index 09fc2f1..5489c54 100644 --- a/scene.cpp +++ b/scene.cpp @@ -1,6 +1,7 @@ #include "scene.hpp" #include "animation.hpp" #include +#include "shaders.hpp" const bool DEBUG=false; @@ -27,7 +28,7 @@ namespace scene { sf::Text text(*$ui.$font, "", 60); - return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid, flipped, text}; + return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid, flipped, nullptr, text}; } Engine::Engine(components::AnimatedScene& scene) : @@ -70,6 +71,11 @@ namespace scene { } } + void Engine::apply_effect(const std::string& actor, const std::string& shader) { + auto& element = actor_config(actor); + element.effect = shaders::get(shader); + } + void Engine::attach_text(const std::string& actor, const std::string& text) { auto& element = actor_config(actor); element.text.setPosition(element.pos); @@ -88,15 +94,14 @@ namespace scene { $ui.render(window); for(auto& fixture : $fixtures) { - window.draw(*fixture.st.sprite); + window.draw(*fixture.st.sprite, fixture.effect.get()); } for(auto& actor : $actors) { - window.draw(*actor.st.sprite); + window.draw(*actor.st.sprite, actor.effect.get()); if(actor.anim.playing) window.draw(actor.text); } - if(DEBUG) $ui.debug_layout(window); } @@ -119,6 +124,8 @@ namespace scene { for(auto& fixture : $fixtures) { if(fixture.anim.playing) { fixture.anim.apply(*fixture.st.sprite, fixture.pos); + } else { + fixture.effect = nullptr; } } @@ -126,6 +133,12 @@ namespace scene { if(actor.anim.playing) { actor.anim.apply(*actor.st.sprite, actor.pos); actor.anim.apply(actor.text, actor.pos); + if(actor.effect) { + actor.effect->setUniform("u_time", actor.anim.subframe); + actor.effect->setUniform("u_duration", 1000); + } + } else { + actor.effect = nullptr; } } } diff --git a/scene.hpp b/scene.hpp index bc3d840..b23ebc0 100644 --- a/scene.hpp +++ b/scene.hpp @@ -21,6 +21,7 @@ namespace scene { float y = 0; bool at_mid=false; bool flipped=false; + std::shared_ptr effect = nullptr; sf::Text text; sf::Vector2f pos{0,0}; }; @@ -46,6 +47,7 @@ namespace scene { void move_actor(const std::string& actor, const std::string& cell_name); void animate_actor(const std::string& actor); void play_animations(); + void apply_effect(const std::string& actor, const std::string& shader); Element& actor_config(const std::string& actor); }; } diff --git a/tools/arena.cpp b/tools/arena.cpp index ae6d0c1..3c5c5fc 100644 --- a/tools/arena.cpp +++ b/tools/arena.cpp @@ -21,6 +21,7 @@ void craft_weapon() { } int main(int, char*[]) { + shaders::init(); components::init(); sfml::Backend backend; guecs::init(&backend);