-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameTimer.as
63 lines (54 loc) · 1.27 KB
/
GameTimer.as
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
package
{
import net.flashpunk.Entity;
import net.flashpunk.graphics.Text;
import net.flashpunk.FP;
public class GameTimer extends Entity
{
private var seconds:Number = 0;
private var minutes:int = 0;
private var paused:Boolean = false;
private var mWorld:GameWorld;
public var time:String;
public function GameTimer(gameWorld:GameWorld)
{
graphic = new Text("00000000");
graphic.scrollX = 0;
graphic.scrollY = 0;
time = minutes.toString() +":"+ int(seconds).toString();
Text(graphic).text = time;
Text(graphic).scale = 1.5;
mWorld = gameWorld;
x = mWorld.cam.x+FP.halfWidth*1.8;
y = mWorld.cam.y+FP.halfHeight/8;
layer = 0;
}
override public function update():void
{
if(!paused)
seconds += FP.elapsed;
if (seconds >= 60)
{
seconds = 0;
minutes++;
}
if (seconds < 10)
time = minutes.toString() +":0" + int(seconds).toString();
else
time = minutes.toString() +":"+ int(seconds).toString();
Text(graphic).text = time;
}
public function pause():void
{
paused = true;
}
public function resume():void
{
paused = false;
}
public function bonusTime():void
{
seconds -= 10;
}
}
}