diff options
-rw-r--r-- | not/Hero.lua | 2 | ||||
-rw-r--r-- | not/PhysicalBody.lua | 1 | ||||
-rw-r--r-- | not/World.lua | 16 |
3 files changed, 16 insertions, 3 deletions
diff --git a/not/Hero.lua b/not/Hero.lua index 13ab3dd..5c3d9f4 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -234,7 +234,7 @@ function Hero:punch (direction) local fixture = self:addFixture(shape, 0) fixture:setSensor(true) fixture:setCategory(3) - fixture:setMask(1,3) + fixture:setMask(1) fixture:setGroupIndex(self.group) fixture:setUserData({Hero.PUNCH_FIXTURE_LIFETIME, direction}) self:playSound(4) diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index fd92f89..804c706 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -11,6 +11,7 @@ PhysicalBody.body =--[[love.physics.newBody]]nil function PhysicalBody:new (x, y, world, imagePath) PhysicalBody.__super.new(self, world, imagePath) self.body = love.physics.newBody(world.world, x, y) + self.body:setUserData(self) end -- Add new fixture to body. diff --git a/not/World.lua b/not/World.lua index 47a1237..92b71ea 100644 --- a/not/World.lua +++ b/not/World.lua @@ -329,6 +329,10 @@ end -- Box2D callbacks -- beginContact function World.beginContact (a, b, coll) + -- TODO: Stop using magical numbers: + -- [1] -> Platform + -- [2] -> Hero + -- [3] -> Punch sensor if a:getCategory() == 1 then local x,y = coll:getNormal() if y < -0.6 then @@ -340,10 +344,18 @@ function World.beginContact (a, b, coll) end end if a:getCategory() == 3 then - b:getUserData():damage(a:getUserData()[2]) + if b:getCategory() == 2 then + b:getUserData():damage(a:getUserData()[2]) + end + if b:getCategory() == 3 then + a:getBody():getUserData():damage(b:getUserData()[2]) + b:getBody():getUserData():damage(a:getUserData()[2]) + end end if b:getCategory() == 3 then - a:getUserData():damage(b:getUserData()[2]) + if a:getCategory() == 2 then + a:getUserData():damage(b:getUserData()[2]) + end end end -- endContact |