I'm trying to make a map grid
I want it to randomly generate (that's the proper term for what I'm doing) a grid of maps using the 3 maps I have for the background
I want it to randomly generate (that's the proper term for what I'm doing) a grid of maps using the 3 maps I have for the background
Create several different sprites.
For example, with names corresponding to their fill color.
Run this code - if you have sprites with different names, put those names in a list called "name" .
init = function()
name = ["red", "blue", "yellow", "green"]
map = new Map( 20, 10, 15, 15 )
for w = 0 to map.width -1
for h = 0 to map.height -1
map.set(w,h, name[ random.nextInt(4) ])
end
end
end
draw = function()
screen.drawMap( map, 0, 0, 300, 150 )
end
Is there a way I could make it so it made it infanite
The Map object can be stretched dynamically after creation.
See example - but it cannot be too large.
mapRandom = function(map)
for w = 0 to map.width -1
for h = 0 to map.height -1
map.set(w,h, name[ random.nextInt(4) ])
end
end
end
init = function()
name = ["red", "blue", "yellow", "green"]
map = new Map( 2, 1, 15, 15 )
mapRandom( map )
tick = 0
end
update = function()
tick += 1
if tick >= 20 then
if map.width < 100 then
map.width += 1
end
if map.height < 50 then
map.height += 1
end
tick = 0
end
mapRandom( map )
end
draw = function()
screen.clear()
screen.drawMap( map, 0, 0, 300, 150 )
screen.drawText( map.width + " " + map.height + " FPS: " + system.fps , 0, screen.height/2 - 10, 20, "orange" )
end
If you need a large area