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 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
end
local function DeleteRight()
return DeleteLeft() + 45
return DeleteLeft() + h / 10 - 12
end
local function DrawSelection( )
@ -41,8 +50,9 @@ local function PopulateGameList()
local x, y = 15, i * h / 10
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.line( DeleteLeft() + 5, y + 5, DeleteRight() - 5, y + h / 10 - 17 )
end
love.graphics.setCanvas()
@ -60,27 +70,27 @@ love.update = function() end
love.draw = function()
love.graphics.draw( canvas, 0, -scrollOffset * h / 10 )
love.graphics.setColor( 1.0, 1.0, 1.0, 0.5 )
love.graphics.draw( canvas, 0, 15 - scrollOffset * h / 10 )
love.graphics.setColor( 0, 0, 0, 0.5 )
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
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
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.print( "DEMOS "..( gameList[selectedGame] or selectedGame ) )
love.graphics.print( "DEMOS."..( gameList[selectedGame] or "" ) )
end
love.mousemoved = function( x, y, dx, dy, istouch)
deleteGame = ( x > DeleteLeft() ) and ( x < DeleteRight() )
selectedGame = scrollOffset + math.floor( 10 * y / h )
deleteGame = ( x > DeleteLeft() )
selectedGame = math.max( math.min( #gameList, scrollOffset + math.floor( 10 * ( y - 15 ) / h ) ), 1)
end
love.keypressed = function( key, code, isRepeat )
local KeyPress = function( key, code, isRepeat )
if code == "return" then
return OnClick()
end
@ -104,11 +114,13 @@ love.keypressed = function( key, code, isRepeat )
end
return
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
OnClick = function( x, y, button, istouch, presses )
OnClick = function( )
if not selectedGame then return end
if #gameList < 1 then return end
@ -118,12 +130,7 @@ OnClick = function( x, y, button, istouch, presses )
end
--Restore main state.
love.update = _Update
love.draw = _Draw
love.mousepressed = _MousePressed
love.keypressed = _KeyPressed
love.resize = _Resize
love.mousemoved = nil
RestoreMainState()
return "demos/"..gameList[selectedGame]
end
@ -131,4 +138,4 @@ end
PopulateGameList()
return OnClick
return OnClick, KeyPress

View File

@ -27,11 +27,11 @@ state = {
state.longestStreak = 0
state.currentStreak = 0
state.lastCollisionTick = 0
state.lastCollisionX = 0
state.lastCollisionY = 0
end,
finishTime = 0.0,
timeToSimulate = 0.0,
isGameStarted = false,
lastBeatScore = 0.0,
currentBeat = 1,
longestStreak = 0,
@ -82,11 +82,13 @@ OnImpact = function( impact )
end
local x, y = math.cos(impact.th), math.sin(impact.th)
particles:setPosition( impact.r * x, impact.r * y )
local x, y = impact.r * math.cos(impact.th), impact.r * math.sin(impact.th)
particles:setPosition( x, y )
particles:setEmissionArea( "normal", 0.1, 0.2, impact.th, true )
particles:emit( 50 * score * score )
state.lastCollisionX, state.lastCollisionY = transform:transformPoint( 1.2 * x, 1.2 * y )
audio.OnImpact( impact, score, pass, state.currentBeat )
marble.OnImpact( impact, state.currentBeat )
wave.OnImpact( impact, state.currentBeat )
@ -138,6 +140,8 @@ end
function love.load()
UpdateWindowTransform( love.graphics.getDimensions() )
options = {}
do--particle system setup
particles = love.graphics.newParticleSystem(
@ -294,6 +298,8 @@ Draw = function()
love.graphics.draw(particles, 0, 0)
wave.Draw( score )
love.graphics.pop()
@ -301,9 +307,11 @@ Draw = function()
marble.Draw()
text.Draw( state.currentBeat )
love.graphics.print( state.tick, 400, 400, 0, 1, 1 )
love.graphics.print( state.currentStreak, 400, 450, 0, 1, 1 )
love.graphics.print( state.lastCollisionTick, 400, 500, 0, 1, 1 )
love.graphics.setColor( 0.3, 0.3, 0.3, 1.0 - score )
local s = "+"..state.currentStreak..(state.currentStreak > 50 and "!" or "")
love.graphics.print( s, state.lastCollisionX, state.lastCollisionY, 0, 0.5 - 0.1 * score, 0.5 - 0.1 * score)
end
@ -345,18 +353,28 @@ Update = function( dt )
end
_Update = Update
local function OptionsMenu()
dofile "options.lua"
end
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)
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
end
end
function love.keypressed( key, code, isRepeat )
if key == "escape" then return love.event.quit() end
if key == "space" then return NewGame() end
if code == "escape" then return love.event.quit() end
if code == "space" then return NewGame() end
if code == "return" then return LoadGame() end --Play demo.
if code == "o" then return OptionsMenu() end
if state.isDemo then return end
return marble.OnKey( state.tick )
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 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 )
@ -59,17 +60,24 @@ local function Draw( beat )
local foot = feet[ beat ]
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",
largeFont,
0, 0,
love.graphics.getWidth(),
"center"
)
love.graphics.printf( "wasd.space",
0, 0.87 * love.graphics.getHeight(),
love.graphics.printf(
[[
wasd move
space restart
return recall
o options]],
instrFont,
0, love.graphics.getHeight() - 4 * instrFont:getHeight(),
love.graphics.getWidth(),
"center"
"left"
)
return
end

View File

@ -49,7 +49,7 @@ local shader = love.graphics.newShader([[
float r = r( atan(p.y, p.x) ) - length( p );
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) ) ;
}
]])