-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTime.py
34 lines (25 loc) · 895 Bytes
/
Time.py
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
import pygame.time
class Time:
def __init__(self):
self.timer = 0
self.previous_result = 0
self.paused = False
def reset_timer(self) -> None:
self.timer = pygame.time.get_ticks() / 1000
self.previous_result = 0
def get_time(self) -> float:
if not self.paused:
self.previous_result = pygame.time.get_ticks() / 1000 - self.timer
return self.previous_result
def force_elapsed_time(self, value: float) -> None:
self.timer = pygame.time.get_ticks() / 1000 - value
def pause(self) -> None:
self.paused = True
def unpause(self) -> None:
if self.paused:
self.paused = False
self.force_elapsed_time(self.previous_result)
def is_paused(self) -> bool:
return self.paused
def get_prev_time(self) -> float:
return self.previous_result