};
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;
};
};
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;
/////////////////////////////
- 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;
(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;
});
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)) &&
#include <entityx/entityx.h>
#include <events.hpp>
+#include <attack.hpp>
#include <render.hpp>
#include <ui.hpp>
#include <engine.hpp>
// 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>()) {
(void)ev;
(void)dt;
+ if (player.component<Health>()->health <= 0)
+ abort();
+
auto& vel = *player.component<Direction>().get();
if (moveLeft & !moveRight)
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();
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);
}
}
{
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>(
<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">
</frame>
</Sprite>
<Direction />
- <Health value="500" />
+ <Health value="5" />
<Solid />
<Physics />
<Name value="SKIRL" />