Open cyanidecupcake opened 7 years ago
Here's a simple example of how Pygame's sound module works. This is cross-platform. You should NEVER have to ask a user what OS they're using; Python can tell you that, if you need to know. However, for sound, you don't need to know what their OS is. Pygame takes care of that.
import pygame
from pygame.locals import *
pygame.mixer.init()
# somewhere in your SETUP
SOUNDS = os.path.join('path','to','your','sounds')
ZAP = pygame.mixer.Sound(SOUNDS + 'zap.ogg')
# use the sounds in your main loop,
# or where ever you want to trigger them
# for example:
for enemy in enemy_hit_list:
ZAP
score -= 1
In future, if you ever actually do need to detect the user's OS, here is how to do it correctly:
if _plat.startswith('linux'):
print('you are using linux')
elif _plat.startswith('darwin'):
print('you are using mac')
elif _plat.startswith('win'):
print('you are using windows')
What if your operating system is a Mac?