aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-10-15 22:50:08 -0400
committerClyne Sullivan <tullivan99@gmail.com>2017-10-15 22:50:08 -0400
commit07b3ae994d0e68b5c266f5aa212024d5064847c2 (patch)
treeb3e6b3d2de445f15ece9da67b4e18383c84a2a78
parentb709a392436d4ed17e214cd9e302ddbd23d71c21 (diff)
scriptable attacks?
-rw-r--r--config/items.xml15
-rw-r--r--include/systems/lua.hpp2
-rw-r--r--shaders/world.frag2
-rw-r--r--src/attack.cpp25
4 files changed, 30 insertions, 14 deletions
diff --git a/config/items.xml b/config/items.xml
index cac7eb1..574ddda 100644
--- a/config/items.xml
+++ b/config/items.xml
@@ -19,15 +19,26 @@
<!-- 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
diff --git a/include/systems/lua.hpp b/include/systems/lua.hpp
index 2df038a..1137308 100644
--- a/include/systems/lua.hpp
+++ b/include/systems/lua.hpp
@@ -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 {
diff --git a/shaders/world.frag b/shaders/world.frag
index 87d86ca..d6f4395 100644
--- a/shaders/world.frag
+++ b/shaders/world.frag
@@ -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++) {
diff --git a/src/attack.cpp b/src/attack.cpp
index c4ad95b..b104736 100644
--- a/src/attack.cpp
+++ b/src/attack.cpp
@@ -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);