2019-05-22 22:57:34 -05:00
|
|
|
local Object = require 'libs.classic'
|
|
|
|
|
|
|
|
local Grid = Object:extend()
|
|
|
|
|
|
|
|
local empty = { skin = "", colour = "" }
|
2020-10-07 14:40:43 -05:00
|
|
|
local oob = { skin = "", colour = "" }
|
2020-11-07 00:12:13 -06:00
|
|
|
local block = { skin = "2tie", colour = "A" }
|
2019-05-22 22:57:34 -05:00
|
|
|
|
2021-01-11 14:46:43 -06:00
|
|
|
function Grid:new(width, height)
|
2019-05-22 22:57:34 -05:00
|
|
|
self.grid = {}
|
|
|
|
self.grid_age = {}
|
2021-01-10 21:40:13 -06:00
|
|
|
self.width = width
|
2021-01-11 14:46:43 -06:00
|
|
|
self.height = height
|
|
|
|
for y = 1, self.height do
|
2019-05-22 22:57:34 -05:00
|
|
|
self.grid[y] = {}
|
|
|
|
self.grid_age[y] = {}
|
2021-01-10 21:40:13 -06:00
|
|
|
for x = 1, self.width do
|
2019-05-22 22:57:34 -05:00
|
|
|
self.grid[y][x] = empty
|
|
|
|
self.grid_age[y][x] = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Grid:clear()
|
2021-01-11 14:46:43 -06:00
|
|
|
for y = 1, self.height do
|
2021-01-10 21:40:13 -06:00
|
|
|
for x = 1, self.width do
|
2019-05-22 22:57:34 -05:00
|
|
|
self.grid[y][x] = empty
|
|
|
|
self.grid_age[y][x] = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-07 14:40:43 -05:00
|
|
|
function Grid:getCell(x, y)
|
2021-01-11 14:46:43 -06:00
|
|
|
if x < 1 or x > self.width or y > self.height then return oob
|
2020-11-06 19:49:44 -06:00
|
|
|
elseif y < 1 then return empty
|
|
|
|
else return self.grid[y][x]
|
|
|
|
end
|
2020-10-07 14:40:43 -05:00
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function Grid:isOccupied(x, y)
|
2020-10-07 14:40:43 -05:00
|
|
|
return self:getCell(x+1, y+1) ~= empty
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function Grid:isRowFull(row)
|
|
|
|
for index, square in pairs(self.grid[row]) do
|
|
|
|
if square == empty then return false end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function Grid:canPlacePiece(piece)
|
2019-06-16 21:16:09 -05:00
|
|
|
if piece.big then
|
|
|
|
return self:canPlaceBigPiece(piece)
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
local offsets = piece:getBlockOffsets()
|
|
|
|
for index, offset in pairs(offsets) do
|
|
|
|
local x = piece.position.x + offset.x
|
|
|
|
local y = piece.position.y + offset.y
|
2020-10-07 14:40:43 -05:00
|
|
|
if self:isOccupied(x, y) then
|
2019-05-22 22:57:34 -05:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2019-06-16 21:16:09 -05:00
|
|
|
function Grid:canPlaceBigPiece(piece)
|
|
|
|
local offsets = piece:getBlockOffsets()
|
|
|
|
for index, offset in pairs(offsets) do
|
|
|
|
local x = piece.position.x + offset.x
|
|
|
|
local y = piece.position.y + offset.y
|
2020-11-06 19:49:44 -06:00
|
|
|
if (
|
|
|
|
self:isOccupied(x * 2 + 0, y * 2 + 0)
|
|
|
|
or self:isOccupied(x * 2 + 1, y * 2 + 0)
|
|
|
|
or self:isOccupied(x * 2 + 0, y * 2 + 1)
|
|
|
|
or self:isOccupied(x * 2 + 1, y * 2 + 1)
|
2020-10-07 14:40:43 -05:00
|
|
|
) then
|
2019-06-16 21:16:09 -05:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function Grid:canPlacePieceInVisibleGrid(piece)
|
2019-06-16 21:16:09 -05:00
|
|
|
if piece.big then
|
|
|
|
return self:canPlaceBigPiece(piece)
|
|
|
|
-- forget canPlaceBigPieceInVisibleGrid for now
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
local offsets = piece:getBlockOffsets()
|
|
|
|
for index, offset in pairs(offsets) do
|
|
|
|
local x = piece.position.x + offset.x
|
|
|
|
local y = piece.position.y + offset.y
|
2020-10-07 14:40:43 -05:00
|
|
|
if y < 4 or self:isOccupied(x, y) ~= empty then
|
2019-05-22 22:57:34 -05:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function Grid:getClearedRowCount()
|
|
|
|
local count = 0
|
2021-01-11 14:46:43 -06:00
|
|
|
for row = 1, self.height do
|
2019-05-22 22:57:34 -05:00
|
|
|
if self:isRowFull(row) then
|
|
|
|
count = count + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return count
|
|
|
|
end
|
|
|
|
|
|
|
|
function Grid:markClearedRows()
|
2021-01-11 14:46:43 -06:00
|
|
|
for row = 1, self.height do
|
2019-05-22 22:57:34 -05:00
|
|
|
if self:isRowFull(row) then
|
2021-01-10 21:40:13 -06:00
|
|
|
for x = 1, self.width do
|
2019-05-22 22:57:34 -05:00
|
|
|
self.grid[row][x] = {
|
|
|
|
skin = self.grid[row][x].skin,
|
|
|
|
colour = "X"
|
|
|
|
}
|
2021-01-06 15:56:44 -06:00
|
|
|
self.grid_age[row][x] = 0
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function Grid:clearClearedRows()
|
2021-01-11 14:46:43 -06:00
|
|
|
for row = 1, self.height do
|
2019-05-22 22:57:34 -05:00
|
|
|
if self:isRowFull(row) then
|
|
|
|
for above_row = row, 2, -1 do
|
|
|
|
self.grid[above_row] = self.grid[above_row - 1]
|
|
|
|
self.grid_age[above_row] = self.grid_age[above_row - 1]
|
|
|
|
end
|
2021-01-10 21:52:56 -06:00
|
|
|
self.grid[1] = {}
|
|
|
|
self.grid_age[1] = {}
|
|
|
|
for i = 1, self.width do
|
|
|
|
self.grid[1][i] = empty
|
|
|
|
self.grid_age[1][i] = 0
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function Grid:copyBottomRow()
|
2021-01-11 14:46:43 -06:00
|
|
|
for row = 1, self.height - 1 do
|
2019-05-22 22:57:34 -05:00
|
|
|
self.grid[row] = self.grid[row+1]
|
|
|
|
self.grid_age[row] = self.grid_age[row+1]
|
|
|
|
end
|
2021-01-11 14:46:43 -06:00
|
|
|
self.grid[self.height] = {}
|
|
|
|
self.grid_age[self.height] = {}
|
2021-01-10 21:52:56 -06:00
|
|
|
for i = 1, self.width do
|
2021-01-11 14:46:43 -06:00
|
|
|
self.grid[self.height][i] = (self.grid[self.height - 1][i] == empty) and empty or block
|
|
|
|
self.grid_age[self.height][i] = 0
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2020-11-01 12:24:52 -06:00
|
|
|
function Grid:garbageRise(row_vals)
|
2021-01-11 14:46:43 -06:00
|
|
|
for row = 1, self.height - 1 do
|
2021-01-10 21:52:56 -06:00
|
|
|
self.grid[row] = self.grid[row+1]
|
|
|
|
self.grid_age[row] = self.grid_age[row+1]
|
|
|
|
end
|
2021-01-11 14:46:43 -06:00
|
|
|
self.grid[self.height] = {}
|
|
|
|
self.grid_age[self.height] = {}
|
2021-01-10 21:52:56 -06:00
|
|
|
for i = 1, self.width do
|
2021-01-11 14:46:43 -06:00
|
|
|
self.grid[self.height][i] = (row_vals[i] == "e") and empty or block
|
|
|
|
self.grid_age[self.height][i] = 0
|
2020-11-01 12:24:52 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-11 21:30:30 -06:00
|
|
|
function Grid:clearSpecificRow(row)
|
2021-01-10 21:40:13 -06:00
|
|
|
for col = 1, self.width do
|
2020-11-11 21:30:30 -06:00
|
|
|
self.grid[row][col] = empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function Grid:applyPiece(piece)
|
2019-06-16 21:16:09 -05:00
|
|
|
if piece.big then
|
|
|
|
self:applyBigPiece(piece)
|
|
|
|
return
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
offsets = piece:getBlockOffsets()
|
|
|
|
for index, offset in pairs(offsets) do
|
|
|
|
x = piece.position.x + offset.x
|
|
|
|
y = piece.position.y + offset.y
|
2021-01-11 14:46:43 -06:00
|
|
|
if y + 1 > 0 and y < self.height then
|
2020-10-07 12:24:28 -05:00
|
|
|
self.grid[y+1][x+1] = {
|
|
|
|
skin = piece.skin,
|
2020-10-10 18:42:56 -05:00
|
|
|
colour = piece.colour
|
2020-10-07 12:24:28 -05:00
|
|
|
}
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-16 21:16:09 -05:00
|
|
|
function Grid:applyBigPiece(piece)
|
|
|
|
offsets = piece:getBlockOffsets()
|
|
|
|
for index, offset in pairs(offsets) do
|
|
|
|
x = piece.position.x + offset.x
|
|
|
|
y = piece.position.y + offset.y
|
|
|
|
for a = 1, 2 do
|
|
|
|
for b = 1, 2 do
|
2020-11-06 19:49:44 -06:00
|
|
|
if y*2+a > 0 then
|
|
|
|
self.grid[y*2+a][x*2+b] = {
|
|
|
|
skin = piece.skin,
|
|
|
|
colour = piece.colour
|
|
|
|
}
|
|
|
|
end
|
2019-06-16 21:16:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-08 19:44:06 -05:00
|
|
|
function Grid:checkForBravo(cleared_row_count)
|
2021-01-11 14:46:43 -06:00
|
|
|
for i = 0, self.height - 1 - cleared_row_count do
|
2021-01-10 21:40:13 -06:00
|
|
|
for j = 0, self.width - 1 do
|
2020-11-06 19:49:44 -06:00
|
|
|
if self:isOccupied(j, i) then return false end
|
|
|
|
end
|
|
|
|
end
|
2020-10-08 19:44:06 -05:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2020-11-17 20:52:20 -06:00
|
|
|
function Grid:checkStackHeight()
|
2021-01-11 14:46:43 -06:00
|
|
|
for i = 0, self.height - 1 do
|
2021-01-10 21:40:13 -06:00
|
|
|
for j = 0, self.width - 1 do
|
2021-01-11 14:46:43 -06:00
|
|
|
if self:isOccupied(j, i) then return self.height - i end
|
2020-11-17 20:52:20 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2020-10-08 20:00:42 -05:00
|
|
|
function Grid:checkSecretGrade()
|
2020-11-06 19:49:44 -06:00
|
|
|
local sgrade = 0
|
|
|
|
for i=23,5,-1 do
|
|
|
|
local validLine = true
|
|
|
|
local emptyCell = 0
|
|
|
|
if i > 13 then
|
|
|
|
emptyCell = 23-i
|
|
|
|
end
|
|
|
|
if i <= 13 then
|
|
|
|
emptyCell = i-5
|
|
|
|
end
|
|
|
|
for j=0,9 do
|
|
|
|
if (not self:isOccupied(j,i) and j ~= emptyCell) or (j == emptyCell and self:isOccupied(j,i)) then
|
|
|
|
validLine = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not self:isOccupied(emptyCell,i-1) then
|
|
|
|
validLine = false
|
|
|
|
end
|
|
|
|
if(validLine) then
|
|
|
|
sgrade = sgrade + 1
|
|
|
|
else
|
|
|
|
return sgrade
|
|
|
|
end
|
|
|
|
end
|
|
|
|
--[[
|
|
|
|
if(sgrade == 0) then return ""
|
|
|
|
elseif(sgrade < 10) then return 10-sgrade
|
|
|
|
elseif(sgrade < 19) then return "S"..(sgrade-9) end
|
|
|
|
return "GM"
|
|
|
|
--]]
|
|
|
|
return sgrade
|
2020-10-08 20:00:42 -05:00
|
|
|
end
|
|
|
|
|
2020-12-30 14:19:53 -06:00
|
|
|
function Grid:hasGemBlocks()
|
2021-01-11 14:46:43 -06:00
|
|
|
for y = 1, self.height do
|
2021-01-10 21:40:13 -06:00
|
|
|
for x = 1, self.width do
|
2020-12-30 14:19:53 -06:00
|
|
|
if self.grid[y][x].skin == "gem" then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2021-01-02 11:21:10 -06:00
|
|
|
function Grid:mirror()
|
|
|
|
local new_grid = {}
|
2021-01-11 14:46:43 -06:00
|
|
|
for y = 1, self.height do
|
2021-01-04 17:01:29 -06:00
|
|
|
new_grid[y] = {}
|
2021-01-10 21:40:13 -06:00
|
|
|
for x = 1, self.width do
|
2021-01-04 17:01:29 -06:00
|
|
|
new_grid[y][x] = empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-11 14:46:43 -06:00
|
|
|
for y = 1, self.height do
|
2021-01-10 21:40:13 -06:00
|
|
|
for x = 1, self.width do
|
2021-01-11 14:46:43 -06:00
|
|
|
new_grid[y][x] = self.grid[y][self.width + 1 - x]
|
2021-01-02 11:21:10 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
self.grid = new_grid
|
|
|
|
end
|
|
|
|
|
2020-12-30 14:19:53 -06:00
|
|
|
function Grid:applyMap(map)
|
|
|
|
for y, row in pairs(map) do
|
|
|
|
for x, block in pairs(row) do
|
|
|
|
self.grid_age[y][x] = 0
|
|
|
|
self.grid[y][x] = block
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function Grid:update()
|
2021-01-11 14:46:43 -06:00
|
|
|
for y = 1, self.height do
|
2021-01-10 21:40:13 -06:00
|
|
|
for x = 1, self.width do
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.grid[y][x] ~= empty then
|
|
|
|
self.grid_age[y][x] = self.grid_age[y][x] + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Grid:draw()
|
2021-01-11 14:46:43 -06:00
|
|
|
for y = 5, self.height do
|
2021-01-10 21:40:13 -06:00
|
|
|
for x = 1, self.width do
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.grid[y][x] ~= empty then
|
2020-11-07 00:12:13 -06:00
|
|
|
if self.grid_age[y][x] < 2 then
|
2019-05-22 22:57:34 -05:00
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
love.graphics.draw(blocks[self.grid[y][x].skin]["F"], 48+x*16, y*16)
|
|
|
|
else
|
2020-11-09 20:13:07 -06:00
|
|
|
if self.grid[y][x].skin == "bone" then
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
2021-01-06 15:56:44 -06:00
|
|
|
elseif self.grid[y][x].colour == "X" then
|
|
|
|
love.graphics.setColor(0.5, 0.5, 0.5, 1 - self.grid_age[y][x] / 15)
|
|
|
|
else
|
2020-11-09 20:13:07 -06:00
|
|
|
love.graphics.setColor(0.5, 0.5, 0.5, 1)
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
love.graphics.draw(blocks[self.grid[y][x].skin][self.grid[y][x].colour], 48+x*16, y*16)
|
|
|
|
end
|
2021-01-06 15:56:44 -06:00
|
|
|
if self.grid[y][x].skin ~= "bone" and self.grid[y][x].colour ~= "X" then
|
2019-06-16 21:16:09 -05:00
|
|
|
love.graphics.setColor(0.8, 0.8, 0.8, 1)
|
|
|
|
love.graphics.setLineWidth(1)
|
2021-01-06 17:01:56 -06:00
|
|
|
if y > 1 and self.grid[y-1][x] == empty or self.grid[y-1][x].colour == "X" then
|
2019-06-16 21:16:09 -05:00
|
|
|
love.graphics.line(48.0+x*16, -0.5+y*16, 64.0+x*16, -0.5+y*16)
|
|
|
|
end
|
2021-01-11 14:46:43 -06:00
|
|
|
if y < self.height and self.grid[y+1][x] == empty or
|
|
|
|
(y + 1 > self.height or self.grid[y+1][x].colour == "X") then
|
2019-06-16 21:16:09 -05:00
|
|
|
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
|
|
|
end
|
|
|
|
if x > 1 and self.grid[y][x-1] == empty then
|
|
|
|
love.graphics.line(47.5+x*16, -0.0+y*16, 47.5+x*16, 16.0+y*16)
|
|
|
|
end
|
2021-01-10 21:40:13 -06:00
|
|
|
if x < self.width and self.grid[y][x+1] == empty then
|
2019-06-16 21:16:09 -05:00
|
|
|
love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16)
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-18 11:17:04 -06:00
|
|
|
function Grid:drawOutline()
|
2021-01-11 14:46:43 -06:00
|
|
|
for y = 5, self.height do
|
2021-01-10 21:40:13 -06:00
|
|
|
for x = 1, self.width do
|
2021-01-10 10:41:34 -06:00
|
|
|
if self.grid[y][x].colour == "X" then
|
|
|
|
love.graphics.setColor(0.5, 0.5, 0.5, 1 - self.grid_age[y][x] / 15)
|
|
|
|
love.graphics.draw(blocks[self.grid[y][x].skin][self.grid[y][x].colour], 48+x*16, y*16)
|
|
|
|
end
|
2021-01-06 20:37:51 -06:00
|
|
|
if self.grid[y][x] ~= empty and self.grid[y][x].colour ~= "X" then
|
2020-11-18 11:17:04 -06:00
|
|
|
love.graphics.setColor(0.8, 0.8, 0.8, 1)
|
|
|
|
love.graphics.setLineWidth(1)
|
2021-01-06 20:37:51 -06:00
|
|
|
if y > 1 and self.grid[y-1][x] == empty or self.grid[y-1][x].colour == "X" then
|
2020-11-18 11:17:04 -06:00
|
|
|
love.graphics.line(48.0+x*16, -0.5+y*16, 64.0+x*16, -0.5+y*16)
|
|
|
|
end
|
2021-01-11 14:46:43 -06:00
|
|
|
if y < self.height and self.grid[y+1][x] == empty or
|
|
|
|
(y + 1 > self.height or self.grid[y+1][x].colour == "X") then
|
2020-11-18 11:17:04 -06:00
|
|
|
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
|
|
|
end
|
|
|
|
if x > 1 and self.grid[y][x-1] == empty then
|
|
|
|
love.graphics.line(47.5+x*16, -0.0+y*16, 47.5+x*16, 16.0+y*16)
|
|
|
|
end
|
2021-01-10 21:40:13 -06:00
|
|
|
if x < self.width and self.grid[y][x+1] == empty then
|
2020-11-18 11:17:04 -06:00
|
|
|
love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-14 08:35:16 -06:00
|
|
|
function Grid:drawInvisible(opacity_function, garbage_opacity_function, lock_flash, brightness)
|
|
|
|
lock_flash = lock_flash == nil and true or lock_flash
|
|
|
|
brightness = brightness == nil and 0.5 or brightness
|
2021-01-11 14:46:43 -06:00
|
|
|
for y = 5, self.height do
|
2021-01-10 21:40:13 -06:00
|
|
|
for x = 1, self.width do
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.grid[y][x] ~= empty then
|
|
|
|
if self.grid[y][x].colour == "X" then
|
2021-01-06 15:56:44 -06:00
|
|
|
opacity = 1 - self.grid_age[y][x] / 15
|
2020-11-07 00:12:13 -06:00
|
|
|
elseif garbage_opacity_function and self.grid[y][x].colour == "A" then
|
2019-05-22 22:57:34 -05:00
|
|
|
opacity = garbage_opacity_function(self.grid_age[y][x])
|
|
|
|
else
|
|
|
|
opacity = opacity_function(self.grid_age[y][x])
|
|
|
|
end
|
2020-11-14 08:35:16 -06:00
|
|
|
love.graphics.setColor(brightness, brightness, brightness, opacity)
|
2019-05-22 22:57:34 -05:00
|
|
|
love.graphics.draw(blocks[self.grid[y][x].skin][self.grid[y][x].colour], 48+x*16, y*16)
|
2020-11-14 08:35:16 -06:00
|
|
|
if lock_flash then
|
|
|
|
if opacity > 0 and self.grid[y][x].colour ~= "X" then
|
|
|
|
love.graphics.setColor(0.64, 0.64, 0.64)
|
|
|
|
love.graphics.setLineWidth(1)
|
2021-01-06 20:37:51 -06:00
|
|
|
if y > 1 and self.grid[y-1][x] == empty or self.grid[y-1][x].colour == "X" then
|
2020-11-14 08:35:16 -06:00
|
|
|
love.graphics.line(48.0+x*16, -0.5+y*16, 64.0+x*16, -0.5+y*16)
|
|
|
|
end
|
2021-01-11 14:46:43 -06:00
|
|
|
if y < self.height and self.grid[y+1][x] == empty or
|
|
|
|
(y + 1 > self.height or self.grid[y+1][x].colour == "X") then
|
2020-11-14 08:35:16 -06:00
|
|
|
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
|
|
|
end
|
|
|
|
if x > 1 and self.grid[y][x-1] == empty then
|
|
|
|
love.graphics.line(47.5+x*16, -0.0+y*16, 47.5+x*16, 16.0+y*16)
|
|
|
|
end
|
2021-01-10 21:40:13 -06:00
|
|
|
if x < self.width and self.grid[y][x+1] == empty then
|
2020-11-14 08:35:16 -06:00
|
|
|
love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16)
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-02 18:05:54 -06:00
|
|
|
function Grid:drawCustom(colour_function, gamestate)
|
|
|
|
--[[
|
|
|
|
colour_function: (game, block, x, y, age) -> (R, G, B, A, outlineA)
|
|
|
|
When called, calls the supplied function on every block passing the block itself as argument
|
|
|
|
as well as coordinates and the grid_age value of the same cell.
|
|
|
|
Should return a RGBA colour for the block, as well as the opacity of the stack outline (0 for no outline).
|
|
|
|
|
|
|
|
gamestate: the gamemode instance itself to pass in colour_function
|
|
|
|
]]
|
2021-01-11 14:46:43 -06:00
|
|
|
for y = 5, self.height do
|
2021-01-10 21:40:13 -06:00
|
|
|
for x = 1, self.width do
|
2021-01-02 18:05:54 -06:00
|
|
|
local block = self.grid[y][x]
|
|
|
|
if block ~= empty then
|
|
|
|
local R, G, B, A, outline = colour_function(gamestate, block, x, y, self.grid_age[y][x])
|
|
|
|
if self.grid[y][x].colour == "X" then
|
2021-01-06 15:56:44 -06:00
|
|
|
A = 1 - self.grid_age[y][x] / 15
|
2021-01-02 18:05:54 -06:00
|
|
|
end
|
|
|
|
love.graphics.setColor(R, G, B, A)
|
|
|
|
love.graphics.draw(blocks[self.grid[y][x].skin][self.grid[y][x].colour], 48+x*16, y*16)
|
|
|
|
if outline > 0 and self.grid[y][x].colour ~= "X" then
|
|
|
|
love.graphics.setColor(0.64, 0.64, 0.64, outline)
|
|
|
|
love.graphics.setLineWidth(1)
|
2021-01-06 20:37:51 -06:00
|
|
|
if y > 1 and self.grid[y-1][x] == empty or self.grid[y-1][x].colour == "X" then
|
|
|
|
love.graphics.line(48.0+x*16, -0.5+y*16, 64.0+x*16, -0.5+y*16)
|
|
|
|
end
|
2021-01-11 14:46:43 -06:00
|
|
|
if y < self.height and self.grid[y+1][x] == empty or
|
|
|
|
(y + 1 > self.height or self.grid[y+1][x].colour == "X") then
|
2021-01-06 20:37:51 -06:00
|
|
|
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
|
|
|
end
|
|
|
|
if x > 1 and self.grid[y][x-1] == empty then
|
|
|
|
love.graphics.line(47.5+x*16, -0.0+y*16, 47.5+x*16, 16.0+y*16)
|
|
|
|
end
|
2021-01-10 21:40:13 -06:00
|
|
|
if x < self.width and self.grid[y][x+1] == empty then
|
2021-01-06 20:37:51 -06:00
|
|
|
love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16)
|
|
|
|
end
|
2021-01-02 18:05:54 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
return Grid
|