mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 18:39:02 -06:00
Custom field heights implemented
This commit is contained in:
parent
6d07a3b820
commit
0c2ba5f0cc
@ -55,7 +55,10 @@ function GameScene:render()
|
|||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.setColor(0, 0, 0, 200)
|
love.graphics.setColor(0, 0, 0, 200)
|
||||||
love.graphics.rectangle("fill", 64, 80, 16 * self.game.grid.width, 320)
|
love.graphics.rectangle(
|
||||||
|
"fill", 64, 80,
|
||||||
|
16 * self.game.grid.width, 16 * (self.game.grid.height - 4)
|
||||||
|
)
|
||||||
|
|
||||||
if self.game.grid.width ~= 10 then
|
if self.game.grid.width ~= 10 then
|
||||||
love.graphics.setColor(174/255, 83/255, 76/255, 1)
|
love.graphics.setColor(174/255, 83/255, 76/255, 1)
|
||||||
@ -63,8 +66,8 @@ function GameScene:render()
|
|||||||
love.graphics.line(
|
love.graphics.line(
|
||||||
60,76,
|
60,76,
|
||||||
68+16*self.game.grid.width,76,
|
68+16*self.game.grid.width,76,
|
||||||
68+16*self.game.grid.width,404,
|
68+16*self.game.grid.width,84+16*(self.game.grid.height-4),
|
||||||
60,404,
|
60,84+16*(self.game.grid.height-4),
|
||||||
60,76
|
60,76
|
||||||
)
|
)
|
||||||
love.graphics.setColor(203/255, 137/255, 111/255, 1)
|
love.graphics.setColor(203/255, 137/255, 111/255, 1)
|
||||||
@ -72,8 +75,8 @@ function GameScene:render()
|
|||||||
love.graphics.line(
|
love.graphics.line(
|
||||||
60,76,
|
60,76,
|
||||||
68+16*self.game.grid.width,76,
|
68+16*self.game.grid.width,76,
|
||||||
68+16*self.game.grid.width,404,
|
68+16*self.game.grid.width,84+16*(self.game.grid.height-4),
|
||||||
60,404,
|
60,84+16*(self.game.grid.height-4),
|
||||||
60,76
|
60,76
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -6,11 +6,12 @@ local empty = { skin = "", colour = "" }
|
|||||||
local oob = { skin = "", colour = "" }
|
local oob = { skin = "", colour = "" }
|
||||||
local block = { skin = "2tie", colour = "A" }
|
local block = { skin = "2tie", colour = "A" }
|
||||||
|
|
||||||
function Grid:new(width)
|
function Grid:new(width, height)
|
||||||
self.grid = {}
|
self.grid = {}
|
||||||
self.grid_age = {}
|
self.grid_age = {}
|
||||||
self.width = width
|
self.width = width
|
||||||
for y = 1, 24 do
|
self.height = height
|
||||||
|
for y = 1, self.height do
|
||||||
self.grid[y] = {}
|
self.grid[y] = {}
|
||||||
self.grid_age[y] = {}
|
self.grid_age[y] = {}
|
||||||
for x = 1, self.width do
|
for x = 1, self.width do
|
||||||
@ -21,7 +22,7 @@ function Grid:new(width)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Grid:clear()
|
function Grid:clear()
|
||||||
for y = 1, 24 do
|
for y = 1, self.height do
|
||||||
for x = 1, self.width do
|
for x = 1, self.width do
|
||||||
self.grid[y][x] = empty
|
self.grid[y][x] = empty
|
||||||
self.grid_age[y][x] = 0
|
self.grid_age[y][x] = 0
|
||||||
@ -30,7 +31,7 @@ function Grid:clear()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Grid:getCell(x, y)
|
function Grid:getCell(x, y)
|
||||||
if x < 1 or x > self.width or y > 24 then return oob
|
if x < 1 or x > self.width or y > self.height then return oob
|
||||||
elseif y < 1 then return empty
|
elseif y < 1 then return empty
|
||||||
else return self.grid[y][x]
|
else return self.grid[y][x]
|
||||||
end
|
end
|
||||||
@ -99,7 +100,7 @@ end
|
|||||||
|
|
||||||
function Grid:getClearedRowCount()
|
function Grid:getClearedRowCount()
|
||||||
local count = 0
|
local count = 0
|
||||||
for row = 1, 24 do
|
for row = 1, self.height do
|
||||||
if self:isRowFull(row) then
|
if self:isRowFull(row) then
|
||||||
count = count + 1
|
count = count + 1
|
||||||
end
|
end
|
||||||
@ -108,7 +109,7 @@ function Grid:getClearedRowCount()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Grid:markClearedRows()
|
function Grid:markClearedRows()
|
||||||
for row = 1, 24 do
|
for row = 1, self.height do
|
||||||
if self:isRowFull(row) then
|
if self:isRowFull(row) then
|
||||||
for x = 1, self.width do
|
for x = 1, self.width do
|
||||||
self.grid[row][x] = {
|
self.grid[row][x] = {
|
||||||
@ -123,7 +124,7 @@ function Grid:markClearedRows()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Grid:clearClearedRows()
|
function Grid:clearClearedRows()
|
||||||
for row = 1, 24 do
|
for row = 1, self.height do
|
||||||
if self:isRowFull(row) then
|
if self:isRowFull(row) then
|
||||||
for above_row = row, 2, -1 do
|
for above_row = row, 2, -1 do
|
||||||
self.grid[above_row] = self.grid[above_row - 1]
|
self.grid[above_row] = self.grid[above_row - 1]
|
||||||
@ -141,29 +142,29 @@ function Grid:clearClearedRows()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Grid:copyBottomRow()
|
function Grid:copyBottomRow()
|
||||||
for row = 1, 23 do
|
for row = 1, self.height - 1 do
|
||||||
self.grid[row] = self.grid[row+1]
|
self.grid[row] = self.grid[row+1]
|
||||||
self.grid_age[row] = self.grid_age[row+1]
|
self.grid_age[row] = self.grid_age[row+1]
|
||||||
end
|
end
|
||||||
self.grid[24] = {}
|
self.grid[self.height] = {}
|
||||||
self.grid_age[24] = {}
|
self.grid_age[self.height] = {}
|
||||||
for i = 1, self.width do
|
for i = 1, self.width do
|
||||||
self.grid[24][i] = (self.grid[23][i] == empty) and empty or block
|
self.grid[self.height][i] = (self.grid[self.height - 1][i] == empty) and empty or block
|
||||||
self.grid_age[24][i] = 0
|
self.grid_age[self.height][i] = 0
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function Grid:garbageRise(row_vals)
|
function Grid:garbageRise(row_vals)
|
||||||
for row = 1, 23 do
|
for row = 1, self.height - 1 do
|
||||||
self.grid[row] = self.grid[row+1]
|
self.grid[row] = self.grid[row+1]
|
||||||
self.grid_age[row] = self.grid_age[row+1]
|
self.grid_age[row] = self.grid_age[row+1]
|
||||||
end
|
end
|
||||||
self.grid[24] = {}
|
self.grid[self.height] = {}
|
||||||
self.grid_age[24] = {}
|
self.grid_age[self.height] = {}
|
||||||
for i = 1, self.width do
|
for i = 1, self.width do
|
||||||
self.grid[24][i] = (row_vals[i] == "e") and empty or block
|
self.grid[self.height][i] = (row_vals[i] == "e") and empty or block
|
||||||
self.grid_age[24][i] = 0
|
self.grid_age[self.height][i] = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -182,7 +183,7 @@ function Grid:applyPiece(piece)
|
|||||||
for index, offset in pairs(offsets) do
|
for index, offset in pairs(offsets) do
|
||||||
x = piece.position.x + offset.x
|
x = piece.position.x + offset.x
|
||||||
y = piece.position.y + offset.y
|
y = piece.position.y + offset.y
|
||||||
if y + 1 > 0 and y < 24 then
|
if y + 1 > 0 and y < self.height then
|
||||||
self.grid[y+1][x+1] = {
|
self.grid[y+1][x+1] = {
|
||||||
skin = piece.skin,
|
skin = piece.skin,
|
||||||
colour = piece.colour
|
colour = piece.colour
|
||||||
@ -210,7 +211,7 @@ function Grid:applyBigPiece(piece)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Grid:checkForBravo(cleared_row_count)
|
function Grid:checkForBravo(cleared_row_count)
|
||||||
for i = 0, 23 - cleared_row_count do
|
for i = 0, self.height - 1 - cleared_row_count do
|
||||||
for j = 0, self.width - 1 do
|
for j = 0, self.width - 1 do
|
||||||
if self:isOccupied(j, i) then return false end
|
if self:isOccupied(j, i) then return false end
|
||||||
end
|
end
|
||||||
@ -219,9 +220,9 @@ function Grid:checkForBravo(cleared_row_count)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Grid:checkStackHeight()
|
function Grid:checkStackHeight()
|
||||||
for i = 0, 23 do
|
for i = 0, self.height - 1 do
|
||||||
for j = 0, self.width - 1 do
|
for j = 0, self.width - 1 do
|
||||||
if self:isOccupied(j, i) then return 24 - i end
|
if self:isOccupied(j, i) then return self.height - i end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
@ -262,7 +263,7 @@ function Grid:checkSecretGrade()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Grid:hasGemBlocks()
|
function Grid:hasGemBlocks()
|
||||||
for y = 1, 24 do
|
for y = 1, self.height do
|
||||||
for x = 1, self.width do
|
for x = 1, self.width do
|
||||||
if self.grid[y][x].skin == "gem" then
|
if self.grid[y][x].skin == "gem" then
|
||||||
return true
|
return true
|
||||||
@ -274,16 +275,16 @@ end
|
|||||||
|
|
||||||
function Grid:mirror()
|
function Grid:mirror()
|
||||||
local new_grid = {}
|
local new_grid = {}
|
||||||
for y = 1, 24 do
|
for y = 1, self.height do
|
||||||
new_grid[y] = {}
|
new_grid[y] = {}
|
||||||
for x = 1, self.width do
|
for x = 1, self.width do
|
||||||
new_grid[y][x] = empty
|
new_grid[y][x] = empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for y = 1, 24 do
|
for y = 1, self.height do
|
||||||
for x = 1, self.width do
|
for x = 1, self.width do
|
||||||
new_grid[y][x] = self.grid[y][11 - x]
|
new_grid[y][x] = self.grid[y][self.width + 1 - x]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.grid = new_grid
|
self.grid = new_grid
|
||||||
@ -299,7 +300,7 @@ function Grid:applyMap(map)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Grid:update()
|
function Grid:update()
|
||||||
for y = 1, 24 do
|
for y = 1, self.height do
|
||||||
for x = 1, self.width do
|
for x = 1, self.width do
|
||||||
if self.grid[y][x] ~= empty then
|
if self.grid[y][x] ~= empty then
|
||||||
self.grid_age[y][x] = self.grid_age[y][x] + 1
|
self.grid_age[y][x] = self.grid_age[y][x] + 1
|
||||||
@ -309,7 +310,7 @@ function Grid:update()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Grid:draw()
|
function Grid:draw()
|
||||||
for y = 5, 24 do
|
for y = 5, self.height do
|
||||||
for x = 1, self.width do
|
for x = 1, self.width do
|
||||||
if self.grid[y][x] ~= empty then
|
if self.grid[y][x] ~= empty then
|
||||||
if self.grid_age[y][x] < 2 then
|
if self.grid_age[y][x] < 2 then
|
||||||
@ -331,8 +332,8 @@ function Grid:draw()
|
|||||||
if y > 1 and self.grid[y-1][x] == empty or self.grid[y-1][x].colour == "X" then
|
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)
|
love.graphics.line(48.0+x*16, -0.5+y*16, 64.0+x*16, -0.5+y*16)
|
||||||
end
|
end
|
||||||
if y < 24 and self.grid[y+1][x] == empty or
|
if y < self.height and self.grid[y+1][x] == empty or
|
||||||
(y + 1 > 24 or self.grid[y+1][x].colour == "X") then
|
(y + 1 > self.height or self.grid[y+1][x].colour == "X") then
|
||||||
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
||||||
end
|
end
|
||||||
if x > 1 and self.grid[y][x-1] == empty then
|
if x > 1 and self.grid[y][x-1] == empty then
|
||||||
@ -348,7 +349,7 @@ function Grid:draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Grid:drawOutline()
|
function Grid:drawOutline()
|
||||||
for y = 5, 24 do
|
for y = 5, self.height do
|
||||||
for x = 1, self.width do
|
for x = 1, self.width do
|
||||||
if self.grid[y][x].colour == "X" then
|
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.setColor(0.5, 0.5, 0.5, 1 - self.grid_age[y][x] / 15)
|
||||||
@ -360,8 +361,8 @@ function Grid:drawOutline()
|
|||||||
if y > 1 and self.grid[y-1][x] == empty or self.grid[y-1][x].colour == "X" then
|
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)
|
love.graphics.line(48.0+x*16, -0.5+y*16, 64.0+x*16, -0.5+y*16)
|
||||||
end
|
end
|
||||||
if y < 24 and self.grid[y+1][x] == empty or
|
if y < self.height and self.grid[y+1][x] == empty or
|
||||||
(y + 1 > 24 or self.grid[y+1][x].colour == "X") then
|
(y + 1 > self.height or self.grid[y+1][x].colour == "X") then
|
||||||
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
||||||
end
|
end
|
||||||
if x > 1 and self.grid[y][x-1] == empty then
|
if x > 1 and self.grid[y][x-1] == empty then
|
||||||
@ -378,7 +379,7 @@ end
|
|||||||
function Grid:drawInvisible(opacity_function, garbage_opacity_function, lock_flash, brightness)
|
function Grid:drawInvisible(opacity_function, garbage_opacity_function, lock_flash, brightness)
|
||||||
lock_flash = lock_flash == nil and true or lock_flash
|
lock_flash = lock_flash == nil and true or lock_flash
|
||||||
brightness = brightness == nil and 0.5 or brightness
|
brightness = brightness == nil and 0.5 or brightness
|
||||||
for y = 5, 24 do
|
for y = 5, self.height do
|
||||||
for x = 1, self.width do
|
for x = 1, self.width do
|
||||||
if self.grid[y][x] ~= empty then
|
if self.grid[y][x] ~= empty then
|
||||||
if self.grid[y][x].colour == "X" then
|
if self.grid[y][x].colour == "X" then
|
||||||
@ -397,8 +398,8 @@ function Grid:drawInvisible(opacity_function, garbage_opacity_function, lock_fla
|
|||||||
if y > 1 and self.grid[y-1][x] == empty or self.grid[y-1][x].colour == "X" then
|
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)
|
love.graphics.line(48.0+x*16, -0.5+y*16, 64.0+x*16, -0.5+y*16)
|
||||||
end
|
end
|
||||||
if y < 24 and self.grid[y+1][x] == empty or
|
if y < self.height and self.grid[y+1][x] == empty or
|
||||||
(y + 1 > 24 or self.grid[y+1][x].colour == "X") then
|
(y + 1 > self.height or self.grid[y+1][x].colour == "X") then
|
||||||
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
||||||
end
|
end
|
||||||
if x > 1 and self.grid[y][x-1] == empty then
|
if x > 1 and self.grid[y][x-1] == empty then
|
||||||
@ -423,7 +424,7 @@ function Grid:drawCustom(colour_function, gamestate)
|
|||||||
|
|
||||||
gamestate: the gamemode instance itself to pass in colour_function
|
gamestate: the gamemode instance itself to pass in colour_function
|
||||||
]]
|
]]
|
||||||
for y = 5, 24 do
|
for y = 5, self.height do
|
||||||
for x = 1, self.width do
|
for x = 1, self.width do
|
||||||
local block = self.grid[y][x]
|
local block = self.grid[y][x]
|
||||||
if block ~= empty then
|
if block ~= empty then
|
||||||
@ -439,8 +440,8 @@ function Grid:drawCustom(colour_function, gamestate)
|
|||||||
if y > 1 and self.grid[y-1][x] == empty or self.grid[y-1][x].colour == "X" then
|
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)
|
love.graphics.line(48.0+x*16, -0.5+y*16, 64.0+x*16, -0.5+y*16)
|
||||||
end
|
end
|
||||||
if y < 24 and self.grid[y+1][x] == empty or
|
if y < self.height and self.grid[y+1][x] == empty or
|
||||||
(y + 1 > 24 or self.grid[y+1][x].colour == "X") then
|
(y + 1 > self.height or self.grid[y+1][x].colour == "X") then
|
||||||
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
love.graphics.line(48.0+x*16, 16.5+y*16, 64.0+x*16, 16.5+y*16)
|
||||||
end
|
end
|
||||||
if x > 1 and self.grid[y][x-1] == empty then
|
if x > 1 and self.grid[y][x-1] == empty then
|
||||||
|
@ -13,7 +13,7 @@ local GameMode = Object:extend()
|
|||||||
GameMode.rollOpacityFunction = function(age) return 0 end
|
GameMode.rollOpacityFunction = function(age) return 0 end
|
||||||
|
|
||||||
function GameMode:new(secret_inputs)
|
function GameMode:new(secret_inputs)
|
||||||
self.grid = Grid(10)
|
self.grid = Grid(10, 24)
|
||||||
self.randomizer = Randomizer()
|
self.randomizer = Randomizer()
|
||||||
self.piece = nil
|
self.piece = nil
|
||||||
self.ready_frames = 100
|
self.ready_frames = 100
|
||||||
|
Loading…
Reference in New Issue
Block a user