your-own-drum/main.lua

118 lines
2.2 KiB
Lua
Raw Normal View History

2023-01-13 13:11:30 +00:00
local love = love
2023-01-13 14:27:17 +00:00
local sound
2023-01-13 15:38:14 +00:00
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.
2023-01-13 14:27:17 +00:00
local function NewGame()
2023-01-13 15:38:14 +00:00
state.beat = {}
state.wave.Reset()
2023-01-13 14:27:17 +00:00
end
2023-01-13 15:38:14 +00:00
local beat = { }
local function IsOnBeat( t )
if not beat.t then
beat.t = t
return true
end
2023-01-13 14:27:17 +00:00
2023-01-13 15:38:14 +00:00
if not beat.dt then
2023-01-13 14:27:17 +00:00
2023-01-13 15:38:14 +00:00
local WEIGHT = 0.25
beat.mu = ( 1.0 - WEIGHT ) * beat.mu + WEIGHT * dt
2023-01-13 14:27:17 +00:00
2023-01-13 15:38:14 +00:00
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
2023-01-13 14:27:17 +00:00
2023-01-13 15:38:14 +00:00
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