-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex_update.py
More file actions
28 lines (22 loc) · 753 Bytes
/
ex_update.py
File metadata and controls
28 lines (22 loc) · 753 Bytes
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
# Ou comment fonctionne un moteur de jeu en background sur les fonctions Update() et Draw() etc
class GameObject:
def __init__(self, name):
self.name = name
self.counter = 0
def update(self):
self.counter += 1
def draw(self):
print(f"{self.name} = {self.counter}")
objects = []
objects.append(GameObject("First"))
objects.append(GameObject("Second"))
objects.append(GameObject("Third"))
while True:
# Read input, truc géré par le moteur de jeu pour lire le clavier etc
# Update
for obj in objects:
# Idéalement on devrait mettre une condition pour vérifier que les objets ont bien une fonction Update()
obj.update()
# Draw
for obj in objects:
obj.draw()