Add some randomness to the audio
This commit is contained in:
parent
a3166153c1
commit
80923decb4
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
|
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
|
||||||
import pygame
|
import pygame
|
||||||
|
import random
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
@ -48,7 +49,12 @@ window.blit(click_text, (text_x, text_y))
|
||||||
# We can import audio files with mixer.Sound()
|
# We can import audio files with mixer.Sound()
|
||||||
# Only .ogg (Ogg Vorbis) format files should be used
|
# Only .ogg (Ogg Vorbis) format files should be used
|
||||||
# The audio program Audacity can be used to convert files to .ogg
|
# 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()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
# The main loop. This while loop runs until "running" is False
|
# The main loop. This while loop runs until "running" is False
|
||||||
|
@ -69,7 +75,7 @@ while running is True:
|
||||||
running = False
|
running = False
|
||||||
# pygame.MOUSEBUTTONDOWN happens the moment a mouse button is clicked
|
# pygame.MOUSEBUTTONDOWN happens the moment a mouse button is clicked
|
||||||
if event.type == pygame.MOUSEBUTTONDOWN and emoji_hover is True:
|
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
|
# pygame.KEYDOWN happens the moment a key is pressed down
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
# If the pressed key is "ESC" button, then let's exit
|
# If the pressed key is "ESC" button, then let's exit
|
||||||
|
|
BIN
PyGame/Basics/snd/toot_echo.ogg
Normal file
BIN
PyGame/Basics/snd/toot_echo.ogg
Normal file
Binary file not shown.
BIN
PyGame/Basics/snd/toot_trip.ogg
Normal file
BIN
PyGame/Basics/snd/toot_trip.ogg
Normal file
Binary file not shown.
BIN
PyGame/Basics/snd/toot_wet.ogg
Normal file
BIN
PyGame/Basics/snd/toot_wet.ogg
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user