示例#1
0
 def update(self, time):
   print ('update', self._filename, self._playing, time, self._start_time, self._end_time)
   if time < self._start_time: pass
   elif self._playing == 'no':
     try:
       music.stop()
       music.load(self._filename)
       music.set_volume(0.01) # 0.0 stops pygame.mixer.music.
       # Workaround for a pygame/libsdl mixer bug.
       #music.play(0, self._start)
       music.play(0, 0)
       self._playing = 'yes'
     except: # Filename not found? Song is too short? SMPEG blows?
       music.stop()
       self._playing = 'no'
   elif time < self._start_time + 1000: # mixer.music can't fade in
     music.set_volume((time - self._start_time) / 1000.0)
   elif (time > self._end_time - 1000) and self._playing == 'yes':
     self._playing = 'fadeout'
     music.fadeout(1000)
   elif time > self._end_time:
     music.stop()
     dt = pygame.time.get_ticks() + 1000 - self._start_time
     self._end_time = dt + self._end_time
     self._start_time = dt + self._start_time
     self._playing = 'no'
示例#2
0
 def update(self, time):
     print('update', self._filename, self._playing, time, self._start_time,
           self._end_time)
     if time < self._start_time: pass
     elif self._playing == 'no':
         try:
             music.stop()
             music.load(self._filename)
             music.set_volume(0.01)  # 0.0 stops pygame.mixer.music.
             # Workaround for a pygame/libsdl mixer bug.
             #music.play(0, self._start)
             music.play(0, 0)
             self._playing = 'yes'
         except:  # Filename not found? Song is too short? SMPEG blows?
             music.stop()
             self._playing = 'no'
     elif time < self._start_time + 1000:  # mixer.music can't fade in
         music.set_volume((time - self._start_time) / 1000.0)
     elif (time > self._end_time - 1000) and self._playing == 'yes':
         self._playing = 'fadeout'
         music.fadeout(1000)
     elif time > self._end_time:
         music.stop()
         dt = pygame.time.get_ticks() + 1000 - self._start_time
         self._end_time = dt + self._end_time
         self._start_time = dt + self._start_time
         self._playing = 'no'
示例#3
0
文件: music.py 项目: dirkakrid/pgzero
def fadeout(seconds):
    """Fade out and eventually stop the music playback.

    :param seconds: The duration in seconds over which the sound will be faded
                    out. For example, to fade out over half a second, call
                    ``music.fadeout(0.5)``.

    """
    _music.fadeout(int(seconds * 1000))
示例#4
0
文件: god.py 项目: pluskid/irobot2
    def start(self):
        self._engine.render()  # initial render to init graphics
        self.put_robots()

        for robot in self._robots.itervalues():
            self.robot_born(robot)

        music.play()
        capture = self._config["system"]["capture"]
        paused = False
        while True:
            terminate = False
            for event in pygame.event.get():
                if event.type == QUIT:
                    terminate = True
                    break
                elif event.type == KEYDOWN:
                    if event.key == K_ESCAPE:
                        terminate = True
                        break
                    elif event.key == K_SPACE:
                        paused = not paused
                        if paused:
                            music.pause()
                        else:
                            music.unpause()
            if terminate:
                break

            time_passed = self._engine.tick()
            if paused:
                continue

            for shoot in self._gp_shoots:
                shoot.step(self, time_passed)

            # TODO: terminate the game when all
            # robot of one team is dead
            all_dead = True
            for robot in self._robots.itervalues():
                if robot["k.alive"] == True:
                    all_dead = False
                    self.perform_action(robot, time_passed)

                if all_dead:
                    break
            self._engine.render()

            self.recover_property(time_passed, prop="cp")

            if capture:
                self._frames.append(self._engine.screen.copy())

        music.fadeout(1000)
        if capture:
            self.save_capture()
        sys.exit()
示例#5
0
文件: music.py 项目: Muneop/test0504
def fadeout(seconds):
    """Fade out and eventually stop the music playback.

    :param seconds: The duration in seconds over which the sound will be faded
                    out. For example, to fade out over half a second, call
                    ``music.fadeout(0.5)``.

    """
    _music.fadeout(int(seconds * 1000))
示例#6
0
    def __init__(self, songs, courses, screen, game):
        InterfaceWindow.__init__(self, screen, "courseselect-bg.png")

        recordkeys = dict([(k.info["recordkey"], k) for k in songs])

        self._courses = [CourseDisplay(c, recordkeys, game) for c in courses]
        self._all_courses = self._courses
        self._index = 0
        self._clock = pygame.time.Clock()
        self._game = game
        self._config = dict(game_config)
        self._configs = []

        self._list = ListBox(FontTheme.Crs_list, [255, 255, 255], 32, 10, 256,
                             [373, 150])
        if mainconfig["folders"]:
            self._create_folders()
            self._create_folder_list()
        else:
            self._folders = None
            self._base_text = _("All Courses")
            self._courses.sort(SORTS[SORT_NAMES[mainconfig["sortmode"] %
                                                NUM_SORTS]])
            self._list.set_items([s.name for s in self._courses])

        self._course = self._courses[self._index]
        self._course.render()

        players = games.GAMES[game].players

        for i in range(players):
            self._configs.append(dict(player_config))

        ActiveIndicator([368, 306], height=32, width=266).add(self._sprites)
        HelpText(CS_HELP, [255, 255, 255], [0, 0, 0], FontTheme.help,
                 [186, 20]).add(self._sprites)

        self._list_gfx = ScrollingImage(self._course.image, [15, 80], 390)
        self._coursetitle = TextDisplay('Crs_course_name', [345, 28], [20, 56])
        self._title = TextDisplay('Crs_course_list_head', [240, 28], [377, 27])
        self._banner = ImageDisplay(self._course.banner, [373, 56])
        self._sprites.add([
            self._list, self._list_gfx, self._title, self._coursetitle,
            self._banner
        ])
        self._screen.blit(self._bg, [0, 0])
        pygame.display.update()
        self.loop()
        music.fadeout(500)
        pygame.time.wait(500)
        # FIXME Does this belong in the menu code? Probably.
        music.load(os.path.join(sound_path, "menu.ogg"))
        music.set_volume(1.0)
        music.play(4, 0.0)
        player_config.update(self._configs[0])  # Save p1's settings
        game_config.update(self._config)  # save game settings
