Render sitelen pona

This commit is contained in:
yaw-man 2023-01-13 14:28:58 -04:00
parent fd520944e4
commit 11865da481
6 changed files with 87 additions and 24 deletions

View File

@ -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

18
sitelenpona.lua Normal file
View File

@ -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

BIN
sitelenpona/q.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

17
text.lua Normal file
View File

@ -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

View File