-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-window.py
78 lines (61 loc) · 2.12 KB
/
main-window.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
import os
import pygame as pg
import counting_objects as co
from level import Level
if not pg.font:
print("Warning, fonts disabled")
if not pg.mixer:
print("Warning, sound disabled")
def main():
"""this function is called when the program starts.
it initializes everything it needs, then runs in
a loop until the function returns."""
# Initialize Everything
pg.init()
screen = pg.display.set_mode((1000, 1000), pg.SCALED)
pg.display.set_caption("Counting Simulator")
# Create The Background
background = pg.Surface(screen.get_size())
background = background.convert()
background.fill((102, 204, 10))
# Load level and failure sound
currentLevel = Level("what is my age", "uh_you_suck.wav", 2, 5)
failureSound = pg.mixer.Sound(currentLevel.failureSound)
# Put Text On The Background, Centered
if pg.font:
font = pg.font.Font(None, 64)
text = font.render("How many objects are there?", True, (10, 10, 10))
textpos = text.get_rect(centerx=background.get_width() / 2, y=background.get_height() - 100)
background.blit(text, textpos)
# Display The Background
screen.blit(background, (0, 0))
pg.display.flip()
# Prepare Game Objects
diamond = co.CountingObjects()
allobjects = pg.sprite.Group(diamond)
allobjects.draw(screen)
clock = pg.time.Clock()
# Main Loop
going = True
while going:
clock.tick(60)
# Handle Input Events
for event in pg.event.get():
if event.type == pg.QUIT:
going = False
elif event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE:
# Close window if user presses ESC
going = False
elif event.type == pg.KEYDOWN:
print("A key! A key, I say!")
pg.mixer.Sound.play(failureSound)
allobjects.update()
# Draw Everything
screen.blit(background, (0, 0))
allobjects.draw(screen)
pg.display.flip()
pg.quit()
# Game Over
# this calls the 'main' function when this script is executed
if __name__ == "__main__":
main()