Fixed bug: options and demo menu not working in fused mode.

This commit is contained in:
yaw-man 2023-01-27 12:15:13 -04:00
parent 0a300b018c
commit 7a1533a6a7
7 changed files with 264 additions and 155 deletions

View File

@ -1,5 +1,6 @@
function love.conf( t )
t.version = "11.4"
t.identity = "Your Own Drum"
t.modules.joystick = false
t.modules.physics = false

View File

@ -1,10 +1,12 @@
--UI for selecting a saved game.
local love = love
local loadGame = {}
local _Update = love.update
local _Draw = love.draw
local _MousePressed = love.mousepressed
local _Resize = love.resize
local _KeyPressed = love.keypressed
love.mouse.setRelativeMode( false )
local function RestoreMainState()
love.update = _Update
@ -13,6 +15,7 @@ local function RestoreMainState()
love.keypressed = _KeyPressed
love.resize = _Resize
love.mousemoved = nil
love.mouse.setRelativeMode( true )
end
local selectedGame = 1
@ -23,6 +26,8 @@ local mouseX, mouseY = 0, 0
local w, h = love.graphics.getDimensions()
local canvas = love.graphics.newCanvas( w, h * (1 + #gameList) / 10.0 )
local font = love.graphics.newFont( 36 )
local deleteIcon = love.graphics.newImage( "sitelenpona/ala.png" )
local playIcon = love.graphics.newImage( "sitelenpona/li.png" )
local OnClick
@ -42,59 +47,71 @@ local function PopulateGameList()
scrollOffset = 0
gameList = assert( love.filesystem.getDirectoryItems( "demos" ) )
canvas = love.graphics.newCanvas( w, h * (1 + #gameList) / 10.0 )
love.graphics.setCanvas( canvas )
love.graphics.clear()
love.graphics.setColor( 0.2, 0.2, 0.2, 0.5 )
love.graphics.setColor( 1, 1, 1, 1 )
love.graphics.setLineWidth( 3 )
for i, name in ipairs( gameList ) do
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.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 )
love.graphics.draw( deleteIcon, DeleteLeft() - 8, y - 8, 0, 0.25, 0.25 )
end
love.graphics.setCanvas()
end
love.resize = function( newWidth, newHeight )
local resizeLoadMenu = function( newWidth, newHeight )
_Resize(newWidth, newHeight )
w, h = love.graphics.getDimensions()
canvas = love.graphics.newCanvas()
canvas = love.graphics.newCanvas( w, h * (1 + #gameList) / 10.0 )
return PopulateGameList()
end
love.update = function() end
love.draw = function()
local updateLoadMenu = function() end
local drawLoadGameMenu = function()
love.graphics.setColor( 1, 1, 1, 1 )
love.graphics.draw( canvas, 0, 15 - scrollOffset * h / 10 )
love.graphics.setColor( 0, 0, 0, 0.5 )
love.graphics.setColor( 1.0, 1.0, 1.0, 1.0 )
love.graphics.rectangle( "fill", 0, 0, w, 10 + h / 10 - 6 )
love.graphics.setColor( 91 / 255, 206 / 255, 250 / 255 )--
love.graphics.print( "BACK")
if not selectedGame then return end
love.graphics.setColor( 1, 1, 1, 0.4 )
if deleteGame then
love.graphics.rectangle( "fill", DeleteLeft(), 15 + ( selectedGame - scrollOffset ) * h / 10, h / 10 - 12, h / 10 - 12, 10, 10 )
love.graphics.rectangle( "fill",
DeleteLeft(), 15 + ( selectedGame - scrollOffset ) * h / 10,
48, 48,
10, 10 )
else
love.graphics.rectangle( "fill", 15, 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 )
48, 10, 10)
end
love.graphics.setColor( 1.0, 1.0, 1.0, 1.0 )
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 "" ) )
end
love.mousemoved = function( x, y, dx, dy, istouch)
local mouseMoved = function( x, y, dx, dy, istouch)
deleteGame = ( x > DeleteLeft() )
selectedGame = math.max( math.min( #gameList, scrollOffset + math.floor( 10 * ( y - 15 ) / h ) ), 1)
if y < 4 + h / 10 then selectedGame = nil end
end
local KeyPress = function( key, code, isRepeat )
if code == "return" then
return OnClick()
end
if not selectedGame then selectedGame = 1 end
if code == "down" then
@ -106,7 +123,7 @@ local KeyPress = function( key, code, isRepeat )
end
return
end
if key == "up" then
if code == "up" then
if selectedGame > 9 then
scrollOffset = scrollOffset - 1
end
@ -121,7 +138,8 @@ local KeyPress = function( key, code, isRepeat )
end
OnClick = function( )
OnClick = function( x, y, button, istouch, presses )
if y and y < 4 + h / 10 then return RestoreMainState() end
if not selectedGame then return end
if #gameList < 1 then return end
@ -136,7 +154,19 @@ OnClick = function( )
end
PopulateGameList()
local wheelMoved = function(x, y)
scrollOffset = math.max( 0, math.min( #gameList, scrollOffset - y * 0.1 ) )
end
return OnClick, KeyPress
local function LoadGameMenu()
love.wheelmoved = wheelMoved
love.mousemoved = mouseMoved
love.draw = drawLoadGameMenu
love.update = updateLoadMenu
love.resize = resizeLoadMenu
PopulateGameList()
end
return { OnClick = OnClick, KeyPress = KeyPress, LoadGameMenu = LoadGameMenu }

View File

@ -15,6 +15,7 @@ local Draw
local Update
local ExtrapolateBeatScore
local _ExtrapolateBeatScore
local mouseControl
local scores
local state
@ -127,6 +128,7 @@ local function NewGame( demoName )
245 / 255, 169 / 255, 184 / 255, 1,
1,1,1,0)
end
mouseControl.Reset()
state.Reset()
marble.Reset()
wave.Reset()
@ -142,9 +144,10 @@ local function NewGame( demoName )
end
function love.load()
love.mouse.setRelativeMode( true )
UpdateWindowTransform( love.graphics.getDimensions() )
options = {}
do--particle system setup
@ -157,7 +160,8 @@ function love.load()
end
options = assert( require( "options" ) )
mouseControl = assert( require "mousecontrols" )
sitelenpona = assert( require "sitelenpona" )
text = assert( require "text" )
marble = assert( require "marble" )
@ -285,6 +289,8 @@ OnVictory = function()
end
Draw = function()
local score = ExtrapolateBeatScore()
@ -352,11 +358,13 @@ end
_Update = Update
local function OptionsMenu()
dofile "options.lua"
if not options then options = require( "options" ) end
return options.EnterMenu()
end
local function LoadGame() -- Load game screen.
local Click, Press = assert( dofile "loadgame.lua" )
if not loadGame then loadGame = assert( require "loadgame" ) end
local Click, Press = assert(loadGame.OnClick), assert(loadGame.KeyPress)
love.mousepressed = function( x, y, button, istouch, presses)
local demoName = Click( x, y, button, istouch, presses )
if demoName then return NewGame( demoName ) end
@ -366,6 +374,8 @@ local function LoadGame() -- Load game screen.
local demoName = Press( key, code, isRepeat )
if demoName then return NewGame( demoName ) end
end
loadGame.LoadGameMenu()
end
function love.keypressed( key, code, isRepeat )
@ -374,11 +384,21 @@ function love.keypressed( key, code, isRepeat )
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 )
return marble.OnKey(
love.keyboard.isScancodeDown( options.up.value ),
love.keyboard.isScancodeDown( options.left.value ),
love.keyboard.isScancodeDown( options.down.value ),
love.keyboard.isScancodeDown( options.right.value )
)
end
function love.keyreleased( key, code )
return marble.OnKey( state.tick )
return marble.OnKey(
love.keyboard.isScancodeDown( options.up.value ),
love.keyboard.isScancodeDown( options.left.value ),
love.keyboard.isScancodeDown( options.down.value ),
love.keyboard.isScancodeDown( options.right.value ) )
end
function love.resize( w, h )
@ -386,6 +406,12 @@ function love.resize( w, h )
if marble then marble.Resize() end
end
--TODO: make this feel better.
function love.mousemoved( x, y, dx, dy, number, istouch )
dx, dy = mouseControl.mousemoved( dx, dy )
if dx then return marble.SetAcceleration( dx, dy ) end
end
function love.mousepressed( x, y, button, istouch, presses )
return NewGame()
end

View File

@ -87,9 +87,10 @@ function marble.Update()
end
function marble.OnKey( tick )
ddx = (love.keyboard.isScancodeDown( "d" ) and 1.0 or 0.0) - (love.keyboard.isScancodeDown( "a" ) and 1.0 or 0.0)
ddy = (love.keyboard.isScancodeDown( "w" ) and 1.0 or 0.0) - (love.keyboard.isScancodeDown( "s" ) and 1.0 or 0.0)
function marble.OnKey( w, a, s, d )
--print( w, a, s, d )
ddx = (d and 1.0 or 0.0) - (a and 1.0 or 0.0)
ddy = (w and 1.0 or 0.0) - (s and 1.0 or 0.0)
--print( tick, ddx, ddy )
local n = math.sqrt( ddx * ddx + ddy * ddy )

25
mousecontrols.lua Normal file
View File

@ -0,0 +1,25 @@
local mouseControl = {}
local love = love
local t = love.timer.getTime()
function mouseControl.Reset()
t = love.timer.getTime()
end
function mouseControl.mousemoved( dx, dy )
local dt = love.timer.getTime()
if dt - t < 1 / 1000.0 then return end
dt, t = dt - t, dt
dx, dy = dx * dt, -dy * dt
local norm = math.sqrt( dx * dx + dy * dy )
if norm > 1 then dx, dy = dx / norm, dy / norm end
if norm < 0.01 then return 0, 0 end
return dx, dy
end
return mouseControl

View File

@ -5,8 +5,144 @@ local update = love.update
local mousepressed = love.mousepressed
local keypressed = love.keypressed
local mousemoved = love.mousemoved
local ExitMenu
local function Restore()
options = options or {}
local options = options
local optionList = {}
local option
if not options.initialized then
options.initialized = true
local keyBindCallback = function(self, code)
self.value = code
end
options.optionValues = {
{ name = "options",
value = "back",
callback = function(self)
return ExitMenu()
end
},
{ name = "high contrast",
value = false,
callback = function(self, code)
if code == "return" or code == "backspace" then return end
self.value = not( self.value )
end
},
{ name = "volume",
value = 1.0,
callback = function(self, code)
local isIncreasing
if (code == "left" or code == "a") then isIncreasing = -1
elseif (code == "right" or code == "d") then isIncreasing = 1
else return false end
self.value = math.max( 0, math.min( 1,
self.value + (isIncreasing * 0.05 )))
return true
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
}
}
do
for i, ov in ipairs( options.optionValues ) do
options[ ov.name ] = ov
end
end
end
local optionIdx = 1
local isAwaitingKey = false
local font = love.graphics.newFont( 32 )
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
local w = love.graphics.getWidth()
love.graphics.setColor( 1,1,1,0.5 )
if isAwaitingKey then
love.graphics.rectangle( "fill", w - 200, optionIdx * 50, 100, 48, 10, 10 )
else
love.graphics.rectangle( "fill", 100, optionIdx * 50, 250, 48, 10, 10 )
end
end
local function SelectNextOption()
optionIdx = math.min( #options.optionValues, optionIdx + 1 )
option = options.optionValues[ optionIdx]
end
local function SelectPreviousOption()
optionIdx = math.max( 1, optionIdx - 1 )
option = options.optionValues[ optionIdx]
end
local function KeyPress(key, code, isRepeat)
if code == "backspace" then return ExitMenu() end
if isAwaitingKey then
if code == "escape" then return end
isAwaitingKey = (options.optionValues[optionIdx]):callback( code )
end
if code == "return" and optionIdx then isAwaitingKey = true; return end
if code == "down" then return SelectNextOption() end
if code == "up" then return SelectPreviousOption() end
end
local function EnterMenu()
draw = love.draw
update = love.update
mousepressed = love.mousepressed
keypressed = love.keypressed
mousemoved = love.mousemoved
love.draw = Draw
love.keypressed = KeyPress
love.update = function() end
end
function ExitMenu()
love.mousemoved = mousemoved
love.keypressed = keypressed
love.mousepressed = mousepressed
@ -14,126 +150,7 @@ local function Restore()
love.draw = draw
end
local options = options
local optionList = {}
options.EnterMenu = EnterMenu
options.ExitMenu = ExitMenu
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(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" )
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]]
return options

View File

@ -9,6 +9,14 @@ function recorder.Reset()
for k, _ in ipairs( recorder ) do recorder[k] = nil end
end
function recorder.UpdateCts( ddx, ddy )
local xByte = 0
local yByte = 0
--i = i + 1
recorder[i] = love.data.pack( "data", "dd", ddx, ddy )
end
function recorder.Update( ddx, ddy )
local byte = 0
if ddx > 0.5 then byte = byte + 1 end
@ -55,6 +63,7 @@ function recorder.NextTick( )
end
function recorder.Save( )
if not love.filesystem.getInfo( "demos" ) then love.filesystem.createDirectory( "demos" ) end
return assert( love.filesystem.write( "demos/"..os.time()..".yod" , table.concat( recorder ) ) )
end