aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-10-17 18:21:38 -0400
committerClyne Sullivan <tullivan99@gmail.com>2017-10-17 18:21:38 -0400
commit03246da32a8452e6a76ccf2f7f97cda4472d1d29 (patch)
treefe69406b677e574365d14099e3d1cd69bde586ed
parent2bd1eaef1b9ec848933a40049ec8866e2b83a47d (diff)
skirl hostility
-rw-r--r--src/attack.cpp7
-rw-r--r--src/systems/movement.cpp9
-rw-r--r--xml/!town.xml3
-rw-r--r--xml/entities.xml13
4 files changed, 28 insertions, 4 deletions
diff --git a/src/attack.cpp b/src/attack.cpp
index b104736..16c7f8a 100644
--- a/src/attack.cpp
+++ b/src/attack.cpp
@@ -109,6 +109,13 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
inrange(point.y, pos.y, pos.y + dim.height, HLINES(size.y))) {
lua::setEntity(&e);
a.attack.script("effect");
+ if (pos.x < point.x) {
+ e.component<Direction>()->x = -0.1;
+ e.component<Direction>()->y = 0.1;
+ } else {
+ e.component<Direction>()->x = 0.1;
+ e.component<Direction>()->y = 0.1;
+ }
if (a.attack.effect.size() > 0)
effects.emplace_back(point, a.attack.effect);
//ParticleSystem::addMultiple(15, ParticleType::DownSlash,
diff --git a/src/systems/movement.cpp b/src/systems/movement.cpp
index 73e5113..642fa6a 100644
--- a/src/systems/movement.cpp
+++ b/src/systems/movement.cpp
@@ -87,14 +87,16 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
// make the entity wander
// TODO initialX and range?
if (entity.has_component<Wander>()) {
+ auto dim = entity.component<Solid>();
float aggro = 0;
+ vec2 self (position.x + dim->width / 2, position.y + dim->height / 2);
LuaList vars = {
LuaVariable("vely", direction.y),
LuaVariable("velx", direction.x),
LuaVariable("playerx", ppos.x),
LuaVariable("playery", ppos.y),
- LuaVariable("selfx", position.x),
- LuaVariable("selfy", position.y),
+ LuaVariable("selfx", self.x),
+ LuaVariable("selfy", self.y),
LuaVariable("aggro", aggro)
};
@@ -106,6 +108,9 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
entity.component<Wander>()->script(aggro ? "hostile" : "update", vars);
if (hasAggro)
entity.component<Aggro>()->yes = aggro > 0 ? 1 : 0;
+
+ position.x = self.x - dim->width / 2;
+ position.y = self.y - dim->height / 2;
}
}
});
diff --git a/xml/!town.xml b/xml/!town.xml
index 30adc94..07d84ac 100644
--- a/xml/!town.xml
+++ b/xml/!town.xml
@@ -27,9 +27,8 @@
<Dialog name="Bob">
<text id="0" nextid="1">
- <!--<give name="Hunters Bow" count="1"/>
+ <give name="Hunters Bow" count="1"/>
<give name="Arrow" count="50"/>
- <option name="Yes"/>-->
<give name="Wood Sword" count="1"/>
<content>
Hey there! The name's Bob. Good to see you've finally woken up from your nap by the cliff there... lol
diff --git a/xml/entities.xml b/xml/entities.xml
index 67f4fc2..16bee0f 100644
--- a/xml/entities.xml
+++ b/xml/entities.xml
@@ -80,6 +80,10 @@
countdown = 0
update = function()
+ if (velx &lt; 0 and math.abs(selfx - playerx) &lt; 150) then
+ aggro = 1
+ end
+
if (countdown == 0) then
countdown = math.random(3000, 5000)
velx = math.random(-1, 1) * 0.005
@@ -88,7 +92,15 @@
end
hostile = function()
+ if (playerx &lt;= selfx) then
+ velx = -0.01
+ else
+ velx = 0.01
+ end
+ if (math.abs(playerx - selfx) &lt; 50) then
+ attack(selfx, selfy)
+ end
end
</Wander>
<Aggro/>
@@ -110,6 +122,7 @@
<Solid />
<Physics />
<Name value="birb" />
+ <Health value="60" />
<Wander>
countdown = 0
onetime = 0