def orchestrate(phonograph_name, once=False):
    if not SOUND_ON:
        return
    global MUSIC_PLAYING
    if MUSIC_PLAYING == phonograph_name:
        return
    path = data.filepath(os.path.join("numerical_phonographs", phonograph_name))
    if MUSIC_PLAYING:
        music.fadeout(1000)
    music.load(path)
    music.play(0 if once else -1)
    MUSIC_PLAYING = phonograph_name
示例#8
0
  def __init__(self, songs, courses, screen, game):
    InterfaceWindow.__init__(self, screen, "courseselect-bg.png")

    recordkeys = dict([(k.info["recordkey"], k) for k in songs])

    self._courses = [CourseDisplay(c, recordkeys, game) for c in courses]
    self._all_courses = self._courses
    self._index = 0
    self._clock = pygame.time.Clock()
    self._game = game
    self._config = dict(game_config)
    self._configs = []

    self._list = ListBox(FontTheme.Crs_list,
                         [255, 255, 255], 32, 10, 256, [373, 150])
    if len(self._courses) > 60 and mainconfig["folders"]:
      self._create_folders()
      self._create_folder_list()
    else:
      self._folders = None
      self._base_text = _("All Courses")
      self._courses.sort(SORTS[SORT_NAMES[mainconfig["sortmode"] % NUM_SORTS]])
      self._list.set_items([s.name for s in self._courses])

    self._course = self._courses[self._index]
    self._course.render()

    players = games.GAMES[game].players

    for i in range(players):
      self._configs.append(dict(player_config))

    ActiveIndicator([368, 306], height = 32, width = 266).add(self._sprites)
    HelpText(CS_HELP, [255, 255, 255], [0, 0, 0], FontTheme.help,
             [186, 20]).add(self._sprites)

    self._list_gfx = ScrollingImage(self._course.image, [15, 80], 390)
    self._coursetitle = TextDisplay('Crs_course_name', [345, 28], [20, 56])
    self._title = TextDisplay('Crs_course_list_head', [240, 28], [377, 27])
    self._banner = ImageDisplay(self._course.banner, [373, 56])
    self._sprites.add([self._list, self._list_gfx, self._title,
                       self._coursetitle, self._banner])
    self._screen.blit(self._bg, [0, 0])
    pygame.display.update()
    self.loop()
    music.fadeout(500)
    pygame.time.wait(500)
    # FIXME Does this belong in the menu code? Probably.
    music.load(os.path.join(sound_path, "menu.ogg"))
    music.set_volume(1.0)
    music.play(4, 0.0)
    player_config.update(self._configs[0]) # Save p1's settings
示例#9
0
文件: music.py 项目: shaik9/rdrive
def change_playlist(new_playlist):
    """Fade out any currently playing music and start playing from the given
	playlist."""
    #print "albow.music: change_playlist" ###
    global current_music, current_playlist, next_change_delay
    if music and new_playlist is not current_playlist:
        current_playlist = new_playlist
        if music_enabled:
            music.fadeout(fadeout_time * 1000)
            next_change_delay = max(0, change_delay - fadeout_time)
            jog_music()
        else:
            current_music = None
示例#10
0
def change_playlist(new_playlist):
    """Fade out any currently playing music and start playing from the given
    playlist."""
    #print "albow.music: change_playlist" ###
    global current_music, current_playlist, next_change_delay
    if music and new_playlist is not current_playlist:
        current_playlist = new_playlist
        if music_enabled:
            music.fadeout(fadeout_time * 1000)
            next_change_delay = max(0, change_delay - fadeout_time)
            jog_music()
        else:
            current_music = None
示例#11
0
    def change_playlist(new_playlist: PlayList):
        """
        Fade out any currently playing music and start playing from the given
        playlist.
        """

        musicLogger.info("change_playlist")

        global current_music, current_playlist, next_change_delay

        if music and new_playlist is not current_playlist:
            current_playlist = new_playlist
            if music_enabled:
                music.fadeout(fadeout_time * 1000)
                next_change_delay = max(0, change_delay - fadeout_time)
                MusicUtilities.jog_music()
            else:
                current_music = None
示例#12
0
文件: songselect.py 项目: asb/pydance
 def update(self, time):
   if self._filename is None: pass
   elif time < self._start_time: pass
   elif not self._playing:
     try:
       music.stop()
       music.load(self._filename)
       music.set_volume(0.01) # 0.0 stops pygame.mixer.music.
       # Workaround for a pygame/libsdl mixer bug.
       #music.play(0, self._start)
       music.play(0, 0)
       self._playing = True
     except: # Filename not found? Song is too short? SMPEG blows?
       music.stop()
       self.playing = False
   elif time < self._start_time + 1000: # mixer.music can't fade in
     music.set_volume((time - self._start_time) / 1000.0)
   elif time > self._end_time - 1000:
     music.fadeout(1000)
     self._playing = False
     self._filename = None
