From 11865da481a9890d41497265c540f1c76708e96a Mon Sep 17 00:00:00 2001 From: yaw-man Date: Fri, 13 Jan 2023 14:28:58 -0400 Subject: [PATCH] Render sitelen pona --- main.lua | 76 +++++++++++++++++++++++++++------------- sitelenpona.lua | 18 ++++++++++ sitelenpona/q.png | Bin 0 -> 1436 bytes text.lua | 17 +++++++++ en.txt => text/en.txt | 0 tok.txt => text/tok.txt | 0 6 files changed, 87 insertions(+), 24 deletions(-) create mode 100644 sitelenpona.lua create mode 100644 sitelenpona/q.png create mode 100644 text.lua rename en.txt => text/en.txt (100%) rename tok.txt => text/tok.txt (100%) 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 0000000000000000000000000000000000000000..0733aca67e94d29a71f651f4f3193afccf5dc253 GIT binary patch literal 1436 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZxy-8q?;Kn_c~qpu?a z!^VE@KZ&eBK4*bPWHAE+-w_aIoT|+y&A`BF=;`7ZQW5v|?(MwWZXynWtN;H$pBr(b z;i1W@Bd>YBM>PoUw-7vFS>4u?YX9%wQ)Z7}uRr@McrYmVP#c}eXP4FM_x<%HH@B2!WEJ0~VnM;ob zNIqd>l(-Vw{QvH(`u{7Q%gQ)2@NG&H*w^;&)xrB-EYB1fY)q?rD*S+M`?R3*0MH8z zX%ZXC;}_p-AS|B8CWE0 z{vFXh(5u`0zT&*GAA@=E)dSIP#X=3UcO-q#o%@sXz>zoKa#R^6TUGziom~A%pup(# z1L?YNk5~*EH?!RfdQr$EaYyp-ex7{~^MUC>*7gsZ{C0+BtE?ZfdHaML4ocLVdm{GW z*tCWJe>MD9Vqm^m{N4P^9w&ypV}0kXZI~sFOuKtuHAPpwfl;Dvof3nv@gI<7Mt|No zGU$DK_px5G=J5GAP}n?h$}X$FF&X4ZpF{7?3$i3Iwas75!O+49LA*a&9Z9E~9r&4db}{fc zvFvC<7{+s?nBklnL$e^`ITZ$hZ$Gv^zEPxbiW3rR6qA3FCUDxw^`Ac<_juALEnuSF zYyGGDY4)`mSzAy{8yM`ia0fg0V9nkAxBpr;BOHe2T_Beyty25_b#@tFPy%9mrgGro zAD0E4f9^}S#CY9%$^uS!d5j8YsO5NQ(xo^MC^Ki1o!vjiwStWqS5#8}0!vf|Pgg&e IbxsLQ03jg{Y5)KL literal 0 HcmV?d00001 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