aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-03-28 11:21:33 -0400
committerClyne Sullivan <tullivan99@gmail.com>2017-03-28 11:21:33 -0400
commit00f879600bcea8f1ec1775c941041ee6346a60ba (patch)
treef9bb9ca811a2a565aed16ccab31cc2847539072f /src
parentceef5de7d838e97c3d7f990023398181ee1500c2 (diff)
skirl can kill
Diffstat (limited to 'src')
-rw-r--r--src/attack.cpp11
-rw-r--r--src/components.cpp10
-rw-r--r--src/player.cpp7
-rw-r--r--src/world.cpp3
4 files changed, 18 insertions, 13 deletions
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<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)) &&
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 <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>()) {
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>()->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);
}
}
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<Health>(
[](entityx::Entity e, Health& h) {
- if (h.health <= 0)
+ if (h.health <= 0) {
e.kill();
//e.destroy();
+ }
});
game::entities.each<Grounded, Position, Solid>(