Final commit before post-jam release, "1.0.0"?

New features since last release:
  - Display score breakdown, high score, and letter grades.
  - Options menu with volume control, keybindings, and true fullscreen.
  - Demos menu. View saved games!
  - Mouse controls, sorta. Mouse controlled menus!
  - High contrast mode.
  - Instructions displayed on startup.
  - Default demo ships with game.
  - Render sitelen pona quote symbols to and te
  - Beat combo indicator.

Outstanding defects:
  - Options menu not persistent.
  - Mouse controls feel like complete dogshit.
This commit is contained in:
yaw-man 2023-01-27 23:17:46 -04:00
parent e1e00dce4c
commit 5dfd415d3b
14 changed files with 261 additions and 79 deletions

View File

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

BIN
demos/yam.yod Normal file

Binary file not shown.

View File

@ -1,17 +1,18 @@
--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 _Update
local _Draw
local _MousePressed
local _MouseMoved
local _Resize
local _KeyPressed
local function RestoreMainState()
love.update = _Update
love.draw = _Draw
love.mousepressed = _MousePressed
love.mousemoved = _MouseMoved
love.keypressed = _KeyPressed
love.resize = _Resize
love.mousemoved = nil
@ -32,7 +33,7 @@ local OnClick
local function DeleteLeft()
return w * 0.75 + 15 + 6
return love.graphics.getWidth() * 0.75 + 15 + 6
end
local function DeleteRight()
@ -46,6 +47,8 @@ end
local function PopulateGameList()
scrollOffset = 0
gameList = assert( love.filesystem.getDirectoryItems( "demos" ) )
local w, h = love.graphics.getDimensions()
canvas = love.graphics.newCanvas( w, h * (1 + #gameList) / 10.0 )
love.graphics.setCanvas( canvas )
@ -74,7 +77,11 @@ end
local updateLoadMenu = function() end
local drawLoadGameMenu = function()
local w, h = love.graphics.getDimensions()
love.graphics.setColor( 1, 1, 1, 1 )
if options["high contrast"].value then
love.graphics.setColor( 0,0,0, 1 )
end
love.graphics.draw( canvas, 0, 15 - scrollOffset * h / 10 )
@ -156,10 +163,18 @@ end
local wheelMoved = function(x, y)
scrollOffset = math.max( 0, math.min( #gameList, scrollOffset - y * 0.1 ) )
--scrollOffset = math.max( 0, math.min( #gameList, scrollOffset - y * 0.1 ) )
end
local function LoadGameMenu()
_Update = love.update
_Draw = love.draw
_MousePressed = love.mousepressed
_MouseMoved = love.mousemoved
_Resize = love.resize
_KeyPressed = love.keypressed
love.mouse.setRelativeMode( false )
love.wheelmoved = wheelMoved
love.mousemoved = mouseMoved
love.draw = drawLoadGameMenu

View File

@ -160,6 +160,7 @@ function love.load()
end
loadGame = assert( require "loadgame" )
options = assert( require( "options" ) )
mouseControl = assert( require "mousecontrols" )
sitelenpona = assert( require "sitelenpona" )
@ -231,7 +232,7 @@ OnVictory = function()
state.isDemo = false
else
scores.Save()
recorder.Save()
recorder.Save( scores.Get(), state.tick)
end
particles:setParticleLifetime( 0, 30 )
@ -262,6 +263,7 @@ OnVictory = function()
marble.Update()
wave.Update()
dt = dt - step
end
@ -331,6 +333,11 @@ Update = function( dt )
while dt > step do
state.tick = state.tick + 1
if mouseControl.isActive then
mouseControl.update()
marble.SetAcceleration( mouseControl.getAcceleration() )
end
if state.isDemo then
local ddx, ddy = recorder.NextTick()
@ -363,8 +370,10 @@ local function OptionsMenu()
end
local function LoadGame() -- Load game screen.
if not loadGame then loadGame = assert( require "loadgame" ) end
local Click, Press = assert(loadGame.OnClick), assert(loadGame.KeyPress)
loadGame.LoadGameMenu()
love.mousepressed = function( x, y, button, istouch, presses)
local demoName = Click( x, y, button, istouch, presses )
if demoName then return NewGame( demoName ) end
@ -375,7 +384,7 @@ local function LoadGame() -- Load game screen.
if demoName then return NewGame( demoName ) end
end
loadGame.LoadGameMenu()
end
function love.keypressed( key, code, isRepeat )
@ -385,6 +394,7 @@ function love.keypressed( key, code, isRepeat )
if code == "o" then return OptionsMenu() end
if state.isDemo then return end
mouseControl.isActive = false
return marble.OnKey(
love.keyboard.isScancodeDown( options.up.value ),
love.keyboard.isScancodeDown( options.left.value ),
@ -395,10 +405,10 @@ end
function love.keyreleased( key, code )
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 ) )
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 )
@ -408,6 +418,7 @@ end
--TODO: make this feel better.
function love.mousemoved( x, y, dx, dy, number, istouch )
mouseControl.isActive = true
dx, dy = mouseControl.mousemoved( dx, dy )
if dx then return marble.SetAcceleration( dx, dy ) end
end

View File

@ -84,6 +84,9 @@ function marble.Update()
oldState[k] = curState[k]
curState[k] = newState[k]
end
--Inertia.
--ddx, ddy = ddx * 0.95, ddy * 0.95
end

View File

@ -1,25 +1,37 @@
local mouseControl = {}
local mouseControl = { isActive = false }
local love = love
local t = love.timer.getTime()
local x, y = 0, 0
local DECAY = 0.8
local SENSITIVITY = 0.8
function mouseControl.Reset()
t = love.timer.getTime()
x, y = 0, 0
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 = SENSITIVITY * dx, SENSITIVITY * dy
dx, dy = dx * dx * dx , dy * dy * dy
x, y = dx + x, y - dy
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
return mouseControl.getAcceleration()
end
function mouseControl.update()
local norm = math.sqrt( x * x + y * y )
local decay = DECAY * norm / ( norm + 1 )
x, y = decay * x, decay * y
end
function mouseControl.getAcceleration()
local norm = math.sqrt( x * x + y * y )
if norm > 1 then return x / norm, y / norm end
if norm < 0.001 then return 0, 0 end
return x, y
end
return mouseControl

View File

@ -16,22 +16,31 @@ if not options.initialized then
options.initialized = true
local keyBindCallback = function(self, code)
self.value = code
self.value = code or self.value
end
options.optionValues = {
{ name = "options",
value = "back",
value = "",
callback = function(self)
return ExitMenu()
end
},
{ name = "fullscreen",
value = false,
callback = function(self)
self.value = not(self.value)
love.window.setFullscreen( self.value )
love.event.push( "resize", love.graphics.getWidth(), love.graphics.getHeight() )
end
},
{ name = "high contrast",
value = false,
callback = function(self, code)
if code == "return" or code == "backspace" then return end
if code == "backspace" then return end
self.value = not( self.value )
return false
end
},
@ -43,8 +52,9 @@ if not options.initialized then
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 = math.max( 0, math.min( 2,
self.value + (isIncreasing * 0.05 )))
love.audio.setVolume( self.value )
return true
end
@ -85,6 +95,9 @@ local isAwaitingKey = false
local font = love.graphics.newFont( 32 )
local function Draw()
love.graphics.setColor( 1,1,1,1 )
if options["high contrast"].value then
love.graphics.setColor( 0, 0, 0, 1 )
end
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")
@ -94,7 +107,7 @@ local function Draw()
local w = love.graphics.getWidth()
love.graphics.setColor( 1,1,1,0.5 )
love.graphics.setColor( 1,1,1,0.5 )
if isAwaitingKey then
love.graphics.rectangle( "fill", w - 200, optionIdx * 50, 100, 48, 10, 10 )
else
@ -113,21 +126,53 @@ local function SelectPreviousOption()
option = options.optionValues[ optionIdx]
end
local function MouseMoved( x, y )
optionIdx =
math.min( #options.optionValues,
math.max( 1,
math.floor( y / 50 )
))
option = options.optionValues[ optionIdx]
if ( x > love.graphics.getWidth() - 200 ) then
isAwaitingKey = true
else
isAwaitingKey = false
end
end
local function KeyPress(key, code, isRepeat)
if code == "backspace" then return ExitMenu() end
if isAwaitingKey then
if not( isAwaitingKey ) then
if code == "backspace" then
return ExitMenu() end
if optionIdx and
code == "return" or
code == "right" then
isAwaitingKey = true
return
end
if code == "down" then return SelectNextOption() end
if code == "up" then return SelectPreviousOption() end
else
if code == "backspace" then isAwaitingKey = false end
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 MousePressed( )
return KeyPress( )
end
local function EnterMenu()
@ -136,13 +181,17 @@ local function EnterMenu()
mousepressed = love.mousepressed
keypressed = love.keypressed
mousemoved = love.mousemoved
love.mouse.setRelativeMode( false )
love.draw = Draw
love.keypressed = KeyPress
love.update = function() end
love.mousemoved = MouseMoved
love.mousepressed = MousePressed
end
function ExitMenu()
love.mouse.setRelativeMode( true )
love.mousemoved = mousemoved
love.keypressed = keypressed
love.mousepressed = mousepressed

View File

@ -6,7 +6,7 @@ local ddxs, ddys
local i = 0
function recorder.Reset()
i = 0
i = 1
for k, _ in ipairs( recorder ) do recorder[k] = nil end
end
@ -30,7 +30,8 @@ function recorder.Load( filename )
ddxs, ddys = {}, {}
local s = love.filesystem.read( filename )
if not s then return end
local k, j = 1, 1
local j = 1
local score, ticks, k = love.data.unpack( "!16<dJ", s, 1)
local n = s:len()
while k < n do
ddxs[j], ddys[j], k = love.data.unpack( "!16<dd", s, k)
@ -47,7 +48,8 @@ function recorder.NextTick( )
return ddxs[i], ddys[i]
end
function recorder.Save( )
function recorder.Save( score, ticks )
recorder[1] = love.data.pack( "string", "!16<dJ", score, ticks )
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

View File

@ -2,31 +2,61 @@ local love = love
local scores = {}
local highScores = {}
local letters = {
letters = { "D", "C", "B", "A", "S", "SS", "SSS" },
ticks = { 50000, 14400, 12000, 10000, 8000, 6000, 5000 },
streaks = { 1, 20, 40, 60, 80, 100, 120 },
score = { 0, 5, 10, 22, 56, 150, 300 },
}
letters.letters[0] = "!"
local function ScoreToLetter( ticks, streak, score )
local streakTier, ticksTier, scoreTier = 0, 0, 0
for i, threshold in ipairs( letters.ticks ) do
if ticks < threshold then ticksTier = i end
end
for i, threshold in ipairs( letters.streaks ) do
if streak > threshold then streakTier = i end
end
for i, threshold in ipairs( letters.score ) do
if score > threshold then scoreTier = i end
end
return letters.letters[ticksTier], letters.letters[streakTier], letters.letters[scoreTier]
end
function scores.OnImpact( tick, isHitSuccessful )
local score = 0
if isHitSuccessful then
scores.streak = scores.streak + 1
scores.longestStreak = math.max( scores.streak, scores.longestStreak )
else
table.insert( scores.streaks, scores.streak)
scores.streak = 0
end
for i, streak in ipairs( scores.streaks ) do
score = score + streak * streak
score = score + math.pow( streak, 1.7 )
end
scores.score = score / math.pow( tick / 120.0, 1.5 )
scores.score = score / ( ( tick / 120.0 ) - 36.0 )
scores.t = tick
end
function scores.Reset()
scores.score = 0
scores.streak = 0
scores.longestStreak = 0
scores.highScore = scores.LoadHighScores()
scores.streaks = {}
end
function scores.Get()
return scores.score
end
function scores.Save()
@ -36,24 +66,53 @@ function scores.Save()
if highScores[j] < scores.score then break end
end
table.insert( highScores, i )
scores.highScore = math.max( scores.score, scores.highScore )
end
function scores.LoadHighScores()
local gameList = assert( love.filesystem.getDirectoryItems( "demos" ) )
local highScore = 0
for i, name in ipairs( gameList ) do
local s = love.filesystem.read( "demos/"..name, 64 )
if ( s:len() > 32 ) then
local gamescore, gameticks = love.data.unpack( "!16<dJ", s, 1)
highScore = math.max( gamescore, highScore )
end
end
return highScore
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" )
local wb = options["high contrast"].value and 0 or 1
love.graphics.setColor( wb, wb, wb, 1 )
local h = 1.0 * love.graphics.getFont():getHeight()
local y = 0.5 * love.graphics.getHeight()
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"
)
local lTick, lStreak, lScore = ScoreToLetter( scores.t, scores.longestStreak, scores.score )
love.graphics.printf(
table.concat{
"time: ",
string.format("%.1f", scores.t / 120.0):gsub("%.", ","),
".",
lTick,
"\n",
"streak: ",
scores.longestStreak,
".",
lStreak,
"\n",
"score: ",
string.format("%.1f", scores.score ):gsub("%.", ","),
".",
lScore,
"\n",
"record: ",
string.format("%.1f", math.max( scores.highScore, scores.score )):gsub("%.", ","),
".!\n"
},
love.graphics.getWidth() * 0.5 - 250, y - 2 * h, 500, "justify" )
end
scores.highScore = scores.LoadHighScores()
return scores

View File

@ -10,12 +10,12 @@ end
sp.Draw = function( t )
local cx, cy = love.graphics.getDimensions()
cx, cy = 0.5 * cx, 0.5 * cy
love.graphics.setColor( 1.0, 1.0, 1.0, 0.5 )
love.graphics.setColor( 1.0, 1.0, 1.0, options["high contrast"].value and 0.2 or 0.5)
if #t == 1 then
love.graphics.draw( sp[t[1]] or sp.pilin, cx - 128, cy - 128 )
elseif #t == 2 then
love.graphics.draw( sp[t[1]] or sp.pilin, cx - 144, cy - 96, 0, 0.75, 0.75 )
love.graphics.draw( sp[t[1]] or sp.pilin, cx - 160, cy - 96, 0, 0.75, 0.75 )
love.graphics.draw( sp[t[2]] or sp.pilin, cx - 16, cy - 96, 0, 0.75, 0.75 )
elseif #t == 3 then
love.graphics.draw( sp[t[1]] or sp.pilin, cx - 128, cy - 64, 0, 0.5, 0.5 )

BIN
sitelenpona/te.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
sitelenpona/to.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -10,7 +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 instrFont = love.graphics.newFont( 24 )
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 )
@ -60,30 +60,52 @@ local function Draw( beat )
local foot = feet[ beat ]
if beat == 1 then
love.graphics.setColor(1.0, 1.0, 1.0, 1.0)
love.graphics.setColor(0, 0, 0, 0.5)
if options["high contrast"].value then
love.graphics.setColor( 1, 1, 1, 1 )
end
love.graphics.rectangle( "fill",
0.5 * love.graphics.getWidth() - 250, 10,
500, 1.1 * largeFont:getHeight(), 10, 10 )
love.graphics.rectangle( "fill",
0.5 * love.graphics.getWidth() - 200, love.graphics.getHeight() - 5.25 * instrFont:getHeight(),
400, 4.5 * instrFont:getHeight(), 50, 50 )
love.graphics.setColor(1.0, 1.0, 1.0, 1.0 )
if options["high contrast"].value then
love.graphics.setColor( 0, 0, 0, 1 )
end
love.graphics.printf( "your.own.drum",
largeFont,
0, 0,
love.graphics.getWidth(),
"center"
)
love.graphics.printf(
[[
wasd move
space restart
return recall
o options]],
WASD MOVE
SPACE RESTART
RETURN DEMOS
O OPTIONS]],
instrFont,
0, love.graphics.getHeight() - 4 * instrFont:getHeight(),
love.graphics.getWidth(),
"left"
0.5 * love.graphics.getWidth() - 150, love.graphics.getHeight() - 5 * instrFont:getHeight(),
300,
"justify"
)
return
end
love.graphics.setColor(1.0, 1.0, 1.0, 0.5)
if options["high contrast"].value then
love.graphics.setColor( 0, 0, 0, 1 )
end
local lineNumber
if poemLines[beat] < 2 then lineNumber = 0
else lineNumber = 2 - poemLines[beat]
@ -96,6 +118,9 @@ o options]],
)
love.graphics.setColor(1.0, 1.0, 1.0, 1.0)
if options["high contrast"].value then
love.graphics.setColor( 0, 0, 0, 1 )
end
love.graphics.printf( foot,
largeFont,
0, 0.87 * love.graphics.getHeight(),
@ -104,6 +129,9 @@ o options]],
)
love.graphics.setColor(1.0, 1.0, 1.0, 0.5)
if options["high contrast"].value then
love.graphics.setColor( 0, 0, 0, 1 )
end
love.graphics.printf( poemLang[beat],
enFont,
-8, 0,--(2 - poemLines[beat]) * smallFont:getHeight(),
@ -115,7 +143,7 @@ o options]],
end
s = love.filesystem.read( "text/en.txt" )
i = 1
i = 0
--Split string into lines.
for line in s:gmatch( ".-\n") do

