-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
78 lines (66 loc) · 2.74 KB
/
Main.py
File metadata and controls
78 lines (66 loc) · 2.74 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 time
import pygame
import UI.Colors as Colors
import UI.Drawable as Drawable
import UI.Textures as Textures
import UI.UIManager as UIManager
def extend_objects(objects_input:list[Drawable.Drawable], extension:list[tuple[Drawable.Drawable,int]]) -> None:
'''Prepends items from extension with second item == -1 to objects, and appends items with 1.'''
for new_object, position in extension:
match position:
case -1: objects_input.insert(0, new_object)
case 1: objects_input.append(new_object)
case _: raise ValueError("Invalid thing %s as ap- or pre-pending direction!" % str(position))
def get_children(object:Drawable.Drawable) -> list[Drawable.Drawable]:
'''Recursively gets the children of the Drawable. Returns a list of the back-children, the parent object, and the front-children, in that order.'''
objects:list[Drawable.Drawable] = []
for child in object.children:
objects.append(child)
objects.extend(get_children(child))
return objects
pygame.init()
DISPLAY_SIZE = (900, 900)
screen = pygame.display.set_mode(DISPLAY_SIZE)
pygame.display.set_icon(Textures.get("logo_32"))
pygame.display.set_caption("0h h1")
clock = pygame.time.Clock()
UIManager.reload_carrier = [False]
objects:list[Drawable.Drawable] = [
UIManager.get_main_object()
]
running = True
while running:
events:list[pygame.event.Event] = []
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# print(event)
events.append(event)
screen.fill(Colors.get("background"))
new_objects:list[Drawable.Drawable] = []
destroy_objects:list[int] = []
for index, object in enumerate(objects):
object_children = [object] + get_children(object)
tick_objects:list[Drawable.Drawable] = []
for child in object_children:
child_return = child.tick(events, child.position)
if child_return is not None: tick_objects.extend(child_return)
new_objects.extend(tick_objects)
screen.blits([(child_surface, child.position) for child in object_children if (child_surface := child.display()) is not None])
if object.should_destroy:
new_objects.extend(object.destroy())
destroy_objects.append(index)
for index in reversed(destroy_objects): # reversed so it doesn't do weird stuff with indexes
del objects[index]
extend_objects(objects, new_objects)
if UIManager.reload_carrier[0]:
UIManager.reload_carrier[0] = False
UIManager.reload()
for object in objects:
object.reload(time.time())
pygame.display.flip()
clock.tick(60)
# print(clock.get_fps())
for object in objects:
object.delete()
pygame.quit()