118 lines
2.2 KiB
Lua
118 lines
2.2 KiB
Lua
local love = love
|
|
local sound
|
|
local state = {
|
|
|
|
isGameStarted = false,
|
|
|
|
particle = {
|
|
x = 0.0,
|
|
y = 0.0,
|
|
dx = 0.0,
|
|
dy = 0.0,
|
|
ddx = 0.0,
|
|
ddy = 0.0,
|
|
Update = function() end,
|
|
Draw = function() end
|
|
},
|
|
|
|
wave = {
|
|
x = { 1.0, 0.0, -0.5, 0.2, 0.4, 0.8, 0.3, 0.9, -0.4, 0.8, 0.5, 0.1, -0.9 },
|
|
dx = { 1.0, 0.0, -0.5, 0.2, 0.4, 0.8, 0.3, 0.9, -0.4, 0.8, 0.5, 0.1, -0.9 },
|
|
ddx = { 1.0, 0.0, -0.5, 0.2, 0.4, 0.8, 0.3, 0.9, -0.4, 0.8, 0.5, 0.1, -0.9 },
|
|
X = function(th) end,
|
|
DX = function(th) end,
|
|
DDX = function(th) end,
|
|
Draw = function() end,
|
|
AddImpulse = function( th, size ) end,
|
|
|
|
ImpactPoint = function( xi, yi, xf, yf )
|
|
local impact = { r = 0, th = 0, t = 0, x = 0, y = 0, dx = 0, dy = 0 }
|
|
return impact
|
|
end,
|
|
|
|
Update = function( dt ) end,
|
|
},
|
|
|
|
beat = {
|
|
t = nil,
|
|
dt = nil,
|
|
mu = nil,
|
|
score = 0,
|
|
},
|
|
}
|
|
|
|
|
|
--Reset game state.
|
|
local function NewGame()
|
|
state.beat = {}
|
|
state.wave.Reset()
|
|
end
|
|
|
|
local beat = { }
|
|
local function IsOnBeat( t )
|
|
if not beat.t then
|
|
beat.t = t
|
|
return true
|
|
end
|
|
|
|
if not beat.dt then
|
|
|
|
|
|
local WEIGHT = 0.25
|
|
beat.mu = ( 1.0 - WEIGHT ) * beat.mu + WEIGHT * dt
|
|
|
|
|
|
if beat.score >= 1.0 then
|
|
beat.score = 0
|
|
return true
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
local function OnImpact( impact )
|
|
--Update beat timer.
|
|
if not beat then
|
|
beat = { mu =
|
|
end
|
|
local dt = impact.t - beat.t
|
|
beat.t = impact.t
|
|
|
|
|
|
|
|
|
|
|
|
--Handle sound.
|
|
love.audio.play(sound)
|
|
end
|
|
|
|
local function OnVictory()
|
|
|
|
end
|
|
|
|
function love.draw()
|
|
love.graphics.setColor(1.0, 1.0, 1.0)
|
|
love.graphics.print("Hello World!", 400, 300)
|
|
love.graphics.print( beat.t, 0, 0 )
|
|
love.graphics.print( beat.dt, 0, 100 )
|
|
love.graphics.setColor(0, 0.4, 0.4)
|
|
--love.graphics.circle("fill", 0, 0, 10)
|
|
end
|
|
|
|
function love.load()
|
|
sound = love.audio.newSource("soundTest.ogg", "static")
|
|
|
|
return NewGame()
|
|
|
|
end
|
|
|
|
function love.update( dt )
|
|
|
|
end
|
|
|
|
|
|
function love.keypressed( key, code, isRepeat )
|
|
if key == "escape" then return love.event.quit() end
|
|
if key == "w" then return OnImpact( ) end
|
|
if key == "enter" then return NewGame() end
|
|
end |