View File

@ -149,7 +149,7 @@ end
--Apply bandlimited impulse to wave, adjust free parameters according to game state.
local function OnImpact( impact, level )
IMPULSESIZE = 10.0 * ( level - 2.0) / 120.0
SOUNDSPEED = 25 - 10 * level / 120
DAMPING = 0.01 * ( 1.0 - 0.4 * level / 120 )
@ -201,7 +201,11 @@ local function Draw( score )
-- Blue circle.
love.graphics.setColor( 91 / 255, 206 / 255, 250 / 255 )
--Black circle.
if options["high contrast"].value then
love.graphics.setColor( 0, 0, 0 )
end
shader:send( "re", unpack( cur.dftre ) )
shader:send( "im", unpack( cur.dftim ) )
shader:send( "score", score )
@ -255,7 +259,7 @@ local function Draw( score )
local r = cur:Interpolate( t )
local x, y = r * math.cos( t ), r * math.sin( t )
love.graphics.circle( "fill", x, y, 0.02 )]]
end
@ -279,12 +283,12 @@ end
Integrate = function( step )
for i = 1, N do
local rxx = cur:SecondDerivative( math.pi * 2.0 * ( i - 1 ) / N )
local r = ( 1.0 - DAMPING ) * ( 2.0 * cur.radii[i] - old.radii[i] + step * step * SOUNDSPEED * rxx ) --Verlet
+ DAMPING --Damping: oscillate toward 1.
--Avoid explosions.
r = math.max( 0.5, math.min( r, 4.0 ) )
new.radii[i] = r
@ -299,11 +303,11 @@ local function DetectCollision( px, py, vpx, vpy )
end
local function Reset()
IMPULSESIZE = 1 / 10.0
SOUNDSPEED = 5.0
DAMPING = 0.1 / 1
old = Wave()
cur = Wave()
new = Wave()