Advertisement
Guest User

Untitled

a guest
Dec 9th, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. function love.load()
  2. Tileset = love.graphics.newImage('images/foresttiles01.png')
  3. TileW, TileH = 60,60
  4. local tilesetW, tilesetH = Tileset:getWidth(),Tileset:getHeight()
  5.  
  6. love.graphics.setBackgroundColor( 54, 54, 54)
  7.  
  8. local quadInfo = {
  9. { 'a', 0, 300 }, -- air
  10. { '#', 60, 0 }, -- grass
  11. { '*', 60, 120 }, -- flowers
  12. { '^', 120, 120 }, -- other flowers
  13. { 'g', 0, 0 } --other grass
  14. }
  15.  
  16. Quads={}
  17. for _,info in ipairs(quadInfo) do
  18. -- info[1] = character, info[2]= x, info[3] = y
  19. Quads[info[1]] = love.graphics.newQuad(info[2], info[3], TileW, TileH, tilesetW, tilesetH)
  20. end
  21.  
  22.  
  23. local tileString = [[
  24. aaaaaaaaaaaaaa
  25. aaaaaaaaaaaaaa
  26. aaaaaaaaaaaaaa
  27. aaaaaaaaaaaaaa
  28. aaaaaaaaaaaaaa
  29. aaaaaaaaaaaaaa
  30. aaaaaaaaaaaaaa
  31. aaaaaaaaaaaaaa
  32. *^^***^^**^^**
  33. #g#g#g#g#g#g#g
  34. ]]
  35.  
  36.  
  37. TileTable = {}
  38.  
  39. local width = #(tileString:match("[^\n]+"))
  40.  
  41. for x = 1,width,1 do TileTable[x] = {} end
  42.  
  43. local rowIndex,columnIndex = 1,1
  44. for row in tileString:gmatch("[^\n]+") do
  45. assert(#row == width, 'Map is not aligned: width of row ' .. tostring(rowIndex) .. ' should be ' .. tostring(width) .. ', but it is ' .. tostring(#row))
  46. columnIndex = 1
  47. for character in row:gmatch(".") do
  48. TileTable[columnIndex][rowIndex] = character
  49. columnIndex = columnIndex + 1
  50. end
  51. rowIndex=rowIndex+1
  52. end
  53. end
  54.  
  55.  
  56. function love.draw()
  57.  
  58. for columnIndex,column in ipairs(TileTable) do
  59. for rowIndex,char in ipairs(column) do
  60. local x,y = (columnIndex-1)*TileW, (rowIndex-1)*TileH
  61. love.graphics.drawq(Tileset, Quads[char], x, y)
  62. end
  63. end
  64.  
  65. end
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement