diff --git a/PyGame/Basics/010_mousesound.py b/PyGame/Basics/010_mousesound.py index 3cd3713..86202ec 100644 --- a/PyGame/Basics/010_mousesound.py +++ b/PyGame/Basics/010_mousesound.py @@ -1,6 +1,7 @@ import os os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide" import pygame +import random import sys pygame.init() @@ -48,7 +49,12 @@ window.blit(click_text, (text_x, text_y)) # We can import audio files with mixer.Sound() # Only .ogg (Ogg Vorbis) format files should be used # The audio program Audacity can be used to convert files to .ogg -audio = pygame.mixer.Sound(os.path.join("snd", "toot.ogg")) +# Here we will import several and put them in a list +audio = [] +audio.append(pygame.mixer.Sound(os.path.join("snd", "toot.ogg"))) +audio.append(pygame.mixer.Sound(os.path.join("snd", "toot_echo.ogg"))) +audio.append(pygame.mixer.Sound(os.path.join("snd", "toot_trip.ogg"))) +audio.append(pygame.mixer.Sound(os.path.join("snd", "toot_wet.ogg"))) clock = pygame.time.Clock() # The main loop. This while loop runs until "running" is False @@ -69,7 +75,7 @@ while running is True: running = False # pygame.MOUSEBUTTONDOWN happens the moment a mouse button is clicked if event.type == pygame.MOUSEBUTTONDOWN and emoji_hover is True: - audio.play() + audio[random.randrange(0, len(audio))].play() # pygame.KEYDOWN happens the moment a key is pressed down if event.type == pygame.KEYDOWN: # If the pressed key is "ESC" button, then let's exit diff --git a/PyGame/Basics/snd/toot_echo.ogg b/PyGame/Basics/snd/toot_echo.ogg new file mode 100644 index 0000000..5d1c2a5 Binary files /dev/null and b/PyGame/Basics/snd/toot_echo.ogg differ diff --git a/PyGame/Basics/snd/toot_trip.ogg b/PyGame/Basics/snd/toot_trip.ogg new file mode 100644 index 0000000..3ecaa4a Binary files /dev/null and b/PyGame/Basics/snd/toot_trip.ogg differ diff --git a/PyGame/Basics/snd/toot_wet.ogg b/PyGame/Basics/snd/toot_wet.ogg new file mode 100644 index 0000000..459d5e0 Binary files /dev/null and b/PyGame/Basics/snd/toot_wet.ogg differ