Fix: "load recording" menu wasn't scrolling correctly.

This commit is contained in:
yaw-man 2023-01-24 18:30:38 -04:00
parent 32a154cabe
commit 0a300b018c
6 changed files with 161 additions and 31 deletions

View File

@ -6,6 +6,15 @@ local _MousePressed = love.mousepressed
local _Resize = love.resize
local _KeyPressed = love.keypressed
local function RestoreMainState()
love.update = _Update
love.draw = _Draw
love.mousepressed = _MousePressed
love.keypressed = _KeyPressed
love.resize = _Resize
love.mousemoved = nil
end
local selectedGame = 1
local scrollOffset = 1
local deleteGame = false
@ -16,14 +25,6 @@ local canvas = love.graphics.newCanvas( w, h * (1 + #gameList) / 10.0 )
local font = love.graphics.newFont( 36 )
local OnClick
local function RestoreMainState()
love.update = _Update
love.draw = _Draw
love.mousepressed = _MousePressed
love.keypressed = _KeyPressed
love.resize = _Resize
love.mousemoved = nil
end
local function DeleteLeft()
return w * 0.75 + 15 + 6
@ -106,7 +107,7 @@ local KeyPress = function( key, code, isRepeat )
return
end
if key == "up" then
if selectedGame > 8 then
if selectedGame > 9 then
scrollOffset = scrollOffset - 1
end
if selectedGame > 1 then

View File

@ -15,6 +15,7 @@ local Draw
local Update
local ExtrapolateBeatScore
local _ExtrapolateBeatScore
local scores
local state
state = {
@ -80,6 +81,8 @@ OnImpact = function( impact )
else
state.currentStreak = 0
end
scores.OnImpact( state.tick, pass )
local x, y = impact.r * math.cos(impact.th), impact.r * math.sin(impact.th)
@ -130,6 +133,7 @@ local function NewGame( demoName )
text.Reset()
audio.Reset()
recorder.Reset()
scores.Reset()
state.isDemo = demoName
if demoName then
@ -161,6 +165,7 @@ function love.load()
DetectCollision = assert ( require "collision" )
audio = assert( require "audio" )
recorder = assert( require "recorder" )
scores = assert( require "scores" )
return NewGame()
end
@ -221,6 +226,7 @@ OnVictory = function()
if state.isDemo then
state.isDemo = false
else
scores.Save()
recorder.Save()
end
@ -240,6 +246,7 @@ OnVictory = function()
particles:setEmissionArea( "normal", 0.01, 0.01, 0, true )
love.graphics.setCanvas( marble.Canvas() )
Draw()
love.graphics.setCanvas()
local totalTime = state.tick / 120.0
@ -266,20 +273,11 @@ OnVictory = function()
love.graphics.draw( particles )
love.graphics.pop()
text.Draw( 119 )
scores.RenderHighScores()
local score = state.longestStreak * state.longestStreak / totalTime
love.graphics.setColor( 1, 1, 1, 1 )
love.graphics.printf(
string.format( "time:\t%.2f\nstreak:\t%d\nscore:%.2f", totalTime, state.longestStreak, score):gsub( "%.", "," ),
0, 0.5 * love.graphics.getHeight() - 2.0* love.graphics.getFont():getHeight(),
love.graphics.getWidth(),
"center"
)
marble.Draw()
end
marble.OnVictory()

View File

@ -1,8 +1,4 @@
--local love = love
local options = options
local optionList = {}
options.isHighContrast = false
local love = love
local draw = love.draw
local update = love.update
@ -18,25 +14,101 @@ local function Restore()
love.draw = draw
end
local optionIdx
local options = options
local optionList = {}
local function Draw()
options.isHighContrast = false
options.keyBinds = {}
local font = love.graphics.newFont( 32 )
local keyBindCallback = function(self, code)
self.value = code
options.keyBinds[self.name] = code
end
options.optionValues = {
{ name = "options",
value = "back",
callback = function(self)
return Restore()
end
},
{ name = "high contrast",
value = false,
callback = function(self)
self.value = true
end
},
{ name = "volume",
value = 1.0,
callback = function(self, isIncreasing)
self.value = math.max( 0, math.min( 1,
self.value + (isIncreasing and 0.05 or -0.05 )))
end
},
{ name = "left",
value = "a",
callback = keyBindCallback
},
{ name = "right",
value = "d",
callback = keyBindCallback
},
{ name = "up",
value = "w",
callback = keyBindCallback
},
{ name = "down",
value = "s",
callback = keyBindCallback
}
}
local function SetKeyBind( dir, code )
end
local optionIdx
local function Draw()
love.graphics.setColor( 1,1,1,1 )
for i, option in ipairs( options.optionValues ) do
love.graphics.printf( option.name, font, 100, i * 50, 1000, "left")
love.graphics.printf( tostring( option.value ), font, -100, i * 50, love.graphics.getWidth(), "right")
end
end
local function Update()
end
local function ToggleSelectedOption()
end
local function MousePress()
end
local function KeyPress()
local function KeyPress(key, code, isRepeat)
print( code )
if code == "backspace" then return Restore() end
if code == "down" then return SelectNextOption() end
if code == "up" then return SelectPreviousOption() end
if code == "left" then return ShrinkOptionValue() end
if code == "right" then return GrowOptionValue() end
end
love.draw = Draw
love.keypressed = KeyPress
--[[function love.draw()
love.graphics.print( "a" )

View File

@ -0,0 +1,59 @@
local love = love
local scores = {}
local highScores = {}
function scores.OnImpact( tick, isHitSuccessful )
local score = 0
if isHitSuccessful then
scores.streak = scores.streak + 1
else
table.insert( scores.streaks, scores.streak)
scores.streak = 0
end
for i, streak in ipairs( scores.streaks ) do
score = score + streak * streak
end
scores.score = score / math.pow( tick / 120.0, 1.5 )
scores.t = tick
end
function scores.Reset()
scores.score = 0
scores.streak = 0
scores.streaks = {}
end
function scores.Get()
end
function scores.Save()
local i = 1
for j = 1, #highScores do
i = j
if highScores[j] < scores.score then break end
end
table.insert( highScores, i )
end
function scores.LoadHighScores()
end
function scores.RenderHighScores()
love.graphics.setColor( 1, 1, 1, 1 )
love.graphics.printf( "Streak:."..scores.score, 0, 0, -1, "center" )
love.graphics.printf( "Score:."..scores.score, 0, 0, -1, "center" )
love.graphics.printf(
string.format( "time:\t%.2f\nstreak:\t%d\nscore:%.2f", scores.t / 120.0, scores.streak, scores.score):gsub( "%.", "," ),
0, 0.5 * love.graphics.getHeight() - 2.0* love.graphics.getFont():getHeight(),
love.graphics.getWidth(),
"center"
)
end
return scores

View File

@ -11,9 +11,9 @@ local mt = { __index = function() return "linja" end }
local s = love.filesystem.read( "text/tok.txt" )
local instrFont = love.graphics.newFont( 18 )
local enFont = love.graphics.setNewFont( "text/linja-sike.ttf", 18 )
local smallFont = love.graphics.setNewFont( "text/linja-sike.ttf", 24 )
local largeFont = love.graphics.setNewFont( "text/linja-sike.ttf", 64 )
local enFont = love.graphics.setNewFont( "text/yod-linja-sike.ttf", 18 )
local smallFont = love.graphics.setNewFont( "text/yod-linja-sike.ttf", 24 )
local largeFont = love.graphics.setNewFont( "text/yod-linja-sike.ttf", 64 )
local i = 1