]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
skirl can kill
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 28 Mar 2017 15:21:33 +0000 (11:21 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 28 Mar 2017 15:21:33 +0000 (11:21 -0400)
include/attack.hpp
include/components.hpp
main.cpp
src/attack.cpp
src/components.cpp
src/player.cpp
src/world.cpp
xml/!town.xml
xml/entities.xml

index ef67a7990fb73d0cdd270bf8ccfbeaf4b5b05c23..0ab513879f9da954e1db3b4f8c5cbcc2b0faabd8 100644 (file)
@@ -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;
 };
 
index 20a1419c395fdc614231cbace845077a8e83328f..dafb859b3d8248bbfbba448712458aa96d56b4ab 100644 (file)
@@ -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;
index 8fb97c13bdbcb051c0532046e0dd3dfb877664fb..2cc578646e48cfd6a76e18c76675fec1039db39a 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -117,8 +117,8 @@ int main(int argc, char *argv[])
        /////////////////////////////
 
 
-       game::engine.getSystem<InventorySystem>()->add("Wood Sword", 1);
        game::engine.getSystem<InventorySystem>()->add("Hunters Bow", 1);
+       game::engine.getSystem<InventorySystem>()->add("Wood Sword", 1);
        game::engine.getSystem<InventorySystem>()->add("Arrow", 198);
 
        std::list<SDL_Event> eventQueue;
index 6fb6cecdb7f460beea5b8c713bc9b0f06a8734ef..e1ce45c12edbe1fa768edd34d6e175adf962f119 100644 (file)
@@ -39,18 +39,16 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
        (void)ev;
        (void)dt;
 
-       auto pid = game::engine.getSystem<PlayerSystem>()->getId();
-
        // handle attacking entities
        en.each<Hit, Position>([&](entityx::Entity p, Hit& hit, Position& ppos) {
                bool die = false;
                en.each<Health, Position, Solid>([&](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<Player>() && 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<ParticleSystem>()->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<WorldSystem>()->isAboveGround(vec2(ppos.x, ppos.y)))
+                               die = !hit.pierce;
+                       } else if (game::engine.getSystem<WorldSystem>()->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<Position, Solid, Health>(
                                [&a](entityx::Entity e, Position& pos, Solid& dim, Health& h) {
-                                       (void)e;
-                                       if (e.has_component<Player>())
+                                       if (!(e.has_component<Player>() ^ a.fromplayer))
                                                return;
 
                                        if (inrange(a.pos.x, pos.x, pos.x + dim.width, HLINES(shortSlashLength)) &&
index dee56a62d75f3f962e74a4c2f0922d412c9a83d5..14599c2303c0b772f9f95fb2a1fba586b71f8c61 100644 (file)
@@ -3,6 +3,7 @@
 #include <entityx/entityx.h>
 #include <events.hpp>
 
+#include <attack.hpp>
 #include <render.hpp>
 #include <ui.hpp>
 #include <engine.hpp>
@@ -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<Aggro>()) {
+                       if (entity.has_component<Aggro>()) {
                                auto ppos = game::engine.getSystem<PlayerSystem>()->getPosition();
                                if (ppos.x > position.x && ppos.x < position.x + entity.component<Solid>()->width) {
-                                       auto& h = entity.component<Health>()->health;
+                                       auto dim = entity.component<Solid>();
+                                       ev.emit<AttackEvent>(vec2(position.x + dim->width, position.y + dim->height),
+                                               AttackType::ShortSlash, false);
+                                       /*auto& h = entity.component<Health>()->health;
                                        if (h > 0) {
                                                fight = true;
                                                toFight = entity;
                                                h = 0;
-                                       }
+                                       }*/
                                } else
                                        direction.x = (ppos.x > position.x) ? .01 : -.01;
                        } else if (entity.has_component<Wander>()) {
index 711ddae3d117d073655fec296d1ef42e502c75e1..204b7f0bbfd2deabb23e3468118566c3e9cae259 100644 (file)
@@ -105,6 +105,9 @@ void PlayerSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
     (void)ev;
     (void)dt;
 
+       if (player.component<Health>()->health <= 0)
+               abort();
+
     auto& vel = *player.component<Direction>().get();
 
     if (moveLeft & !moveRight)
@@ -221,7 +224,7 @@ void PlayerSystem::receive(const UseItemEvent& uie)
                        auto loc = getPosition();
                        auto &solid = *player.component<Solid>().get();
                        loc.x += solid.width / 2, loc.y += solid.height / 2;
-                       game::events.emit<AttackEvent>(loc, AttackType::ShortSlash);
+                       game::events.emit<AttackEvent>(loc, AttackType::ShortSlash, true);
                } else if (uie.item->type == "Bow") {
                        if (game::engine.getSystem<InventorySystem>()->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<Solid>(dim.x, dim.y);
-                               e.assign<Hit>(10);
+                               e.assign<Hit>(10, false);
                        }
                }
 
index 9a475766295a2396e12d9621c8abb4f1d3b522d9..3688e98467fba3d3543cb4767f06c43ed47221c8 100644 (file)
@@ -1089,9 +1089,10 @@ void WorldSystem::detect(entityx::TimeDelta dt)
 {
        game::entities.each<Health>(
                [](entityx::Entity e, Health& h) {
-               if (h.health <= 0)
+               if (h.health <= 0) {
                        e.kill();
                        //e.destroy();
+               }
        });
 
        game::entities.each<Grounded, Position, Solid>(
index 7506f700c8cdff3875f8053de60924a959db746d..9351652dc511256df105223aa993a018dda5f082 100644 (file)
@@ -13,7 +13,6 @@
     <structure type="1" position="300.0,100.0"/>
     <structure inside="bobshouse.xml" type="1" position="10.0,100.0"/>
        <skirl />
-       <skirl />
 </World>
 
 <Dialog name="Bob">
index 60fe149866428e8b38404d76ad09c72b568bad79..df2751a48296769f146bece2bc1c6baf3cb7cce9 100644 (file)
@@ -62,7 +62,7 @@
                </frame>
        </Sprite>
        <Direction />
-       <Health value="500" />
+       <Health value="5" />
        <Solid />
        <Physics />
        <Name value="SKIRL" />