示例#13
0
文件: songselect.py 项目: asb/pydance
 def preview(self, song):
   if mainconfig["previewmusic"] and not song.isfolder:
     if (song.info["filename"].lower().endswith("mp3") and
         mainconfig["previewmusic"] == 2):
       music.stop()
       self._playing = False
       return
     if len(song.info["preview"]) == 2:
       # A DWI/SM/dance-style preview, an offset in the song and a length
       # to play starting at the offset.
       self._start, length = song.info["preview"]
       self._filename = song.info["filename"]
     else:
       # KSF-style preview, a separate filename to play.
       self._start, length = 0, 100
       self._filename = song.info["preview"]
     if self._playing: music.fadeout(500)
     self._playing = False
     self._start_time = pygame.time.get_ticks() + 500
     self._end_time = int(self._start_time + length * 1000)
   elif song.isfolder: music.fadeout(500)
示例#14
0
 def update(self, time):
     if self._filename is None: pass
     elif time < self._start_time: pass
     elif not self._playing:
         try:
             music.stop()
             music.load(self._filename)
             music.set_volume(0.01)  # 0.0 stops pygame.mixer.music.
             # Workaround for a pygame/libsdl mixer bug.
             #music.play(0, self._start)
             music.play(0, 0)
             self._playing = True
         except:  # Filename not found? Song is too short? SMPEG blows?
             music.stop()
             self.playing = False
     elif time < self._start_time + 1000:  # mixer.music can't fade in
         music.set_volume((time - self._start_time) / 1000.0)
     elif time > self._end_time - 1000:
         music.fadeout(1000)
         self._playing = False
         self._filename = None
示例#15
0
 def preview(self, song):
   if mainconfig["previewmusic"] and not song.isfolder:
     if (song.info["filename"].lower().endswith("mp3") and
         mainconfig["previewmusic"] == 2):
       music.stop()
       self._playing = False
       return
     if len(song.info["preview"]) == 2:
       # A DWI/SM/dance-style preview, an offset in the song and a length
       # to play starting at the offset.
       self._start, length = song.info["preview"]
       self._filename = song.info["filename"]
     else:
       # KSF-style preview, a separate filename to play.
       self._start, length = 0, 100
       self._filename = song.info["preview"]
     if self._playing: music.fadeout(500)
     self._playing = False
     self._start_time = pygame.time.get_ticks() + 500
     self._end_time = int(self._start_time + length * 1000)
   elif song.isfolder: music.fadeout(500)
示例#16
0
文件: songselect.py 项目: asb/pydance
  def __init__(self, songs, courses, screen, game):

    InterfaceWindow.__init__(self, screen, "newss-bg.png")
    songs = [s for s in songs if s.difficulty.has_key(game)]
    
    if len(songs) == 0:
      error.ErrorMessage(screen, _("You don't have any songs for the game mode (")
                         + game + _(") that you selected.")) #TODO: format using % for better i18n
      return


    # Construct a mapping between songs displays and dance displays.
    songs_and_dances = [(SongItemDisplay(s, game),
                         [DanceItemDisplay(s, game, diff) for diff in s.diff_list[game]])
                        for s in songs]

    for (s,ds) in songs_and_dances:
      for d in ds:
        s.danceitems[d.diff]=d
        d.songitem=s

    self._songs = [s[0] for s in songs_and_dances]
    self._dances = reduce(lambda x,y: x+y[1],songs_and_dances,[])

    self._index = 0
    self._game = game
    self._config = dict(game_config)
    self._all_songs = self._songs
    self._all_dances = self._dances
    self._all_valid_songs = [s for s in self._songs if s.info["valid"]]
    self._all_valid_dances = [d for d in self._dances if d.info["valid"]]

    self._list = ListBox(FontTheme.SongSel_list,
                         [255, 255, 255], 26, 16, 220, [408, 56])
    # please use set constructions after python 2.4 is adopted
    sort_name = self._update_songitems()

    if len(self._songs) > 60 and mainconfig["folders"]:
      self._create_folders()
      self._create_folder_list()
    else:
      self._folders = None
      self._base_text = sort_name.upper()

      self._songitems.sort(key=SORTS[sort_name])
      self._list.set_items([s.info["title"] for s in self._songitems])

    self._preview = SongPreview()
    self._preview.preview(self._songitems[self._index])
    self._song = self._songitems[self._index]

    # Both players must have the same difficulty in locked modes.
    self._locked = games.GAMES[self._game].couple

    players = games.GAMES[game].players
#    self._diffs = [] # Current difficulty setting
    self._diff_widgets = [] # Difficulty widgets
    self._configs = []
    self._diff_names = [] # Current chosen difficulties
    self._pref_diff_names = [] # Last manually selected difficulty names
    self._last_player = 0 # Last player to change a difficulty

    for i in range(players):
      self._configs.append(dict(player_config))
      d = DifficultyBox([84 + (233 * i), 434])
      self._pref_diff_names.append(util.DIFFICULTY_LIST[0])
      if not self._song.isfolder:
        self._diff_names.append(self._song.diff_list[0])
        diff_name = self._diff_names[i]
        rank = records.get(self._song.info["recordkey"],
                           diff_name, self._game)[0]
        grade = grades.grades[self._config["grade"]].grade_by_rank(rank)
        d.set(diff_name, DIFF_COLORS.get(diff_name, [127, 127, 127]),
              self._song.difficulty[diff_name], grade)
      else:
        self._diff_names.append(" ")        
        d.set(_("None"), [127, 127, 127], 0, "?")
      self._diff_widgets.append(d)
    
    ActiveIndicator([405, 259], width = 230).add(self._sprites)
    self._banner = BannerDisplay([205, 230])
    self._banner.set_song(self._song)
    self._sprites.add(HelpText(SS_HELP, [255, 255, 255], [0, 0, 0],
                               FontTheme.help, [206, 20]))

    self._title = TextDisplay('SongSel_sort_mode', [210, 28], [414, 27])
    self._sprites.add(self._diff_widgets +
                      [self._banner, self._list, self._title])
    self._screen.blit(self._bg, [0, 0])
    pygame.display.update()
    self.loop()
    music.fadeout(500)
    pygame.time.wait(500)
    # FIXME Does this belong in the menu code? Probably.
    music.load(os.path.join(sound_path, "menu.ogg"))
    music.set_volume(1.0)
    music.play(4, 0.0)
    player_config.update(self._configs[0]) # Save p1's settings
