diff options
author | Aki <nthirtyone@gmail.com> | 2017-01-14 20:45:08 +0100 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-01-14 20:45:08 +0100 |
commit | 44f94f0752063852ededa73c0bb7eada50b08f33 (patch) | |
tree | 2a3576c325c1fa94d230f18f1bf184755b526ebd | |
parent | 9fbf7eeb56c50d53abac28cdadc0b35d2d794407 (diff) | |
download | roflnauts-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.lua | 27 | ||||
-rw-r--r-- | world.lua | 6 |
2 files changed, 20 insertions, 13 deletions
@@ -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) @@ -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) |