Merge pull request #13 from SashLilac/arbitrary-widths

Init arbitrary widths functionality.
This commit is contained in:
Ishaan Bhardwaj 2021-01-10 22:59:05 -05:00 committed by GitHub
commit 08da67c434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 38 deletions

View File

@ -50,9 +50,28 @@ function GameScene:render()
) )
-- game frame -- game frame
love.graphics.draw(misc_graphics["frame"], 48, 64) -- love.graphics.draw(misc_graphics["frame"], 48, 64)
love.graphics.setColor(0, 0, 0, 200) love.graphics.setColor(0, 0, 0, 200)
love.graphics.rectangle("fill", 64, 80, 160, 320) love.graphics.rectangle("fill", 64, 80, 16 * self.game.grid.width, 320)
love.graphics.setColor(174/255, 83/255, 76/255, 1)
love.graphics.setLineWidth(8)
love.graphics.line(
60,76,
68+16*self.game.grid.width,76,
68+16*self.game.grid.width,404,
60,404,
60,76
)
love.graphics.setColor(203/255, 137/255, 111/255, 1)
love.graphics.setLineWidth(4)
love.graphics.line(
60,76,
68+16*self.game.grid.width,76,
68+16*self.game.grid.width,404,
60,404,
60,76
)
self.game:drawGrid() self.game:drawGrid()
self.game:drawPiece() self.game:drawPiece()

View File

