Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function love.load()
- Tileset = love.graphics.newImage('images/foresttiles01.png')
- TileW, TileH = 60,60
- local tilesetW, tilesetH = Tileset:getWidth(),Tileset:getHeight()
- love.graphics.setBackgroundColor( 54, 54, 54)
- local quadInfo = {
- { 'a', 0, 300 }, -- air
- { '#', 60, 0 }, -- grass
- { '*', 60, 120 }, -- flowers
- { '^', 120, 120 }, -- other flowers
- { 'g', 0, 0 } --other grass
- }
- Quads={}
- for _,info in ipairs(quadInfo) do
- -- info[1] = character, info[2]= x, info[3] = y
- Quads[info[1]] = love.graphics.newQuad(info[2], info[3], TileW, TileH, tilesetW, tilesetH)
- end
- local tileString = [[
- aaaaaaaaaaaaaa
- aaaaaaaaaaaaaa
- aaaaaaaaaaaaaa
- aaaaaaaaaaaaaa
- aaaaaaaaaaaaaa
- aaaaaaaaaaaaaa
- aaaaaaaaaaaaaa
- aaaaaaaaaaaaaa
- *^^***^^**^^**
- #g#g#g#g#g#g#g
- ]]
- TileTable = {}
- local width = #(tileString:match("[^\n]+"))
- for x = 1,width,1 do TileTable[x] = {} end
- local rowIndex,columnIndex = 1,1
- for row in tileString:gmatch("[^\n]+") do
- assert(#row == width, 'Map is not aligned: width of row ' .. tostring(rowIndex) .. ' should be ' .. tostring(width) .. ', but it is ' .. tostring(#row))
- columnIndex = 1
- for character in row:gmatch(".") do
- TileTable[columnIndex][rowIndex] = character
- columnIndex = columnIndex + 1
- end
- rowIndex=rowIndex+1
- end
- end
- function love.draw()
- for columnIndex,column in ipairs(TileTable) do
- for rowIndex,char in ipairs(column) do
- local x,y = (columnIndex-1)*TileW, (rowIndex-1)*TileH
- love.graphics.drawq(Tileset, Quads[char], x, y)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement