mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-12-22 16:29:02 -06:00
Framework for custom line clear animations added
Colored fadeout is the default
This commit is contained in:
parent
77f24f5ee5
commit
a047e51681
@ -83,6 +83,7 @@ function GameScene:render()
|
||||
end
|
||||
|
||||
self.game:drawGrid()
|
||||
if self.game.lcd > 0 then self.game:drawLineClearAnimation() end
|
||||
self.game:drawPiece()
|
||||
self.game:drawNextQueue(self.ruleset)
|
||||
self.game:drawScoringInfo()
|
||||
|
@ -111,18 +111,24 @@ function Grid:getClearedRowCount()
|
||||
end
|
||||
|
||||
function Grid:markClearedRows()
|
||||
local block_table = {}
|
||||
for row = 1, self.height do
|
||||
if self:isRowFull(row) then
|
||||
block_table[row] = {}
|
||||
for x = 1, self.width do
|
||||
block_table[row][x] = {
|
||||
skin = self.grid[row][x].skin,
|
||||
colour = self.grid[row][x].colour,
|
||||
}
|
||||
self.grid[row][x] = {
|
||||
skin = self.grid[row][x].skin,
|
||||
colour = "X"
|
||||
}
|
||||
self.grid_age[row][x] = 0
|
||||
--self.grid_age[row][x] = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
return block_table
|
||||
end
|
||||
|
||||
function Grid:clearClearedRows()
|
||||
@ -396,7 +402,8 @@ function Grid:draw()
|
||||
if self.grid[y][x].skin == "bone" then
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
elseif 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, 0, 0, 0)
|
||||
--love.graphics.setColor(0.5, 0.5, 0.5, 1 - self.grid_age[y][x] / 15)
|
||||
else
|
||||
love.graphics.setColor(0.5, 0.5, 0.5, 1)
|
||||
end
|
||||
@ -427,10 +434,12 @@ end
|
||||
function Grid:drawOutline()
|
||||
for y = 5, self.height do
|
||||
for x = 1, self.width do
|
||||
--[[
|
||||
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
|
||||
]]
|
||||
if self.grid[y][x] ~= empty and self.grid[y][x].colour ~= "X" then
|
||||
love.graphics.setColor(0.8, 0.8, 0.8, 1)
|
||||
love.graphics.setLineWidth(1)
|
||||
@ -459,7 +468,8 @@ function Grid:drawInvisible(opacity_function, garbage_opacity_function, lock_fla
|
||||
for x = 1, self.width do
|
||||
if self.grid[y][x] ~= empty then
|
||||
if self.grid[y][x].colour == "X" then
|
||||
opacity = 1 - self.grid_age[y][x] / 15
|
||||
opacity = 0
|
||||
--opacity = 1 - self.grid_age[y][x] / 15
|
||||
elseif garbage_opacity_function and self.grid[y][x].colour == "A" then
|
||||
opacity = garbage_opacity_function(self.grid_age[y][x])
|
||||
else
|
||||
@ -506,7 +516,8 @@ function Grid:drawCustom(colour_function, gamestate)
|
||||
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
|
||||
A = 1 - self.grid_age[y][x] / 15
|
||||
A = 0
|
||||
--A = 1 - self.grid_age[y][x] / 15
|
||||
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)
|
||||
|
@ -63,6 +63,7 @@ function GameMode:new(secret_inputs)
|
||||
self.hard_drop_locked = false
|
||||
self.lock_on_soft_drop = false
|
||||
self.lock_on_hard_drop = false
|
||||
self.cleared_block_table = {}
|
||||
self.used_randomizer = nil
|
||||
self.hold_queue = nil
|
||||
self.held = false
|
||||
@ -244,7 +245,7 @@ function GameMode:update(inputs, ruleset)
|
||||
self:onPieceLock(self.piece, cleared_row_count)
|
||||
self:updateScore(self.level, self.drop_bonus, cleared_row_count)
|
||||
|
||||
self.grid:markClearedRows()
|
||||
self.cleared_block_table = self.grid:markClearedRows()
|
||||
self.piece = nil
|
||||
if self.enable_hold then
|
||||
self.held = false
|
||||
@ -536,6 +537,67 @@ function GameMode:getHighScoreData()
|
||||
}
|
||||
end
|
||||
|
||||
function GameMode:drawLineClearAnimation()
|
||||
-- animation function
|
||||
-- params: block x, y, skin, colour
|
||||
-- returns: table with RGBA, skin, colour, x, y
|
||||
|
||||
-- Fadeout (default)
|
||||
-- [[
|
||||
function animation(x, y, skin, colour)
|
||||
return {
|
||||
1, 1, 1,
|
||||
-0.25 + 1.25 * (self.lcd / self:getLineClearDelay()),
|
||||
skin, colour,
|
||||
48 + x * 16, y * 16
|
||||
}
|
||||
end
|
||||
--]]
|
||||
|
||||
-- Flash
|
||||
--[[
|
||||
function animation(x, y, skin, colour)
|
||||
return {
|
||||
1, 1, 1,
|
||||
self.lcd % 6 < 3 and 1 or 0.25,
|
||||
skin, colour,
|
||||
48 + x * 16, y * 16
|
||||
}
|
||||
end
|
||||
--]]
|
||||
|
||||
-- TGM1 pop-out
|
||||
--[[
|
||||
function animation(x, y, skin, colour)
|
||||
local p = 0.48
|
||||
local l = (
|
||||
(self:getLineClearDelay() - self.lcd) / self:getLineClearDelay()
|
||||
)
|
||||
local dx = l * (x - (1 + self.grid.width) / 2)
|
||||
local dy = l * (y - (1 + self.grid.height) / 2)
|
||||
return {
|
||||
1, 1, 1, 1, skin, colour,
|
||||
48 + (x + dx) * 16,
|
||||
(y + dy) * 16 + (464 / (p - 1)) * l * (p - l)
|
||||
}
|
||||
end
|
||||
--]]
|
||||
|
||||
for y, row in pairs(self.cleared_block_table) do
|
||||
for x, block in pairs(row) do
|
||||
local animation_table = animation(x, y, block.skin, block.colour)
|
||||
love.graphics.setColor(
|
||||
animation_table[1], animation_table[2],
|
||||
animation_table[3], animation_table[4]
|
||||
)
|
||||
love.graphics.draw(
|
||||
blocks[animation_table[5]][animation_table[6]],
|
||||
animation_table[7], animation_table[8]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function GameMode:drawPiece()
|
||||
if self.piece ~= nil then
|
||||
self.piece:draw(
|
||||
|
Loading…
Reference in New Issue
Block a user