Advertisement
joseleeph

Untitled

Jan 5th, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. Map = Class{} -- error: attempt to call global 'Class' (a boolean value)
  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
  10. self.mapWidth = 30
  11. self.mapHeight = 28
  12.  
  13. self.tiles = {}
  14.  
  15. self.tileSprites = generateQuads(self.spritesheet, self.tileWidth, self.tileHeight)
  16. for y = 1, self.mapHeight/2 do -- iterate top to bottom through the map and go down to halfway through the map
  17. for x = 1, self.mapWidth do -- columns and rows
  18. self:setTile(x, y, TILE_EMPTY) -- this function is writted below
  19. end
  20. end
  21.  
  22. -- starts halfway down the map, populates with bricks
  23. for y = self.mapHeight/2, self.mapHeight do -- loop through half the image... halfway onwards... increments implicitly. you can increment a different value with a ,
  24. --start halfway down the map
  25. for x = 1, self.mapWidth/2 do
  26. self:setTile(x, y, TILE_BRICK) -- starts halfway down the map and populates it with bricks
  27. end
  28. end
  29. end
  30.  
  31. function Map:SetTile(x, y, tile)
  32. self.tiles[(y-1)*self.mapWidth + x] = tile
  33. end
  34.  
  35.  
  36. function Map:getTile(x, y)
  37. return self.tiles[(y-1)*self.mapWidth + x] -- return the same value
  38. end
  39.  
  40. function Map:update(dt)
  41.  
  42. end
  43.  
  44. function Map:render()
  45. for y = 1, self.mapHeight do
  46. for x = 1, self.mapWidth do
  47. love.graphics.draw(self.spritesheet, self.tileSprites[self:getTile(x, y)],
  48. (x-1)*self.tileWidth, (y-1)*self.tileHeight)
  49. end
  50. end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement