Tile.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. -- Copyright (c) 2011-2012 Casey Baxter
  2. -- See LICENSE file for details
  3. ---------------------------------------------------------------------------------------------------
  4. -- -= Tile =-
  5. ---------------------------------------------------------------------------------------------------
  6. -- Setup
  7. local assert = assert
  8. local Tile = {class = "Tile"}
  9. Tile.__index = Tile
  10. -- Creates a new tile and returns it.
  11. function Tile:new(id, tileset, quad, width, height, prop, tiletype)
  12. if not id or not tileset or not quad then
  13. error("Tile:new - Needs at least 3 parameters for id, tileset and quad.")
  14. end
  15. local tile = setmetatable({}, Tile)
  16. tile.id = id -- The id of the tile
  17. tile.tileset = tileset -- The tileset this tile belongs to
  18. tile.quad = quad -- The of the tileset that defines the tile
  19. tile.width = width or 0 -- The width of the tile in pixels
  20. tile.height = height or 0 -- The height of the tile in pixels
  21. tile.properties = prop or {} -- The properties of the tile set in Tiled
  22. tile.type = tiletype
  23. return tile
  24. end
  25. -- Draws the tile at the given location
  26. function Tile:draw(x, y, rotation, scaleX, scaleY, offsetX, offsetY)
  27. love.graphics.draw(self.tileset.image, self.quad, self.tileset.offsetX + x,
  28. self.tileset.offsetY + y, rotation, scaleX, scaleY, offsetX, offsetY)
  29. end
  30. -- Return the Tile class
  31. return Tile