-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timer.h
46 lines (40 loc) · 912 Bytes
/
Timer.h
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
//
// Created by Jake on 12/3/2023.
//
#include <SFML/Graphics.hpp>
#pragma once
//this class comes from Joseph's minesweeper project from Programming Fundamentals 2
class Timer{
sf::Clock gameTimer;
bool isPaused;
int curTime;
public:
Timer() {
isPaused = false;
curTime = 0;
gameTimer.restart();
}
void startTime() {
if (isPaused) {
gameTimer.restart();
}
isPaused = false;
}
void restartTime() {
gameTimer.restart();
curTime = 0;
isPaused = false;
}
void pauseTime() {
if (!isPaused) {
curTime += gameTimer.getElapsedTime().asMicroseconds();
}
isPaused = true;
}
int getMicroSecondsElapsed() {
if (!isPaused) {
return curTime + gameTimer.getElapsedTime().asMicroseconds();
}
return curTime;
}
};