示例#17
0
    def loop(self):
        pid, ev = ui.ui.poll()
        self._list.set_index(self._index)
        self._title.set_text(self._base_text + " - %d/%d" %
                             (self._index + 1, len(self._songitems)))
        while not (ev == ui.CANCEL and
                   (not self._folders or self._song.isfolder)):
            # Inactive player. If the event isn't set to ui.PASS, we try to use
            # the pid later, which will be bad.
            if pid >= len(self._diff_names):
                ev = ui.PASS
            elif pid >= 0 and ev in (ui.UP,
                                     ui.DOWN):  # Only use menuing UP/DOWN
                ev = ui.PASS
            elif pid < 0 and ev in (
                    ui.LEFT, ui.RIGHT):  # Need LEFT/RIGHT player-specific
                ev = ui.PASS
            elif ev == ui.UP:
                self._index -= 1
            elif ev == ui.DOWN:
                self._index += 1
            elif ev == ui.PGUP:
                self._index -= 7
                ev = ui.UP
            elif ev == ui.PGDN:
                self._index += 7
                ev = ui.DOWN

            elif ev == ui.LEFT:
                if not self._song.isfolder:
                    namei = self._song.diff_list.index(self._diff_names[pid])
                    namei = (namei - 1) % len(self._song.diff_list)
                    name = self._song.diff_list[namei]
                    self._diff_names[pid] = name
                    self._pref_diff_names[pid] = name
                    self._last_player = pid

            elif ev == ui.RIGHT:
                if not self._song.isfolder:
                    namei = self._song.diff_list.index(self._diff_names[pid])
                    namei = (namei + 1) % len(self._song.diff_list)
                    name = self._song.diff_list[namei]
                    self._diff_names[pid] = name
                    self._pref_diff_names[pid] = name
                    self._last_player = pid

            elif ev == ui.RANDOM:
                if self._song.isfolder:
                    if len(self._all_valid_songitems) > 0:
                        self._song = random.choice(self._all_valid_songitems)
                        fol = self._song.folder[SORT_NAMES[
                            mainconfig["sortmode"]]]
                        self._create_song_list(fol)
                        self._index = self._songitems.index(self._song)
                    else:
                        error.ErrorMessage(
                            screen,
                            _("You don't have any songs that are marked ") +
                            _("\"valid\" for random selection."))
                else:
                    valid_songs = [
                        s for s in self._songitems if s.info["valid"]
                    ]
                    if len(valid_songs) > 0:
                        self._song = random.choice(valid_songs)
                        self._index = self._songitems.index(self._song)
                    else:
                        error.ErrorMessage(
                            screen,
                            _("You don't have any songs here that ") +
                            _("are marked \"valid\" for random selection."))
            elif ev == ui.OPTIONS:
                opts = options.OptionScreen(self._configs, self._config,
                                            self._screen)
                self._screen.blit(self._bg, [0, 0])
                self.update()
                pygame.display.update()
                if opts.start_dancing:
                    ev = ui.CONFIRM
                    continue

            elif ev == ui.SORT:
                s = self._songitems[self._index]
                mainconfig["sortmode"] = (mainconfig["sortmode"] +
                                          1) % NUM_SORTS
                sort_name = self._update_songitems()
                if self._folders:
                    if s.isfolder:
                        self._create_folder_list()
                    else:
                        s = self._find_resorted()
                        self._create_song_list(s.folder[sort_name])
                        self._index = self._songitems.index(s)
                else:
                    s = self._find_resorted()
                    self._base_text = _(sort_name).upper()
                    self._songitems.sort(key=SORTS[sort_name])
                    self._index = self._songitems.index(s)
                    self._list.set_items(
                        [s.info["title"] for s in self._songitems])

            elif ev == ui.CONFIRM:
                if self._song.isfolder:
                    self._create_song_list(self._song.name)
                    self._index = 0
                else:
                    music.fadeout(500)
                    dance.play(self._screen,
                               [(self._song.filename, self._diff_names)],
                               self._configs, self._config, self._game)
                    music.fadeout(500)  # The just-played song
                    self._screen.blit(self._bg, [0, 0])
                    pygame.display.update()
                    ui.ui.clear()

            elif ev == ui.CANCEL:
                # first: get the parent folder of the active song
                sort_name = SORT_NAMES[mainconfig["sortmode"]]
                fol = folder_name(self._song.folder[sort_name], sort_name)
                # next: change folder
                self._create_folder_list()
                for d in self._diff_widgets:
                    d.set("None", [127, 127, 127], 0, "?")

                lst = [s.info["title"] for s in self._songitems]
                self._index = lst.index(fol)

            elif ev == ui.FULLSCREEN:
                mainconfig["fullscreen"] ^= 1
                pygame.display.toggle_fullscreen()

            self._index %= len(self._songitems)
            self._song = self._songitems[self._index]

            if self._locked and ev in [ui.LEFT, ui.RIGHT]:
                for i, sd in enumerate(self._diff_names):
                    self._diff_names[i] = self._diff_names[pid]
                    self._pref_diff_names[i] = self._diff_names[pid]

            if ev in [
                    ui.CANCEL, ui.UP, ui.DOWN, ui.RANDOM, ui.CONFIRM, ui.SORT
            ]:
                self._preview.preview(self._song)
                self._banner.set_song(self._song)

            if ev in [
                    ui.CANCEL, ui.UP, ui.DOWN, ui.RANDOM, ui.CONFIRM, ui.SORT
            ]:
                if ev == ui.UP: self._list.set_index(self._index, -1)
                elif ev == ui.DOWN: self._list.set_index(self._index, 1)
                else: self._list.set_index(self._index, 0)  # don't animate
                self._title.set_text(self._base_text + " - %d/%d" %
                                     (self._index + 1, len(self._songitems)))

            if ev in [ui.UP, ui.DOWN, ui.RANDOM, ui.SORT, ui.CONFIRM]:
                if not self._song.isfolder:
                    for pl, dname in enumerate(self._diff_names):
                        name = self._pref_diff_names[pl]
                        if name in self._song.diff_list:
                            self._diff_names[pl] = name
                        elif self._unify_difficulties(
                                name) in self._song.diff_list:
                            self._diff_names[pl] = self._unify_difficulties(
                                name)
                        else:
                            # if both name and the song's difficulty list can be indexed:
                            # find the nearest defined difficulty
                            if  (name in util.DIFFICULTY_LIST or
                                self._unify_difficulties(name) in util.DIFFICULTY_LIST) and \
                                reduce(lambda a,b: a and b in util.DIFFICULTY_LIST,
                                       self._song.diff_list , True ):
                                name = self._unify_difficulties(name)
                                namei = util.DIFFICULTY_LIST.index(name)
                                diffi = [
                                    util.DIFFICULTY_LIST.index(d)
                                    for d in self._song.diff_list
                                ]
                                dds = [abs(d - namei) for d in diffi]
                                self._diff_names[pl] = self._song.diff_list\
                                                                          [dds.index(min(dds))]
                            else:  # no sensible way to resolve this: jump to middle of list
                                difflen = len(self._song.diff_list)
                                self._diff_names[pl] = self._song.diff_list[
                                    difflen / 2]

            if ev in [
                    ui.UP, ui.DOWN, ui.LEFT, ui.RIGHT, ui.RANDOM, ui.CONFIRM
            ]:
                if not self._song.isfolder:
                    for i, name in enumerate(self._diff_names):
                        rank = records.get(self._song.info["recordkey"], name,
                                           self._game)[0]
                        grade = grades.grades[
                            self._config["grade"]].grade_by_rank(rank)
                        self._diff_widgets[i].set(
                            name, DIFF_COLORS.get(name, [127, 127, 127]),
                            self._song.difficulty[name], grade)

            self.update()
            pid, ev = ui.ui.poll()
