Exercise 1:
import pygame
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode([640,480])
pygame.time.delay(1000)
s1 = pygame.mixer.Sound("splat.wav")
s1.play()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
Exercise 2:
import pygame
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode([640,480])
pygame.time.delay(1000)
pygame.mixer.music.load("bg_music.mp3")
pygame.mixer.music.play(1)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
Exercise 3:
import pygame
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode([640,480])
pygame.time.delay(1000)
s1 = pygame.mixer.Sound("splat.wav")
s1.set_volume(0.20)
s1.play()
pygame.mixer.music.load("bg_music.mp3")
pygame.mixer.music.set_volume(0.10)
pygame.mixer.music.play()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
Exercise 4:
import pygame
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode([640,480])
pygame.display.set_caption("Sound Test")
s1 = pygame.mixer.Sound("splat.wav")
s1.set_volume(0.02)
pygame.mixer.music.load("bg_music.mp3")
pygame.mixer.music.set_volume(0.01)
pygame.mixer.music.play()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if not pygame.mixer.music.get_busy():
'''get_busy() to check music is played over or not'''
s1.play()
pygame.time.delay(1000)
running = False
pygame.quit()
[…] Game (Part 2)| |____Unit 65 Airplane Game (Part 1)| |____Unit 66 Airplane Game (Part 2)| |____Unit 67 Pygame Sounds| |____Unit 68 Air Fight (Part 1)| |____Unit 69 Air Fight (Part 2)| |____Unit 70 Air Fight (Part […]