]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
skirl hostility
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 17 Oct 2017 22:21:38 +0000 (18:21 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 17 Oct 2017 22:21:38 +0000 (18:21 -0400)
src/attack.cpp
src/systems/movement.cpp
xml/!town.xml
xml/entities.xml

index b1047364e01c0a940d1daec05a8da71057be0c5d..16c7f8ab60395d34d4b56dc10f3e609cbcbfdefc 100644 (file)
@@ -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,
index 73e5113ca0912937802be0f2e9985fdd37b03c2f..642fa6a611a461d4a76b816fef72fd2a87b771b9 100644 (file)
@@ -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;
                        }
                }
        });
index 30adc94546d3761aadb096c30054c48d28dfad73..07d84acc5693af9d6ba9038c42cbc854c789be17 100644 (file)
@@ -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
index 67f4fc274f84ee27206d7cd29dee7f7092275a15..16bee0f4a5ca0c450e6537288a6e6bdf909acadc 100644 (file)
                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
                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/>
        <Solid />
        <Physics />
        <Name value="birb" />
+       <Health value="60" />
        <Wander>
                countdown = 0
                onetime = 0