示例#18
0
    def __init__(self, songs, courses, screen, game):

        InterfaceWindow.__init__(self, screen, "newss-bg.png")
        songs = [s for s in songs if s.difficulty.has_key(game)]

        if len(songs) == 0:
            error.ErrorMessage(
                screen,
                _("You don't have any songs for the game mode (") + game +
                _(") that you selected.")
            )  #TODO: format using % for better i18n
            return

        # Construct a mapping between songs displays and dance displays.
        songs_and_dances = [
            (SongItemDisplay(s, game),
             [DanceItemDisplay(s, game, diff) for diff in s.diff_list[game]])
            for s in songs
        ]

        for (s, ds) in songs_and_dances:
            for d in ds:
                s.danceitems[d.diff] = d
                d.songitem = s

        self._songs = [s[0] for s in songs_and_dances]
        self._dances = reduce(lambda x, y: x + y[1], songs_and_dances, [])

        self._index = 0
        self._game = game
        self._config = dict(game_config)
        self._all_songs = self._songs
        self._all_dances = self._dances
        self._all_valid_songs = [s for s in self._songs if s.info["valid"]]
        self._all_valid_dances = [d for d in self._dances if d.info["valid"]]

        self._list = ListBox(FontTheme.SongSel_list, [255, 255, 255], 26, 16,
                             220, [408, 56])
        # please use set constructions after python 2.4 is adopted
        sort_name = self._update_songitems()

        if mainconfig["folders"]:
            self._create_folders()
            self._create_folder_list()
        else:
            self._folders = None
            self._base_text = sort_name.upper()

            self._songitems.sort(key=SORTS[sort_name])
            self._list.set_items([s.info["title"] for s in self._songitems])

        self._preview = SongPreview()
        self._preview.preview(self._songitems[self._index])
        self._song = self._songitems[self._index]

        # Both players must have the same difficulty in locked modes.
        self._locked = games.GAMES[self._game].couple

        players = games.GAMES[game].players
        #    self._diffs = [] # Current difficulty setting
        self._diff_widgets = []  # Difficulty widgets
        self._configs = []
        self._diff_names = []  # Current chosen difficulties
        self._pref_diff_names = []  # Last manually selected difficulty names
        self._last_player = 0  # Last player to change a difficulty

        for i in range(players):
            self._configs.append(dict(player_config))
            d = DifficultyBox([84 + (233 * i), 434])
            self._pref_diff_names.append(util.DIFFICULTY_LIST[0])
            if not self._song.isfolder:
                self._diff_names.append(self._song.diff_list[0])
                diff_name = self._diff_names[i]
                rank = records.get(self._song.info["recordkey"], diff_name,
                                   self._game)[0]
                grade = grades.grades[self._config["grade"]].grade_by_rank(
                    rank)
                d.set(diff_name, DIFF_COLORS.get(diff_name, [127, 127, 127]),
                      self._song.difficulty[diff_name], grade)
            else:
                self._diff_names.append(" ")
                d.set(_("None"), [127, 127, 127], 0, "?")
            self._diff_widgets.append(d)

        ActiveIndicator([405, 259], width=230).add(self._sprites)
        self._banner = BannerDisplay([205, 230])
        self._banner.set_song(self._song)
        self._sprites.add(
            HelpText(SS_HELP, [255, 255, 255], [0, 0, 0], FontTheme.help,
                     [206, 20]))

        self._title = TextDisplay('SongSel_sort_mode', [210, 28], [414, 27])
        self._sprites.add(self._diff_widgets +
                          [self._banner, self._list, self._title])
        self._screen.blit(self._bg, [0, 0])
        pygame.display.update()
        self.loop()
        music.fadeout(500)
        pygame.time.wait(500)
        # FIXME Does this belong in the menu code? Probably.
        music.load(os.path.join(sound_path, "menu.ogg"))
        music.set_volume(1.0)
        music.play(4, 0.0)
        player_config.update(self._configs[0])  # Save p1's settings
        game_config.update(self._config)  # save game settings
