-
Notifications
You must be signed in to change notification settings - Fork 0
/
stackframe.py
53 lines (41 loc) · 1.23 KB
/
stackframe.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
import pygame, sys
def runStack(stack):
if stack:
stack[-1].poll()
stack[-1].update()
else:
return False
if stack:
stack[-1].render()
stack[-1].paint()
else:
return False
return True
class StackFrame(object):
def __init__(self, stack, window, renderOver=None, music=None):
self.stack = stack
self.window = window
if music is not None:
self.music = pygame.mixer.Sound(music)
if renderOver is not None:
self.renderOver = renderOver
def poll(self):
for event in pygame.event.get(pygame.QUIT):
sys.exit()
def render(self):
if hasattr(self, 'renderOver'):
self.stack[self.renderOver].render()
def paint(self):
if hasattr(self, 'renderOver'):
self.stack[self.renderOver].paint()
def update(self):
if hasattr(self, 'music'):
try:
if not self.channel.get_busy():
self.channel = self.music.play()
except AttributeError:
self.channel = self.music.play()
def kill(self):
self.stack.remove(self)
def quit(self):
del self.stack[:]