summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2018-04-09 01:56:08 +0200
committerAki <nthirtyone@gmail.com>2018-04-09 01:56:08 +0200
commit6124f00707856980f1c5a7809ebf03351783f4a4 (patch)
treefe01cc030d298993d90f8c0dd68c5474405be3f7
parent5ce7f80fcdbc16ed74d56865df3114a800b3788d (diff)
downloadroflnauts-6124f00707856980f1c5a7809ebf03351783f4a4.zip
roflnauts-6124f00707856980f1c5a7809ebf03351783f4a4.tar.gz
roflnauts-6124f00707856980f1c5a7809ebf03351783f4a4.tar.bz2
Punch animations firing now also happens in Hero
-rw-r--r--not/Hero.lua33
-rw-r--r--not/Player.lua13
2 files changed, 28 insertions, 18 deletions
diff --git a/not/Hero.lua b/not/Hero.lua
index 650eed4..f49ed14 100644
--- a/not/Hero.lua
+++ b/not/Hero.lua
@@ -328,14 +328,37 @@ end
-- Creates temporary fixture for hero's body that acts as sensor.
-- direction: ("left", "right", "up", "down")
-- Sensor fixture is deleted after time set in UserData[1]; deleted by `not.Hero.update`.
+-- TODO: While it's good that punch animation changes are here, it is still bad. There is too much similar code in this method.
function Hero:punch (direction)
self.punchCooldown = Hero.PUNCH_COOLDOWN
- -- Choose shape based on punch direction.
+ self.salto = false
+
local shape
- if direction == "left" then shape = Hero.PUNCH_LEFT end
- if direction == "right" then shape = Hero.PUNCH_RIGHT end
- if direction == "up" then shape = Hero.PUNCH_UP end
- if direction == "down" then shape = Hero.PUNCH_DOWN end
+ if direction == "left" then
+ shape = Hero.PUNCH_LEFT
+ if self.current ~= self.animations.damage then
+ self:setAnimation("attack")
+ end
+ end
+ if direction == "right" then
+ shape = Hero.PUNCH_RIGHT
+ if self.current ~= self.animations.damage then
+ self:setAnimation("attack")
+ end
+ end
+ if direction == "up" then
+ shape = Hero.PUNCH_UP
+ if self.current ~= self.animations.damage then
+ self:setAnimation("attack_up")
+ end
+ end
+ if direction == "down" then
+ shape = Hero.PUNCH_DOWN
+ if self.current ~= self.animations.damage then
+ self:setAnimation("attack_down")
+ end
+ end
+
-- Create and set sensor fixture.
local fixture = self:addFixture(shape, 0)
fixture:setSensor(true)
diff --git a/not/Player.lua b/not/Player.lua
index c6c4431..3722cb3 100644
--- a/not/Player.lua
+++ b/not/Player.lua
@@ -45,24 +45,11 @@ function Player:controlpressed (set, action, key)
-- Punching
if action == "attack" and self.punchCooldown <= 0 then
local f = self.facing
- self.salto = false
if self:isControlDown("up") then
- -- Punch up
- if self.current ~= self.animations.damage then
- self:setAnimation("attack_up")
- end
self:punch("up")
elseif self:isControlDown("down") then
- -- Punch down
- if self.current ~= self.animations.damage then
- self:setAnimation("attack_down")
- end
self:punch("down")
else
- -- Punch horizontal
- if self.current ~= self.animations.damage then
- self:setAnimation("attack")
- end
if f == 1 then
self:punch("right")
else