def diminuendo(milliseconds):
    if not SOUND_ON:
        return
    music.fadeout(milliseconds)
    global MUSIC_PLAYING
    MUSIC_PLAYING = None
示例#20
0
    def play_game_over(self):
        """Проигрывание мелодии и голоса вместе при проигрыше уровня"""

        music.fadeout(500)
        self.sounds['game_over'].play()
示例#21
0
    def loop(self):
        pid, ev = ui.ui.poll()
        root_idx = 0
        self._list.set_index(self._index)
        self._title.set_text(self._base_text + " - %d/%d" %
                             (self._index + 1, len(self._courses)))
        while not (ev == ui.CANCEL and
                   (not self._folders or self._course.isfolder)):
            # Inactive player. If the event isn't set to ui.PASS, we try to use
            # the pid later, which will be bad.
            if pid >= len(self._configs): ev = ui.PASS

            elif ev == ui.UP: self._index -= 1
            elif ev == ui.DOWN: self._index += 1
            elif ev == ui.PGUP:
                self._index -= 4
                ev = ui.UP
            elif ev == ui.PGDN:
                self._index += 4
                ev = ui.DOWN

            elif ev == ui.SELECT:
                if self._course.isfolder:
                    self._course = random.choice(self._all_courses)
                    root_idx = [fol.name for fol in self._courses
                                ].index(self._course.folder[SORT_NAMES[
                                    mainconfig["sortmode"]]])

                    fol = self._course.folder[SORT_NAMES[
                        mainconfig["sortmode"]]]
                    self._create_course_list(fol)
                    self._index = self._courses.index(self._course)
                else:
                    self._course = random.choice(self._courses)
                    self._index = self._courses.index(self._course)

            elif ev == ui.SORT:
                s = self._courses[self._index]
                mainconfig["sortmode"] = (mainconfig["sortmode"] +
                                          1) % NUM_SORTS
                if self._folders:
                    if s.isfolder:
                        self._create_folder_list()
                    else:
                        self._create_course_list(
                            s.folder[SORT_NAMES[mainconfig["sortmode"]]])
                        self._index = self._courses.index(s)
                else:
                    self._courses.sort(
                        SORTS[SORT_NAMES[mainconfig["sortmode"]]])
                    self._index = self._courses.index(s)
                    self._list.set_items([s.name for s in self._courses])

            elif ev == ui.START:
                options.OptionScreen(self._configs, self._config, self._screen)
                self._screen.blit(self._bg, [0, 0])
                self.update()
                pygame.display.update()

            elif ev == ui.CONFIRM:
                if self._course.isfolder:
                    self._create_course_list(self._course.name)
                    root_idx = self._index
                    self._index = 0
                else:
                    music.fadeout(500)
                    course = self._course.course
                    course.setup(self._screen, self._configs, self._config,
                                 self._game)
                    dance.play(self._screen, course, self._configs,
                               self._config, self._game)
                    course.done()
                    music.fadeout(500)  # The just-played song
                    self._screen.blit(self._bg, [0, 0])
                    pygame.display.update()
                    ui.ui.empty()
                    ui.ui.clear()

            elif ev == ui.CANCEL:
                self._create_folder_list()
                self._index = root_idx

            elif ev == ui.FULLSCREEN:
                mainconfig["fullscreen"] ^= 1
                pygame.display.toggle_fullscreen()

            self._index %= len(self._courses)
            self._course = self._courses[self._index]

            if ev in [
                    ui.CANCEL, ui.UP, ui.DOWN, ui.SELECT, ui.CONFIRM, ui.SORT
            ]:
                if ev == ui.UP: self._list.set_index(self._index, -1)
                elif ev == ui.DOWN: self._list.set_index(self._index, 1)
                else: self._list.set_index(self._index, 0)  # don't animate
                self._course.render()
                self._coursetitle.set_text(self._course.name)
                self._banner.set_image(self._course.banner)
                self._list_gfx.set_image(self._course.image)
                self._title.set_text(self._base_text + " - %d/%d" %
                                     (self._index + 1, len(self._courses)))
            self.update()
            pid, ev = ui.ui.poll()
