-
Notifications
You must be signed in to change notification settings - Fork 0
/
Countdown.lua
executable file
·63 lines (56 loc) · 1.25 KB
/
Countdown.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
local Color = require('Color')
local CountDown = {
}
-- Displays a countdown
function CountDown:count()
self.timeLimit = self.timeLimit-1
self.timeLeft.text = self.timeLimit
if(self.timeLimit == 0)then
self.timeLeft.text = "GO!"
-- flash text
self.timeLeft:setTextColor(unpack(Color.green))
timer.performWithDelay(
200,function()
self.timeLeft:setTextColor(unpack(Color.yellow))
end
)
timer.performWithDelay(
400,function()
self.timeLeft:setTextColor(unpack(Color.red))
end
)
timer.performWithDelay(
600,function()
self.timeLeft:setTextColor(unpack(Color.blue))
end
)
timer.performWithDelay(
800,
function()
self.timeLeft:removeSelf()
end
)
end
timer.performWithDelay(
1000,
function() self:count() end,
timeLimit)
end
-- start countdown
function CountDown:start()
self:count()
end
-- initialize countdown
function CountDown:init(timeLimit, xPos, yPos)
local timeLeft = display.newText(
timeLimit,
xPos,
yPos,
native.systemFontBold,
display.contentWidth / 3
)
timeLeft:setTextColor(unpack(Color.white))
self.timeLeft = timeLeft
self.timeLimit = timeLimit
end
return CountDown