2020-12-04 19:53:09 -06:00
|
|
|
require 'funcs'
|
|
|
|
|
|
|
|
local GameMode = require 'tetris.modes.gamemode'
|
|
|
|
|
|
|
|
local Bag7Randomizer = require 'tetris.randomizers.bag7'
|
|
|
|
|
|
|
|
local LudicrousSpeed = GameMode:extend()
|
|
|
|
|
|
|
|
LudicrousSpeed.name = "Ludicrous Speed"
|
|
|
|
LudicrousSpeed.hash = "LSpeed"
|
|
|
|
LudicrousSpeed.tagline = "Don't make Keanu sad. Always stay above the speed limit."
|
|
|
|
|
|
|
|
function LudicrousSpeed:new()
|
|
|
|
self.super:new()
|
|
|
|
|
2021-10-13 18:12:08 -05:00
|
|
|
self.time_limit = 300
|
2022-01-30 16:05:59 -06:00
|
|
|
self.delays = {}
|
|
|
|
self.last_piece = 0
|
2020-12-04 19:53:09 -06:00
|
|
|
self.pps_limit = 1
|
|
|
|
|
|
|
|
self.randomizer = Bag7Randomizer()
|
|
|
|
|
|
|
|
self.lock_drop = true
|
|
|
|
self.lock_hard_drop = true
|
|
|
|
self.instant_soft_drop = false
|
|
|
|
self.instant_hard_drop = true
|
|
|
|
self.enable_hold = true
|
2020-12-22 21:09:17 -06:00
|
|
|
self.next_queue_length = 6
|
2020-12-04 19:53:09 -06:00
|
|
|
end
|
|
|
|
|
2022-01-30 16:05:59 -06:00
|
|
|
local function mean(t)
|
|
|
|
local sum = 0
|
|
|
|
|
2022-08-11 22:52:55 -05:00
|
|
|
for _, v in pairs(t) do
|
2022-01-30 16:05:59 -06:00
|
|
|
sum = sum + v
|
|
|
|
end
|
|
|
|
|
|
|
|
return sum / #t
|
|
|
|
end
|
|
|
|
|
2020-12-04 19:53:09 -06:00
|
|
|
function LudicrousSpeed:getGravity()
|
|
|
|
if self.lines < 180 then
|
|
|
|
return (0.8 - (math.floor(self.lines / 10) * 0.007)) ^ -math.floor(self.lines / 10) / 60
|
|
|
|
else return 20 end
|
|
|
|
end
|
|
|
|
|
|
|
|
function LudicrousSpeed:getARE() return 0 end
|
|
|
|
function LudicrousSpeed:getLineARE() return 0 end
|
|
|
|
function LudicrousSpeed:getLineClearDelay() return 0 end
|
2020-12-18 20:57:36 -06:00
|
|
|
function LudicrousSpeed:getDasLimit() return config.das end
|
|
|
|
function LudicrousSpeed:getARR() return config.arr end
|
2021-01-24 13:56:02 -06:00
|
|
|
function LudicrousSpeed:getDasCutDelay() return config.dcd end
|
2020-12-04 19:53:09 -06:00
|
|
|
function LudicrousSpeed:getDropSpeed() return 20 end
|
|
|
|
|
2022-01-30 16:05:59 -06:00
|
|
|
function LudicrousSpeed:getPPS()
|
|
|
|
if #self.delays == 0 then return 0 end
|
|
|
|
local delays = copy(self.delays)
|
2022-08-11 22:52:55 -05:00
|
|
|
delays[0] = self.frames - self.last_piece
|
2022-08-12 03:43:01 -05:00
|
|
|
return 60 / mean(delays)
|
2020-12-04 19:53:09 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
function LudicrousSpeed:advanceOneFrame()
|
|
|
|
if self.ready_frames == 0 then
|
|
|
|
self.frames = self.frames + 1
|
2022-01-30 16:05:59 -06:00
|
|
|
if self:getPPS() < self.pps_limit then
|
2020-12-04 19:53:09 -06:00
|
|
|
self.time_limit = self.time_limit - 1
|
|
|
|
self.game_over = self.time_limit <= 0
|
2021-10-13 18:12:08 -05:00
|
|
|
else self.time_limit = 300 end
|
2020-12-04 19:53:09 -06:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2022-01-30 16:05:59 -06:00
|
|
|
function LudicrousSpeed:onPieceLock(...)
|
|
|
|
self.super:onPieceLock(...)
|
|
|
|
self.delays[#self.delays + 1] = self.frames - self.last_piece
|
|
|
|
if #self.delays >= 25 then
|
|
|
|
table.remove(self.delays, 1)
|
|
|
|
end
|
|
|
|
self.last_piece = self.frames
|
2020-12-04 19:53:09 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
function LudicrousSpeed:onLineClear(cleared_row_count)
|
|
|
|
self.lines = self.lines + cleared_row_count
|
|
|
|
self.pps_limit = 1 + math.floor(self.lines / 10) / 10
|
|
|
|
end
|
|
|
|
|
|
|
|
function LudicrousSpeed:drawGrid()
|
|
|
|
self.grid:draw()
|
|
|
|
self:drawGhostPiece()
|
|
|
|
end
|
|
|
|
|
|
|
|
function LudicrousSpeed:drawScoringInfo()
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
|
2021-10-20 17:12:47 -05:00
|
|
|
if config["side_next"] then
|
|
|
|
love.graphics.printf("NEXT", 240, 72, 40, "left")
|
|
|
|
else
|
|
|
|
love.graphics.printf("NEXT", 64, 40, 40, "left")
|
|
|
|
end
|
|
|
|
|
|
|
|
local text_x = config["side_next"] and 316 or 240
|
|
|
|
|
|
|
|
love.graphics.setFont(font_3x5_2)
|
2020-12-04 19:53:09 -06:00
|
|
|
love.graphics.printf("LINES", text_x, 120, 80, "left")
|
|
|
|
love.graphics.printf("piece/sec", text_x, 180, 80, "left")
|
|
|
|
love.graphics.printf("REQUIRED PPS", text_x, 240, 120, "left")
|
2022-08-12 03:43:01 -05:00
|
|
|
if self.time_limit < 300 then
|
2022-08-12 03:48:27 -05:00
|
|
|
if self.time_limit % 4 < 2 and self.time_limit ~= 0 then
|
2022-08-12 03:43:01 -05:00
|
|
|
love.graphics.setColor(1, 0.3, 0.3, 1)
|
|
|
|
end
|
|
|
|
love.graphics.printf("SPEED UP!", text_x, 300, 120, "left")
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
end
|
2020-12-04 19:53:09 -06:00
|
|
|
|
|
|
|
love.graphics.print(
|
|
|
|
self.das.direction .. " " ..
|
|
|
|
self.das.frames .. " " ..
|
|
|
|
strTrueValues(self.prev_inputs) ..
|
|
|
|
self.drop_bonus
|
|
|
|
)
|
|
|
|
|
|
|
|
love.graphics.setFont(font_3x5_4)
|
2021-10-13 18:12:08 -05:00
|
|
|
if self.time_limit < 300 then
|
2022-08-12 03:43:01 -05:00
|
|
|
love.graphics.printf(formatTime(self.time_limit):sub(-4, -1), text_x, 320, 160, "left")
|
2021-10-13 18:12:08 -05:00
|
|
|
end
|
2020-12-04 19:53:09 -06:00
|
|
|
|
|
|
|
love.graphics.setFont(font_3x5_3)
|
|
|
|
love.graphics.printf(self.lines, text_x, 140, 80, "left")
|
2022-08-12 03:43:01 -05:00
|
|
|
love.graphics.printf(("%.02f"):format(self:getPPS()), text_x, 200, 80, "left")
|
|
|
|
love.graphics.printf(("%.02f"):format(self.pps_limit), text_x, 260, 80, "left")
|
2020-12-04 19:53:09 -06:00
|
|
|
|
|
|
|
love.graphics.setFont(font_8x11)
|
|
|
|
love.graphics.printf(formatTime(self.frames), 64, 420, 160, "center")
|
|
|
|
end
|
|
|
|
|
|
|
|
function LudicrousSpeed:getBackground()
|
|
|
|
return math.floor(self.lines / 10)
|
|
|
|
end
|
|
|
|
|
|
|
|
function LudicrousSpeed:getHighscoreData()
|
|
|
|
return {
|
|
|
|
lines = self.lines,
|
|
|
|
frames = self.frames,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-08-11 22:52:55 -05:00
|
|
|
return LudicrousSpeed
|