Changeset 247

Show
Ignore:
Timestamp:
01/05/07 03:57:30 (5 years ago)
Author:
mg
Message:

Added support for music. Sadly, no actual music yet.

Location:
trunk
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/setup.py

    r237 r247  
    5050      packages=['pyspacewar'], 
    5151      package_dir={'pyspacewar': 'src/pyspacewar'}, 
    52       package_data={'pyspacewar': ['images/*', 'sounds/*']}, 
     52      package_data={'pyspacewar': ['images/*', 'sounds/*', 'music/*']}, 
    5353     ) 
  • trunk/src/pyspacewar/ui.py

    r246 r247  
    10921092    mouse_visible = False 
    10931093    keys_repeat = False 
     1094    music = None 
    10941095 
    10951096    inherit_pause_from_prev_mode = False 
     
    11171118        else: 
    11181119            pygame.key.set_repeat() 
     1120        if self.music: 
     1121            self.ui.play_music(self.music) 
    11191122 
    11201123    def leave(self, next_mode=None): 
     
    12371240 
    12381241    paused = False 
     1242    music = 'demo' 
    12391243 
    12401244    def init(self): 
     
    16001604 
    16011605    paused = False 
     1606    music = 'game' 
    16021607 
    16031608    def init(self): 
     
    16391644 
    16401645    paused = False 
     1646    music = 'gravitywars' 
    16411647 
    16421648    def init(self): 
     
    17801786 
    17811787    _ui_mode = None         # Previous user interface mode 
     1788 
     1789    now_playing = None      # Filename of the current music track 
    17821790 
    17831791    # Some debug information 
     
    18541862        self._init_trail_colors() 
    18551863        self._load_sounds() 
     1864        self._load_music() 
    18561865        self._load_planet_images() 
    18571866        self._load_background() 
     
    19831992        self.respawn_sound = pygame.mixer.Sound(find('sounds', 'coin2.wav')) 
    19841993        self.menu_sound = pygame.mixer.Sound(find('sounds', 'briefcs1.wav')) 
     1994 
     1995    def _load_music(self): 
     1996        """Load music files.""" 
     1997        self.music_files = { 
     1998                'demo': find('music', 'demo.ogg'), 
     1999                'game': find('music', 'game.ogg'), 
     2000                'gravitywars': find('music', 'gravitywars.ogg'), 
     2001            } 
     2002 
     2003    def play_music(self, which): 
     2004        """Loop the music file for a certain mode.""" 
     2005        if which == self.now_playing: 
     2006            return 
     2007        filename = self.music_files.get(which) 
     2008        if not filename: 
     2009            pygame.mixer.music.stop() 
     2010        else: 
     2011            try: 
     2012                pygame.mixer.music.load(filename) 
     2013                pygame.mixer.music.play(-1) 
     2014            except pygame.error: 
     2015                # Don't print warnings while I don't have any music actually 
     2016                # bundled with pyspacewar 
     2017                # print "pyspacewar: could not load %s" % filename 
     2018                pygame.mixer.music.stop() 
     2019        self.now_playing = which 
    19852020 
    19862021    def _init_fonts(self):