Mercurial > rinkhals
view gamelib/sound.py @ 93:1fd56b625b24
Added ability to handle extracting from zip archives after download, although the code is becoming slightly hairy as a result
Added some nicely licensed chicken and rooster samples from OLPC
author | David Fraser <davidf@sjsoft.com> |
---|---|
date | Wed, 02 Sep 2009 11:19:18 +0000 |
parents | 23a8b2e49e9f |
children | 529a4d41c67a |
line wrap: on
line source
import os import pygame import data import constants SOUND_INITIALIZED = False def init_sound(): """initialize the sound system""" global SOUND_INITIALIZED try: pygame.mixer.init(constants.FREQ, constants.BITSIZE, constants.CHANNELS, constants.BUFFER) SOUND_INITIALIZED = True except pygame.error, exc: print >>sys.stderr, "Could not initialize sound system: %s" % exc def play_sound(filename): """plays the sound with the given filename from the data sounds directory""" if not SOUND_INITIALIZED: return file_path = data.filepath("sounds", filename) if not os.path.exists(file_path): return pygame.mixer.music.load(file_path) pygame.mixer.music.play()