-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
77 lines (64 loc) · 2.25 KB
/
main.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
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
import turtle
from render import Render
from object import load_objects_from_file
from player import Player
from writer import Writer
class Main:
def __init__(self, level=0):
self.level = level
self.screen = turtle.Screen()
self.screen.listen()
self.render = Render()
self.writer = Writer()
self.player = Player(self.handle_event)
self.debounce = False
self.main_menu()
self.screen.mainloop()
def main_menu(self):
self.debounce = True
self.render.clear()
self.player.clear()
self.player.ht()
self.writer.text("Press 'Enter' to Start", position=(0, 375), clear = True)
self.debounce = False
self.screen.onkey(self.start_game, "Return")
def start_game(self):
if self.debounce:
return
self.debounce = True
print(self.debounce)
self.writer.clear()
objects = load_objects_from_file(f"levels/{self.level}.json")
if not objects:
self.level = 0
return self.main_menu()
self.render.clear()
self.render.update(objects)
self.player.objects = objects
self.player.set_start()
self.player.clear()
self.player.st()
self.render_velocity()
self.player.mainloop()
def render_velocity(self):
if self.debounce:
self.writer.text(
f"{round(self.player.x_velocity)}, {round(self.player.y_velocity)}",
position=(0, -388),
clear=True,
)
self.screen.ontimer(self.render_velocity, self.player.tick)
def handle_event(self, type):
match type:
case "death":
self.debounce = False
self.writer.clear()
self.writer.text("You Died!", position=(0, 375),clear=True)
self.writer.text("Press 'Enter' to Restart", position=(0, 350))
self.screen.onkey(self.start_game, "Return")
case "end":
self.level += 1
self.debounce = False
self.start_game()
if __name__ == "__main__":
Main()