@ -6,13 +6,14 @@ 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() function Grid:new(width)
self.grid = {} self.grid = {}
self.grid_age = {} self.grid_age = {}
self.width = width
for y = 1, 24 do for y = 1, 24 do
self.grid[y] = {} self.grid[y] = {}
self.grid_age[y] = {} self.grid_age[y] = {}
for x = 1, 10 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
end end
@ -21,7 +22,7 @@ end
function Grid:clear() function Grid:clear()
for y = 1, 24 do for y = 1, 24 do
for x = 1, 10 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
end end
@ -29,7 +30,7 @@ function Grid:clear()
end end
function Grid:getCell(x, y) function Grid:getCell(x, y)
if x < 1 or x > 10 or y > 24 then return oob if x < 1 or x > self.width or y > 24 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
@ -109,7 +110,7 @@ end
function Grid:markClearedRows() function Grid:markClearedRows()
for row = 1, 24 do for row = 1, 24 do
if self:isRowFull(row) then if self:isRowFull(row) then
for x = 1, 10 do for x = 1, self.width do
self.grid[row][x] = { self.grid[row][x] = {
skin = self.grid[row][x].skin, skin = self.grid[row][x].skin,
colour = "X" colour = "X"
@ -128,8 +129,12 @@ function Grid:clearClearedRows()
self.grid[above_row] = self.grid[above_row - 1] self.grid[above_row] = self.grid[above_row - 1]
self.grid_age[above_row] = self.grid_age[above_row - 1] self.grid_age[above_row] = self.grid_age[above_row - 1]
end end
self.grid[1] = {empty, empty, empty, empty, empty, empty, empty, empty, empty, empty} self.grid[1] = {}
self.grid_age[1] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} self.grid_age[1] = {}
for i = 1, self.width do
self.grid[1][i] = empty
self.grid_age[1][i] = 0
end
end end
end end
return true return true
@ -140,10 +145,11 @@ function Grid:copyBottomRow()
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] = {empty, empty, empty, empty, empty, empty, empty, empty, empty, empty} self.grid[24] = {}
self.grid_age[24] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} self.grid_age[24] = {}
for col = 1, 10 do for i = 1, self.width do
self.grid[24][col] = (self.grid[23][col] == empty) and empty or block self.grid[24][i] = (self.grid[23][i] == empty) and empty or block
self.grid_age[24][i] = 0
end end
return true return true
end end
@ -153,13 +159,15 @@ function Grid:garbageRise(row_vals)
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] = {empty, empty, empty, empty, empty, empty, empty, empty, empty, empty} self.grid[24] = {}
self.grid_age[24] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} self.grid_age[24] = {}
for col = 1, 10 do for i = 1, self.width do
self.grid[24][col] = (row_vals[col] == "e") and empty or block self.grid[24][i] = (row_vals[i] == "e") and empty or block
self.grid_age[24][i] = 0
end end
end end
-- may be outdated soon
function Grid:applyFourWide() function Grid:applyFourWide()
for row = 1, 24 do for row = 1, 24 do
local x = self.grid[row] local x = self.grid[row]
@ -172,16 +180,17 @@ function Grid:applyFourWide()
end end
end end
-- may be outdated soon
function Grid:applyCeiling(lines) function Grid:applyCeiling(lines)
for row = 1, lines do for row = 1, lines do
for col = 1, 9 do for col = 1, self.width - 1 do
self.grid[row][col] = block self.grid[row][col] = block
end end
end end
end end
function Grid:clearSpecificRow(row) function Grid:clearSpecificRow(row)
for col = 1, 10 do for col = 1, self.width do
self.grid[row][col] = empty self.grid[row][col] = empty
end end
end end
@ -224,7 +233,7 @@ end
function Grid:checkForBravo(cleared_row_count) function Grid:checkForBravo(cleared_row_count)
for i = 0, 23 - cleared_row_count do for i = 0, 23 - cleared_row_count do
for j = 0, 9 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
end end
@ -233,7 +242,7 @@ end
function Grid:checkStackHeight() function Grid:checkStackHeight()
for i = 0, 23 do for i = 0, 23 do
for j = 0, 9 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 24 - i end
end end
end end
@ -276,7 +285,7 @@ end
function Grid:hasGemBlocks() function Grid:hasGemBlocks()
for y = 1, 24 do for y = 1, 24 do
for x = 1, 10 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
end end
@ -289,13 +298,13 @@ function Grid:mirror()
local new_grid = {} local new_grid = {}
for y = 1, 24 do for y = 1, 24 do
new_grid[y] = {} new_grid[y] = {}
for x = 1, 10 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, 24 do
for x = 1, 10 do for x = 1, self.width do
new_grid[y][x] = self.grid[y][11 - x] new_grid[y][x] = self.grid[y][11 - x]
end end
end end
@ -313,7 +322,7 @@ end
function Grid:update() function Grid:update()
for y = 1, 24 do for y = 1, 24 do
for x = 1, 10 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
end end
@ -323,7 +332,7 @@ end
function Grid:draw() function Grid:draw()
for y = 5, 24 do for y = 5, 24 do
for x = 1, 10 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
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
@ -351,7 +360,7 @@ function Grid:draw()
if x > 1 and self.grid[y][x-1] == empty then 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) love.graphics.line(47.5+x*16, -0.0+y*16, 47.5+x*16, 16.0+y*16)
end end
if x < 10 and self.grid[y][x+1] == empty then if x < self.width and self.grid[y][x+1] == empty then
love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16) love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16)
end end
end end
@ -362,7 +371,7 @@ end
function Grid:drawOutline() function Grid:drawOutline()
for y = 5, 24 do for y = 5, 24 do
for x = 1, 10 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)
love.graphics.draw(blocks[self.grid[y][x].skin][self.grid[y][x].colour], 48+x*16, y*16) love.graphics.draw(blocks[self.grid[y][x].skin][self.grid[y][x].colour], 48+x*16, y*16)
@ -380,7 +389,7 @@ function Grid:drawOutline()
if x > 1 and self.grid[y][x-1] == empty then 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) love.graphics.line(47.5+x*16, -0.0+y*16, 47.5+x*16, 16.0+y*16)
end end
if x < 10 and self.grid[y][x+1] == empty then if x < self.width and self.grid[y][x+1] == empty then
love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16) love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16)
end end
end end
@ -392,7 +401,7 @@ function Grid:drawInvisible(opacity_function, garbage_opacity_function, lock_fla
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, 24 do
for x = 1, 10 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
opacity = 1 - self.grid_age[y][x] / 15 opacity = 1 - self.grid_age[y][x] / 15
@ -417,7 +426,7 @@ function Grid:drawInvisible(opacity_function, garbage_opacity_function, lock_fla
if x > 1 and self.grid[y][x-1] == empty then 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) love.graphics.line(47.5+x*16, -0.0+y*16, 47.5+x*16, 16.0+y*16)
end end
if x < 10 and self.grid[y][x+1] == empty then if x < self.width and self.grid[y][x+1] == empty then
love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16) love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16)
end end
end end
@ -437,7 +446,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, 24 do
for x = 1, 10 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
local R, G, B, A, outline = colour_function(gamestate, block, x, y, self.grid_age[y][x]) local R, G, B, A, outline = colour_function(gamestate, block, x, y, self.grid_age[y][x])
@ -459,7 +468,7 @@ function Grid:drawCustom(colour_function, gamestate)
if x > 1 and self.grid[y][x-1] == empty then 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) love.graphics.line(47.5+x*16, -0.0+y*16, 47.5+x*16, 16.0+y*16)
end end
if x < 10 and self.grid[y][x+1] == empty then if x < self.width and self.grid[y][x+1] == empty then
love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16) love.graphics.line(64.5+x*16, -0.0+y*16, 64.5+x*16, 16.0+y*16)
end end
end end

View File

@ -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() self.grid = Grid(10)
self.randomizer = Randomizer() self.randomizer = Randomizer()
self.piece = nil self.piece = nil
self.ready_frames = 100 self.ready_frames = 100

View File

@ -2,6 +2,7 @@ require 'funcs'
local GameMode = require 'tetris.modes.gamemode' local GameMode = require 'tetris.modes.gamemode'
local Piece = require 'tetris.components.piece' local Piece = require 'tetris.components.piece'
local Grid = require 'tetris.components.grid'
local History4RollsRandomizer = require 'tetris.randomizers.history_4rolls' local History4RollsRandomizer = require 'tetris.randomizers.history_4rolls'
@ -16,6 +17,8 @@ MarathonA1Game.tagline = "Can you score enough points to reach the title of Gran
function MarathonA1Game:new() function MarathonA1Game:new()
MarathonA1Game.super:new() MarathonA1Game.super:new()
self.grid = Grid(8)
self.roll_frames = 0 self.roll_frames = 0
self.combo = 1 self.combo = 1
self.bravos = 0 self.bravos = 0