示例#22
0
    def play_victory(self):
        """Проигрывание мелодии при успешном прохождении уровня"""

        music.fadeout(500)
        self.sounds['victory'].play()
示例#23
0
 def stop(self,fadeout=3):
     fadeout = int(fadeout)
     if fadeout:
         music.fadeout(fadeout*1000)
     else:
         music.stop()
示例#24
0
文件: songselect.py 项目: asb/pydance
  def loop(self):
    pid, ev = ui.ui.poll()
    self._list.set_index(self._index)
    self._title.set_text(self._base_text + " - %d/%d" % (self._index + 1,
                                                         len(self._songitems)))
    while not (ev == ui.CANCEL and (not self._folders or self._song.isfolder)):
      # Inactive player. If the event isn't set to ui.PASS, we try to use
      # the pid later, which will be bad.
      if pid >= len(self._diff_names): ev = ui.PASS
      
      elif ev == ui.UP: self._index -= 1
      elif ev == ui.DOWN: self._index += 1
      elif ev == ui.PGUP:
        self._index -= 7
        ev = ui.UP
      elif ev == ui.PGDN:
        self._index += 7
        ev = ui.DOWN

      elif ev == ui.LEFT:
        if not self._song.isfolder:
          namei = self._song.diff_list.index(self._diff_names[pid])
          namei = (namei -1) % len(self._song.diff_list)
          name = self._song.diff_list[namei]
          self._diff_names[pid] = name
          self._pref_diff_names[pid] = name
          self._last_player = pid

      elif ev == ui.RIGHT:
        if not self._song.isfolder:
          namei = self._song.diff_list.index(self._diff_names[pid])
          namei = (namei + 1) % len(self._song.diff_list)
          name = self._song.diff_list[namei]
          self._diff_names[pid] = name
          self._pref_diff_names[pid] = name
          self._last_player = pid

      elif ev == ui.SELECT:
        if self._song.isfolder:
          if len(self._all_valid_songitems) > 0:
            self._song = random.choice(self._all_valid_songitems)
            fol = self._song.folder[SORT_NAMES[mainconfig["sortmode"]]]
            self._create_song_list(fol)
            self._index = self._songitems.index(self._song)      
          else:
            error.ErrorMessage(screen,
                               _("You don't have any songs that are marked ") +
                               _("\"valid\" for random selection."))
        else:
          valid_songs = [s for s in self._songitems if s.info["valid"]]
          if len(valid_songs) > 0:
            self._song = random.choice(valid_songs)
            self._index = self._songitems.index(self._song)
          else:
            error.ErrorMessage(screen, _("You don't have any songs here that ") +
                               _("are marked \"valid\" for random selection."))
      elif ev == ui.START:
        options.OptionScreen(self._configs, self._config, self._screen)
        self._screen.blit(self._bg, [0, 0])
        self.update()
        pygame.display.update()

      elif ev == ui.SORT:
        s = self._songitems[self._index]
        mainconfig["sortmode"] = (mainconfig["sortmode"] + 1) % NUM_SORTS
        sort_name = self._update_songitems()
        if self._folders:
          if s.isfolder:
            self._create_folder_list()
          else:
            s = self._find_resorted()
            self._create_song_list(s.folder[sort_name])
            self._index = self._songitems.index(s)
        else:
          s = self._find_resorted()
          self._base_text = _(sort_name).upper()
          self._songitems.sort(key=SORTS[sort_name])
          self._index = self._songitems.index(s)
          self._list.set_items([s.info["title"] for s in self._songitems])

      elif ev == ui.CONFIRM:
        if self._song.isfolder:
          self._create_song_list(self._song.name)
          self._index = 0
        else:
          music.fadeout(500)
          dance.play(self._screen, [(self._song.filename, self._diff_names)],
                     self._configs, self._config, self._game)
          music.fadeout(500) # The just-played song
          self._screen.blit(self._bg, [0, 0])
          pygame.display.update()
          ui.ui.clear()

      elif ev == ui.CANCEL:
        # first: get the parent folder of the active song
        sort_name = SORT_NAMES[mainconfig["sortmode"]]
        fol = folder_name(self._song.folder[sort_name], sort_name)
        # next: change folder
        self._create_folder_list()
        for d in self._diff_widgets:
          d.set("None", [127, 127, 127], 0, "?")

        lst = [s.info["title"] for s in self._songitems]
        self._index = lst.index(fol)

      elif ev == ui.FULLSCREEN:
        mainconfig["fullscreen"] ^= 1
        pygame.display.toggle_fullscreen()

      self._index %= len(self._songitems)
      self._song = self._songitems[self._index]

      if self._locked and ev in [ui.LEFT, ui.RIGHT]:
        for i, sd in enumerate(self._diff_names):
          self._diff_names[i] = self._diff_names[pid]
          self._pref_diff_names[i] = self._diff_names[pid]

      if ev in [ui.CANCEL, ui.UP, ui.DOWN, ui.SELECT, ui.CONFIRM, ui.SORT]:
        self._preview.preview(self._song)
        self._banner.set_song(self._song)

      if ev in [ui.CANCEL, ui.UP, ui.DOWN, ui.SELECT, ui.CONFIRM, ui.SORT]:
        if ev == ui.UP: self._list.set_index(self._index, -1)
        elif ev == ui.DOWN: self._list.set_index(self._index, 1)
        else: self._list.set_index(self._index, 0) # don't animate
        self._title.set_text(self._base_text + " - %d/%d" % (self._index + 1,
                                                             len(self._songitems)))

      if ev in [ui.UP, ui.DOWN, ui.SELECT, ui.SORT, ui.CONFIRM]:
        if not self._song.isfolder:
          for pl, dname in enumerate(self._diff_names):
            name = self._pref_diff_names[pl]
            if name in self._song.diff_list:
               self._diff_names[pl] = name
            elif self._unify_difficulties(name) in self._song.diff_list:
               self._diff_names[pl] = self._unify_difficulties(name)
            else: 
              # if both name and the song's difficulty list can be indexed:
              # find the nearest defined difficulty
              if  (name in util.DIFFICULTY_LIST or
                  self._unify_difficulties(name) in util.DIFFICULTY_LIST) and \
                  reduce(lambda a,b: a and b in util.DIFFICULTY_LIST, 
                         self._song.diff_list , True ):
                name = self._unify_difficulties(name)
                namei = util.DIFFICULTY_LIST.index(name)
                diffi = [util.DIFFICULTY_LIST.index(d) for 
                                        d in self._song.diff_list]
                dds = [abs(d - namei) for d in diffi]
                self._diff_names[pl] = self._song.diff_list\
                                                          [dds.index(min(dds))]
              else: # no sensible way to resolve this: jump to middle of list
                difflen = len(self._song.diff_list)
                self._diff_names[pl] = self._song.diff_list[difflen/2]
          
      if ev in [ui.UP, ui.DOWN, ui.LEFT, ui.RIGHT, ui.SELECT, ui.CONFIRM]:
        if not self._song.isfolder:
          for i, name in enumerate(self._diff_names):
            rank = records.get(self._song.info["recordkey"],
                               name, self._game)[0]
            grade = grades.grades[self._config["grade"]].grade_by_rank(rank)
            self._diff_widgets[i].set(name,
                                      DIFF_COLORS.get(name, [127,127,127]),
                                      self._song.difficulty[name],
                                    grade)
      
      self.update()
      pid, ev = ui.ui.poll()
