From 00f879600bcea8f1ec1775c941041ee6346a60ba Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 28 Mar 2017 11:21:33 -0400 Subject: skirl can kill --- include/attack.hpp | 5 +++-- include/components.hpp | 5 +++-- main.cpp | 2 +- src/attack.cpp | 11 ++++------- src/components.cpp | 10 +++++++--- src/player.cpp | 7 +++++-- src/world.cpp | 3 ++- xml/!town.xml | 1 - xml/entities.xml | 2 +- 9 files changed, 26 insertions(+), 20 deletions(-) diff --git a/include/attack.hpp b/include/attack.hpp index ef67a79..0ab5138 100644 --- a/include/attack.hpp +++ b/include/attack.hpp @@ -13,11 +13,12 @@ enum class AttackType : char { }; struct AttackEvent { - AttackEvent(vec2 p, AttackType at, int pow = 10) - : pos(p), type(at), power(pow) {} + AttackEvent(vec2 p, AttackType at, bool fp, int pow = 10) + : pos(p), type(at), fromplayer(fp), power(pow) {} vec2 pos; AttackType type; + bool fromplayer; int power; }; diff --git a/include/components.hpp b/include/components.hpp index 20a1419..dafb859 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -611,10 +611,11 @@ struct Aggro : public Component { }; struct Hit : public Component { - Hit(int d) - : damage(d) {} + Hit(int d, bool p = false) + : damage(d), pierce(p) {} int damage; + bool pierce; void fromXML(XMLElement* imp, XMLElement* def) final { (void)imp; diff --git a/main.cpp b/main.cpp index 8fb97c1..2cc5786 100644 --- a/main.cpp +++ b/main.cpp @@ -117,8 +117,8 @@ int main(int argc, char *argv[]) ///////////////////////////// - game::engine.getSystem()->add("Wood Sword", 1); game::engine.getSystem()->add("Hunters Bow", 1); + game::engine.getSystem()->add("Wood Sword", 1); game::engine.getSystem()->add("Arrow", 198); std::list eventQueue; diff --git a/src/attack.cpp b/src/attack.cpp index 6fb6cec..e1ce45c 100644 --- a/src/attack.cpp +++ b/src/attack.cpp @@ -39,18 +39,16 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev, (void)ev; (void)dt; - auto pid = game::engine.getSystem()->getId(); - // handle attacking entities en.each([&](entityx::Entity p, Hit& hit, Position& ppos) { bool die = false; en.each([&](entityx::Entity e, Health& health, Position& pos, Solid& dim) { - if (e.id() != pid && inrange(ppos.x, pos.x, pos.x + dim.width) && inrange(ppos.y, pos.y - 2, pos.y + dim.height)) { + if (!e.has_component() && inrange(ppos.x, pos.x, pos.x + dim.width) && inrange(ppos.y, pos.y - 2, pos.y + dim.height)) { health.health -= hit.damage; game::engine.getSystem()->addMultiple(15, ParticleType::SmallBlast, [&](){ return vec2(pos.x + dim.width / 2, pos.y + dim.height / 2); }, 300, 7); - die = true; - } else if (game::engine.getSystem()->isAboveGround(vec2(ppos.x, ppos.y))) + die = !hit.pierce; + } else if (game::engine.getSystem()->isAboveGround(vec2(ppos.x, ppos.y - 5))) die = true; }); @@ -65,8 +63,7 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev, case AttackType::LongSlash: en.each( [&a](entityx::Entity e, Position& pos, Solid& dim, Health& h) { - (void)e; - if (e.has_component()) + if (!(e.has_component() ^ a.fromplayer)) return; if (inrange(a.pos.x, pos.x, pos.x + dim.width, HLINES(shortSlashLength)) && diff --git a/src/components.cpp b/src/components.cpp index dee56a6..14599c2 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -50,15 +51,18 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e // make the entity wander // TODO initialX and range? - if (0 && entity.has_component()) { + if (entity.has_component()) { auto ppos = game::engine.getSystem()->getPosition(); if (ppos.x > position.x && ppos.x < position.x + entity.component()->width) { - auto& h = entity.component()->health; + auto dim = entity.component(); + ev.emit(vec2(position.x + dim->width, position.y + dim->height), + AttackType::ShortSlash, false); + /*auto& h = entity.component()->health; if (h > 0) { fight = true; toFight = entity; h = 0; - } + }*/ } else direction.x = (ppos.x > position.x) ? .01 : -.01; } else if (entity.has_component()) { diff --git a/src/player.cpp b/src/player.cpp index 711ddae..204b7f0 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -105,6 +105,9 @@ void PlayerSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, (void)ev; (void)dt; + if (player.component()->health <= 0) + abort(); + auto& vel = *player.component().get(); if (moveLeft & !moveRight) @@ -221,7 +224,7 @@ void PlayerSystem::receive(const UseItemEvent& uie) auto loc = getPosition(); auto &solid = *player.component().get(); loc.x += solid.width / 2, loc.y += solid.height / 2; - game::events.emit(loc, AttackType::ShortSlash); + game::events.emit(loc, AttackType::ShortSlash, true); } else if (uie.item->type == "Bow") { if (game::engine.getSystem()->take("Arrow", 1)) { auto e = game::entities.create(); @@ -238,7 +241,7 @@ void PlayerSystem::receive(const UseItemEvent& uie) sprite->addSpriteSegment(SpriteData(tex.sprite), 0); auto dim = HLINES(sprite->getSpriteSize()); e.assign(dim.x, dim.y); - e.assign(10); + e.assign(10, false); } } diff --git a/src/world.cpp b/src/world.cpp index 9a47576..3688e98 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1089,9 +1089,10 @@ void WorldSystem::detect(entityx::TimeDelta dt) { game::entities.each( [](entityx::Entity e, Health& h) { - if (h.health <= 0) + if (h.health <= 0) { e.kill(); //e.destroy(); + } }); game::entities.each( diff --git a/xml/!town.xml b/xml/!town.xml index 7506f70..9351652 100644 --- a/xml/!town.xml +++ b/xml/!town.xml @@ -13,7 +13,6 @@ - diff --git a/xml/entities.xml b/xml/entities.xml index 60fe149..df2751a 100644 --- a/xml/entities.xml +++ b/xml/entities.xml @@ -62,7 +62,7 @@ - + -- cgit v1.2.3