Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Map = Class{}
- TILE_BRICK = 1
- TILE_EMPTY = 4
- function Map:init()
- self.spritesheet = love.graphics.newImage('graphics/spritesheet.png')
- self.tileWidth = 16
- self.tileHeight = 16 -- tileheight is declared here
- self.mapWidth = 30 -- tilewidth is just pixel size. the map width is how many tiles wide the map is
- self.mapHeight = 28
- self.tiles = {}
- self.tileSprites = generateQuads(self.spritesheet, self.tileWidth, self.tileHeight)
- for y = 1, self.mapHeight/2 do
- for x = 1, self.mapWidth do
- self:setTile(x, y, TILE_EMPTY)
- end
- end
- for y = self.mapHeight/2, self.mapHeight do
- for x = 1, self.mapWidth/2 do
- self:setTile(x, y, TILE_BRICK)
- end
- end
- end
- function Map:SetTile(x, y, tile)
- self.tiles[(y-1)*self.mapWidth + x] = tile
- end
- function Map:getTile(x, y)
- return self.tiles[(y-1)*self.mapWidth + x]
- end
- function Map:update(dt)
- end
- function Map:render()
- for y = 1, self.mapHeight do
- for x = 1, self.mapWidth do
- love.graphics.draw(self.spritesheet, self.tileSprites[self:getTile(x, y)],
- (x-1)*self.tileWidth, (y-1)*self.tileHeight)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement