MakerBox-NZ / pygame_trukavev2

uay
0 stars 0 forks source link

Operating System Options #8

Open cyanidecupcake opened 7 years ago

cyanidecupcake commented 7 years ago

What if your operating system is a Mac?

notklaatu commented 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
notklaatu commented 7 years ago

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')