Skip to content

Commit 1d074b8

Browse files
committed
Adds sound effects.
1 parent 337ab68 commit 1d074b8

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

Arcade Explo A.wav

30.8 KB
Binary file not shown.

DST-AngryMod.mp3

2.2 MB
Binary file not shown.

game.py

+16
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def __init__(self, x_pos, groups):
6060
self.velocity = random.randint(3, 10)
6161

6262
self.add(groups)
63+
self.explosion_sound = pygame.mixer.Sound("Arcade Explo A.wav")
64+
self.explosion_sound.set_volume(0.4)
6365

6466
def update(self):
6567
x, y = self.rect.center
@@ -72,6 +74,11 @@ def update(self):
7274

7375
self.rect.center = x, y
7476

77+
def kill(self):
78+
x, y = self.rect.center
79+
if pygame.mixer.get_init():
80+
self.explosion_sound.play(maxtime=1000)
81+
super(EnemySprite, self).kill()
7582
class StatusSprite(pygame.sprite.Sprite):
7683
def __init__(self, ship, groups):
7784
super(StatusSprite, self).__init__()
@@ -153,6 +160,7 @@ def create_starfield(group):
153160

154161
def main():
155162
pygame.font.init()
163+
pygame.mixer.init()
156164
screen = pygame.display.set_mode((X_MAX, Y_MAX), DOUBLEBUF)
157165
everything = pygame.sprite.Group()
158166
enemies = pygame.sprite.Group()
@@ -173,6 +181,14 @@ def main():
173181
for i in range(10):
174182
pos = random.randint(0, X_MAX)
175183
EnemySprite(pos, [everything, enemies])
184+
185+
# Get some music
186+
if pygame.mixer.get_init():
187+
pygame.mixer.music.load("DST-AngryMod.mp3")
188+
pygame.mixer.music.set_volume(0.8)
189+
pygame.mixer.music.play(-1)
190+
191+
176192

177193

178194
while True:

0 commit comments

Comments
 (0)