Now I can attach arbitrary shaders to sprites based on things that happen in the world.

This commit is contained in:
Zed A. Shaw 2025-04-20 00:09:56 -04:00
parent bec8fe0a13
commit 787be78a69
6 changed files with 53 additions and 16 deletions

View file

@ -15,6 +15,7 @@
#include "rituals.hpp"
#include "battle.hpp"
#include <iostream>
#include "shaders.hpp"
using std::string;
using namespace fmt;
@ -176,6 +177,7 @@ void System::death(GameLevel &level, components::ComponentMap& components) {
world.remove<Personality>(ent);
world.remove<ai::EntityAI>(ent);
world.remove<Animation>(ent);
world.remove<SpriteEffect>(ent);
if(auto snd = world.get_if<Sound>(ent)) {
sound::stop(snd->attack);
@ -235,6 +237,11 @@ void System::combat(GameLevel &level) {
player_combat.attack(enemy.combat), 0
};
if(result.player_did > 0) {
auto effect = shaders::get("flame");
world.set<SpriteEffect>(enemy.entity, {100, effect});
}
if(enemy.ai.wants_to("kill_enemy")) {
result.enemy_did = enemy.combat.attack(player_combat);
animate_entity(world, enemy.entity);
@ -390,3 +397,20 @@ std::wstring System::draw_map(GameLevel level, size_t view_x, size_t view_y, int
return result;
}
std::shared_ptr<sf::Shader> System::sprite_effect(GameLevel &level, DinkyECS::Entity entity) {
if(level.world->has<SpriteEffect>(entity)) {
auto& se = level.world->get<SpriteEffect>(entity);
if(se.frames > 0) {
se.frames--;
return se.effect;
} else {
level.world->remove<SpriteEffect>(entity);
return nullptr;
}
} else {
return nullptr;
}
}