-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
70 lines (55 loc) · 2.01 KB
/
Copy pathapp.py
File metadata and controls
70 lines (55 loc) · 2.01 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
import sys
import pygame as pg
from .settings import *
from .ui import *
from .grid import Graph
class App:
def __init__(self):
pg.init()
pg.display.set_caption(CAPTION)
self.screen = pg.display.set_mode(SIZE, 0, 32)
self.clock = pg.time.Clock()
# UI
self.instructions = Button("Instructions", (100, 30), (10, 10))
self.instructions.on_click(self.show_instructions)
'''self.settings = Button("Settings", (100, 30), (10, 50))
self.settings.on_click(self.show_settings)'''
self.pause = Button("Pause", (100, 30), (790, 10), bg_color=pg.Color('blue'), anchor='topright')
self.pause.on_click(self.do_pause)
self.sett, self.inst = False, False
self.paused = False
# Navigation Graph
self.graph = Graph((600, 500), (50, 150))
def show_instructions(self):
self.inst = not self.inst
'''def show_settings(self):
self.sett = not self.sett'''
def do_pause(self):
self.pause.set_text("Pause" if self.paused else "Resume")
self.paused = not self.paused
def run(self):
while True:
for ev in pg.event.get():
if ev.type == pg.QUIT:
pg.quit()
sys.exit()
'''self.settings.event(ev)'''
self.instructions.event(ev)
self.pause.event(ev)
self.graph.event(ev)
# Draw
self.screen.fill(BACKGROUND)
draw_header(self.screen)
self.graph.draw(self.screen)
self.instructions.draw(self.screen)
'''self.settings.draw(self.screen)'''
self.pause.draw(self.screen)
if self.inst:
draw_instructions(self.screen)
'''if self.sett:
draw_settings(self.screen)'''
pg.display.flip()
# Update
dt = self.clock.tick(FPS) / 1000.0
if not self.paused:
self.graph.update(dt)