Skip to content

Commit

Permalink
Added sounds
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Klemmer <[email protected]>
  • Loading branch information
JoeKlemmer committed May 16, 2020
1 parent 7a469e9 commit 1736f16
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Binary file added background.wav
Binary file not shown.
Binary file added explosion.wav
Binary file not shown.
Binary file added laser.wav
Binary file not shown.
15 changes: 11 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
import time
import math
from pygame import mixer

# Initialize pygame engine
pygame.init()
Expand All @@ -19,6 +20,10 @@
else:
background = pygame.image.load("background-1154x768.jpg")

# Background sound
mixer.music.load("background.wav")
mixer.music.play(-1)

# Set the clock speed delta
clock = pygame.time.Clock()

Expand Down Expand Up @@ -123,6 +128,8 @@ def isCollision(enemyX, enemyY, bulletX, bulletY):
playerX_change = 6
if event.key == pygame.K_SPACE:
if bullet_state == "ready":
bullet_sound = mixer.Sound("laser.wav")
bullet_sound.play()
bulletX = playerX
fire_bullet(bulletX, bulletY)

Expand Down Expand Up @@ -157,6 +164,8 @@ def isCollision(enemyX, enemyY, bulletX, bulletY):
# Test for collsion
collision = isCollision(enemyX[i], enemyY[i], bulletX, bulletY)
if collision:
explosion_sound = mixer.Sound("explosion.wav")
explosion_sound.play()
bulletY = int(height * 0.85)
bullet_state = "ready"
score_value += 1
Expand All @@ -176,9 +185,7 @@ def isCollision(enemyX, enemyY, bulletX, bulletY):

player(playerX, playerY)
show_score(textX, textY)

# Update the screen
pygame.display.update()
clock.tick(60)

if shots_fired > 0:
print("Hit percentage is: " + str((score / shots_fired) * 100) + "%")
clock.tick(60)

0 comments on commit 1736f16

Please sign in to comment.