From 0a300b018c357d2cafa7c96cc7171f424a591369 Mon Sep 17 00:00:00 2001 From: yaw-man Date: Tue, 24 Jan 2023 18:30:38 -0400 Subject: [PATCH] Fix: "load recording" menu wasn't scrolling correctly. --- loadgame.lua | 19 +++-- main.lua | 18 ++-- options.lua | 90 ++++++++++++++++++-- scores.lua | 59 +++++++++++++ text.lua | 6 +- text/{linja-sike.ttf => yod-linja-sike.ttf} | Bin 6 files changed, 161 insertions(+), 31 deletions(-) rename text/{linja-sike.ttf => yod-linja-sike.ttf} (100%) diff --git a/loadgame.lua b/loadgame.lua index 3df4710..4719d9d 100644 --- a/loadgame.lua +++ b/loadgame.lua @@ -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 diff --git a/main.lua b/main.lua index be644d0..2ada7c8 100644 --- a/main.lua +++ b/main.lua @@ -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() diff --git a/options.lua b/options.lua index eafb6f6..41293c1 100644 --- a/options.lua +++ b/options.lua @@ -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" ) diff --git a/scores.lua b/scores.lua index e69de29..beb5ca1 100644 --- a/scores.lua +++ b/scores.lua @@ -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 \ No newline at end of file diff --git a/text.lua b/text.lua index efa70f0..722ddb6 100644 --- a/text.lua +++ b/text.lua @@ -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 diff --git a/text/linja-sike.ttf b/text/yod-linja-sike.ttf similarity index 100% rename from text/linja-sike.ttf rename to text/yod-linja-sike.ttf