Exemple #1
0
    def spin_wheel():  # add wheel turning music pipipipipipip todo
        SPIN_SPEED = 0.02
        global wheel_state
        spin_strength = random.randint(100, 250)
        show_player()
        mixer.music.load('misc/sound/Bonus Wheel Music.wav')
        mixer.music.play(-1)
        while spin_strength:
            wheel_path = "misc/wheels/{}.gif".format(wheel_state)
            screen.bgpic(wheel_path)

            if spin_strength < 4:
                delay(SPIN_SPEED * 8)
                mixer.Channel(0).play(mixer.Sound('misc/sound/ding.wav'))
            elif spin_strength < 10:
                delay(SPIN_SPEED * 6)
                mixer.Channel(0).play(mixer.Sound('misc/sound/ding.wav'))
            elif spin_strength < 40:
                delay(SPIN_SPEED * 4)
                mixer.Channel(0).play(mixer.Sound('misc/sound/ding.wav'))
            else:
                delay(SPIN_SPEED)
                mixer.Channel(0).play(mixer.Sound('misc/sound/fastding.wav'))
            screen.update()

            wheel_state += 1
            spin_strength -= 1
            if wheel_state == 24:
                wheel_state = 0

        wheel_state = wheel_state - 1 if wheel_state != 0 else 23
        delay(3)  # todo release fix
        mixer.music.fadeout(1)
        return wheel_outcomes[wheel_state]
Exemple #2
0
 def changeState(key):
   global state, score, level, shapes, total_score
   if checkState():
     mixer.Channel(0).play(sound1)
     if score == GAME_WIDTH:
       mixer.Channel(1).play(lvl_sound)
       total_score += score
       score = 0
       level += 1
       shapes = []
       for i in range(4):      
         generatePlayer(level+1)
         shapes.append(player)
       renderBottom(shapes, shapesCanvas)
       if level == len(LEVELS):
         you_won()
     else:
       score += 1
     renderBar(score)
   else:
     mixer.Channel(0).play(sound2)
     score -= 1
     if score == -1:
       game_over()
     renderBar(score)
   generateState()
   renderState(state, player)
Exemple #3
0
    def __init__(self):
        super(BattleCity, self).__init__()

        self.setWindowFlags(Qt.WindowCloseButtonHint)
        self.setWindowIcon(QIcon('./images/tank_icon.png'))
        self.setWindowTitle("Battle City")

        mixer.init()
        self.channel_0 = mixer.Channel(0)
        self.channel_1 = mixer.Channel(1)
        self.channel_2 = mixer.Channel(2)
        self.channel_3 = mixer.Channel(3)

        self.gameplay_soundtrack = mixer.Sound(
            "./sounds/gameplay_sountrack.ogg")
        self.losing_sound = mixer.Sound("./sounds/losing_sound.ogg")
        self.bullet_fired_sound = mixer.Sound("./sounds/fire_sound.wav")
        self.bullet_impact_sound = mixer.Sound("./sounds/impact_sound.wav")

        self.main_window_width = 1600
        self.main_window_height = 900
        self.board_width = 1200
        self.board_height = 675
        self.stat_width = 300
        self.stat_height = 675

        self.stat_font_size = 2
        self.main_window_layout = None
        self.mode = None

        self.initUI()
        self.classicPalette()
Exemple #4
0
    def get_action(self, board):
        mixer.Channel(2).play(mixer.Sound('./Resources/ROBOT_SE/my_turn.ogg'))

        try: 
            color, loc = self.det.getLoc()
            if self.first_action:
                self.first_action = False
                from time import sleep
                sleep(2)
                mixer.Channel(2).play(mixer.Sound('./Resources/ROBOT_SE/lesson.ogg'))
            while color != self.player:
                print(color)
                color, loc = self.det.getLoc()
            
            
            print(loc)            
            location = loc
            if isinstance(location, str):  # for python3
                location = [int(n, 10) for n in location.split(",")]
            move = board.location_to_move(location)
        except Exception as e:
            print('exeception found in "get action" with "{}"'.format(e))
            move = -1
        if move == -1 or move not in board.availables:
            print("invalid move:{}".format(move))
            time.sleep(10)
            move = self.get_action(board)
        return move
