-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathengine.py
More file actions
73 lines (55 loc) · 2.02 KB
/
engine.py
File metadata and controls
73 lines (55 loc) · 2.02 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
from tools import *
class Loop:
def __init__(self, WINDOW_SIZE: tuple | None = None, FPS: int = 60, font_path: None | str = None, screen = None):
initialized = pygame.display.get_init()
pygame.mixer.pre_init(44100, -16, 2, 512)
pygame.init()
if not screen:
if WINDOW_SIZE:
self.WINDOW_SIZE = self.WIDTH, self.HEIGHT = WINDOW_SIZE
if not initialized:
self.screen = pygame.display.set_mode(self.WINDOW_SIZE)
else:
WINDOW_SIZE = pygame.display.Info()
self.WINDOW_SIZE = (WINDOW_SIZE.current_w, WINDOW_SIZE.current_h)
if not initialized:
self.screen = pygame.display.set_mode(self.WINDOW_SIZE, pygame.FULLSCREEN)
else:
self.screen = screen
self.WINDOW_SIZE = self.WIDTH, self.HEIGHT = self.screen.get_size()
self.FPS = FPS
self.display = pygame.Surface(self.WINDOW_SIZE)
self.clock = pygame.time.Clock()
self.events = None
self.running = True
if font_path:
self.font_path = font_path
self.font2 = Font(font_path, 2)
self.font3 = Font(font_path, 3)
self.font4 = Font(font_path, 4)
self.font5 = Font(font_path, 5)
self.user_init()
self.loop_on = True
def run(self):
while self.running:
self.display.fill((0, 0, 0))
self.action()
self.user_events()
self.screen.blit(self.display, (0, 0))
pygame.display.update()
self.clock.tick(self.FPS)
self.user_end_action()
self.running = True
def action(self):
self.events = pygame.event.get()
def get_events(self):
return self.events
# user function
def user_init(self):
pass
# user function
def user_events(self):
pass
# user function
def user_end_action(self):
pass