Adding options menu, local leaderboard.
This commit is contained in:
parent
337e0ce154
commit
32a154cabe
49
loadgame.lua
49
loadgame.lua
|
@ -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,31 +70,31 @@ 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
|
||||
|
||||
|
||||
if code == "down" then
|
||||
|
||||
if selectedGame < #gameList then
|
||||
|
@ -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
|
40
main.lua
40
main.lua
|
@ -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,10 +82,12 @@ 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 )
|
||||
|
@ -137,6 +139,8 @@ end
|
|||
|
||||
function love.load()
|
||||
UpdateWindowTransform( love.graphics.getDimensions() )
|
||||
|
||||
options = {}
|
||||
|
||||
|
||||
do--particle system setup
|
||||
|
@ -293,6 +297,8 @@ Draw = function()
|
|||
love.graphics.setColor( 1.0, 1.0, 1.0, 1.0 )
|
||||
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
|
||||
|
|
|
@ -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]]
|
34
text.lua
34
text.lua
|
@ -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 )
|
||||
|
@ -39,11 +40,11 @@ for foot in s:gmatch( ".-%-" ) do
|
|||
local j = 1
|
||||
|
||||
for w in foot:gmatch( [["]] ) do
|
||||
|
||||
|
||||
word[j] = isTe and "te" or "to"
|
||||
isTe = not( isTe )
|
||||
j = j + 1
|
||||
|
||||
|
||||
end
|
||||
|
||||
for w in foot:gmatch( "%a+" ) do
|
||||
|
@ -57,21 +58,28 @@ end
|
|||
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",
|
||||
0, 0,
|
||||
love.graphics.getWidth(),
|
||||
"center"
|
||||
largeFont,
|
||||
0, 0,
|
||||
love.graphics.getWidth(),
|
||||
"center"
|
||||
)
|
||||
|
||||
love.graphics.printf( "wasd.space",
|
||||
0, 0.87 * love.graphics.getHeight(),
|
||||
love.graphics.getWidth(),
|
||||
"center"
|
||||
)
|
||||
return
|
||||
love.graphics.printf(
|
||||
[[
|
||||
wasd move
|
||||
space restart
|
||||
return recall
|
||||
o options]],
|
||||
instrFont,
|
||||
0, love.graphics.getHeight() - 4 * instrFont:getHeight(),
|
||||
love.graphics.getWidth(),
|
||||
"left"
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
|
|
4
wave.lua
4
wave.lua
|
@ -46,10 +46,10 @@ local shader = love.graphics.newShader([[
|
|||
vec2 p = (3.0 * screen_coords - 1.5 * love_ScreenSize.xy ) / love_ScreenSize.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 ) ;
|
||||
|
||||
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) ) ;
|
||||
}
|
||||
]])
|
||||
|
||||
|
|
Loading…
Reference in New Issue