]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
scriptable attacks?
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 16 Oct 2017 02:50:08 +0000 (22:50 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 16 Oct 2017 02:50:08 +0000 (22:50 -0400)
config/items.xml
include/systems/lua.hpp
shaders/world.frag
src/attack.cpp

index cac7eb1a2c537c2231f3c962640f67c83ac0a3b2..574dddae82162a1981a133c3f46fa4e84506846c 100644 (file)
 <!-- WEAPONS -->
 <item name="Wood Sword"     type="Sword"    damage="3"  maxStackSize="1"  sound="assets/sounds/longSwing.wav"  sprite="assets/items/SWORD_WOOD.png" cooldown="250">
        <attack range="6, 2" power="1" effect="assets/effects/starAttack.gif">
-               update = function()
+               i = 1
+
+               effect = function()
                        flash(255, 0, 0)
                        damage(8)
                end
+
+               hit = function()
+                       if (i &lt; 30) then
+                               xrange = i
+                               i = i + 1
+                       else
+                               xrange = 0
+                       end
+               end
        </attack>
 </item>
 <item name="Hunters Bow"    type="Bow"      damage="2"  maxStackSize="1"    sprite="assets/items/bow.png" cooldown="600">
        <attack effect="assets/effects/starAttack.gif">
-               update = function()
+               effect = function()
                        flash(255, 0, 255)
                        damage(4)
                end
index 2df038aa00b54b3027467684140d71d1d4312517..1137308d5cebb2e656c46fa210cd66ef8dd2fa03 100644 (file)
@@ -44,11 +44,11 @@ public:
                lua_setglobal(state, name.c_str());
        }
 
+       void operator()(const std::string& func = "update") const;
        void operator()(const std::string& func, std::vector<LuaVariable> vars) const;
        void operator()(const std::string& func, std::vector<double>& rets, std::vector<LuaVariable> vars) const;
        void operator()(std::vector<LuaVariable> vars) const;
        void operator()(std::vector<double>& rets, std::vector<LuaVariable> vars) const;
-       void operator()(const std::string& func = "update") const;
 };
 
 class LuaSystem {
index 87d86cad28d9616eda2cc7d42a0f4a8e18385686..d6f4395978f2d53f10d0b433739c9ed1931a7cfd 100644 (file)
@@ -17,7 +17,7 @@ void main()
        vec4 pixTex = texture2D(texture, texLoc);
     if (pixTex.a < 0.1f) 
                discard;
-  
+   
        vec4 shadeColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
        if (lightImpact > 0.0f) {
                for (int i = 0; i < lightSize; i++) {
index c4ad95bb7b099bb2df5925f78d0438c463fcd8b2..b1047364e01c0a940d1daec05a8da71057be0c5d 100644 (file)
@@ -75,7 +75,7 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
                        (void)health;
                        if (!e.has_component<Player>() && inrange(ppos.x, pos.x, pos.x + dim.width) && inrange(ppos.y, pos.y - 2, pos.y + dim.height)) {
                                lua::setEntity(&e);
-                               hit.attack->script();
+                               hit.attack->script("effect");
                                if (hit.effect.size() > 0)
                                        effects.emplace_back(vec2(ppos.x, ppos.y), hit.effect);
                                //ParticleSystem::addMultiple(15, ParticleType::SmallBlast,
@@ -91,9 +91,13 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
 
        // handle emitted attacks (player's)
        for (const auto& a : attacks) {
+               //vec2 point = a.pos + a.attack.offset;
+               //vec2 size = a.attack.range;
+               //point.y -= size.y / 2; // center range height
+               
                vec2 point = a.pos + a.attack.offset;
-               vec2 size = a.attack.range;
-               point.y -= size.y / 2; // center range height
+               vec2 size;
+               a.attack.script("hit", {LuaVariable("xrange", size.x)});
 
                en.each<Position, Solid, Health>(
                        [&](entityx::Entity e, Position& pos, Solid& dim, Health& h) {
@@ -104,7 +108,7 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
                                if (inrange(point.x, pos.x, pos.x + dim.width, HLINES(size.x)) &&
                                        inrange(point.y, pos.y, pos.y + dim.height, HLINES(size.y))) {
                                        lua::setEntity(&e);
-                                       a.attack.script();
+                                       a.attack.script("effect");
                                        if (a.attack.effect.size() > 0)
                                                effects.emplace_back(point, a.attack.effect);
                                        //ParticleSystem::addMultiple(15, ParticleType::DownSlash,
@@ -126,13 +130,14 @@ void AttackSystem::render(void)
        for (auto& ae : effects) {
                ae.effect(ae.counter / RATE); // bind current frame
                auto dim = ae.effect.getTextureDim();
+               auto s = ae.pos - (dim / 2);
                GLfloat verts[] = {
-                       ae.pos.x,         ae.pos.y,         z, 0, 0,
-                       ae.pos.x + dim.x, ae.pos.y,         z, 1, 0,
-                       ae.pos.x + dim.x, ae.pos.y + dim.y, z, 1, 1,
-                       ae.pos.x + dim.x, ae.pos.y + dim.y, z, 1, 1,
-                       ae.pos.x,         ae.pos.y + dim.y, z, 0, 1,
-                       ae.pos.x,         ae.pos.y,         z, 0, 0
+                       s.x,         s.y,         z, 0, 0,
+                       s.x + dim.x, s.y,         z, 1, 0,
+                       s.x + dim.x, s.y + dim.y, z, 1, 1,
+                       s.x + dim.x, s.y + dim.y, z, 1, 1,
+                       s.x,         s.y + dim.y, z, 0, 1,
+                       s.x,         s.y,         z, 0, 0
                };
                glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), verts);
                glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), verts + 3);