I am working on a tile-based game. However, due to things such as furniture my map has multiple layers. I have (for the time being) created a square to represent my player. In order to stop my player walking on furniture, I need to make a function that checks for the layer. How do I do that? (Supposing I need to check the layer on the tile to the immediate right of my player) Pseudo-code ideas:
function checkLayers()
for every layer in map
if layer == "furniturelayer" then
stop player
end
end
end
EDIT: I have found a possible way to do it, but it does not work. I have an array containing the GID of all tiles that are collidable. I am then looping through all layers and checking if the tile has that GID. Code:
function gCheckGID(gMap, gLayer, tileX, tileY)
tilex = gMap.layers[gLayer]:get(tileX, tileY)
return tilex.id
end
function gCheckMovement(gMap, gArray, gTileX, gTileY)
local retVal = true
local layerArray = gMap.layers
local layers = table.getn(layerArray)
for layerCounter = 1, layers, 1 do
currGID = gCheckGID(gMap, layerArray[layerCounter], gTileX, gTileY)
for gidCounter = 1, table.getn(gArray), 1 do
if currGID == gArray[gidCounter] then
retVal = false
break
end
end
end
return retVal
end
I can then use an if statement to get the result and determine whether to move my character or not.