-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.cpp
More file actions
42 lines (35 loc) · 818 Bytes
/
Timer.cpp
File metadata and controls
42 lines (35 loc) · 818 Bytes
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
//
// Timer.cpp
//
// Engine includes.
#include "DisplayManager.h"
#include "EventStep.h"
#include "LogManager.h"
// Game includes.
#include "Timer.h"
Timer::Timer() {
setViewString(TIMER_STRING);
setColor(df::YELLOW);
setBorder(false);
setLocation(df::TOP_RIGHT);
setValue(0);
// Need to update time each second, so count "step" events.
#ifdef DF_REGISTER_INTEREST
registerInterest(df::STEP_EVENT);
#endif
step_count = 0;
}
// Handle event.
int Timer::eventHandler(const df::Event *p_e) {
// If step, increment score every second (30 steps)
if (p_e->getType() == df::STEP_EVENT) {
step_count++;
if (step_count == 30) { // 1 second has elapsed
setValue(getValue() + 1);
step_count = 0;
}
return 1;
}
// If we get here, have ignored this event.
return 0;
}