-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvarious.py
More file actions
78 lines (59 loc) · 2.16 KB
/
Copy pathvarious.py
File metadata and controls
78 lines (59 loc) · 2.16 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pygame
import time
import sys
from logger import logger as log
class TimerObj:
def __init__(
self,
duration: int,
starting: float = 0,
paused: bool = False
) -> None:
'''
duration: duration of the timer
starting: starting point of the timer
paused: create paused timer when set to True
'''
self.duration = duration
self.paused = paused
self.time = starting
def tick(self, delta_time: float) -> bool:
if self.paused:
return False
self.time += delta_time
if self.time > self.duration:
self.time %= self.duration
return True
def pause(self): self.paused = True
def resume(self): self.paused = False
class key_map:
def __init__(self,up,down,left,right):
log.debug(f'Initializing keybindings: {up}, {down}, {left}, {right}')
self.up = pygame.key.key_code(up)
self.down = pygame.key.key_code(down)
self.left = pygame.key.key_code(left)
self.right = pygame.key.key_code(right)
self.keys = [self.up,self.down,self.left,self.right]
def __contains__(self, key) -> bool:
return key in self.keys
def timer(func: callable) -> callable:
def wrapper(*args, **kwargs) -> object:
log.debug(f'Starting Benchmark on function: {func.__name__}')
tick = time.perf_counter()
output = func(*args, **kwargs)
tock = time.perf_counter()
log.debug(f'Benchmark ended on function: {func.__name__}')
log.debug(f'Benchmark result: {tock-tick} (s)')
return output
return wrapper
def print_new_game(running: str = '') -> None:
"""Simple function to better separete the logs of each game"""
log.debug('')
log.debug('========== NEW GAME STARTING ==========')
log.debug(f'Current time: {time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}')
log.debug(f'OS: {sys.platform}')
log.debug(f'Python version: {sys.version}')
log.debug(f'Pygame version: {pygame.version.ver}')
if running:
log.debug(f'Running: {running}')
log.debug('')