Changeset 529:0ffb493a6fa4


Ignore:
Timestamp:
04/09/11 22:11:18 (12 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Rebase:
65333531393961383936666534666462353038303364643662343032353030386432323536323362
Message:

Add support for sounds for breaking objects.

Location:
skaapsteker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/sound.py

    r505 r529  
    66from .constants import FREQ, BITSIZE, CHANNELS, BUFFER
    77
     8_GLOBAL_SOUND = None
     9
     10
     11def load_sound(key, track_name, volume=None):
     12    if _GLOBAL_SOUND is not None:
     13        _GLOBAL_SOUND.load_sound(key, track_name, volume)
     14
     15def play_sound(key):
     16    if _GLOBAL_SOUND is not None:
     17        _GLOBAL_SOUND.play_sound(key)
     18
     19
    820class SoundSystem(object):
    921
    1022    def __init__(self, want_sound):
     23        global _GLOBAL_SOUND
    1124        if want_sound:
    1225            # See if we can actually enabled sound
     
    2336
    2437        self._sounds = {}
     38        _GLOBAL_SOUND = self
    2539
    2640
     
    3852            mixer.music.stop()
    3953
    40     def load_sound(self, key, track_name):
     54    def load_sound(self, key, track_name, volume=None):
    4155        if key in self._sounds:
    4256            # First caller wins on duplicate keys
     
    4660        else:
    4761            self._sounds[key] = pygame.mixer.Sound(data.filepath(track_name))
     62            if volume is not None:
     63                self._sounds[key].set_volume(volume)
    4864
    4965    def play_sound(self, key):
  • skaapsteker/sprites/items.py

    r525 r529  
    1 from .. import engine, data
     1from .. import engine, data, sound
    22from .base import Item, PC_LAYER, PROJECTILE_LAYER
    33
     
    1313    whole_image_file = None
    1414    broken_image_file = None
     15    breaking_sound = (None, None)
    1516
    1617    collides_with = set([PC_LAYER, PROJECTILE_LAYER])
     
    1920        super(BreakableItem, self).setup(**opts)
    2021        self.broken = broken
    21 
     22        if self.breaking_sound[0] is not None:
     23            track, volume = self.breaking_sound
     24            sound.load_sound(track, track, volume)
    2225
    2326    def setup_image_data(self, pos):
     
    3033        self.broken = True
    3134        self.setup_image_data(self._starting_tile_pos)
     35        if self.breaking_sound[0] is not None:
     36            sound.play_sound(self.breaking_sound[0])
    3237
    3338    def damage(self, damage):
     
    216221    whole_image_file = 'props/vase-whole.png'
    217222    broken_image_file = 'props/vase-broken.png'
     223    breaking_sound = ('sounds/vase breaking.ogg', 0.1)
    218224
    219225
Note: See TracChangeset for help on using the changeset viewer.