Correct map.get syntax
Hello all. Complete noob here. I'm just trying to write my own very simple collision system for a top down zelda like game. I've used the various quickengine solutions, but I want to try to figure out how this stuff works from the ground up.
I'm trying to use the map.get function. According to the docs, it should be returning the name of the sprite name at the given co-ords, but whatever I try I keep getting a return of 0.
Can someone please confirm the EXACT correct syntax for map.get?
Thanks
If you created the map in the MicroStudio editor, you will get access to the map as follows:
myMap.get( x, y ) - returns the name of the Sprite located in this place.
name = "name maps string"
myMap = maps[ name ]
str = myMap.get( 0, 0 )
if str == "icon" then
//....
end
You can also minify the Sprite in map.
update = function()
myMap.set( random.nextInt( myMap.width), random.nextInt( myMap.height ))
end
Look for Quick Engine in the Explore section. It has everything you need including collisions with map tiles.
Thanks Loginus. I've figured this out now, but from what I can see, map.get only works on integers. However, I need it to ideally check 0.2 ahead of my character in each direction. Is there a way to do this?
Code snippet from QuickEngine
https://microstudio.dev/i/gilles/quickengine/
// Returns the map cell at the given (x, y) position.
Quick.mapCellAt = function(map,x,y)
local blockw = map.width/map.map.width
local blockh = map.height/map.map.height
local cx = floor((x-(map.x-map.width/2))/blockw)
local cy = floor((y-(map.y-map.height/2))/blockh)
return map.map.get(cx,cy)
end
direct = object x = 0 y = 0 end
if keyboard.UP then direct.y = -0.2
elsif keyboard.DOWN then direct.y = +0.2
elsif keyboard.LEFT then direct.x = -0.2
elsif keyboard.RIGHT then direct.x = +0.2 end
if mapCellAt( myMap, player.x + direct.x, player.y + direct.y ) then else end
Sorry for the delayed reply, AMAZING THANK YOU!!!