From 7ad366dcec68c703499e3f6f72b345d1adeac1da Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 17 Jul 2017 14:15:36 +0200 Subject: Moved landing method to Hero from World --- not/Hero.lua | 9 +++++++++ not/World.lua | 8 +------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 014eeb2..ff07c36 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -219,6 +219,15 @@ function Hero:createEffect (name, dx, dy) self.world:createEffect(name, x, y) end +-- Called by World when Hero starts contact with Platform (lands). +function Hero:land () + self.inAir = false + self.jumpCounter = 2 + self.salto = false + self.smoke = false + self:createEffect("land") +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`. diff --git a/not/World.lua b/not/World.lua index 3a5b051..47a1237 100644 --- a/not/World.lua +++ b/not/World.lua @@ -332,13 +332,7 @@ function World.beginContact (a, b, coll) if a:getCategory() == 1 then local x,y = coll:getNormal() if y < -0.6 then - -- TODO: move landing to `not.Hero` - -- Move them to Hero - b:getUserData().inAir = false - b:getUserData().jumpCounter = 2 - b:getUserData().salto = false - b:getUserData().smoke = false - b:getUserData():createEffect("land") + b:getUserData():land() end local vx, vy = b:getUserData().body:getLinearVelocity() if math.abs(x) == 1 or (y < -0.6 and x == 0) then -- cgit v1.1