Exemple #5
0
 def _work(self):
     """Replenish sample buffer."""
     if (sum(len(q) for q in self.generators) == 0
             and self._next_tone == [None, None, None, None]):
         # check if mixer can be quit
         self._check_quit()
         return
     self._check_init_mixer()
     for voice in range(4):
         if mixer.Channel(voice).get_queue() is not None:
             # nothing to do
             continue
         while True:
             if self._next_tone[voice] is None or self._next_tone[
                     voice].loop:
                 try:
                     self._next_tone[voice] = self.generators[
                         voice].popleft()
                 except IndexError:
                     if self._next_tone[voice] is None:
                         current_chunk = None
                         break
             current_chunk = self._next_tone[voice].build_chunk(
                 CHUNK_LENGTH)
             if current_chunk is not None:
                 break
             self._next_tone[voice] = None
         if current_chunk is not None:
             # enqueue chunk in mixer
             snd = pygame.sndarray.make_sound(current_chunk)
             mixer.Channel(voice).queue(snd)
Exemple #6
0
    def play(self, hand_index, index):
        from utils.selected_instrument import selected_instr
        tune = None
        channel_ = mixer.Channel(0)
        if(index != 6 and index != 7 and index != 0):
            try:
                tune = self.note_dict[selected_instr][self.current_map[selected_instr][hand_index][str(index)]]
                channel_ = mixer.Channel(
                    index-1) if hand_index == 0 else mixer.Channel(4+index)
            except:
                pass

        if(index == 0):
            self.active[hand_index] = [False, False, False, False, False]
            pass
        elif(index == 1 and not self.active[hand_index][0] and tune):
            self.active[hand_index] = [True, False, False, False, False]
            channel_.play(tune)

        elif(index == 2 and not self.active[hand_index][1] and tune):
            channel_.play(tune)
            self.active[hand_index] = [False, True, False, False, False]

        elif(index == 3 and not self.active[hand_index][2] and tune):
            channel_.play(tune)
            self.active[hand_index] = [False, False, True, False, False]

        elif(index == 4 and not self.active[hand_index][3] and tune):
            channel_.play(tune)
            self.active[hand_index] = [False, False, False, True, False]

        elif(index == 5 and not self.active[hand_index][4] and tune):
            channel_.play(tune)
            self.active[hand_index] = [False, False, False, False, True]
Exemple #7
0
 def _stop_channel(self, channel):
     """Stop sound on a channel."""
     if mixer.get_init():
         mixer.Channel(channel).stop()
         # play short silence to avoid blocking the channel
         # otherwise it won't play on queue()
         silence = pygame.sndarray.make_sound(numpy.zeros(1, numpy.int16))
         mixer.Channel(channel).play(silence)
