Skip to content

Commit

Permalink
Add Sound effects
Browse files Browse the repository at this point in the history
Add sound effect for when player gets a point or clicks mouse.
All sound effects are original work.
  • Loading branch information
SohamKukreti committed Apr 7, 2024
1 parent 63c7fd1 commit 7a9dbe1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, handle):
self.game = main.Game(self)
self.build_toolbar()
self._pygamecanvas = sugargame.canvas.PygameCanvas(
self, main=self.game.run, modules=[pygame.display, pygame.font]
self, main=self.game.run, modules=[pygame.display, pygame.font, pygame.mixer]
)
self.set_canvas(self._pygamecanvas)
self._pygamecanvas.grab_focus()
Expand Down
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, parent, x, y):
self.right = 0
self.down = 0
self.owner = None
self.point_sound = pygame.mixer.Sound('assets/point.ogg')

def check(self):
return ((self.up + self.left + self.right + self.down) == 4)
Expand All @@ -47,6 +48,7 @@ def setOwner(self, owner):
else:
self.owner = 'B'
PLAYER_B = PLAYER_B + 1
self.point_sound.play()
self.showOwner()

def showOwner(self):
Expand Down Expand Up @@ -379,6 +381,8 @@ def where(self, pos):

def run(self):
self.screen = pygame.display.get_surface()
self.click_sound = pygame.mixer.Sound('assets/click.ogg')
self.click_sound.set_volume(0.4)
if not self.screen:
self.screen = pygame.display.set_mode((900, 700))
pygame.display.set_caption(_('Dots and boxes'))
Expand All @@ -395,6 +399,7 @@ def run(self):
if event.type == pygame.QUIT:
run = False
elif event.type == pygame.MOUSEBUTTONDOWN:
self.click_sound.play()
pos = event.pos
ret = self.where(pos)
if ret == False:
Expand All @@ -417,6 +422,7 @@ def run(self):
run2 = False
self.draw_grid()
elif event.type == pygame.MOUSEBUTTONDOWN:
self.click_sound.play()
run2 = False
self.draw_grid()
pygame.display.flip()
Expand Down
Binary file added sounds/click.ogg
Binary file not shown.
Binary file added sounds/point.ogg
Binary file not shown.

0 comments on commit 7a9dbe1

Please sign in to comment.