diff options
author | Aki <nthirtyone@gmail.com> | 2016-05-17 21:33:42 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2016-05-17 21:33:42 +0200 |
commit | 8a79b873c95bb155a70a460efd460dfc35b493bb (patch) | |
tree | 843aa924f48afdf641cd6c9ea5b49270f048b49b | |
parent | c9bce04e8187e0b6ef9bc8950a094b1dbd44566c (diff) | |
download | roflnauts-8a79b873c95bb155a70a460efd460dfc35b493bb.zip roflnauts-8a79b873c95bb155a70a460efd460dfc35b493bb.tar.gz roflnauts-8a79b873c95bb155a70a460efd460dfc35b493bb.tar.bz2 |
createEffect relative to player
-rw-r--r-- | player.lua | 17 | ||||
-rw-r--r-- | world.lua | 2 |
2 files changed, 15 insertions, 4 deletions
@@ -138,7 +138,7 @@ function Player:keypressed (key) -- Jumping if key == self.key_jump then if not self.inAir then - self.world:createEffect("jump", self.body:getX()-12, self.body:getY()-15) + self:createEffect("jump") self.jumpactive = true if (self.current == self.animations.attack) or (self.current == self.animations.attack_up) or @@ -146,7 +146,7 @@ function Player:keypressed (key) self:changeAnimation("idle") end elseif self.jumpdouble then - self.world:createEffect("doublejump", self.body:getX()-12, self.body:getY()-15) + self:createEffect("doublejump") self.jumpactive = true self.jumpdouble = false end @@ -219,6 +219,17 @@ function Player:changeAnimation(animation) self.current = self.animations[animation] end +-- Spawn `Effect` relative to `Player` +function Player:createEffect(name) + if name == "trail" or name == "hit" then + -- 16px effect: -4 -7 + self.world:createEffect(name, self.body:getX()-4, self.body:getY()-7) + elseif name ~= nil then + -- 24px effect: -12 -15 + self.world:createEffect(name, self.body:getX()-12, self.body:getY()-15) + end +end + -- Punch of `Player` -- REWORK NEEDED Issue #8 function Player:hit (horizontal, vertical) @@ -256,7 +267,7 @@ end -- Taking damage of `Player` by successful hit test function Player:damage (horizontal, vertical) - self.world:createEffect("hit", self.body:getX()-4, self.body:getY()-7) + self:createEffect("hit") self.body:applyLinearImpulse((34+12*self.combo)*horizontal, (50+10*self.combo)*vertical + 15) self:changeAnimation("damage") end
\ No newline at end of file @@ -177,7 +177,7 @@ function World.beginContact(a, b, coll) print(b:getUserData().name .. " is not in air") b:getUserData().inAir = false b:getUserData().jumpdouble = true - b:getUserData().world:createEffect("land", b:getBody():getX()-12, b:getBody():getY()-15) + b:getUserData():createEffect("land") end end |