summaryrefslogtreecommitdiffhomepage
path: root/not/Hero.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-04-04 12:49:51 +0200
committerAki <nthirtyone@gmail.com>2017-04-04 12:49:51 +0200
commit94fe36185b24315abccc55477c92961adf4d409c (patch)
tree9fe4c88f5eb63e1ce603429a15d317e8f1b76f49 /not/Hero.lua
parentcd025014eac8d1adf70bc3238de5c034dea80c78 (diff)
downloadroflnauts-94fe36185b24315abccc55477c92961adf4d409c.zip
roflnauts-94fe36185b24315abccc55477c92961adf4d409c.tar.gz
roflnauts-94fe36185b24315abccc55477c92961adf4d409c.tar.bz2
Punching method renamed, updated to use new stuff
Diffstat (limited to 'not/Hero.lua')
-rw-r--r--not/Hero.lua44
1 files changed, 18 insertions, 26 deletions
diff --git a/not/Hero.lua b/not/Hero.lua
index daed8fc..e28c2ef 100644
--- a/not/Hero.lua
+++ b/not/Hero.lua
@@ -238,22 +238,22 @@ function Hero:controlpressed (set, action, key)
if self.current ~= self.animations.damage then
self:setAnimation("attack_up")
end
- self:hit("up")
+ self:punch("up")
elseif isDown(controlset, "down") then
-- Punch down
if self.current ~= self.animations.damage then
self:setAnimation("attack_down")
end
- self:hit("down")
+ self:punch("down")
else
-- Punch horizontal
if self.current ~= self.animations.damage then
self:setAnimation("attack")
end
if f == 1 then
- self:hit("right")
+ self:punch("right")
else
- self:hit("left")
+ self:punch("left")
end
self.punchdir = 1
end
@@ -335,39 +335,31 @@ function Hero:createEffect (name)
end
end
--- Punch of `Hero`
--- direction: left, right, up, down
--- creates temporary fixture for player's body that acts as sensor; fixture is deleted after time set in UserData[1]; deleted by Hero:update(dt)
--- TODO: attack functions needs to be renamed, because even I have problems understanding them.
-function Hero:hit (direction)
- -- start cooldown
+-- 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: Magic numbers present in `not.Hero.punch`.
+function Hero:punch (direction)
self.punchCooldown = Hero.punchCooldown -- INITIAL from metatable
- -- actual punch
- -- TODO: use `PhysicalBody.addFixture`.
- local fixture
- if direction == "left" then
- fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-2,-6, -20,-6, -20,6, -2,6), 0)
- end
- if direction == "right" then
- fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(2,-6, 20,-6, 20,6, 2,6), 0)
- end
- if direction == "up" then
- fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-8,-4, -8,-20, 8,-20, 8,-4), 0)
- end
- if direction == "down" then
- fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-8,4, -8,20, 8,20, 8,4), 0)
- end
+ -- Choose shape based on punch direction.
+ local shape
+ if direction == "left" then shape = {-2,-6, -20,-6, -20,6, -2,6} end
+ if direction == "right" then shape = {2,-6, 20,-6, 20,6, 2,6} end
+ if direction == "up" then shape = {-8,-4, -8,-20, 8,-20, 8,-4} end
+ if direction == "down" then shape = {-8,4, -8,20, 8,20, 8,4} end
+ -- Create and set sensor fixture.
+ local fixture = self:addFixture(shape, 0)
fixture:setSensor(true)
fixture:setCategory(3)
fixture:setMask(1,3)
fixture:setGroupIndex(self.group)
fixture:setUserData({0.08, direction})
- -- sound
self:playSound(4)
end
-- Taking damage of `Hero` by successful hit test
-- currently called from World's startContact
+-- TODO: attack functions needs to be renamed, because even I have problems understanding them.
function Hero:damage (direction)
local horizontal, vertical = 0, 0
if direction == "left" then