Init arbitrary widths

This commit is contained in:
Ishaan Bhardwaj 2021-01-10 22:40:13 -05:00
parent 9d44d1e771
commit 0f09d47e60
4 changed files with 51 additions and 26 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"
@ -142,7 +143,7 @@ function Grid:copyBottomRow()
end end
self.grid[24] = {empty, empty, empty, empty, empty, empty, empty, empty, empty, empty} self.grid[24] = {empty, empty, empty, empty, empty, empty, empty, empty, empty, empty}
self.grid_age[24] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} self.grid_age[24] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
for col = 1, 10 do for col = 1, self.width do
self.grid[24][col] = (self.grid[23][col] == empty) and empty or block self.grid[24][col] = (self.grid[23][col] == empty) and empty or block
end end
return true return true
@ -155,11 +156,12 @@ function Grid:garbageRise(row_vals)
end end
self.grid[24] = {empty, empty, empty, empty, empty, empty, empty, empty, empty, empty} self.grid[24] = {empty, empty, empty, empty, empty, empty, empty, empty, empty, empty}
self.grid_age[24] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} self.grid_age[24] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
for col = 1, 10 do for col = 1, self.width do
self.grid[24][col] = (row_vals[col] == "e") and empty or block self.grid[24][col] = (row_vals[col] == "e") and empty or block
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 +174,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 +227,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 +236,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 +279,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 +292,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 +316,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 +326,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 +354,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 +365,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 +383,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 +395,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 +420,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 +440,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 +462,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