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 zcmb_aZA?>V6h4<;3T36xLPjevS*0{Mo4f$PJ2@#n4FCZ$JgES1tf(!QyeZNW3 z%#m&OEkN0nZ>{Xip5G7Du+!7_JhoFa{9~j}8R} zB}{Yhns&DH@Q#I%(Hz?E2SHl2Y%S=naCsmfFGaD`%Wkuw z;2R33XZ?k5BA5`#43HuU7I^xRD7Ng$jCO+)&w$HS9fS&nJ0!3Sk;|A2ra`Om;4>4` z^Tn$XE@LW)F510n6CwSsq0)!^i;s=Wx$1}ySs=S*yVg3rxfx?NAsaVXOp$Ah!AT>x5s2>i^dO%p9=X{gN{1U*m53Fw#ua!;1>m&g;L{ADeP7J zfgep!u&^(>vaEtHS7^9?&USh$H0@J51Wn2%-@@>F=D-TupQuo+qfVy%^|2d!oYUV+ z@0l)OVd~&0Cw23WpxJlIksP5Ozg77yNcQ$!6isISK5r%`aARRQ*O7IU93aUU8+Vi4>V~XWqy}Gu^6N zuX{oj4XS9kIfxK9l5a17E-&jJ(zdcuqbJUb$F`99_&HVc=EI~JSWPJdpF}gmx%id! z9$EJ^u|AZaE&x3a?K=Cs7+tRbLnvsNh=B*bHpfkisVL+(+W)S-^y$oMphdn`Z#2p* zjZ543SYLO9^V6BU5mj&$>9kOITa>s?w@)?EJGLg)JSX;o+}KM%&n?@&FzOMMN-hv} zmWK~J