Advertisement
joseleeph

Untitled

Jan 5th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. Map = Class{}
  2.  
  3. TILE_BRICK = 1
  4. TILE_EMPTY = 4
  5.  
  6. function Map:init()
  7. self.spritesheet = love.graphics.newImage('graphics/spritesheet.png')
  8. self.tileWidth = 16
  9. self.tileHeight = 16 -- tileheight is declared here
  10. self.mapWidth = 30 -- tilewidth is just pixel size. the map width is how many tiles wide the map is
  11. self.mapHeight = 28
  12.  
  13. self.tiles = {}
  14.  
  15. self.tileSprites = generateQuads(self.spritesheet, self.tileWidth, self.tileHeight)
  16.  
  17.  
  18. for y = 1, self.mapHeight/2 do
  19. for x = 1, self.mapWidth do
  20. self:setTile(x, y, TILE_EMPTY)
  21. end
  22. end
  23.  
  24.  
  25. for y = self.mapHeight/2, self.mapHeight do
  26. for x = 1, self.mapWidth/2 do
  27. self:setTile(x, y, TILE_BRICK)
  28. end
  29. end
  30. end
  31.  
  32. function Map:SetTile(x, y, tile)
  33. self.tiles[(y-1)*self.mapWidth + x] = tile
  34. end
  35.  
  36.  
  37. function Map:getTile(x, y)
  38. return self.tiles[(y-1)*self.mapWidth + x]
  39. end
  40.  
  41. function Map:update(dt)
  42.  
  43. end
  44.  
  45. function Map:render()
  46. for y = 1, self.mapHeight do
  47. for x = 1, self.mapWidth do
  48. love.graphics.draw(self.spritesheet, self.tileSprites[self:getTile(x, y)],
  49. (x-1)*self.tileWidth, (y-1)*self.tileHeight)
  50. end
  51. end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement