2019-05-22 22:57:34 -05:00
|
|
|
local Object = require 'libs.classic'
|
|
|
|
require 'funcs'
|
|
|
|
|
2020-10-27 06:17:00 -05:00
|
|
|
local playedReadySE = false
|
|
|
|
local playedGoSE = false
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
local Grid = require 'tetris.components.grid'
|
2021-01-07 17:42:49 -06:00
|
|
|
local Randomizer = require 'tetris.randomizers.bag7'
|
2021-01-07 15:53:46 -06:00
|
|
|
local BagRandomizer = require 'tetris.randomizers.bag'
|
2019-05-22 22:57:34 -05:00
|
|
|
|
|
|
|
local GameMode = Object:extend()
|
|
|
|
|
2021-02-05 20:44:29 -06:00
|
|
|
GameMode.name = ""
|
|
|
|
GameMode.hash = ""
|
|
|
|
GameMode.tagline = ""
|
2019-05-22 22:57:34 -05:00
|
|
|
GameMode.rollOpacityFunction = function(age) return 0 end
|
|
|
|
|
2021-08-21 11:08:03 -05:00
|
|
|
function GameMode:new(config, secret_inputs)
|
2021-01-11 14:46:43 -06:00
|
|
|
self.grid = Grid(10, 24)
|
2019-05-22 22:57:34 -05:00
|
|
|
self.randomizer = Randomizer()
|
|
|
|
self.piece = nil
|
|
|
|
self.ready_frames = 100
|
|
|
|
self.frames = 0
|
|
|
|
self.game_over_frames = 0
|
|
|
|
self.score = 0
|
|
|
|
self.level = 0
|
|
|
|
self.lines = 0
|
2021-01-14 16:52:23 -06:00
|
|
|
self.squares = 0
|
2019-05-22 22:57:34 -05:00
|
|
|
self.drop_bonus = 0
|
|
|
|
self.are = 0
|
|
|
|
self.lcd = 0
|
|
|
|
self.das = { direction = "none", frames = -1 }
|
|
|
|
self.move = "none"
|
|
|
|
self.prev_inputs = {}
|
|
|
|
self.next_queue = {}
|
|
|
|
self.game_over = false
|
|
|
|
self.clear = false
|
|
|
|
self.completed = false
|
|
|
|
-- configurable parameters
|
|
|
|
self.lock_drop = false
|
|
|
|
self.lock_hard_drop = false
|
|
|
|
self.instant_hard_drop = false
|
|
|
|
self.instant_soft_drop = true
|
|
|
|
self.enable_hold = false
|
|
|
|
self.enable_hard_drop = true
|
|
|
|
self.next_queue_length = 1
|
2019-06-16 21:24:06 -05:00
|
|
|
self.additive_gravity = true
|
2021-02-11 14:46:56 -06:00
|
|
|
self.classic_lock = false
|
2019-05-22 22:57:34 -05:00
|
|
|
self.draw_section_times = false
|
|
|
|
self.draw_secondary_section_times = false
|
2019-06-16 21:16:09 -05:00
|
|
|
self.big_mode = false
|
2020-11-16 11:48:28 -06:00
|
|
|
self.irs = true
|
|
|
|
self.ihs = true
|
2021-01-14 16:52:23 -06:00
|
|
|
self.square_mode = false
|
2021-01-14 18:22:53 -06:00
|
|
|
self.immobile_spin_bonus = false
|
2020-11-06 19:49:44 -06:00
|
|
|
self.rpc_details = "In game"
|
2020-12-04 14:16:13 -06:00
|
|
|
self.SGnames = {
|
|
|
|
"9", "8", "7", "6", "5", "4", "3", "2", "1",
|
|
|
|
"S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9",
|
|
|
|
"GM"
|
|
|
|
}
|
2019-05-22 22:57:34 -05:00
|
|
|
-- variables related to configurable parameters
|
|
|
|
self.drop_locked = false
|
|
|
|
self.hard_drop_locked = false
|
2020-11-06 19:49:44 -06:00
|
|
|
self.lock_on_soft_drop = false
|
|
|
|
self.lock_on_hard_drop = false
|
2021-02-10 17:35:51 -06:00
|
|
|
self.cleared_block_table = {}
|
2021-03-03 10:54:43 -06:00
|
|
|
self.last_lcd = 0
|
2021-01-07 15:53:46 -06:00
|
|
|
self.used_randomizer = nil
|
2019-05-22 22:57:34 -05:00
|
|
|
self.hold_queue = nil
|
|
|
|
self.held = false
|
|
|
|
self.section_start_time = 0
|
|
|
|
self.section_times = { [0] = 0 }
|
|
|
|
self.secondary_section_times = { [0] = 0 }
|
2021-08-21 11:08:03 -05:00
|
|
|
|
|
|
|
self.config = config
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:getARR() return 1 end
|
|
|
|
function GameMode:getDropSpeed() return 1 end
|
|
|
|
function GameMode:getARE() return 25 end
|
|
|
|
function GameMode:getLineARE() return 25 end
|
|
|
|
function GameMode:getLockDelay() return 30 end
|
|
|
|
function GameMode:getLineClearDelay() return 40 end
|
|
|
|
function GameMode:getDasLimit() return 15 end
|
2021-01-24 13:55:35 -06:00
|
|
|
function GameMode:getDasCutDelay() return 0 end
|
2021-02-01 13:50:31 -06:00
|
|
|
function GameMode:getGravity() return 1/64 end
|
2019-05-22 22:57:34 -05:00
|
|
|
|
|
|
|
function GameMode:getNextPiece(ruleset)
|
2021-07-11 13:04:22 -05:00
|
|
|
local shape = self.used_randomizer:nextPiece()
|
2019-05-22 22:57:34 -05:00
|
|
|
return {
|
2021-01-06 21:53:44 -06:00
|
|
|
skin = self:getSkin(),
|
2021-07-11 13:04:22 -05:00
|
|
|
shape = shape,
|
|
|
|
orientation = ruleset:getDefaultOrientation(shape),
|
2019-05-22 22:57:34 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-01-06 21:53:44 -06:00
|
|
|
function GameMode:getSkin()
|
|
|
|
return "2tie"
|
|
|
|
end
|
|
|
|
|
2021-02-19 10:01:18 -06:00
|
|
|
function GameMode:initialize(ruleset)
|
2019-05-22 22:57:34 -05:00
|
|
|
-- generate next queue
|
2021-01-07 15:53:46 -06:00
|
|
|
self.used_randomizer = (
|
|
|
|
ruleset.pieces == self.randomizer.possible_pieces and
|
|
|
|
self.randomizer or
|
|
|
|
(
|
|
|
|
ruleset.pieces == 7 and
|
|
|
|
Randomizer() or
|
|
|
|
BagRandomizer(ruleset.pieces)
|
|
|
|
)
|
|
|
|
)
|
2021-02-19 10:01:18 -06:00
|
|
|
self.ruleset = ruleset
|
2021-02-03 10:42:21 -06:00
|
|
|
for i = 1, math.max(self.next_queue_length, 1) do
|
2019-05-22 22:57:34 -05:00
|
|
|
table.insert(self.next_queue, self:getNextPiece(ruleset))
|
|
|
|
end
|
2020-11-06 19:49:44 -06:00
|
|
|
self.lock_on_soft_drop = ({ruleset.softdrop_lock, self.instant_soft_drop, false, true })[config.gamesettings.manlock]
|
|
|
|
self.lock_on_hard_drop = ({ruleset.harddrop_lock, self.instant_hard_drop, true, false})[config.gamesettings.manlock]
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:update(inputs, ruleset)
|
2021-01-14 18:34:02 -06:00
|
|
|
if self.game_over or self.completed then
|
2021-01-14 20:51:47 -06:00
|
|
|
self.game_over_frames = self.game_over_frames + 1
|
2019-05-22 22:57:34 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-12-14 21:43:50 -06:00
|
|
|
if config.gamesettings.diagonal_input == 2 then
|
|
|
|
if inputs["left"] or inputs["right"] then
|
|
|
|
inputs["up"] = false
|
|
|
|
inputs["down"] = false
|
|
|
|
elseif inputs["up"] or inputs["down"] then
|
|
|
|
inputs["left"] = false
|
|
|
|
inputs["right"] = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
-- advance one frame
|
2020-11-30 11:34:21 -06:00
|
|
|
if self:advanceOneFrame(inputs, ruleset) == false then return end
|
2019-05-22 22:57:34 -05:00
|
|
|
|
2021-01-14 18:27:20 -06:00
|
|
|
self:chargeDAS(inputs, self:getDasLimit(), self:getARR())
|
2019-05-22 22:57:34 -05:00
|
|
|
|
2020-11-29 10:11:47 -06:00
|
|
|
-- set attempt flags
|
2021-02-21 09:41:05 -06:00
|
|
|
if inputs["left"] or inputs["right"] then self:onAttemptPieceMove(self.piece, self.grid) end
|
|
|
|
if (
|
2020-11-29 10:11:47 -06:00
|
|
|
inputs["rotate_left"] or inputs["rotate_right"] or
|
|
|
|
inputs["rotate_left2"] or inputs["rotate_right2"] or
|
|
|
|
inputs["rotate_180"]
|
2021-02-21 09:41:05 -06:00
|
|
|
) then
|
2021-02-16 14:27:57 -06:00
|
|
|
self:onAttemptPieceRotate(self.piece, self.grid)
|
2020-11-29 10:11:47 -06:00
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.piece == nil then
|
|
|
|
self:processDelays(inputs, ruleset)
|
|
|
|
else
|
|
|
|
-- perform active frame actions such as fading out the next queue
|
|
|
|
self:whilePieceActive()
|
|
|
|
local gravity = self:getGravity()
|
|
|
|
|
2020-11-16 11:48:28 -06:00
|
|
|
if self.enable_hold and inputs["hold"] == true and self.held == false and self.prev_inputs["hold"] == false then
|
2019-05-22 22:57:34 -05:00
|
|
|
self:hold(inputs, ruleset)
|
|
|
|
self.prev_inputs = inputs
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2021-02-11 21:11:35 -06:00
|
|
|
if (self.lock_drop or (
|
|
|
|
not ruleset.are or self:getARE() == 0
|
|
|
|
)) and inputs["down"] ~= true then
|
2019-05-22 22:57:34 -05:00
|
|
|
self.drop_locked = false
|
|
|
|
end
|
|
|
|
|
2021-02-11 21:11:35 -06:00
|
|
|
if (self.lock_hard_drop or (
|
|
|
|
not ruleset.are or self:getARE() == 0
|
|
|
|
)) and inputs["up"] ~= true then
|
2019-05-22 22:57:34 -05:00
|
|
|
self.hard_drop_locked = false
|
|
|
|
end
|
|
|
|
|
2021-01-24 13:55:35 -06:00
|
|
|
-- diff vars to use in checks
|
2019-05-28 23:52:54 -05:00
|
|
|
local piece_y = self.piece.position.y
|
2021-02-16 14:27:57 -06:00
|
|
|
local piece_x = self.piece.position.x
|
2021-01-24 13:55:35 -06:00
|
|
|
local piece_rot = self.piece.rotation
|
2019-05-28 23:52:54 -05:00
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
ruleset:processPiece(
|
|
|
|
inputs, self.piece, self.grid, self:getGravity(), self.prev_inputs,
|
2021-07-11 13:04:22 -05:00
|
|
|
(
|
|
|
|
inputs.up and self.lock_on_hard_drop and not self.hard_drop_locked
|
|
|
|
) and "none" or self.move,
|
|
|
|
self:getLockDelay(), self:getDropSpeed(),
|
2019-06-16 21:24:06 -05:00
|
|
|
self.drop_locked, self.hard_drop_locked,
|
2021-02-11 14:46:56 -06:00
|
|
|
self.enable_hard_drop, self.additive_gravity, self.classic_lock
|
2019-05-22 22:57:34 -05:00
|
|
|
)
|
|
|
|
|
2019-05-28 23:52:54 -05:00
|
|
|
local piece_dy = self.piece.position.y - piece_y
|
2021-02-16 14:27:57 -06:00
|
|
|
local piece_dx = self.piece.position.x - piece_x
|
2021-01-24 13:55:35 -06:00
|
|
|
local piece_drot = self.piece.rotation - piece_rot
|
|
|
|
|
|
|
|
-- das cut
|
|
|
|
if (
|
|
|
|
(piece_dy ~= 0 and (inputs.up or inputs.down)) or
|
|
|
|
(piece_drot ~= 0 and (
|
|
|
|
inputs.rotate_left or inputs.rotate_right or
|
|
|
|
inputs.rotate_left2 or inputs.rotate_right2 or
|
|
|
|
inputs.rotate_180
|
|
|
|
))
|
|
|
|
) then
|
2021-02-16 14:27:57 -06:00
|
|
|
self:dasCut()
|
2021-01-24 13:55:35 -06:00
|
|
|
end
|
2019-05-28 23:52:54 -05:00
|
|
|
|
2021-02-21 09:48:15 -06:00
|
|
|
if (piece_dx ~= 0) then
|
|
|
|
self.piece.last_rotated = false
|
|
|
|
self:onPieceMove(self.piece, self.grid, piece_dx)
|
|
|
|
end
|
|
|
|
if (piece_dy ~= 0) then
|
|
|
|
self.piece.last_rotated = false
|
|
|
|
self:onPieceDrop(self.piece, self.grid, piece_dy)
|
|
|
|
end
|
2021-05-22 13:41:51 -05:00
|
|
|
if (piece_drot ~= 0) then
|
|
|
|
self.piece.last_rotated = true
|
|
|
|
self:onPieceRotate(self.piece, self.grid, piece_drot)
|
|
|
|
end
|
2021-02-16 14:27:57 -06:00
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
if inputs["up"] == true and
|
|
|
|
self.piece:isDropBlocked(self.grid) and
|
2019-05-28 23:52:54 -05:00
|
|
|
not self.hard_drop_locked then
|
2021-03-10 12:30:29 -06:00
|
|
|
self:onHardDrop(piece_dy)
|
2020-10-10 18:42:56 -05:00
|
|
|
if self.lock_on_hard_drop then
|
2020-12-28 22:32:41 -06:00
|
|
|
self.piece_hard_dropped = true
|
2019-05-28 23:52:54 -05:00
|
|
|
self.piece.locked = true
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
2019-05-28 23:52:54 -05:00
|
|
|
if inputs["down"] == true then
|
2021-03-10 12:30:29 -06:00
|
|
|
if not (
|
|
|
|
self.piece:isDropBlocked(self.grid) and
|
|
|
|
piece_drot ~= 0
|
|
|
|
) then
|
|
|
|
self:onSoftDrop(piece_dy)
|
|
|
|
end
|
2019-05-28 23:52:54 -05:00
|
|
|
if self.piece:isDropBlocked(self.grid) and
|
|
|
|
not self.drop_locked and
|
2020-10-10 18:42:56 -05:00
|
|
|
self.lock_on_soft_drop
|
2019-05-28 23:52:54 -05:00
|
|
|
then
|
|
|
|
self.piece.locked = true
|
2021-06-06 10:38:47 -05:00
|
|
|
self.piece_soft_locked = true
|
2019-05-28 23:52:54 -05:00
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if self.piece.locked == true then
|
2021-02-21 09:41:05 -06:00
|
|
|
-- spin detection, immobile only for now
|
2021-05-22 13:41:51 -05:00
|
|
|
if self.immobile_spin_bonus and
|
|
|
|
self.piece.last_rotated and (
|
2021-02-21 09:41:05 -06:00
|
|
|
self.piece:isDropBlocked(self.grid) and
|
|
|
|
self.piece:isMoveBlocked(self.grid, { x=-1, y=0 }) and
|
|
|
|
self.piece:isMoveBlocked(self.grid, { x=1, y=0 }) and
|
|
|
|
self.piece:isMoveBlocked(self.grid, { x=0, y=-1 })
|
|
|
|
) then
|
|
|
|
self.piece.spin = true
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
self.grid:applyPiece(self.piece)
|
2021-02-21 09:41:05 -06:00
|
|
|
|
|
|
|
-- mark squares (can be overridden)
|
2021-01-14 16:52:23 -06:00
|
|
|
if self.square_mode then
|
|
|
|
self.squares = self.squares + self.grid:markSquares()
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
local cleared_row_count = self.grid:getClearedRowCount()
|
2019-06-03 22:12:48 -05:00
|
|
|
self:onPieceLock(self.piece, cleared_row_count)
|
2019-05-22 22:57:34 -05:00
|
|
|
self:updateScore(self.level, self.drop_bonus, cleared_row_count)
|
|
|
|
|
2021-02-10 17:35:51 -06:00
|
|
|
self.cleared_block_table = self.grid:markClearedRows()
|
2019-06-03 22:12:48 -05:00
|
|
|
self.piece = nil
|
|
|
|
if self.enable_hold then
|
|
|
|
self.held = false
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
if cleared_row_count > 0 then
|
2020-10-26 08:21:49 -05:00
|
|
|
playSE("erase")
|
2019-05-22 22:57:34 -05:00
|
|
|
self.lcd = self:getLineClearDelay()
|
2021-03-03 10:54:43 -06:00
|
|
|
self.last_lcd = self.lcd
|
2021-01-09 22:17:24 -06:00
|
|
|
self.are = (
|
|
|
|
ruleset.are and self:getLineARE() or 0
|
|
|
|
)
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.lcd == 0 then
|
|
|
|
self.grid:clearClearedRows()
|
2021-02-15 11:26:52 -06:00
|
|
|
self:afterLineClear(cleared_row_count)
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.are == 0 then
|
|
|
|
self:initializeOrHold(inputs, ruleset)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self:onLineClear(cleared_row_count)
|
|
|
|
else
|
2021-01-09 22:17:24 -06:00
|
|
|
if self:getARE() == 0 or not ruleset.are then
|
2019-05-22 22:57:34 -05:00
|
|
|
self:initializeOrHold(inputs, ruleset)
|
|
|
|
else
|
|
|
|
self.are = self:getARE()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.prev_inputs = inputs
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:updateScore() end
|
|
|
|
|
|
|
|
function GameMode:advanceOneFrame()
|
|
|
|
if self.clear then
|
|
|
|
self.completed = true
|
|
|
|
elseif self.ready_frames == 0 then
|
|
|
|
self.frames = self.frames + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- event functions
|
|
|
|
function GameMode:whilePieceActive() end
|
2021-02-16 14:27:57 -06:00
|
|
|
function GameMode:onAttemptPieceMove(piece, grid) end
|
|
|
|
function GameMode:onAttemptPieceRotate(piece, grid) end
|
2021-02-21 09:48:15 -06:00
|
|
|
function GameMode:onPieceMove(piece, grid, dx) end
|
|
|
|
function GameMode:onPieceRotate(piece, grid, drot) end
|
|
|
|
function GameMode:onPieceDrop(piece, grid, dy) end
|
2020-10-26 08:21:49 -05:00
|
|
|
function GameMode:onPieceLock(piece, cleared_row_count)
|
|
|
|
playSE("lock")
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function GameMode:onLineClear(cleared_row_count) end
|
2021-02-15 11:26:52 -06:00
|
|
|
function GameMode:afterLineClear(cleared_row_count) end
|
2020-10-26 08:21:49 -05:00
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function GameMode:onPieceEnter() end
|
2020-12-05 19:30:59 -06:00
|
|
|
function GameMode:onHold() end
|
2019-05-22 22:57:34 -05:00
|
|
|
|
2019-05-28 23:52:54 -05:00
|
|
|
function GameMode:onSoftDrop(dropped_row_count)
|
2021-06-09 19:15:37 -05:00
|
|
|
self.drop_bonus = self.drop_bonus + (
|
|
|
|
(self.piece.big and 2 or 1) * dropped_row_count
|
|
|
|
)
|
2019-05-28 23:52:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:onHardDrop(dropped_row_count)
|
2021-06-09 19:15:37 -05:00
|
|
|
self:onSoftDrop(dropped_row_count * 2)
|
2019-05-28 23:52:54 -05:00
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function GameMode:onGameOver()
|
2021-01-20 09:53:22 -06:00
|
|
|
switchBGM(nil)
|
2021-01-14 20:51:47 -06:00
|
|
|
love.graphics.setColor(0, 0, 0, 1 - 2 ^ (-self.game_over_frames / 30))
|
|
|
|
love.graphics.rectangle(
|
|
|
|
"fill", 64, 80,
|
|
|
|
16 * self.grid.width, 16 * (self.grid.height - 4)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:onGameComplete()
|
|
|
|
self:onGameOver()
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
2021-02-19 10:01:18 -06:00
|
|
|
function GameMode:onExit() end
|
|
|
|
|
2019-07-07 16:23:17 -05:00
|
|
|
-- DAS functions
|
|
|
|
|
|
|
|
function GameMode:startRightDAS()
|
|
|
|
self.move = "right"
|
|
|
|
self.das = { direction = "right", frames = 0 }
|
2020-11-29 10:11:47 -06:00
|
|
|
if self:getDasLimit() == 0 then
|
|
|
|
self:continueDAS()
|
|
|
|
end
|
2019-07-07 16:23:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:startLeftDAS()
|
|
|
|
self.move = "left"
|
|
|
|
self.das = { direction = "left", frames = 0 }
|
2020-11-29 10:11:47 -06:00
|
|
|
if self:getDasLimit() == 0 then
|
|
|
|
self:continueDAS()
|
|
|
|
end
|
2019-07-07 16:23:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:continueDAS()
|
|
|
|
local das_frames = self.das.frames + 1
|
|
|
|
if das_frames >= self:getDasLimit() then
|
|
|
|
if self.das.direction == "left" then
|
|
|
|
self.move = (self:getARR() == 0 and "speed" or "") .. "left"
|
|
|
|
self.das.frames = self:getDasLimit() - self:getARR()
|
|
|
|
elseif self.das.direction == "right" then
|
|
|
|
self.move = (self:getARR() == 0 and "speed" or "") .. "right"
|
|
|
|
self.das.frames = self:getDasLimit() - self:getARR()
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
else
|
|
|
|
self.move = "none"
|
2019-07-07 16:23:17 -05:00
|
|
|
self.das.frames = das_frames
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:stopDAS()
|
|
|
|
self.move = "none"
|
|
|
|
self.das = { direction = "none", frames = -1 }
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:chargeDAS(inputs)
|
2021-02-22 20:43:01 -06:00
|
|
|
if config.gamesettings.das_last_key == 2 then
|
2019-07-07 16:23:17 -05:00
|
|
|
if inputs["right"] == true and self.das.direction ~= "right" and not self.prev_inputs["right"] then
|
|
|
|
self:startRightDAS()
|
|
|
|
elseif inputs["left"] == true and self.das.direction ~= "left" and not self.prev_inputs["left"] then
|
|
|
|
self:startLeftDAS()
|
|
|
|
elseif inputs[self.das.direction] == true then
|
|
|
|
self:continueDAS()
|
|
|
|
else
|
|
|
|
self:stopDAS()
|
|
|
|
end
|
|
|
|
else -- default behaviour, das first key pressed
|
|
|
|
if inputs[self.das.direction] == true then
|
|
|
|
self:continueDAS()
|
|
|
|
elseif inputs["right"] == true then
|
|
|
|
self:startRightDAS()
|
|
|
|
elseif inputs["left"] == true then
|
|
|
|
self:startLeftDAS()
|
|
|
|
else
|
|
|
|
self:stopDAS()
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-16 14:27:57 -06:00
|
|
|
function GameMode:dasCut()
|
|
|
|
self.das.frames = math.max(
|
|
|
|
self.das.frames - self:getDasCutDelay(),
|
|
|
|
-(self:getDasCutDelay() + 1)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-12-28 22:32:41 -06:00
|
|
|
function GameMode:areCancel(inputs, ruleset)
|
2021-06-06 10:38:47 -05:00
|
|
|
if ruleset.are_cancel and strTrueValues(inputs) ~= "" and
|
2020-12-29 13:00:11 -06:00
|
|
|
not self.prev_inputs.up and
|
2021-06-06 10:38:47 -05:00
|
|
|
(self.piece_hard_dropped or
|
|
|
|
(self.piece_soft_locked and not self.prev_inputs.down)) then
|
2020-12-28 22:32:41 -06:00
|
|
|
self.lcd = 0
|
|
|
|
self.are = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-11 13:04:22 -05:00
|
|
|
function GameMode:checkBufferedInputs(inputs)
|
|
|
|
if (
|
|
|
|
config.gamesettings.buffer_lock ~= 1 and
|
|
|
|
not self.prev_inputs["up"] and inputs["up"] and
|
|
|
|
self.enable_hard_drop
|
|
|
|
) then
|
|
|
|
self.buffer_hard_drop = true
|
|
|
|
end
|
|
|
|
if (
|
|
|
|
config.gamesettings.buffer_lock ~= 1 and
|
|
|
|
not self.prev_inputs["down"] and inputs["down"]
|
|
|
|
) then
|
|
|
|
self.buffer_soft_drop = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function GameMode:processDelays(inputs, ruleset, drop_speed)
|
2020-10-27 06:17:00 -05:00
|
|
|
if self.ready_frames == 100 then
|
|
|
|
playedReadySE = false
|
|
|
|
playedGoSE = false
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.ready_frames > 0 then
|
2021-07-11 13:04:22 -05:00
|
|
|
self:checkBufferedInputs(inputs)
|
2020-10-27 06:17:00 -05:00
|
|
|
if not playedReadySE then
|
|
|
|
playedReadySE = true
|
|
|
|
playSEOnce("ready")
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
self.ready_frames = self.ready_frames - 1
|
2020-10-27 06:17:00 -05:00
|
|
|
if self.ready_frames == 50 and not playedGoSE then
|
|
|
|
playedGoSE = true
|
|
|
|
playSEOnce("go")
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.ready_frames == 0 then
|
|
|
|
self:initializeOrHold(inputs, ruleset)
|
|
|
|
end
|
|
|
|
elseif self.lcd > 0 then
|
2021-07-11 13:04:22 -05:00
|
|
|
self:checkBufferedInputs(inputs)
|
2019-05-22 22:57:34 -05:00
|
|
|
self.lcd = self.lcd - 1
|
2020-12-28 22:32:41 -06:00
|
|
|
self:areCancel(inputs, ruleset)
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.lcd == 0 then
|
2021-02-15 11:26:52 -06:00
|
|
|
local cleared_row_count = self.grid:getClearedRowCount()
|
2019-05-22 22:57:34 -05:00
|
|
|
self.grid:clearClearedRows()
|
2021-02-15 11:26:52 -06:00
|
|
|
self:afterLineClear(cleared_row_count)
|
2020-10-26 08:21:49 -05:00
|
|
|
playSE("fall")
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.are == 0 then
|
|
|
|
self:initializeOrHold(inputs, ruleset)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif self.are > 0 then
|
2021-07-11 13:04:22 -05:00
|
|
|
self:checkBufferedInputs(inputs)
|
2019-05-22 22:57:34 -05:00
|
|
|
self.are = self.are - 1
|
2020-12-28 22:32:41 -06:00
|
|
|
self:areCancel(inputs, ruleset)
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.are == 0 then
|
|
|
|
self:initializeOrHold(inputs, ruleset)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:initializeOrHold(inputs, ruleset)
|
2021-01-24 13:55:35 -06:00
|
|
|
if (
|
2021-08-08 23:29:22 -05:00
|
|
|
(self.frames == 0 or (ruleset.are and self:getARE() ~= 0))
|
|
|
|
and self.ihs or false
|
2021-01-24 13:55:35 -06:00
|
|
|
) and self.enable_hold and inputs["hold"] == true then
|
2020-12-05 19:30:59 -06:00
|
|
|
self:hold(inputs, ruleset, true)
|
2019-05-22 22:57:34 -05:00
|
|
|
else
|
|
|
|
self:initializeNextPiece(inputs, ruleset, self.next_queue[1])
|
|
|
|
end
|
|
|
|
self:onPieceEnter()
|
|
|
|
if not self.grid:canPlacePiece(self.piece) then
|
|
|
|
self.game_over = true
|
2021-08-08 23:29:22 -05:00
|
|
|
return
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
2021-06-26 15:27:33 -05:00
|
|
|
ruleset:dropPiece(
|
|
|
|
inputs, self.piece, self.grid, self:getGravity(),
|
|
|
|
self:getDropSpeed(), self.drop_locked, self.hard_drop_locked
|
|
|
|
)
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
2020-12-05 19:30:59 -06:00
|
|
|
function GameMode:hold(inputs, ruleset, ihs)
|
2019-05-22 22:57:34 -05:00
|
|
|
local data = copy(self.hold_queue)
|
|
|
|
if self.piece == nil then
|
|
|
|
self.hold_queue = self.next_queue[1]
|
|
|
|
table.remove(self.next_queue, 1)
|
|
|
|
table.insert(self.next_queue, self:getNextPiece(ruleset))
|
|
|
|
else
|
|
|
|
self.hold_queue = {
|
|
|
|
skin = self.piece.skin,
|
|
|
|
shape = self.piece.shape,
|
2021-08-11 18:44:57 -05:00
|
|
|
orientation = ruleset:getDefaultOrientation(self.piece.shape),
|
2019-05-22 22:57:34 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
if data == nil then
|
|
|
|
self:initializeNextPiece(inputs, ruleset, self.next_queue[1])
|
|
|
|
else
|
|
|
|
self:initializeNextPiece(inputs, ruleset, data, false)
|
|
|
|
end
|
|
|
|
self.held = true
|
2020-12-05 19:30:59 -06:00
|
|
|
if ihs then playSE("ihs")
|
|
|
|
else playSE("hold") end
|
2019-05-22 22:57:34 -05:00
|
|
|
self:onHold()
|
2021-06-26 15:27:33 -05:00
|
|
|
if not self.grid:canPlacePiece(self.piece) then
|
|
|
|
self.game_over = true
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
2021-08-08 23:29:22 -05:00
|
|
|
function GameMode:initializeNextPiece(
|
|
|
|
inputs, ruleset, piece_data, generate_next_piece
|
|
|
|
)
|
|
|
|
if not inputs.hold and not self.buffer_soft_drop and self.lock_drop or (
|
2021-07-11 16:10:51 -05:00
|
|
|
not ruleset.are or self:getARE() == 0
|
|
|
|
) then
|
|
|
|
self.drop_locked = true
|
|
|
|
end
|
2021-08-08 23:29:22 -05:00
|
|
|
if not inputs.hold and not self.buffer_hard_drop and self.lock_hard_drop or (
|
2021-07-11 16:10:51 -05:00
|
|
|
not ruleset.are or self:getARE() == 0
|
|
|
|
) then
|
|
|
|
self.hard_drop_locked = true
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
self.piece = ruleset:initializePiece(
|
2021-06-26 15:27:33 -05:00
|
|
|
inputs, piece_data, self.grid, self:getGravity(),
|
2019-05-22 22:57:34 -05:00
|
|
|
self.prev_inputs, self.move,
|
|
|
|
self:getLockDelay(), self:getDropSpeed(),
|
2021-06-26 15:27:33 -05:00
|
|
|
self.drop_locked, self.hard_drop_locked, self.big_mode,
|
2021-01-24 13:55:35 -06:00
|
|
|
(
|
|
|
|
self.frames == 0 or (ruleset.are and self:getARE() ~= 0)
|
2021-04-20 15:11:49 -05:00
|
|
|
) and self.irs or false
|
2019-05-22 22:57:34 -05:00
|
|
|
)
|
2021-07-11 16:10:51 -05:00
|
|
|
if config.gamesettings.buffer_lock == 3 then
|
|
|
|
if self.buffer_hard_drop then
|
|
|
|
local prev_y = self.piece.position.y
|
|
|
|
self.piece:dropToBottom(self.grid)
|
|
|
|
self.piece.locked = self.lock_on_hard_drop
|
|
|
|
self:onHardDrop(self.piece.position.y - prev_y)
|
|
|
|
end
|
|
|
|
if self.buffer_soft_drop then
|
|
|
|
if (
|
|
|
|
self.lock_on_soft_drop and
|
|
|
|
self.piece:isDropBlocked(self.grid)
|
|
|
|
) then
|
|
|
|
self.piece.locked = true
|
|
|
|
end
|
2021-04-20 15:11:49 -05:00
|
|
|
end
|
2021-01-06 15:06:17 -06:00
|
|
|
end
|
2021-07-11 16:10:51 -05:00
|
|
|
self.piece_hard_dropped = false
|
|
|
|
self.piece_soft_locked = false
|
|
|
|
self.buffer_hard_drop = false
|
|
|
|
self.buffer_soft_drop = false
|
2021-04-20 15:11:49 -05:00
|
|
|
if self.piece:isDropBlocked(self.grid) and
|
|
|
|
self.grid:canPlacePiece(self.piece) then
|
|
|
|
playSE("bottom")
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
if generate_next_piece == nil then
|
|
|
|
table.remove(self.next_queue, 1)
|
|
|
|
table.insert(self.next_queue, self:getNextPiece(ruleset))
|
|
|
|
end
|
2021-01-06 21:53:44 -06:00
|
|
|
self:playNextSound(ruleset)
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
2021-01-06 21:53:44 -06:00
|
|
|
function GameMode:playNextSound(ruleset)
|
|
|
|
playSE("blocks", ruleset.next_sounds[self.next_queue[1].shape])
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:getHighScoreData()
|
|
|
|
return {
|
|
|
|
score = self.score
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-02-10 22:10:10 -06:00
|
|
|
function GameMode:animation(x, y, skin, colour)
|
|
|
|
return {
|
2021-03-04 14:18:32 -06:00
|
|
|
1, 1, 1,
|
|
|
|
-0.25 + 1.25 * (self.lcd / self.last_lcd),
|
|
|
|
skin, colour,
|
|
|
|
48 + x * 16, y * 16
|
2021-02-10 22:10:10 -06:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-06-26 15:27:33 -05:00
|
|
|
function GameMode:canDrawLCA()
|
|
|
|
return self.lcd > 0
|
|
|
|
end
|
|
|
|
|
2021-02-10 17:35:51 -06:00
|
|
|
function GameMode:drawLineClearAnimation()
|
|
|
|
-- animation function
|
|
|
|
-- params: block x, y, skin, colour
|
|
|
|
-- returns: table with RGBA, skin, colour, x, y
|
|
|
|
|
|
|
|
-- Fadeout (default)
|
2021-02-10 22:10:10 -06:00
|
|
|
--[[
|
2021-02-10 17:35:51 -06:00
|
|
|
function animation(x, y, skin, colour)
|
|
|
|
return {
|
|
|
|
1, 1, 1,
|
2021-03-03 10:54:43 -06:00
|
|
|
-0.25 + 1.25 * (self.lcd / self.last_lcd),
|
2021-02-10 17:35:51 -06:00
|
|
|
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)
|
2021-02-11 14:46:56 -06:00
|
|
|
local p = 0.5
|
2021-02-10 17:35:51 -06:00
|
|
|
local l = (
|
2021-03-03 10:54:43 -06:00
|
|
|
(self.last_lcd - self.lcd) / self.last_lcd
|
2021-02-10 17:35:51 -06:00
|
|
|
)
|
|
|
|
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
|
2021-02-10 22:10:10 -06:00
|
|
|
local animation_table = self:animation(x, y, block.skin, block.colour)
|
2021-02-10 17:35:51 -06:00
|
|
|
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
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function GameMode:drawPiece()
|
|
|
|
if self.piece ~= nil then
|
2021-02-11 14:46:56 -06:00
|
|
|
local b = (
|
|
|
|
self.classic_lock and
|
|
|
|
(
|
|
|
|
self.piece:isDropBlocked(self.grid) and
|
|
|
|
1 - self.piece.gravity or 1
|
|
|
|
) or
|
|
|
|
1 - (self.piece.lock_delay / self:getLockDelay())
|
2019-05-22 22:57:34 -05:00
|
|
|
)
|
2021-02-11 14:46:56 -06:00
|
|
|
self.piece:draw(1, 0.25 + 0.75 * b, self.grid)
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:drawGhostPiece(ruleset)
|
2021-08-08 23:29:22 -05:00
|
|
|
if self.piece == nil or not self.grid:canPlacePiece(self.piece) then
|
|
|
|
return
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
local ghost_piece = self.piece:withOffset({x=0, y=0})
|
|
|
|
ghost_piece.ghost = true
|
|
|
|
ghost_piece:dropToBottom(self.grid)
|
|
|
|
ghost_piece:draw(0.5)
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:drawNextQueue(ruleset)
|
2021-03-10 12:58:08 -06:00
|
|
|
local colourscheme
|
|
|
|
if ruleset.pieces == 7 then
|
|
|
|
colourscheme = ({ruleset.colourscheme, ColourSchemes.Arika, ColourSchemes.TTC})[config.gamesettings.piece_colour]
|
|
|
|
else
|
|
|
|
colourscheme = ruleset.colourscheme
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
function drawPiece(piece, skin, offsets, pos_x, pos_y)
|
|
|
|
for index, offset in pairs(offsets) do
|
2021-02-18 14:09:27 -06:00
|
|
|
local x = offset.x + ruleset:getDrawOffset(piece, rotation).x + ruleset.spawn_positions[piece].x
|
|
|
|
local y = offset.y + ruleset:getDrawOffset(piece, rotation).y + 4.7
|
2020-10-10 18:42:56 -05:00
|
|
|
love.graphics.draw(blocks[skin][colourscheme[piece]], pos_x+x*16, pos_y+y*16)
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
for i = 1, self.next_queue_length do
|
|
|
|
self:setNextOpacity(i)
|
|
|
|
local next_piece = self.next_queue[i].shape
|
|
|
|
local skin = self.next_queue[i].skin
|
|
|
|
local rotation = self.next_queue[i].orientation
|
|
|
|
if config.side_next then -- next at side
|
|
|
|
drawPiece(next_piece, skin, ruleset.block_offsets[next_piece][rotation], 192, -16+i*48)
|
|
|
|
else -- next at top
|
|
|
|
drawPiece(next_piece, skin, ruleset.block_offsets[next_piece][rotation], -16+i*80, -32)
|
|
|
|
end
|
|
|
|
end
|
2020-12-02 12:41:47 -06:00
|
|
|
if self.hold_queue ~= nil and self.enable_hold then
|
2021-01-15 14:46:28 -06:00
|
|
|
self:setHoldOpacity()
|
2019-05-22 22:57:34 -05:00
|
|
|
drawPiece(
|
|
|
|
self.hold_queue.shape,
|
|
|
|
self.hold_queue.skin,
|
|
|
|
ruleset.block_offsets[self.hold_queue.shape][self.hold_queue.orientation],
|
|
|
|
-16, -32
|
|
|
|
)
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2021-01-15 14:46:28 -06:00
|
|
|
function GameMode:setNextOpacity(i)
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
2020-11-03 15:56:08 -06:00
|
|
|
end
|
2021-01-15 14:46:28 -06:00
|
|
|
|
|
|
|
function GameMode:setHoldOpacity()
|
2021-01-15 15:00:15 -06:00
|
|
|
local colour = self.held and 0.6 or 1
|
|
|
|
love.graphics.setColor(colour, colour, colour, 1)
|
2020-11-03 15:56:08 -06:00
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
|
2021-02-01 14:41:43 -06:00
|
|
|
function GameMode:getBackground()
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2021-02-02 13:51:49 -06:00
|
|
|
function GameMode:getHighscoreData()
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
2021-02-01 14:41:43 -06:00
|
|
|
function GameMode:drawGrid()
|
|
|
|
self.grid:draw()
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function GameMode:drawScoringInfo()
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
love.graphics.setFont(font_3x5_2)
|
|
|
|
|
|
|
|
if config["side_next"] then
|
|
|
|
love.graphics.printf("NEXT", 240, 72, 40, "left")
|
|
|
|
else
|
|
|
|
love.graphics.printf("NEXT", 64, 40, 40, "left")
|
|
|
|
end
|
|
|
|
|
|
|
|
love.graphics.print(
|
|
|
|
self.das.direction .. " " ..
|
|
|
|
self.das.frames .. " " ..
|
2020-10-06 12:14:00 -05:00
|
|
|
strTrueValues(self.prev_inputs) ..
|
2019-05-28 23:52:54 -05:00
|
|
|
self.drop_bonus
|
2019-05-22 22:57:34 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
love.graphics.setFont(font_8x11)
|
|
|
|
love.graphics.printf(formatTime(self.frames), 64, 420, 160, "center")
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:drawSectionTimes(current_section)
|
|
|
|
local section_x = 530
|
|
|
|
|
|
|
|
for section, time in pairs(self.section_times) do
|
|
|
|
if section > 0 then
|
|
|
|
love.graphics.printf(formatTime(time), section_x, 40 + 20 * section, 90, "left")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
love.graphics.printf(formatTime(self.frames - self.section_start_time), section_x, 40 + 20 * current_section, 90, "left")
|
|
|
|
end
|
|
|
|
|
2020-12-06 10:38:45 -06:00
|
|
|
function GameMode:sectionColourFunction(section)
|
|
|
|
return { 1, 1, 1, 1 }
|
|
|
|
end
|
|
|
|
|
2021-01-20 09:53:22 -06:00
|
|
|
function GameMode:drawSectionTimesWithSecondary(current_section, section_limit)
|
2021-01-25 21:26:55 -06:00
|
|
|
section_limit = section_limit or math.huge
|
2019-05-22 22:57:34 -05:00
|
|
|
local section_x = 530
|
|
|
|
local section_secondary_x = 440
|
|
|
|
|
|
|
|
for section, time in pairs(self.section_times) do
|
|
|
|
if section > 0 then
|
|
|
|
love.graphics.printf(formatTime(time), section_x, 40 + 20 * section, 90, "left")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for section, time in pairs(self.secondary_section_times) do
|
2020-12-06 10:38:45 -06:00
|
|
|
love.graphics.setColor(self:sectionColourFunction(section))
|
2019-05-22 22:57:34 -05:00
|
|
|
if section > 0 then
|
|
|
|
love.graphics.printf(formatTime(time), section_secondary_x, 40 + 20 * section, 90, "left")
|
|
|
|
end
|
2020-12-06 10:38:45 -06:00
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
local current_x
|
|
|
|
if table.getn(self.section_times) < table.getn(self.secondary_section_times) then
|
|
|
|
current_x = section_x
|
|
|
|
else
|
|
|
|
current_x = section_secondary_x
|
|
|
|
end
|
|
|
|
|
2021-01-20 09:53:22 -06:00
|
|
|
if current_section <= section_limit then
|
|
|
|
love.graphics.printf(formatTime(self.frames - self.section_start_time), current_x, 40 + 20 * current_section, 90, "left")
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
2021-02-15 11:26:52 -06:00
|
|
|
function GameMode:drawSectionTimesWithSplits(current_section, section_limit)
|
|
|
|
section_limit = section_limit or math.huge
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
local section_x = 440
|
|
|
|
local split_x = 530
|
|
|
|
|
|
|
|
local split_time = 0
|
|
|
|
|
|
|
|
for section, time in pairs(self.section_times) do
|
|
|
|
if section > 0 then
|
2021-02-16 14:27:57 -06:00
|
|
|
love.graphics.setColor(self:sectionColourFunction(section))
|
2019-05-22 22:57:34 -05:00
|
|
|
love.graphics.printf(formatTime(time), section_x, 40 + 20 * section, 90, "left")
|
2021-02-16 14:27:57 -06:00
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
2019-05-22 22:57:34 -05:00
|
|
|
split_time = split_time + time
|
|
|
|
love.graphics.printf(formatTime(split_time), split_x, 40 + 20 * section, 90, "left")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-15 11:26:52 -06:00
|
|
|
if (current_section <= section_limit) then
|
|
|
|
love.graphics.printf(formatTime(self.frames - self.section_start_time), section_x, 40 + 20 * current_section, 90, "left")
|
|
|
|
love.graphics.printf(formatTime(self.frames), split_x, 40 + 20 * current_section, 90, "left")
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
2021-06-09 19:15:37 -05:00
|
|
|
function GameMode:drawBackground()
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
love.graphics.draw(
|
|
|
|
backgrounds[self:getBackground()],
|
|
|
|
0, 0, 0,
|
|
|
|
0.5, 0.5
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:drawFrame()
|
|
|
|
-- game frame
|
|
|
|
if self.grid.width == 10 and self.grid.height == 24 then
|
|
|
|
love.graphics.draw(misc_graphics["frame"], 48, 64)
|
2021-08-08 23:29:22 -05:00
|
|
|
else
|
2021-06-09 19:15:37 -05:00
|
|
|
love.graphics.setColor(174/255, 83/255, 76/255, 1)
|
|
|
|
love.graphics.setLineWidth(8)
|
|
|
|
love.graphics.line(
|
|
|
|
60,76,
|
|
|
|
68+16*self.grid.width,76,
|
|
|
|
68+16*self.grid.width,84+16*(self.grid.height-4),
|
|
|
|
60,84+16*(self.grid.height-4),
|
|
|
|
60,76
|
|
|
|
)
|
|
|
|
love.graphics.setColor(203/255, 137/255, 111/255, 1)
|
|
|
|
love.graphics.setLineWidth(4)
|
|
|
|
love.graphics.line(
|
|
|
|
60,76,
|
|
|
|
68+16*self.grid.width,76,
|
|
|
|
68+16*self.grid.width,84+16*(self.grid.height-4),
|
|
|
|
60,84+16*(self.grid.height-4),
|
|
|
|
60,76
|
|
|
|
)
|
|
|
|
love.graphics.setLineWidth(1)
|
2021-08-08 23:29:22 -05:00
|
|
|
love.graphics.setColor(0, 0, 0, 200)
|
|
|
|
love.graphics.rectangle(
|
|
|
|
"fill", 64, 80,
|
|
|
|
16 * self.grid.width, 16 * (self.grid.height - 4)
|
|
|
|
)
|
2021-06-09 19:15:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameMode:drawReadyGo()
|
|
|
|
-- ready/go graphics
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
|
|
|
|
if self.ready_frames <= 100 and self.ready_frames > 52 then
|
|
|
|
love.graphics.draw(misc_graphics["ready"], 144 - 50, 240 - 14)
|
|
|
|
elseif self.ready_frames <= 50 and self.ready_frames > 2 then
|
|
|
|
love.graphics.draw(misc_graphics["go"], 144 - 27, 240 - 14)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function GameMode:drawCustom() end
|
|
|
|
|
2021-08-19 13:16:34 -05:00
|
|
|
function GameMode:drawIfPaused()
|
|
|
|
love.graphics.setFont(font_3x5_3)
|
|
|
|
love.graphics.printf("GAME PAUSED!", 64, 160, 160, "center")
|
|
|
|
end
|
|
|
|
|
2021-08-08 23:29:22 -05:00
|
|
|
-- transforms specified in here will transform the whole screen
|
2021-08-11 18:44:57 -05:00
|
|
|
-- if you want a transform for a particular component, push the
|
|
|
|
-- default transform by using love.graphics.push(), do your
|
|
|
|
-- transform, and then love.graphics.pop() at the end of that
|
|
|
|
-- component's draw call!
|
2021-08-08 23:29:22 -05:00
|
|
|
function GameMode:transformScreen() end
|
|
|
|
|
2021-07-11 13:04:22 -05:00
|
|
|
function GameMode:draw(paused)
|
2021-08-08 23:29:22 -05:00
|
|
|
self:transformScreen()
|
2021-07-11 13:04:22 -05:00
|
|
|
self:drawBackground()
|
|
|
|
self:drawFrame()
|
|
|
|
self:drawGrid()
|
|
|
|
self:drawPiece()
|
|
|
|
self:drawNextQueue(self.ruleset)
|
|
|
|
self:drawScoringInfo()
|
|
|
|
self:drawReadyGo()
|
|
|
|
self:drawCustom()
|
|
|
|
if self:canDrawLCA() then
|
|
|
|
self:drawLineClearAnimation()
|
|
|
|
end
|
|
|
|
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
love.graphics.setFont(font_3x5_2)
|
|
|
|
if config.gamesettings.display_gamemode == 1 then
|
|
|
|
love.graphics.printf(
|
|
|
|
self.name .. " - " .. self.ruleset.name,
|
|
|
|
0, 460, 640, "left"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
if paused then
|
2021-08-19 13:16:34 -05:00
|
|
|
self:drawIfPaused()
|
2021-07-11 13:04:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if self.completed then
|
|
|
|
self:onGameComplete()
|
|
|
|
elseif self.game_over then
|
|
|
|
self:onGameOver()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-21 11:08:03 -05:00
|
|
|
function GameMode:provideSettings()
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
return GameMode
|