75 lines
1.5 KiB
Lua
75 lines
1.5 KiB
Lua
require "field"
|
|
|
|
game={}
|
|
game.field=field(40,30)
|
|
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()
|
|
game.meh=enemyBasic(6,game.field.height)
|
|
table.insert(game.field.contents, game.meh)
|
|
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 radar={
|
|
i=1,
|
|
recurring=true,
|
|
func=function()
|
|
for k,v in pairs(game.field.contents) do
|
|
if v.x==player.x then
|
|
aud.meh:stop()
|
|
aud.meh:play()
|
|
return
|
|
end
|
|
end
|
|
end
|
|
}
|
|
local beep={
|
|
i=4,
|
|
recurring=true,
|
|
func=function()
|
|
aud.beep:stop()
|
|
aud.beep:play()
|
|
end
|
|
}
|
|
game.events.radar=radar
|
|
-- game.events.beep=beep
|
|
end |