[SOLVED] adnzzzzZ windfield collision classes confusion

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
kuzika
Prole
Posts: 16
Joined: Tue Apr 21, 2020 3:58 pm

Re: [SOLVED] adnzzzzZ windfield collision classes confusion

Post by kuzika »

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

Code: Select all

love.load()
--under everything else
require("worldstate")
end
worldstate.lua

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)
player.lua

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
pushstuff2.png
pushstuff2.png (211.7 KiB) Viewed 1683 times
It works just fine. I think now this is the best way to handle this.
pushstuff5.love
(357.89 KiB) Downloaded 96 times
"kuzika" literally means "to burry"
User avatar
4vZEROv
Party member
Posts: 126
Joined: Wed Jan 02, 2019 8:44 pm

Re: [SOLVED] adnzzzzZ windfield collision classes confusion

Post by 4vZEROv »

If you use the world:setEnter callback there is no way for you to know when a contact occurs that "ObjectA" will be the shape2 and not the shape1.

Code: Select all

myWorld:setEnter(function(s1,s2,c,i)
	if (s1:getClass() == "ObjectA" and s2:getClass() == "Player") or 
	(s1:getClass() == "Player" and s2:getClass() == "ObjectA") then 
		-- code --
	end
end)
I alse see in your player.lua file that you still have

Code: Select all

    self.player.collider:setPostsolve(function(s1,s2)
        if s2:getClass() == "ObjectA" then
            self.player.state = "pushing"
        end
    end)
inside the update function. Don't !
The four callbacks (enter/exit/pre/post) only need to be set once, they will be automaticaly called every frame inside your 'myWorld:update(dt)' function.

Aside from that the code looks better.

If you have any bug/question/request concerning the library you can contact by pm, on github or twitter.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 7 guests