Add some randomness to the audio

This commit is contained in:
Junior 2024-06-11 20:24:36 -04:00
parent a3166153c1
commit 80923decb4
4 changed files with 8 additions and 2 deletions

View File

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.