-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.pde
More file actions
49 lines (45 loc) · 1.19 KB
/
Timer.pde
File metadata and controls
49 lines (45 loc) · 1.19 KB
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
//Timer Class
/// not: must call update and pass the seconds elapsed since last timer update call as argument for timer to work
class Timer {
float waitTime;
float curWaitTime;
boolean looping;
boolean finished;
boolean running;
//Setup timer, set running to true to start immediatley
public Timer( float _waitTime, boolean _looping, boolean _running ) {
waitTime = _waitTime;
curWaitTime = waitTime;
looping = _looping;
finished = false;
running = _running;
}
//Returns true if timer expired or finished, false is running or stopped.
public boolean update(float deltaTime ) {
if ( !running ) {
return false;
}
//descrease timer
curWaitTime -= deltaTime;
//If timer expired
if ( curWaitTime <= 0.f ) {
//If timer set to loop, start timer again and return true
if ( looping ) {
curWaitTime += waitTime;
return true;
}
// if not looping then set finished flag
else {
curWaitTime = 0.f;
finished = true;
}
}
return finished;
}
// resets the timer and starts it
public void reset() {
curWaitTime = waitTime;
finished = false;
running = true;
}
}