Added a cut_scene function. used a space between spoken strings with the space key in display_text.
This commit is contained in:
		@@ -64,6 +64,8 @@ def initialize_gui(gameTitle):
 | 
			
		||||
    # start the display (required by the event loop)
 | 
			
		||||
    pygame.display.set_mode((320, 200))
 | 
			
		||||
    pygame.display.set_caption(gameTitle)
 | 
			
		||||
    # 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'}
 | 
			
		||||
    soundFiles = [f for f in listdir("sounds/") if isfile(join("sounds/", f)) and (f.split('.')[1].lower() in ["ogg","wav"])]
 | 
			
		||||
    #lets make a dict with pygame.mixer.Sound() objects {'bottle':<soundobject>}
 | 
			
		||||
@@ -74,6 +76,18 @@ def initialize_gui(gameTitle):
 | 
			
		||||
    time.sleep(soundData['game-intro'].get_length())
 | 
			
		||||
    return soundData
 | 
			
		||||
 | 
			
		||||
def cut_scene(sounds, soundName):
 | 
			
		||||
    pygame.event.clear()
 | 
			
		||||
    pygame.mixer.stop()
 | 
			
		||||
    c = pygame.mixer.Channel(0)
 | 
			
		||||
    c.play(sounds[soundName])
 | 
			
		||||
    while pygame.mixer.get_busy():
 | 
			
		||||
        pygame.event.poll()
 | 
			
		||||
        if event.type == pygame.KEYDOWN:
 | 
			
		||||
            pygame.mixer.stop()
 | 
			
		||||
        pygame.event.pump()
 | 
			
		||||
    return
 | 
			
		||||
 | 
			
		||||
def play_random(sounds, soundName, pause = False):
 | 
			
		||||
    key = []
 | 
			
		||||
    for i in sounds.keys():
 | 
			
		||||
@@ -112,7 +126,7 @@ def display_text(text):
 | 
			
		||||
            if event.key == pygame.K_DOWN and i < len(text) - 1: i = i + 1
 | 
			
		||||
            if event.key == pygame.K_UP and i > 0: i = i - 1
 | 
			
		||||
            if event.key == pygame.K_SPACE:
 | 
			
		||||
                speak(''.join(text[1:]))
 | 
			
		||||
                speak(' '.join(text[1:]))
 | 
			
		||||
            else:
 | 
			
		||||
                speak(text[i])
 | 
			
		||||
            if event.key == pygame.K_c:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user