require "field"

game={}
game.field=field(40,20)
game.player=player
game.ticker=ticker(0.125)
game.currentTrack={}
game.trackRunning=false
game.useTrack=true
game.events={} -- events are tables that contain recurring (bool), i (period or counter), and func



function game.update(dt)
if game.useTrack then
if not game.trackRunning and c.music:tell()>=c.info.startTime then
game.ticker:calibrate(love.timer.getTime()-(game.currentTrack.music:tell()-game.currentTrack.info.startTime))
game.trackRunning=true
end -- if calibration
end -- if usetrack
local ticked=game.ticker:update(dt)
player.update(dt)
game.field:update(dt)
end -- update

function game.loadTrack(t)
game.currentTrack=t
game.ticker.tickTime=t.timeStep
t.music:setVolume(t.info.volumeBase)
game.trackRunning=false
end -- loadtrack

function game.init()
table.insert(game.field.contents, enemyBasic(5,20))
function game.ticker:tick()
for k,event in pairs(game.events) do
local adjustedTicks=game.ticker.ticks-1+(event.shift or 0)
if event.recurring then
if adjustedTicks%event.i==0 then
event.func()
end -- if fire recurring event
else
event.i=event.i-1
if event.i==0 then
event.func()
event=nil
end -- if fire one-shot event
end -- if recurring
end -- for events
end
local click={
i=2,
recurring=true,
func=function()
aud.meh:stop()
aud.meh:play()
end
}
local beep={
i=4,
recurring=true,
func=function()
aud.beep:stop()
aud.beep:play()
end
}
-- game.events.click=click
-- game.events.beep=beep
end