2017-06-19 02:15:21 -04:00
|
|
|
--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 = {}
|
2017-06-22 00:52:28 -04:00
|
|
|
|
|
|
|
--generates tile blocks
|
2017-06-19 02:15:21 -04:00
|
|
|
function maplib.createmap()
|
2017-06-22 00:52:28 -04:00
|
|
|
|
|
|
|
local dir = love.filesystem.getAppdataDirectory()
|
|
|
|
|
|
|
|
love.filesystem.createDirectory(dir.."map")
|
|
|
|
|
|
|
|
files = love.filesystem.getDirectoryItems( love.filesystem.getAppdataDirectory() )
|
|
|
|
|
|
|
|
file = love.filesystem.newFile( "map.txt" )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(files["map"])
|
|
|
|
|
|
|
|
|
2017-06-19 02:15:21 -04:00
|
|
|
for x = 1,mapwidth do
|
|
|
|
tiles[x] = {}
|
|
|
|
for y = 1,mapheight do
|
2017-06-22 00:52:28 -04:00
|
|
|
local value = love.math.noise( x/mapwidth, y/mapheight )
|
2017-06-19 02:15:21 -04:00
|
|
|
tiles[x][y] = {}
|
2017-06-22 00:52:28 -04:00
|
|
|
if value > 0.5 then
|
|
|
|
tiles[x][y]["block"] = 1--love.math.random(0,1)
|
|
|
|
else
|
|
|
|
tiles[x][y]["block"] = 0
|
|
|
|
end
|
|
|
|
|
2017-06-19 02:15:21 -04:00
|
|
|
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
|
2017-06-20 01:44:23 -04:00
|
|
|
local graphic
|
|
|
|
if tiles[x][y]["block"] == 0 then
|
2017-06-20 04:16:34 -04:00
|
|
|
graphic = "" --air
|
2017-06-20 01:44:23 -04:00
|
|
|
elseif tiles[x][y]["block"] == 1 then
|
2017-06-20 04:16:34 -04:00
|
|
|
graphic = "#" --stone
|
|
|
|
elseif tiles[x][y]["block"] == 2 then
|
|
|
|
graphic = "/" --stairs
|
2017-06-20 01:44:23 -04:00
|
|
|
end
|
|
|
|
love.graphics.print(graphic, 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
|
|
|
|
|
|
|
|
]]--
|