Open-Terrarium/map.lua

52 lines
850 B
Lua
Raw Normal View History

2017-06-19 02:15:21 -04:00
math.randomseed( os.time() )
--the map library
maplib = {}
--create tiles
mapheight = 48
2017-06-19 02:46:07 -04:00
mapwidth = 30
2017-06-19 02:15:21 -04:00
tiles = {}
function maplib.createmap()
for x = 1,mapwidth do
tiles[x] = {}
for y = 1,mapheight do
tiles[x][y] = {}
local randomtile = math.random(0,1)
if randomtile == 0 then
tiles[x][y]["tile"] = ""
tiles[x][y]["block"] = 0
2017-06-19 02:15:21 -04:00
elseif randomtile == 1 then
tiles[x][y]["tile"] = "*"
tiles[x][y]["block"] = 1
2017-06-19 02:15:21 -04:00
end
end
end
end
--executed in love.draw to draw map
function maplib.draw()
2017-06-19 02:46:07 -04:00
love.graphics.setFont(font)
2017-06-19 02:15:21 -04:00
love.graphics.setColor(255,255,255,255)
for x = 1,mapwidth do
for y = 1,mapheight do
love.graphics.print(tiles[x][y]["tile"], x*scale, y*scale)
2017-06-19 02:15:21 -04:00
end
end
end
--[[ a test
for x = 1,10 do
local line = ""
for y = 1,10 do
line = line..tiles.x.y
end
print(line.."\n")
end
]]--