Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Map = Class{} -- error: attempt to class global 'Class' (a boolean value)
- TILE_BRICK = 1
- TILE_EMPTY = 4
- function Map:init()
- self.spritesheet = love.graphics.newImage('graphics/spritesheet.png') -- creating the map. we need a spritesheet to reference to map the tiles to quads. the function will point to a texture file and load it into memory. it is a texture object.
- self.tileWidth = 16
- self.tileheight = 16
- self.mapWidth = 30 -- tilewidth is just pixel size. the map width is how many tiles wide the map is
- self.mapHeight = 28
- self.tiles = {} -- the actual tile map... we will iterate over these number, and draw the right texture with the right number down the line
- self.tileSprites = generateQuads(self.spritesheet, self.tileWidth, self.tileHeight)
- -- populate the tile map with the numbers. 1 is the brick that we want to use, and 4 is an empty tile which will represent the sky.
- -- filling the map with empty tiles
- 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
- --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) -- the tiles are numbers... a simple way to represent them
- 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