mirror of
https://github.com/kikito/cron.lua.git
synced 2024-12-19 18:34:20 +00:00
added demo files
This commit is contained in:
parent
acfe8cb00f
commit
93de2ebdd7
48
main.lua
Normal file
48
main.lua
Normal file
@ -0,0 +1,48 @@
|
||||
local cron = require 'cron'
|
||||
|
||||
local counter = 10
|
||||
local exploded = false
|
||||
local defused = false
|
||||
|
||||
local bombClock
|
||||
local exitClock
|
||||
|
||||
function ticktack()
|
||||
if exploded or defused then return end
|
||||
counter = counter - 1
|
||||
if counter <= 0 then
|
||||
exploded = true
|
||||
exitClock = cron.after(2, love.event.quit)
|
||||
end
|
||||
end
|
||||
|
||||
function love.keypressed(key, unicode)
|
||||
if exploded or defused then return end
|
||||
if key == ' ' then
|
||||
defused = true
|
||||
exitClock = cron.after(2, love.event.quit)
|
||||
end
|
||||
end
|
||||
|
||||
function love.load()
|
||||
bombClock = cron.every(1, ticktack) -- execute the ticktack function every second
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
bombClock:update(dt)
|
||||
if exitClock then exitClock:update(dt) end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
local msg
|
||||
if exploded then
|
||||
msg = 'BOOM! Game over. Bye!'
|
||||
elseif defused then
|
||||
msg = "Good job! You saved the day! Bye!"
|
||||
else
|
||||
msg = 'You have ' .. tostring(counter) .. ' seconds left to defuse the bomb - press space to defuse it!'
|
||||
end
|
||||
love.graphics.print(msg, 100, 200 )
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user