Creating a Border using Sprite Blocks
Posted: Mon Dec 21, 2020 5:51 am
I'm trying to make this game, and I'm starting with implementing the borders, but it's harder than I thought. However, I'm able to make a layer for the bottom part of the screen, but I don't know what to do for the other three sides.
Here's what I've got so far:
I've also attached a screenshot of the result.
Here's what I've got so far:
Code: Select all
require 'Util'
Map = Class{}
TILE_BRICK = 2
TILE_EMPTY = -1
local x = 1
function Map:init()
self.spritesheet = love.graphics.newImage('images/Blocks.png')
self.sprites = generateQuads(self.spritesheet, 16, 20)
self.tileWidth = 16
self.tileHeight = 16
self.mapWidth = 30
self.mapHeight = 28
self.tiles = {}
self.mapWidthPixels = self.mapWidth * self.tileWidth
self.mapHeightPixels = self.mapHeight * self.tileHeight
for y = 1, self.mapHeight do
for x = 1, self.mapWidth do
self:setTile(x, y, TILE_EMPTY)
end
end
for y = self.mapHeight / 2 + 1, self.mapHeight do
for x = 1, self.mapWidth do
self:setTile(x, y, TILE_BRICK)
end
end
end
function Map:getTile(x, y)
return self.tiles[(y - 1) * self.mapWidth + x]
end
function Map:setTile(x, y, id)
self.tiles[(y - 1) * self.mapWidth + x] = id
end
function Map:render()
for y = 1, self.mapHeight do
for x = 1, self.mapWidth do
local tile = self:getTile(x, y)
if tile ~= TILE_EMPTY then
love.graphics.draw(self.spritesheet, self.sprites[tile],
(x - 1) * self.tileWidth, (y - 1) * self.tileHeight)
end
end
end
end