Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sound effects #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.