Animations are refactored to let me spawn in an 'attack animation' but I think the data model is wrong. Rather than spawning in an animation every time I can probably just make one, reposition it, then tell it to play. I'll have to try it.

This commit is contained in:
Zed A. Shaw 2025-09-12 11:56:11 -04:00
parent 8384b11993
commit ad3e580495
15 changed files with 109 additions and 56 deletions

View file

@ -27,8 +27,6 @@ using namespace DinkyECS;
using lighting::LightSource;
void System::set_position(World& world, SpatialMap& collision, Entity entity, Position pos) {
dbc::check(world.has<Tile>(entity), "entity doesn't have tile");
world.set<Position>(entity, pos);
bool has_collision = world.has<Collision>(entity);
collision.insert(pos.location, entity, has_collision);
@ -238,11 +236,6 @@ void System::combat(int attack_id) {
auto& level = GameDB::current_level();
auto& collider = *level.collision;
auto& world = *level.world;
auto& the_belt = world.get_the<ritual::Belt>();
if(!the_belt.has(attack_id)) return;
auto& ritual = the_belt.get(attack_id);
const auto& player_pos = GameDB::player_position();
auto& player_combat = world.get<Combat>(level.player);
@ -272,13 +265,7 @@ void System::combat(int attack_id) {
};
if(result.player_did > 0) {
using enum ritual::Element;
if(ritual.element == FIRE || ritual.element == LIGHTNING) {
auto effect = shaders::get(
ritual.element == FIRE ? "flame" : "lightning");
world.set<SpriteEffect>(enemy.entity, {100, effect});
}
spawn_attack(world, attack_id);
}
if(enemy_action == combat::BattleAction::ATTACK) {
@ -656,3 +643,43 @@ gui::Event System::shortest_rotate(Point player_at, Point aiming_at, Point targe
return normalized < 180.0 ? gui::Event::ROTATE_LEFT : gui::Event::ROTATE_RIGHT;
}
void System::clear_attack() {
auto world = GameDB::current_world();
std::vector<Entity> dead_anim;
world->query<Animation, Temporary>([&](auto ent, auto& anim, auto&) {
if(!anim.playing) dead_anim.push_back(ent);
});
for(auto ent : dead_anim) {
world->remove<Sprite>(ent);
world->remove<Animation>(ent);
world->remove<SpriteEffect>(ent);
remove_from_world(ent);
}
}
void System::spawn_attack(World& world, int attack_id) {
using enum ritual::Element; // for FIRE vs LIGHTNING
auto& the_belt = world.get_the<ritual::Belt>();
dbc::check(the_belt.has(attack_id), "STOP passing invalid attack IDs to the system.");
auto& ritual = the_belt.get(attack_id);
auto effect = ritual.element == FIRE ? "burning_animation" : "lightning_animation";
auto effect_id = world.entity();
world.set<Sprite>(effect_id, {effect, 256, 256, 1.0});
world.set<Temporary>(effect_id, {true});
auto shader = shaders::get(ritual.element == FIRE ? "flame" : "lightning");
world.set<SpriteEffect>(effect_id, {100, shader});
auto anim = animation::load(effect);
anim.play();
world.set<Animation>(effect_id, anim);
drop_item(effect_id);
}