-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.py
38 lines (30 loc) · 1.26 KB
/
audio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from pygame.mixer import Sound
from pygame.mixer import music
class Audio:
"""A class to manage audio files for Alien Warfare"""
def __init__(self):
"""Initialize the audio used throughout the game."""
# Setup background music
self.setup_background_music()
# Play background music
self.play_background_music()
# Setup Sounds
self.spaceship_laser = Sound("sounds/spaceship_laser.mp3")
self.spaceship_laser.set_volume(0.03)
self.alien_bullet_collision = Sound("sounds/alien_bullet_collision.mp3")
self.alien_bullet_collision.set_volume(0.03)
def play_spaceship_laser_sound(self):
"""Plays the spaceship laser sound."""
self.spaceship_laser.play(1000)
self.spaceship_laser.fadeout(1000)
def play_alien_bullet_collision_sound(self):
"""Plays the collision sound of the alien and bullet."""
self.alien_bullet_collision.play(1000)
self.alien_bullet_collision.fadeout(1000)
def setup_background_music(self):
"""Set up the background music"""
music.load("sounds/apocalypse_background.mp3")
music.set_volume(0.04)
def play_background_music(self):
"""Plays the background music"""
music.play(-1)