Adding options menu, local leaderboard.

This commit is contained in:
yaw-man 2023-01-22 11:22:51 -04:00
parent 337e0ce154
commit 32a154cabe
6 changed files with 147 additions and 47 deletions

View File

@ -16,12 +16,21 @@ local canvas = love.graphics.newCanvas( w, h * (1 + #gameList) / 10.0 )
local font = love.graphics.newFont( 36 ) local font = love.graphics.newFont( 36 )
local OnClick 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() local function DeleteLeft()
return w * 0.75 + 15 + 6 return w * 0.75 + 15 + 6
end end
local function DeleteRight() local function DeleteRight()
return DeleteLeft() + 45 return DeleteLeft() + h / 10 - 12
end end
local function DrawSelection( ) local function DrawSelection( )
@ -41,8 +50,9 @@ local function PopulateGameList()
local x, y = 15, i * h / 10 local x, y = 15, i * h / 10
love.graphics.printf( gameList[i], font, x + 10, y, 0.75 * w, "left" ) love.graphics.printf( gameList[i], font, x + 10, y, 0.75 * w, "left" )
love.graphics.rectangle( "line", x, y, w * 0.75, h / 10 - 12, 10, 10 ) --love.graphics.rectangle( "line", x, y, w * 0.5, h / 10 - 12, 10, 10 )
love.graphics.rectangle( "line", DeleteLeft(), y, h / 10 - 12, h / 10 - 12, 10, 10 ) love.graphics.rectangle( "line", DeleteLeft(), y, h / 10 - 12, h / 10 - 12, 10, 10 )
love.graphics.line( DeleteLeft() + 5, y + 5, DeleteRight() - 5, y + h / 10 - 17 )
end end
love.graphics.setCanvas() love.graphics.setCanvas()
@ -60,31 +70,31 @@ love.update = function() end
love.draw = function() love.draw = function()
love.graphics.draw( canvas, 0, -scrollOffset * h / 10 ) love.graphics.draw( canvas, 0, 15 - scrollOffset * h / 10 )
love.graphics.setColor( 1.0, 1.0, 1.0, 0.5 ) love.graphics.setColor( 0, 0, 0, 0.5 )
if deleteGame then if deleteGame then
love.graphics.rectangle( "fill", DeleteLeft(), ( selectedGame - scrollOffset ) * h / 10, h / 10 - 12, h / 10 - 12, 10, 10 ) love.graphics.rectangle( "fill", DeleteLeft(), 15 + ( selectedGame - scrollOffset ) * h / 10, h / 10 - 12, h / 10 - 12, 10, 10 )
else else
love.graphics.rectangle( "fill", 15, ( selectedGame - scrollOffset ) * h / 10, w * 0.75, h / 10 - 12, 10, 10 ) love.graphics.rectangle( "fill", 15, 15 + ( selectedGame - scrollOffset ) * h / 10, w * 0.75, h / 10 - 12, 10, 10 )
end end
love.graphics.setColor( 1.0, 1.0, 1.0, 1.0 ) love.graphics.setColor( 1.0, 1.0, 1.0, 1.0 )
love.graphics.rectangle( "fill", 0, 0, w, h / 10 - 6 ) love.graphics.rectangle( "fill", 0, 0, w, 10 + h / 10 - 6 )
love.graphics.setColor( 91 / 255, 206 / 255, 250 / 255 ) love.graphics.setColor( 91 / 255, 206 / 255, 250 / 255 )
love.graphics.print( "DEMOS "..( gameList[selectedGame] or selectedGame ) ) love.graphics.print( "DEMOS."..( gameList[selectedGame] or "" ) )
end end
love.mousemoved = function( x, y, dx, dy, istouch) love.mousemoved = function( x, y, dx, dy, istouch)
deleteGame = ( x > DeleteLeft() ) and ( x < DeleteRight() ) deleteGame = ( x > DeleteLeft() )
selectedGame = scrollOffset + math.floor( 10 * y / h ) selectedGame = math.max( math.min( #gameList, scrollOffset + math.floor( 10 * ( y - 15 ) / h ) ), 1)
end end
love.keypressed = function( key, code, isRepeat ) local KeyPress = function( key, code, isRepeat )
if code == "return" then if code == "return" then
return OnClick() return OnClick()
end end
if code == "down" then if code == "down" then
if selectedGame < #gameList then if selectedGame < #gameList then
@ -104,11 +114,13 @@ love.keypressed = function( key, code, isRepeat )
end end
return return
end end
if key == "right" or key == "left" then deleteGame = not( deleteGame ) end if code == "left" then deleteGame = false end
if code == "right" then deleteGame = true end
if code == "escape" or code == "backspace" then return RestoreMainState() end
end end
OnClick = function( x, y, button, istouch, presses )
OnClick = function( )
if not selectedGame then return end if not selectedGame then return end
if #gameList < 1 then return end if #gameList < 1 then return end
@ -118,12 +130,7 @@ OnClick = function( x, y, button, istouch, presses )
end end
--Restore main state. --Restore main state.
love.update = _Update RestoreMainState()
love.draw = _Draw
love.mousepressed = _MousePressed
love.keypressed = _KeyPressed
love.resize = _Resize
love.mousemoved = nil
return "demos/"..gameList[selectedGame] return "demos/"..gameList[selectedGame]
end end
@ -131,4 +138,4 @@ end
PopulateGameList() PopulateGameList()
return OnClick return OnClick, KeyPress

View File

@ -27,11 +27,11 @@ state = {
state.longestStreak = 0 state.longestStreak = 0
state.currentStreak = 0 state.currentStreak = 0
state.lastCollisionTick = 0 state.lastCollisionTick = 0
state.lastCollisionX = 0
state.lastCollisionY = 0
end, end,
finishTime = 0.0,
timeToSimulate = 0.0, timeToSimulate = 0.0,
isGameStarted = false,
lastBeatScore = 0.0, lastBeatScore = 0.0,
currentBeat = 1, currentBeat = 1,
longestStreak = 0, longestStreak = 0,
@ -82,10 +82,12 @@ OnImpact = function( impact )
end end
local x, y = math.cos(impact.th), math.sin(impact.th) local x, y = impact.r * math.cos(impact.th), impact.r * math.sin(impact.th)
particles:setPosition( impact.r * x, impact.r * y ) particles:setPosition( x, y )
particles:setEmissionArea( "normal", 0.1, 0.2, impact.th, true ) particles:setEmissionArea( "normal", 0.1, 0.2, impact.th, true )
particles:emit( 50 * score * score ) particles:emit( 50 * score * score )
state.lastCollisionX, state.lastCollisionY = transform:transformPoint( 1.2 * x, 1.2 * y )
audio.OnImpact( impact, score, pass, state.currentBeat ) audio.OnImpact( impact, score, pass, state.currentBeat )
marble.OnImpact( impact, state.currentBeat ) marble.OnImpact( impact, state.currentBeat )
@ -137,6 +139,8 @@ end
function love.load() function love.load()
UpdateWindowTransform( love.graphics.getDimensions() ) UpdateWindowTransform( love.graphics.getDimensions() )
options = {}
do--particle system setup do--particle system setup
@ -293,6 +297,8 @@ Draw = function()
love.graphics.setColor( 1.0, 1.0, 1.0, 1.0 ) love.graphics.setColor( 1.0, 1.0, 1.0, 1.0 )
love.graphics.draw(particles, 0, 0) love.graphics.draw(particles, 0, 0)
wave.Draw( score ) wave.Draw( score )
love.graphics.pop() love.graphics.pop()
@ -301,9 +307,11 @@ Draw = function()
marble.Draw() marble.Draw()
text.Draw( state.currentBeat ) text.Draw( state.currentBeat )
love.graphics.print( state.tick, 400, 400, 0, 1, 1 ) love.graphics.setColor( 0.3, 0.3, 0.3, 1.0 - score )
love.graphics.print( state.currentStreak, 400, 450, 0, 1, 1 ) local s = "+"..state.currentStreak..(state.currentStreak > 50 and "!" or "")
love.graphics.print( state.lastCollisionTick, 400, 500, 0, 1, 1 ) love.graphics.print( s, state.lastCollisionX, state.lastCollisionY, 0, 0.5 - 0.1 * score, 0.5 - 0.1 * score)
end end
@ -345,18 +353,28 @@ Update = function( dt )
end end
_Update = Update _Update = Update
local function OptionsMenu()
dofile "options.lua"
end
local function LoadGame() -- Load game screen. local function LoadGame() -- Load game screen.
local loadGame = assert( dofile "loadgame.lua" ) local Click, Press = assert( dofile "loadgame.lua" )
love.mousepressed = function( x, y, button, istouch, presses) love.mousepressed = function( x, y, button, istouch, presses)
local demoName = loadGame( x, y, button, istouch, presses ) local demoName = Click( x, y, button, istouch, presses )
if demoName then return NewGame( demoName ) end
end
love.keypressed = function( key, code, isRepeat)
local demoName = Press( key, code, isRepeat )
if demoName then return NewGame( demoName ) end if demoName then return NewGame( demoName ) end
end end
end end
function love.keypressed( key, code, isRepeat ) function love.keypressed( key, code, isRepeat )
if key == "escape" then return love.event.quit() end if code == "escape" then return love.event.quit() end
if key == "space" then return NewGame() end if code == "space" then return NewGame() end
if code == "return" then return LoadGame() end --Play demo. if code == "return" then return LoadGame() end --Play demo.
if code == "o" then return OptionsMenu() end
if state.isDemo then return end if state.isDemo then return end
return marble.OnKey( state.tick ) return marble.OnKey( state.tick )
end end

67
options.lua Normal file
View File

@ -0,0 +1,67 @@
--local love = love
local options = options
local optionList = {}
options.isHighContrast = false
local draw = love.draw
local update = love.update
local mousepressed = love.mousepressed
local keypressed = love.keypressed
local mousemoved = love.mousemoved
local function Restore()
love.mousemoved = mousemoved
love.keypressed = keypressed
love.mousepressed = mousepressed
love.update = update
love.draw = draw
end
local optionIdx
local function Draw()
end
local function Update()
end
local function MousePress()
end
local function KeyPress()
end
love.draw = Draw
--[[function love.draw()
love.graphics.print( "a" )
end
function love.update()
end]]
--[[love.mousepressed = function()
end
love.draw = function()
end
love.update = function()
end
love.keypressed = function()
end
love.mousemoved = function()
end]]

0
scores.lua Normal file
View File

View File

@ -10,6 +10,7 @@ local poemLines = {[0] = 0}
local mt = { __index = function() return "linja" end } local mt = { __index = function() return "linja" end }
local s = love.filesystem.read( "text/tok.txt" ) 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 enFont = love.graphics.setNewFont( "text/linja-sike.ttf", 18 )
local smallFont = love.graphics.setNewFont( "text/linja-sike.ttf", 24 ) local smallFont = love.graphics.setNewFont( "text/linja-sike.ttf", 24 )
local largeFont = love.graphics.setNewFont( "text/linja-sike.ttf", 64 ) local largeFont = love.graphics.setNewFont( "text/linja-sike.ttf", 64 )
@ -39,11 +40,11 @@ for foot in s:gmatch( ".-%-" ) do
local j = 1 local j = 1
for w in foot:gmatch( [["]] ) do for w in foot:gmatch( [["]] ) do
word[j] = isTe and "te" or "to" word[j] = isTe and "te" or "to"
isTe = not( isTe ) isTe = not( isTe )
j = j + 1 j = j + 1
end end
for w in foot:gmatch( "%a+" ) do for w in foot:gmatch( "%a+" ) do
@ -57,21 +58,28 @@ end
local function Draw( beat ) local function Draw( beat )
local foot = feet[ beat ] local foot = feet[ beat ]
if beat == 1 then if beat == 1 then
love.graphics.setColor(0.0, 0.0, 0.0, 1.0) love.graphics.setColor(1.0, 1.0, 1.0, 1.0)
love.graphics.printf( "your.own.drum", love.graphics.printf( "your.own.drum",
0, 0, largeFont,
love.graphics.getWidth(), 0, 0,
"center" love.graphics.getWidth(),
"center"
) )
love.graphics.printf( "wasd.space", love.graphics.printf(
0, 0.87 * love.graphics.getHeight(), [[
love.graphics.getWidth(), wasd move
"center" space restart
) return recall
return o options]],
instrFont,
0, love.graphics.getHeight() - 4 * instrFont:getHeight(),
love.graphics.getWidth(),
"left"
)
return
end end

View File

@ -46,10 +46,10 @@ local shader = love.graphics.newShader([[
vec2 p = (3.0 * screen_coords - 1.5 * love_ScreenSize.xy ) / love_ScreenSize.y; vec2 p = (3.0 * screen_coords - 1.5 * love_ScreenSize.xy ) / love_ScreenSize.y;
p.y = -p.y; p.y = -p.y;
float r = r( atan(p.y, p.x) ) - length( p ); float r = r( atan(p.y, p.x) ) - length( p );
float q = float( r < 0.05 ) * clamp( 1.0 - score, 0.0, 1.0 ) ; float q = float( r < 0.05 ) * clamp( 1.0 - score, 0.0, 1.0 ) ;
return vec4( q + (1.0 + clamp( score, 0.0, 1.0 ) * r * r * 0.5) * color.xyz, float(r > 0.0) ) ; return vec4( q + (1.0 + clamp( score, 0.0, 1.0 ) * r * r * 0.3) * color.xyz, float(r > 0.0) ) ;
} }
]]) ]])