#include #include #include #include constexpr int shortSlashLength = 100; constexpr int longSlashLength = 200; // math helpers because we don't trust stdlib template inline T abs(const T& n) { static_assert(std::is_arithmetic::value, "abs expects numbers"); return n >= 0 ? n : -n; } void AttackSystem::receive(const AttackEvent& ae) { attacks.emplace_front(ae); } void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev, entityx::TimeDelta dt) { (void)en; (void)ev; (void)dt; for (const auto& a : attacks) { switch (a.type) { case AttackType::ShortSlash: en.each( [&a](entityx::Entity e, Position& pos, Solid& dim, Health& h) { (void)e; if (e.has_component()) return; if ((pos.x > a.pos.x && pos.x < a.pos.x + shortSlashLength) || (pos.x + dim.width < a.pos.x && pos.x + dim.width > a.pos.x - shortSlashLength)) { h.health -= a.power; game::engine.getSystem()->addMultiple(10, ParticleType::DownSlash, [&](){ return vec2(pos.x + dim.width / 2, pos.y + dim.height / 2); }, 300, 7); } } ); break; case AttackType::LongSlash: break; default: break; } } attacks.clear(); }