-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-window.py
81 lines (64 loc) · 2.41 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
79
80
81
import os
import pygame as pg
if not pg.font:
print("Warning, fonts disabled")
if not pg.mixer:
print("Warning, sound disabled")
main_dir = os.path.split(os.path.abspath(__file__))[0]
data_dir = os.path.join(main_dir, "data")
def load_image(name, colorkey=None, scale=1):
fullname = os.path.join(data_dir, name)
image = pg.image.load(fullname)
size = image.get_size()
size = (size[0] * scale, size[1] * scale)
image = pg.transform.scale(image, size)
image = image.convert()
if colorkey is not None:
if colorkey == -1:
colorkey = image.get_at((0, 0))
image.set_colorkey(colorkey, pg.RLEACCEL)
return image, image.get_rect()
class CountingObjects(pg.sprite.Sprite):
"""moves the objects to be counted around the screen"""
def __init__(self):
pg.sprite.Sprite.__init__(self) # call Sprite initializer
self.image, self.rect = load_image("diamond.png", -1, 4)
screen = pg.display.get_surface()
self.area = screen.get_rect()
self.rect.topleft = 10, 90
self.move = 18
def _walk(self):
"""move the object across the screen, and turn at the ends"""
newpos = self.rect.move((self.move, 0))
if not self.area.contains(newpos):
if self.rect.left < self.area.left or self.rect.right > self.area.right:
self.move = -self.move
newpos = self.rect.move((self.move, 0))
self.image = pg.transform.flip(self.image, True, False)
self.rect = newpos
# pygame setup
pg.init()
screen = pg.display.set_mode((1000, 1000), pg.SCALED)
pg.display.set_caption("Counting Simulator")
clock = pg.time.Clock()
running = True
background = pg.Surface(screen.get_size())
background = background.convert()
background.fill((102, 204, 10))
if pg.font:
font = pg.font.Font(None, 64)
text = font.render("How many sheep are there?", True, (10, 10, 10))
textpos = text.get_rect(centerx=background.get_width() / 2, y=background.get_height() - 100)
background.blit(text, textpos)
while running:
# poll for events
# pg.QUIT event means the user clicked X to close your window
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
screen.blit(background, (0, 0))
# RENDER YOUR GAME HERE
# flip() the display to put your work on screen
pg.display.flip()
clock.tick(60) # limits FPS to 60
pg.quit()