diff --git a/main.lua b/main.lua index 5d51ff0..3767754 100644 --- a/main.lua +++ b/main.lua @@ -1,15 +1,30 @@ local love = love +local sitelenpona +local text + local sounds = { } -local state = { + +local state +state = { + + Reset = function() + state.beat = {} + state.startTime = love.timer.getTime() + state.currentBeat = 1 + end, isGameStarted = false, beatScoreThreshold = 1.0, currentBeat = 1, startTime = 0.0, + + stickX = 0.0, + stickY = 0.0, + stickT = 0.0, particle = { x = 0.0, @@ -46,14 +61,16 @@ local state = { }, } +function love.load() + sounds.goodPing = love.audio.newSource("soundTest.ogg", "static") + sounds.badPing = love.audio.newSource("chime8.ogg", "static") + sitelenpona = assert( require "sitelenpona" ) + text = assert( require "text" ) + return state.Reset() ---Reset game state. -local function NewGame() - state.beat = {} - state.startTime = love.timer.getTime() - state.currentBeat = 1 end + local function BeatScore( t ) local beat = state.beat @@ -84,11 +101,11 @@ local function BeatScore( t ) --Calculate beat score. local score = dt * dt / ( mu * mu ) - local TOLERANCE = 1.15 + local TOLERANCE = 1.00001 if dt < mu then - return 1.15 * score + return TOLERANCE * score else - return 1.15 / score + return TOLERANCE / score end end @@ -107,12 +124,11 @@ local function OnImpact( impact ) if state.currentBeat >= 120 then return OnVictory() end - love.audio.play(sounds.goodPing) else - state.beatScoreThreshold = state.beatScoreThreshold - score + state.beatScoreThreshold = state.beatScoreThreshold - 0.05 love.audio.play(sounds.badPing) end @@ -123,29 +139,41 @@ end function love.draw() love.graphics.setColor(1.0, 1.0, 1.0) - love.graphics.print("Hello World!", 400, 300) - love.graphics.print( state.beat.mu or 0, 0, 0, 0, 10, 10 ) - love.graphics.print( state.beat.t or 0, 0, 100, 0, 10, 10 ) - love.graphics.print( state.beatScoreThreshold, 0, 200, 0, 10, 10 ) + love.graphics.print( state.beat.mu or 0, 0) + love.graphics.print( state.beat.t or 0, 0, 10) + love.graphics.print( state.beatScoreThreshold, 0, 20) love.graphics.setColor(0, 0.4, 0.4) - --love.graphics.circle("fill", 0, 0, 10) + sitelenpona.Draw( text.tok[state.currentBeat] ) + love.graphics.setColor(0.5, 0.2, 0.8, 0.5) + love.graphics.circle("fill", 0, 0, 10) end -function love.load() - sounds.goodPing = love.audio.newSource("soundTest.ogg", "static") - sounds.badPing = love.audio.newSource("chime8.ogg", "static") - return NewGame() - -end function love.update( dt ) end +local function UpdateStick() + state.stickT = love.timer.getTime() + local x = (love.keyboard.isDown( "w" ) and 1.0 or 0.0) - (love.keyboard.isDown( "s" ) and 1.0 or 0.0) + local y = (love.keyboard.isDown( "d" ) and 1.0 or 0.0) - (love.keyboard.isDown( "a" ) and 1.0 or 0.0) + local n = math.sqrt( x * x + y * y ) + if n < 0.001 then + state.stickX = x + state.stickY = y + else + state.stickX = x / n + state.stickY = y / n + end +end function love.keypressed( key, code, isRepeat ) if key == "escape" then return love.event.quit() end - if key == "w" then return OnImpact{ t = love.timer.getTime() } end - if key == "enter" then return NewGame() end + if key == "enter" then return OnImpact{ t = love.timer.getTime() } end + return UpdateStick() +end + +function love.keyreleased( key, code ) + return UpdateStick() end \ No newline at end of file diff --git a/sitelenpona.lua b/sitelenpona.lua new file mode 100644 index 0000000..54b4bdd --- /dev/null +++ b/sitelenpona.lua @@ -0,0 +1,18 @@ +--Render Sitelen Pona text. One file per glyph. +local love = love +local sp = {} + +local info = love.filesystem.getInfo( "sitelenpona" ) +for _, filename in ipairs(love.filesystem.getDirectoryItems( "sitelenpona" )) do + sp[filename:gsub( ".png", "" )] = love.graphics.newImage( "sitelenpona/"..filename ) +end +--Render one glyph in the center. +sp.Draw = function( str ) + local w, h = love.graphics.getDimensions() + local x, y = 0.5 * w - 128, 0.5 * h - 128 + love.graphics.setColor( 1.0, 1.0, 1.0, 0.5 ) + love.graphics.draw( sp[str] or sp.q, x, y ) +end + + +return sp \ No newline at end of file diff --git a/sitelenpona/q.png b/sitelenpona/q.png new file mode 100644 index 0000000..0733aca Binary files /dev/null and b/sitelenpona/q.png differ diff --git a/text.lua b/text.lua new file mode 100644 index 0000000..653f39c --- /dev/null +++ b/text.lua @@ -0,0 +1,17 @@ +--Load poems. +local love = love +local txt = {} + +local info = love.filesystem.getInfo( "text" ) +for _, filename in ipairs(love.filesystem.getDirectoryItems( "text" )) do + local s = love.filesystem.read( "text/"..filename ) + local t = {} + local i = 1 + for w in s:gmatch( "%a+") do + t[i] = w + i = i + 1 + end + txt[filename:gsub( ".txt", "" )] = t +end + +return txt \ No newline at end of file diff --git a/en.txt b/text/en.txt similarity index 100% rename from en.txt rename to text/en.txt diff --git a/tok.txt b/text/tok.txt similarity index 100% rename from tok.txt rename to text/tok.txt