示例#25
0
  def loop(self):
    pid, ev = ui.ui.poll()
    root_idx = 0
    self._list.set_index(self._index)
    self._title.set_text(self._base_text + " - %d/%d" % (self._index + 1,
                                                         len(self._courses)))
    while not (ev == ui.CANCEL and
               (not self._folders or self._course.isfolder)):
      # Inactive player. If the event isn't set to ui.PASS, we try to use
      # the pid later, which will be bad.
      if pid >= len(self._configs): ev = ui.PASS
      
      elif ev == ui.UP: self._index -= 1
      elif ev == ui.DOWN: self._index += 1
      elif ev == ui.PGUP:
        self._index -= 4
        ev = ui.UP
      elif ev == ui.PGDN:
        self._index += 4
        ev = ui.DOWN

      elif ev == ui.SELECT:
        if self._course.isfolder:
          self._course = random.choice(self._all_courses)
          root_idx = [fol.name for fol in self._courses].index(self._course.folder[SORT_NAMES[mainconfig["sortmode"]]])
            
          fol = self._course.folder[SORT_NAMES[mainconfig["sortmode"]]]
          self._create_course_list(fol)
          self._index = self._courses.index(self._course)
        else:
          self._course = random.choice(self._courses)
          self._index = self._courses.index(self._course)

      elif ev == ui.SORT:
        s = self._courses[self._index]
        mainconfig["sortmode"] = (mainconfig["sortmode"] + 1) % NUM_SORTS
        if self._folders:
          if s.isfolder:
            self._create_folder_list()
          else:
            self._create_course_list(s.folder[SORT_NAMES[mainconfig["sortmode"]]])
            self._index = self._courses.index(s)
        else:
          self._courses.sort(SORTS[SORT_NAMES[mainconfig["sortmode"]]])
          self._index = self._courses.index(s)
          self._list.set_items([s.name for s in self._courses])

      elif ev == ui.START:
        options.OptionScreen(self._configs, self._config, self._screen)
        self._screen.blit(self._bg, [0, 0])
        self.update()
        pygame.display.update()

      elif ev == ui.CONFIRM:
        if self._course.isfolder:
          self._create_course_list(self._course.name)
          root_idx = self._index
          self._index = 0
        else:
          music.fadeout(500)
          course = self._course.course
          course.setup(self._screen, self._configs, self._config, self._game)
          dance.play(self._screen, course, self._configs,
                     self._config, self._game)
          course.done()
          music.fadeout(500) # The just-played song
          self._screen.blit(self._bg, [0, 0])
          pygame.display.update()
          ui.ui.empty()
          ui.ui.clear()

      elif ev == ui.CANCEL:
        self._create_folder_list()
        self._index = root_idx

      elif ev == ui.FULLSCREEN:
        mainconfig["fullscreen"] ^= 1
        pygame.display.toggle_fullscreen()

      self._index %= len(self._courses)
      self._course = self._courses[self._index]

      if ev in [ui.CANCEL, ui.UP, ui.DOWN, ui.SELECT, ui.CONFIRM, ui.SORT]:
        if ev == ui.UP: self._list.set_index(self._index, -1)
        elif ev == ui.DOWN: self._list.set_index(self._index, 1)
        else: self._list.set_index(self._index, 0) # don't animate
        self._course.render()
        self._coursetitle.set_text(self._course.name)
        self._banner.set_image(self._course.banner)
        self._list_gfx.set_image(self._course.image)
        self._title.set_text(self._base_text +
                             " - %d/%d" % (self._index + 1,
                                           len(self._courses)))
      self.update()
      pid, ev = ui.ui.poll()
示例#26
0
 def fadeout(self, msec):
     music.fadeout(msec)
     self.stop = True