Gridlocked Civilians

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
FatalMarshmallow
Prole
Posts: 17
Joined: Mon Jul 30, 2012 9:15 pm

Gridlocked Civilians

Post by FatalMarshmallow »

In an attempt to create a bunch of gridlocked civilians, I came across this problem. It would appear that neither the player nor the NPC can move in a direction previously moved in by the other. I'm sure the solution is obvious, but I can't see it for the life of me.
Any help is appreciated.
FatalMarshmallow
Attachments
Example.love
0.8.0
(5.59 KiB) Downloaded 106 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Gridlocked Civilians

Post by Robin »

Here's your problem:

Code: Select all

function testMap(x, y)
    if map[(civ.grid_y / 32) + y][(civ.grid_x / 32) + x] == 1 then
        return false
    end
	if map[(player.grid_y / 32) + y][(player.grid_x / 32) + x] == 1 then
        return false
    end
    return true
end
This function checks if the player and the NPC can move in that direction. If either can't, neither can. Solution:

Code: Select all

function testMap(obj, x, y)
    if map[obj.grid_y / 32 + y][obj.grid_x / 32 + x] == 1 then
        return false
    end
    return true
end

-- or, better yet:
function testMap(obj, x, y)
    return map[obj.grid_y / 32 + y][obj.grid_x / 32 + x] ~= 1
end
Don't forget to replace calls to testMap with ones that include either player or civ as a first argument, depending on which one you're going to move.
Help us help you: attach a .love.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Gridlocked Civilians

Post by jjmafiae »

cant you post in "support & dev" forum instead of the General forum?
FatalMarshmallow
Prole
Posts: 17
Joined: Mon Jul 30, 2012 9:15 pm

Re: Gridlocked Civilians

Post by FatalMarshmallow »

Thanks for the help, I'm an idiot.
Also, my bad for posting in general, will double check in future.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 9 guests