-
Notifications
You must be signed in to change notification settings - Fork 0
/
startscreen.py
80 lines (70 loc) · 2.86 KB
/
startscreen.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
78
79
80
from pyglet.gl import *
class StartScreen(object):
TITLE = 0
HIGH_SCORE = 1
def __init__(self, width, height, version_string, high_score_list,
display_time_s, end_screen_callback):
self.width = width
self.height = height
self.high_score_list = high_score_list
self.end_screen_callback = end_screen_callback
self.sisyfos_label = \
pyglet.text.Label('Sisyfos',
font_name=None,
font_size=75,
x=width//2, y=375,
anchor_x='center', anchor_y='center')
self.instruction_label = \
pyglet.text.Label('Press space to play!',
font_name=None,
font_size=36,
x=width//2, y=275,
anchor_x='center', anchor_y='center')
self.version_label = \
pyglet.text.Label(version_string,
font_name=None,
font_size=12,
x=5, y=5)
self.mode = self.TITLE
def switch_mode(dt):
if self.mode == self.TITLE:
self.mode = self.HIGH_SCORE
self.make_high_score_labels()
else:
assert(self.mode == self.HIGH_SCORE)
self.mode = self.TITLE
pyglet.clock.schedule_interval(switch_mode, display_time_s)
self.on_resize(self.width, self.height)
def make_high_score_labels(self):
self.labels = []
y_base = self.height - 110
for i, (name, score) in enumerate(self.high_score_list):
label = \
pyglet.text.Label('%d. %s %d' % (i + 1, name, score),
font_name=None,
font_size=20,
x=self.width//2, y=y_base - i * 40,
anchor_x='center', anchor_y='center')
self.labels.append(label)
def on_draw(self):
glClearColor(0.0, 0.0, 0.0, 1.0)
glClear(GL_COLOR_BUFFER_BIT)
if self.mode == self.TITLE:
self.sisyfos_label.draw()
self.instruction_label.draw()
self.version_label.draw()
else:
assert(self.mode == self.HIGH_SCORE)
for label in self.labels:
label.draw()
def on_resize(self, width, height):
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, width, 0, height, -1.0, 1.0)
glMatrixMode(GL_MODELVIEW)
def on_key_press(self, symbol, modifiers):
if symbol == pyglet.window.key.SPACE:
self.end_screen_callback()
def on_key_release(self, symbol, modifiers):
pass