Updated cut_scene.

This commit is contained in:
Storm Dragon 2019-12-05 12:33:54 -05:00
parent 4bce821cbe
commit bb711fb7a5

View File

@ -70,6 +70,9 @@ def initialize_gui(gameTitle):
# start the display (required by the event loop) # start the display (required by the event loop)
pygame.display.set_mode((320, 200)) pygame.display.set_mode((320, 200))
pygame.display.set_caption(gameTitle) pygame.display.set_caption(gameTitle)
# Set 32 channels for sound by default
pygame.mixer.init()
pygame.mixer.set_num_channels(32)
# Reserve the cut scene channel # Reserve the cut scene channel
pygame.mixer.set_reserved(0) pygame.mixer.set_reserved(0)
# Load sounds from the sound directory and creates a list like that {'bottle': 'bottle.ogg'} # Load sounds from the sound directory and creates a list like that {'bottle': 'bottle.ogg'}
@ -88,19 +91,23 @@ def cut_scene(sounds, soundName):
c = pygame.mixer.Channel(0) c = pygame.mixer.Channel(0)
c.play(sounds[soundName]) c.play(sounds[soundName])
while pygame.mixer.get_busy(): while pygame.mixer.get_busy():
pygame.event.poll() event = pygame.event.poll()
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN and event.key in [pygame.K_RETURN, pygame.K_SPACE]:
pygame.mixer.stop() pygame.mixer.stop()
pygame.event.pump() pygame.event.pump()
return
def play_random(sounds, soundName, pause = False): def play_random(sounds, soundName, pause = False, interrupt = False):
key = [] key = []
for i in sounds.keys(): for i in sounds.keys():
if re.match("^" + soundName + ".*", i): if re.match("^" + soundName + ".*", i):
key.append(i) key.append(i)
randomKey = random.choice(key) randomKey = random.choice(key)
if interrupt == False:
sounds[randomKey].play() sounds[randomKey].play()
else:
cut_scene(sounds, randomKey)
# Cut scenes override the pause option
return
if pause == True: if pause == True:
time.sleep(sounds[randomKey].get_length()) time.sleep(sounds[randomKey].get_length())