-
Notifications
You must be signed in to change notification settings - Fork 1
/
scene.py
56 lines (48 loc) · 1.59 KB
/
scene.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
import datingsim, pygame
class Scene():
def __init__(self):
self.buttons = pygame.sprite.Group()
self.all_sprites = pygame.sprite.Group()
self.bg_surf = None
self.done = False
self.main_surface = pygame.display.get_surface()
def main_loop(self):
while not self.done:
self.main_loop_before()
for e in pygame.event.get():
if e.type is pygame.QUIT:
datingsim.quit()
pygame.quit()
quit()
elif e.type is pygame.MOUSEBUTTONDOWN:
for button in self.buttons:
if button.rect.collidepoint(e.pos):
button.on_click()
if self.bg_surf:
self.main_surface.blit(self.bg_surf, (0, 0))
else:
self.main_surface.fill((0, 0, 0))
self.all_sprites.update()
self.all_sprites.draw(self.main_surface)
pygame.display.flip()
self.main_loop_after()
pygame.time.wait(1000//20)
self.ath()
def main_loop_before(self):
"""Overide this method to add behavior at start of loop."""
pass
def main_loop_after(self):
"""Overide this method to add behavior at end of loop.
Runs after draw and before delay."""
pass
def ath(self):
pass
@staticmethod
def test():
pygame.init()
datingsim.init()
Scene().main_loop()
if __name__ == '__main__':
pygame.init()
datingsim.init()
Scene.test()