Can now see an enemy take damage, and a damage number, but the effect is inverted.

This commit is contained in:
Zed A. Shaw 2025-12-28 02:05:30 -05:00
parent f175a5d4aa
commit 8208d146de
5 changed files with 26 additions and 11 deletions

View file

@ -1,6 +1,7 @@
#include "scene.hpp"
#include "animation.hpp"
#include <ranges>
#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;
}
}
}