Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Map = Class{} -- error: attempt to call global 'Class' (a boolean value)
- TILE_BRICK = 1
- TILE_EMPTY = 4
- function Map:init()
- self.spritesheet = love.graphics.newImage('graphics/spritesheet.png')
- self.tileWidth = 16
- self.tileheight = 16
- self.mapWidth = 30
- self.mapHeight = 28
- self.tiles = {}
- self.tileSprites = generateQuads(self.spritesheet, self.tileWidth, self.tileHeight)
- for y = 1, self.mapHeight/2 do -- iterate top to bottom through the map and go down to halfway through the map
- for x = 1, self.mapWidth do -- columns and rows
- self:setTile(x, y, TILE_EMPTY) -- this function is writted below
- end
- end
- -- starts halfway down the map, populates with bricks
- 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 ,
- --start halfway down the map
- for x = 1, self.mapWidth/2 do
- self:setTile(x, y, TILE_BRICK) -- starts halfway down the map and populates it with bricks
- 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] -- return the same value
- 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