cambridge/tetris/modes/interval_training.lua

161 lines
4.1 KiB
Lua
Raw Normal View History

2019-05-22 22:57:34 -05:00
require 'funcs'
local GameMode = require 'tetris.modes.gamemode'
local Piece = require 'tetris.components.piece'
local History6RollsRandomizer = require 'tetris.randomizers.history_6rolls_35bag'
2019-05-22 22:57:34 -05:00
local IntervalTrainingGame = GameMode:extend()
IntervalTrainingGame.name = "Interval Training"
IntervalTrainingGame.hash = "IntervalTraining"
IntervalTrainingGame.tagline = "Can you clear the time hurdles when the game goes this fast?"
2019-05-22 22:57:34 -05:00
function IntervalTrainingGame:new()
self.level = 0
2019-05-22 22:57:34 -05:00
IntervalTrainingGame.super:new()
self.roll_frames = 0
self.combo = 1
self.randomizer = History6RollsRandomizer()
2019-05-22 22:57:34 -05:00
self.section_start_time = 0
self.section_times = { [0] = 0 }
self.lock_drop = true
self.enable_hold = true
self.next_queue_length = 3
end
function IntervalTrainingGame:initialize(ruleset)
self.section_time_limit = 1800
if ruleset.world then self.section_time_limit = 37 * 60 end
self.super.initialize(self, ruleset)
end
2019-05-22 22:57:34 -05:00
function IntervalTrainingGame:getARE()
return 6
2019-05-22 22:57:34 -05:00
end
function IntervalTrainingGame:getLineARE()
return 6
2019-05-22 22:57:34 -05:00
end
function IntervalTrainingGame:getDasLimit()
return 7
2019-05-22 22:57:34 -05:00
end
function IntervalTrainingGame:getLineClearDelay()
return 4
2019-05-22 22:57:34 -05:00
end
function IntervalTrainingGame:getLockDelay()
return 15
end
function IntervalTrainingGame:getGravity()
return 20
end
function IntervalTrainingGame:getSection()
return math.floor(level / 100) + 1
end
function IntervalTrainingGame:advanceOneFrame()
if self.clear then
self.roll_frames = self.roll_frames + 1
if self.roll_frames > 2968 then
self.completed = true
end
elseif self.ready_frames == 0 then
self.frames = self.frames + 1
if self:getSectionTime() >= self.section_time_limit then
self.game_over = true
end
end
return true
end
function IntervalTrainingGame:onPieceEnter()
if (self.level % 100 ~= 99 and self.level ~= 998) and not self.clear and self.frames ~= 0 then
2019-05-22 22:57:34 -05:00
self.level = self.level + 1
end
end
function IntervalTrainingGame:onLineClear(cleared_row_count)
2020-11-03 10:52:52 -06:00
local cleared_level_bonus = {1, 2, 4, 6}
2019-05-22 22:57:34 -05:00
if not self.clear then
2020-11-03 10:52:52 -06:00
local new_level = self.level + cleared_level_bonus[cleared_row_count]
2019-05-22 22:57:34 -05:00
self:updateSectionTimes(self.level, new_level)
self.level = math.min(new_level, 999)
if self.level == 999 then
self.clear = true
end
end
end
function IntervalTrainingGame:getSectionTime()
return self.frames - self.section_start_time
end
function IntervalTrainingGame:updateSectionTimes(old_level, new_level)
if math.floor(old_level / 100) < math.floor(new_level / 100) then
-- record new section
table.insert(self.section_times, self:getSectionTime())
self.section_start_time = self.frames
2020-11-03 10:55:30 -06:00
end
2019-05-22 22:57:34 -05:00
end
function IntervalTrainingGame:drawGrid(ruleset)
self.grid:draw()
end
function IntervalTrainingGame:getHighscoreData()
return {
level = self.level,
frames = self.frames,
}
end
function IntervalTrainingGame:drawScoringInfo()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setFont(font_3x5_2)
love.graphics.print(
self.das.direction .. " " ..
self.das.frames .. " " ..
strTrueValues(self.prev_inputs)
2019-05-22 22:57:34 -05:00
)
love.graphics.printf("NEXT", 64, 40, 40, "left")
2020-11-03 10:52:52 -06:00
if not self.clear then love.graphics.printf("TIME LEFT", 240, 250, 80, "left") end
2019-05-22 22:57:34 -05:00
love.graphics.printf("LEVEL", 240, 320, 40, "left")
local current_section = math.floor(self.level / 100) + 1
self:drawSectionTimesWithSplits(current_section)
love.graphics.setFont(font_3x5_3)
love.graphics.printf(self.level, 240, 340, 40, "right")
-- draw time left, flash red if necessary
local time_left = self.section_time_limit - math.max(self:getSectionTime(), 0)
2020-11-03 10:52:52 -06:00
if not self.game_over and time_left < frameTime(0,10) and time_left % 4 < 2 then
2019-05-22 22:57:34 -05:00
love.graphics.setColor(1, 0.3, 0.3, 1)
end
2020-11-03 10:52:52 -06:00
if not self.clear then love.graphics.printf(formatTime(time_left), 240, 270, 160, "left") end
2019-05-22 22:57:34 -05:00
love.graphics.setColor(1, 1, 1, 1)
love.graphics.printf(self:getSectionEndLevel(), 240, 370, 40, "right")
end
function IntervalTrainingGame:getSectionEndLevel()
if self.level >= 900 then return 999
2019-05-22 22:57:34 -05:00
else return math.floor(self.level / 100 + 1) * 100 end
end
function IntervalTrainingGame:getBackground()
return math.floor(self.level / 100)
end
return IntervalTrainingGame