summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-01-14 20:45:08 +0100
committerAki <nthirtyone@gmail.com>2017-01-14 20:45:08 +0100
commit44f94f0752063852ededa73c0bb7eada50b08f33 (patch)
tree2a3576c325c1fa94d230f18f1bf184755b526ebd
parent9fbf7eeb56c50d53abac28cdadc0b35d2d794407 (diff)
downloadroflnauts-44f94f0752063852ededa73c0bb7eada50b08f33.zip
roflnauts-44f94f0752063852ededa73c0bb7eada50b08f33.tar.gz
roflnauts-44f94f0752063852ededa73c0bb7eada50b08f33.tar.bz2
Working hits; I really need to move it from world to player
-rw-r--r--player.lua27
-rw-r--r--world.lua6
2 files changed, 20 insertions, 13 deletions
diff --git a/player.lua b/player.lua
index 5f95027..ba6e838 100644
--- a/player.lua
+++ b/player.lua
@@ -424,20 +424,21 @@ function Player:hit(direction)
self:playSound(4)
end
--- Hittest
--- Should be replaced with actual sensor; after moving collision callbacks into Player
-function Player:testHit(target, ox, oy, sx, sy)
- local x, y = self.body:getPosition()
- for v=0,2 do
- for h=0,2,1+v%2 do
- if target.fixture:testPoint(x+ox+h*sx, y+oy+v*sy) then return true end
- end
- end
- return false
-end
-
-- Taking damage of `Player` by successful hit test
-function Player:damage(horizontal, vertical)
+function Player:damage(direction)
+ local horizontal, vertical = 0, 0
+ if direction == "left" then
+ horizontal = -1
+ end
+ if direction == "right" then
+ horizontal = 1
+ end
+ if direction == "up" then
+ vertical = -1
+ end
+ if direction == "down" then
+ vertical = 1
+ end
self:createEffect("hit")
local x,y = self.body:getLinearVelocity()
self.body:setLinearVelocity(x,0)
diff --git a/world.lua b/world.lua
index 57b8cd7..b01948e 100644
--- a/world.lua
+++ b/world.lua
@@ -379,6 +379,12 @@ function World.beginContact(a, b, coll)
b:getUserData():playSound(3)
end
end
+ if a:getCategory() == 3 then
+ b:getUserData():damage(a:getUserData()[2])
+ end
+ if b:getCategory() == 3 then
+ a:getUserData():damage(b:getUserData()[2])
+ end
end
-- endContact
function World.endContact(a, b, coll)