Exemple #8
0
    def __load(self, plane_id, color_id):
        self.group_image = []
        self.ammo_image = []
        self.ammo_number = []
        self.ammo_sounds = []
        self.ammo_index = 0
        #on ouvre le fichier de specs json et on récupère le dossier des animations de l'avion
        data = json.load(open(SPEC_DIR, "r"))["body"]
        path_image = path.join(data[plane_id]["image"], str(color_id))

        #on charge des specs...
        self.speed = data[plane_id]["vitesse"]
        self.ammo = data[plane_id]["munitions"]
        self.shoot_delay = self.ammo[0]["frequence_de_tir"]
        self.max_life = data[plane_id]["vie"]
        self.actual_life = self.max_life

        #on paramètre le rectangle d'affichage de la vie avec un rect extérieur pour la bordure noir
        #et un intérieur de couleur pour l'affichage de la vie
        self.rect_life = Rect(0 + WIDTH // 4, HEIGHT - 10, WIDTH - WIDTH // 2,
                              10)
        self.rect_life_inner = self.rect_life.copy()
        self.rect_life_inner.left += 1
        self.rect_life_inner.top += 1
        self.rect_life_inner.width -= 2
        self.rect_life_inner.height -= 2

        #on génère 100 nuances de couleures entre rouge et vert
        self.color_scale = list(Color("red").range_to(Color("green"), 100))
        #on récupère la première que l'on converti du format (1, 1, 1) à (250, 250, 250)
        rgb_color = self.color_scale[99].rgb
        self.actual_color = (int(rgb_color[0] * 250), int(rgb_color[1] * 250),
                             int(rgb_color[2] * 250))

        #on réserve de channels de son pour le son de l'avion et celui de ses munitions
        mixer.set_reserved(PLAYER_CHANNEL)
        mixer.set_reserved(AMMO_CHANNEL)
        #on les récupères, on change leur volume et on lance le son de l'avion à l'infini
        self.ammo_channel = mixer.Channel(AMMO_CHANNEL)
        self.ammo_channel.set_volume(BULLET_SOUND_PLAYER)
        self.sound_channel = mixer.Channel(PLAYER_CHANNEL)
        self.sound_channel.set_volume(SOUND_PLAYER)
        self.sound_channel.play(mixer.Sound(data[plane_id]["sound"]), -1)

        #pour chaque images d'animations de l'avion on les charge, on les transforme et on les ajoute à l'array finale
        for file in os.listdir(path_image):
            img = image.load(path.join(path_image, file)).convert_alpha()
            img = transform.scale(img, (100, 75))
            self.group_image.append(img)
        #idem pour chaque munition avec les trois array representant les images, le nombre de munitions et les sons par munitions
        for file in self.ammo:
            img = image.load(path.join(file["image"])).convert_alpha()
            size = (img.get_width() // 3, img.get_height() // 3)
            img = transform.scale(img, size)
            img.set_colorkey(BLACK)
            self.ammo_image.append(img)
            self.ammo_number.append(file["base_munitions"])
            self.ammo_sounds.append(mixer.Sound(file["sound"]))
    def __init__(self):
        # screen settings
        self.screen_width = 1200
        self.screen_height = 800
        self.stars_limit = 8
        print('Automatic screen resolution: ' + str(self.screen_width) + ' ' + str(self.screen_height))
        self.bg_color = (0, 0, 0)

        self.ship_speed_factor = None
        self.ship_limit = 3

        self.bullet_speed_factor = None
        self.bullet_width = 3
        self.bullet_height = 15
        self.bullet_color = (255, 255, 255)
        self.bullets_allowed = 3

        self.bunker_block_size = 10
        self.bunker_color = (0, 255, 0)

        self.beam_speed_factor = None
        self.beams_allowed = 1

        self.audio_channels = 5
        self.ship_channel = mixer.Channel(0)
        self.alien_channel = mixer.Channel(1)
        self.death_channel = mixer.Channel(2)
        self.ufo_channel = mixer.Channel(3)
        self.music_channel = mixer.Channel(4)
        self.normal_music_interval = 725
        self.music_interval = self.normal_music_interval
        self.music_speedup = 25
        self.bgm = [
            mixer.Sound('resources/Sounds/Venussong.wav')
        ]
        self.bgm_index = None
        self.last_beat = None

        self.normal_alien_speed = 2
        self.alien_speed_limit = None
        self.alien_base_limit = None
        self.alien_speed_factor = None
        self.ufo_speed = None
        self.last_ufo = None
        self.ufo_min_interval = 10000
        self.fleet_drop_speed = 10
        self.fleet_direction = None
        self.alien_points = None
        self.ufo_point_values = [50, 100, 150]
        self.beam_stamp = None
        self.beam_time = 1000

        self.speedup_scale = 1.1

        self.initialize_dynamic_settings()
        self.initialize_audio_settings()
Exemple #10
0
 def handleMusic(self):
     if self.musicFlag == -1:
         mixer.Channel(0).pause()
         self.musicFlag = 1
     elif self.musicFlag == 0:
         mixer.Channel(0).play(mixer.Sound('./card/001.ogg'), loops=-1)
         self.musicFlag = -1
     else:
         mixer.Channel(0).unpause()
         self.musicFlag = -1
Exemple #11
0
    def __init__(self):
        """Initialize the game settings."""
        # Screen Settings
        self.screen_width = 1200
        self.screen_height = 800
        self.bg_color = (200, 200, 200)

        # Ship settings
        self.ship_speed_factor = None
        self.ship_limit = 3

        # Bullet Settings
        self.bullet_speed_factor = None
        self.bullet_width = 3
        self.bullet_height = 15
        self.bullet_color = (60, 60, 60)
        self.bullets_allowed = 3

        # Alien laser settings
        self.laser_speed_factor = None
        self.lasers_allowed = 1
        self.laser_time = 1000
        self.laser_stamp = None

        # Alien settings
        self.alien_speed_factor = None
        self.fleet_drop_speed = 10
        self.fleet_direction = None
        self.alien_points = None

        # UFO settings
        self.ufo_speed_factor = None
        self.time_from_last_ufo = None
        self.ufo_interval = 25000
        self.ufo_points = [50, 100, 150]

        # Bunker setting
        self.bunker_block_size = 12
        self.bunker_color = (0, 255, 0)

        # How quickly the game speeds up
        self.speedup_scale = 1.2
        
        # How quickly the alien point values increase
        self.score_scale = 2

        # Initialize a channel for each object that needs one
        self.audio_channels = 4
        self.ship_channel = mixer.Channel(0)
        self.alien_channel = mixer.Channel(1)
        self.death_channel = mixer.Channel(2)
        self.ufo_channel = mixer.Channel(3)

        self.initialize_dynamic_settings()
        self.initialize_audio_settings()
Exemple #12
0
    def __JustPlay(self, music_link, destroy):
        tosend = {"status": "", "continue": False}

        try:
            mkdir("tempmusic")
        except (FileExistsError):
            pass

        self.__rootLogger.debug(f"Music link is: {music_link}")
        self.__rootLogger.debug("Starting mp3 download.")

        tosend[
            "status"] = f"Music link is: {music_link}. Starting mp3 download."
        self.__toSend = tosend

        music_name = YouTubeMP3Downloader(music_link,
                                          path_to_download="tempmusic",
                                          logger=self.__rootLogger)

        if music_name == None:
            self.__rootLogger.error(
                "No music returned from YouTube MP3 downloader function.")
            tosend[
                "status"] = "No music returned from YouTube MP3 downloader function."
            self.__toSend = tosend
            return False

        if not self.__isPlaying:
            tosend["status"] = f"Playing {music_name}."
            self.__toSend = tosend

            music = mixer.Sound(f"tempmusic\\{music_name}")
            channel = mixer.Channel(0)
            self.__rootLogger.info(f"Playing '{music_name}.'")
            channel.play(music)

            while True:
                self.__isPlaying = True
                if not mixer.Channel(0).get_busy():
                    self.__rootLogger.info(f"'{music_name} finished.")
                    self.__isPlaying = False
                    tosend["status"] = "Music finished"
                    tosend["continue"] = True
                    self.__toSend = tosend
                    break

            if destroy:
                remove(path.join("tempmusic", music_name))

            return True

        else:
            return False
Exemple #13
0
 def __init__(self, trackNum, loop, channel):
     try:
         self.trackNum = trackNum
         self.loop = loop
         self.channel = channel
         mixer.init(channels=AUDIO_CHANNELS) 
         trackFile = DIRECTORY + 'TRACK' + self.trackNum + '.wav'
         self.soundFile = mixer.Sound(trackFile)
         mixer.Channel(self.channel)
         mixer.Channel(self.channel).set_volume(VOLUME)
     except:
         errMsg.append("20 S.L.162")
Exemple #14
0
    def fadeout_music(self, time_ms = 450, channel=CH_ALL_MUSIC_CHANNELS):
        """ """
        if not self.enabled: return

        if(channel==CH_ALL_MUSIC_CHANNELS):
            mixer.music.fadeout(time_ms)
            mixer.Channel(CH_MUSIC_1).fadeout(time_ms)
            mixer.Channel(CH_MUSIC_2).fadeout(time_ms)
        elif channel ==CH_MUSIC:
            mixer.music.fadeout(time_ms)
        else:
            mixer.Channel(channel).fadeout(time_ms)
Exemple #15
0
    def __set_volume(self, new_volume):
        """ sets a volume to a value, should be in the range [0..1] """

        if not self.enabled: return
        self.volume = new_volume

        mixer.Channel(CH_VOICE).set_volume(self.volume)

        # adjust current Music mixer and Music channel volume level based on current track at new volume
        mixer.music.set_volume (new_volume * self.music_ducking_effect * self.current_music_track_volume)
        mixer.Channel(CH_MUSIC_1).set_volume (new_volume * self.music_ducking_effect) # for these, the sound file has
        mixer.Channel(CH_MUSIC_2).set_volume (new_volume * self.music_ducking_effect) # self.current_music_track_volume
Exemple #16
0
    def play_music(self, key, loops=0, start_time=0.0, channel=CH_MUSIC):
        """Start playing music at the given *key*."""
        # self.logger.info("PLAY MUSIC " + str(key) + " on channel " + str(channel))
        if not self.enabled: return
        if key in self.music:
            if len(self.music[key]) > 1:
                # self.logger.info("Randomize Music")
                random.shuffle(self.music[key])

            if channel > 0:
                # playback music via regular "sound" mechanism
                if (start_time > 0):
                    raise ValueError, "play_music does not support start_time>0 for non standard channels"

                vol = self.music[key][0]["volume"]
                sound_file = self.music[key][0]["file"]
                mixer.Channel(channel).set_volume(self.volume *
                                                  self.music_ducking_effect)

                if (self.music[key][0]["sound_obj"] is not None):
                    new_sound = self.music[key][0]["sound_obj"]
                else:
                    self.logger.warning(
                        "NOTE: Using non-streaming playback on music track [%s]; it is recommended you pre-load this track (change asset_manager entry to streaming_load:False)."
                        % key)

                    new_sound = mixer.Sound(str(sound_file))
                    new_sound.set_volume(vol)

                self.logger.info("Music loaded, now telling to play")
                mixer.Channel(channel).play(new_sound, loops)
            else:
                # playback on standard pyGame music object
                # get the volume
                self.current_music_track_volume = self.load_music(key)

                if (self.music[key][0]["sound_obj"] is not None):
                    self.logger.warning(
                        "NOTE: Using streaming playback on a pre loaded music track, [%s]; recommended you play to a different channel."
                        % key)

                # self.logger.info("Music loaded, now setting volume and telling to play")
                mixer.music.set_volume(self.volume *
                                       self.music_ducking_effect *
                                       self.current_music_track_volume)

                mixer.music.play(loops, start_time)
                # self.logger.info("Play command issue, now unpause?")
                mixer.music.unpause()
                # self.logger.info("play music request complete")

        else:
            self.logger.info("KEY NOT FOUND" + str(key))
Exemple #17
0
    def stop_music(self, channel=CH_ALL_MUSIC_CHANNELS):
        """Stop the currently-playing music."""
        if not self.enabled: return

        if(channel==CH_ALL_MUSIC_CHANNELS):
            mixer.music.stop()
            mixer.Channel(CH_MUSIC_1).stop()
            mixer.Channel(CH_MUSIC_2).stop()
        elif channel == CH_MUSIC:
            mixer.music.stop()
        else:
            self.logger.info("stopping music on channel: %s" % channel)
            mixer.Channel(channel).stop()
Exemple #18
0
    def __init__(self):
        self.music_channel = mixer.Channel(0)
        self.music_channel.set_volume(0.2)
        self.sfx_channel = mixer.Channel(1)
        self.sfx_channel.set_volume(0.2)

        self.allowSFX = True

        self.soundtrack = mixer.Sound("./sfx/main_theme.ogg")
        self.coin = mixer.Sound("./sfx/coin.ogg")
        self.bump = mixer.Sound("./sfx/bump.ogg")
        self.stomp = mixer.Sound("./sfx/stomp.ogg")
        self.jump = mixer.Sound("./sfx/small_jump.ogg")
        self.death = mixer.Sound("./sfx/death.wav")
    def __init__(self):
        # screen settings
        self.screen_width = 1200
        self.screen_height = 800
        self.stars_limit = 8
        print('Automatic screen resolution: ' + str(self.screen_width) + ' ' + str(self.screen_height))
        self.bg_color = (0, 0, 0)

        # ship settings
        self.ship_speed_factor = None
        self.ship_limit = 3

        # bullet settings
        self.bullet_speed_factor = None
        self.bullet_width = 3
        self.bullet_height = 15
        self.bullet_color = (255, 255, 255)
        self.bullets_allowed = 3

        # beam settings
        self.beam_speed_factor = None
        self.beams_allowed = 1

        # sound settings
        self.alien_death_sound = mixer.Sound('sound/alien_death.wav')
        self.alien_fire_sound = mixer.Sound('sound/alien_shoot.wav')
        self.ship_fire_sound = mixer.Sound('sound/ship_shoot.wav')
        self.ship_death_sound = mixer.Sound('sound/ship_death.wav')
        self.alien_death_sound.set_volume(0.3)
        self.alien_fire_sound.set_volume(0.3)
        self.ship_fire_sound.set_volume(0.3)
        self.ship_death_sound.set_volume(0.5)
        self.audio_channels = 3
        self.ship_channel = mixer.Channel(0)
        self.alien_channel = mixer.Channel(1)
        self.death_channel = mixer.Channel(2)

        # alien settings
        self.alien_speed_factor = None
        self.fleet_drop_speed = 10
        self.fleet_direction = None
        self.alien_points = None
        self.score_scale = 1.5

        # How quickly the game speeds up
        self.speedup_scale = 1.1
        self.initialize_dynamic_settings()
        self.initialize_audio_settings()
    def __init__(self, root_directory, music_controller=None):
        mixer.init()
        self.channel = mixer.Channel(0)
        self.music_controller = music_controller

        #load in all the sounds and store references in proper dictionaries
        self.period_sounds = []
        for i in range(0, 41):
            sound_file_name = 'period' + str(
                i) + '.wav' if i >= 10 else 'period0' + str(i) + '.wav'
            sound_file_name = os.path.join(root_directory, sound_file_name)
            self.period_sounds.append(mixer.Sound(sound_file_name))

        self.time_remaining_sounds = []
        for i in range(0, 61):
            if i == 0:
                sound_file_name = os.path.join(root_directory,
                                               'fivecountdown.wav')
            else:
                minutes_remaining_str = str(
                    i // 2) if (i // 2) >= 10 else '0' + str(i // 2)
                seconds_remaing_str = '00' if i % 2 == 0 else '30'
                sound_file_name = f'remaining{minutes_remaining_str}{seconds_remaing_str}.wav'
                sound_file_name = os.path.join(root_directory, sound_file_name)
            self.time_remaining_sounds.append(mixer.Sound(sound_file_name))

        self.misc_sounds = {}
        self.misc_sounds['beepthree'] = mixer.Sound(
            os.path.join(root_directory, 'beepthree.wav'))
        self.misc_sounds['boxingbell'] = mixer.Sound(
            os.path.join(root_directory, 'boxingbell.wav'))
        self.misc_sounds['endofscript'] = mixer.Sound(
            os.path.join(root_directory, 'endofscript.wav'))
    def __init__(self, ai_settings, screen):
        """Initialize the ship, and set its starting position."""
        super(Ship, self).__init__()
        self.screen = screen
        self.ai_settings = ai_settings

        # Load the ship image, and get its rect.
        self.ss = spritesheet('images/SpriteSheet.png')
        self.image = self.ss.image_at((0,160,32,32))
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()

        # Start each new ship at the bottom center of the screen.
        self.rect.centerx = self.screen_rect.centerx
        self.rect.bottom = self.screen_rect.bottom

        # Store a decimal value for the ship's center.
        self.center = float(self.rect.centerx)

        # Movement flags.
        self.moving_right = False
        self.moving_left = False

        # Sound
        self.death_sound = pygame.mixer.Sound('sound/explosion.wav')
        self.fire_sound = pygame.mixer.Sound('sound/shoot.wav')
        self.channel = mixer.Channel(1)
        self.channel.set_volume(0.01)

        # Death tag
        self.dead = False

        # Death index
        self.dIndex = 0
Exemple #22
0
def main():
    init()
    screen = pygame.display.set_mode((500, 500))
    sound = build_sound(69, 1)  # 69 is A4
    channel = mixer.Channel(0)  # don't use mixer.find_channel()
    clock = pygame.time.Clock()
    while 1:
        clock.tick(60)
        for event in pygame.event.get():
            if event.type == QUIT:
                return
            if event.type == KEYDOWN and event.key == K_ESCAPE:
                return
            if event.type == KEYDOWN and event.key == K_SPACE:
                if channel and channel.get_busy():  # sound not over
                    # sound.get_num_channels() lists active chans, not busy ones
                    channel.stop()
                else:
                    channel.play(sound)  # background thread plays this

        # display color to match channel state
        if channel and channel.get_busy():
            screen.fill((255, 0, 0))
        else:
            screen.fill((0, 0, 255))
        pygame.display.flip()
Exemple #23
0
    def playMusic(self, keyword):
        usedChannels = [n for n in self.music_channels.values]

        for n in range(5):
            if not (n in usedChannels):
                self.music_channels[keyword] = n
                mixer.Channel(n).play(self.music[keyword], -1)
Exemple #24
0
 def playTrack(self):
     try:
         mixer.Channel(self.channel).play(self.soundFile,loops=self.loop)
     except NameError:
         errMsg.append("12 S.L.162")
     except AttributeError:
         errMsg.append("20 S.L.162")
Exemple #25
0
 def get_sound(self,file_name,channel_number,a,volum=1):# a- колличество повторений, а=0 -один раз проиграть, а=-1 - проигрывать беcконечно
      mixer.init(44010, -16, channel_number,2024)
      mixer.init()
      sound=mixer.Sound(file_name)
      sound.set_volume(volum)
      channel = mixer.Channel(channel_number)
      channel.play(sound,a)
Exemple #26
0
def init():
    global channel1
    global channel2
    global channel3
    global console
    global help_commands

    mixer.init()
    channel1 = mixer.Channel(0)
    channel2 = mixer.Channel(1)
    channel3 = mixer.Channel(2)
    channel2.set_volume(0.25)
    channel3.set_volume(0.25)

    console = Console()
    help_commands = """[default on red]bath[/] - take a bath in our hot springs :umbrella: 
Exemple #27
0
    def test_channel(self):
        """Ensure Channel() creation works."""
        channel = mixer.Channel(0)

        # self.assertIsInstance(channel, mixer.Channel)  # Would be nice.
        # type(pygame.mixer.Channel) gives <class 'builtin_function_or_method'>
        # Check class name instead.
        self.assertEqual(channel.__class__.__name__, 'Channel')
Exemple #28
0
    def test_get_busy(self):
        """Ensure an idle channel's busy state is correct."""
        expected_busy = False
        channel = mixer.Channel(0)

        busy = channel.get_busy()

        self.assertEqual(busy, expected_busy)
Exemple #29
0
 def set_volume(self, volume=None):
     "set_volume( volume): sets volume of all channels (0-1)"
     if volume is None:
         volume = self.volume
     else:
         self.volume = volume
     for i in range(mixer.get_num_channels()):
         mixer.Channel(i).set_volume(volume)
Exemple #30
0
    def test_get_volume(self):
        """Ensure a channel's volume can be retrieved."""
        expected_volume = 1.0  # default
        channel = mixer.Channel(0)

        volume = channel.get_volume()

        self.assertAlmostEqual(volume, expected_volume)