Re: [SOLVED] adnzzzzZ windfield collision classes confusion
Posted: Fri May 08, 2020 9:06 pm
I now have a worldstate.lua that contains the world enter and exit functions, this is required in main love.load() under everything else. The player.lua simply checks the player.state itself. All the collision checks will be handled in worldstate.lua from now on and nowhere else as the world updates itself in love.update().
main.lua
worldstate.lua
player.lua
It works just fine. I think now this is the best way to handle this.
main.lua
Code: Select all
love.load()
--under everything else
require("worldstate")
end
Code: Select all
myWorld:setEnter(function(s1,s2,c,i)
if s2:getClass() == "ObjectA" and
(p.player.vx > 0 or p.player.vy > 0)
then
p.player.state = "pushing"
end
end)
myWorld:setExit(function(s1,s2,c,i)
if s2:getClass() == "ObjectA" and
(p.player.vx > 0 or p.player.vy > 0)
then
p.player.state = "walking"
elseif p.player.vx == 0 and p.player.vy == 0 then
p.player.state = "standing"
end
end)
Code: Select all
p.draw = function(self)
local pose = sprites.stand_cycle
if self.player.state == "pushing" then
pose = sprites.player_pushing
elseif self.player.state == "walking" then
pose = sprites.player_walking
elseif self.player.state == "standing" then
pose = sprites.player_standing
end
--the rest of the code draws the pose
end