diff --git a/libstormgames.py b/libstormgames.py index 118e0c6..afc821a 100755 --- a/libstormgames.py +++ b/libstormgames.py @@ -70,6 +70,9 @@ def initialize_gui(gameTitle): # start the display (required by the event loop) pygame.display.set_mode((320, 200)) 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 pygame.mixer.set_reserved(0) # 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.play(sounds[soundName]) while pygame.mixer.get_busy(): - pygame.event.poll() - if event.type == pygame.KEYDOWN: + event = pygame.event.poll() + if event.type == pygame.KEYDOWN and event.key in [pygame.K_RETURN, pygame.K_SPACE]: pygame.mixer.stop() pygame.event.pump() - return -def play_random(sounds, soundName, pause = False): +def play_random(sounds, soundName, pause = False, interrupt = False): key = [] for i in sounds.keys(): if re.match("^" + soundName + ".*", i): key.append(i) randomKey = random.choice(key) - sounds[randomKey].play() + if interrupt == False: + sounds[randomKey].play() + else: + cut_scene(sounds, randomKey) + # Cut scenes override the pause option + return if pause == True: time.sleep(sounds[randomKey].get_length())