Exemplo n.º 1
0
    def thunder(self, inc):
        wait = random.randint(0, 2+inc)

        while (self._last == wait):
            wait = random.randint(0, 2+inc)

        self._last = wait
        print "intensity:", wait
        thunder = Sound("%s/thunder_0%d.wav" % (self._data_folder, wait))
        if wait < 6:
            self.lightning.set_C(ON)
            self.lightning.send()
            time.sleep(random.uniform(0.5, 1.5))
            self.lightning.set_C(OFF)
            self.lightning.send()
            time.sleep(wait)

        if wait < 6:
            self.lightning.set_B(OFF)
            self.lightning.send()
        thunder.play()
        if wait < 6:
            time.sleep(0.3)
            self.lightning.set_B(ON)
            self.lightning.send()
        time.sleep(thunder.get_length()-0.3)
        thunder.fadeout(200)
        time.sleep(wait)
Exemplo n.º 2
0
class SoundEffect:
    """Class wrapping ``pygame.mixer.Sound`` with the ability to enable/disable sound globally

    Use this instead of ``pygame.mixer.Sound``. The interface is fully transparent.
    """
    def __init__(self, source, ui_config):
        self._ui_config = ui_config
        if ui_config.sound_on:
            self.sound = Sound(source)

    def play(self, loops=0, maxtime=0, fade_ms=0):
        if self._ui_config:
            self.sound.play(loops, maxtime, fade_ms)

    def stop(self):
        if self._ui_config:
            self.sound.stop()

    def fadeout(self, time):
        if self._ui_config:
            self.sound.fadeout(time)

    def set_volume(self, value):
        if self._ui_config:
            self.sound.set_volume(value)

    def get_volume(self):
        if self._ui_config:
            return self.sound.get_volume()

    def get_num_channels(self):
        if self._ui_config:
            return self.sound.get_num_channels()

    def get_length(self):
        if self._ui_config:
            return self.get_length()

    def get_raw(self):
        if self._ui_config:
            return self.sound.get_raw()
Exemplo n.º 3
0
class Sound:
    """Class wrapping ``pygame.mixer.Sound`` with the ability to enable/disable sound globally

    Use this instead of ``pygame.mixer.Sound``. The interface is fully transparent.
    """
    def __init__(self, source):
        if config.SOUND:
            self.sound = OldSound(source)

    def play(self, loops=0, maxtime=0, fade_ms=0):
        if config.SOUND:
            self.sound.play(loops, maxtime, fade_ms)

    def stop(self):
        if config.SOUND:
            self.sound.stop()

    def fadeout(self, time):
        if config.SOUND:
            self.sound.fadeout(time)

    def set_volume(self, value):
        if config.SOUND:
            self.sound.set_volume(value)

    def get_volume(self):
        if config.SOUND:
            return self.sound.get_volume()

    def get_num_channels(self):
        if config.SOUND:
            return self.sound.get_num_channels()

    def get_length(self):
        if config.SOUND:
            return self.get_length()

    def get_raw(self):
        if config.SOUND:
            return self.sound.get_raw()