Changeset 243:4050e77dade6


Ignore:
Timestamp:
04/07/11 14:42:54 (12 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Message:

Add support for background music tracks

Location:
skaapsteker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/cutscene.py

    r183 r243  
    1010
    1111class CutScene(Scene):
    12     def __init__(self, game_state, text, background):
     12    def __init__(self, game_state, text, background, music=None):
    1313        super(CutScene, self).__init__(game_state)
    1414        self.text = text
     
    1818        self.start_time = pygame.time.get_ticks()
    1919        self.run_time = 60000 # ms
     20        self._background_music = None
     21        if music and pygame.mixer.get_init():
     22            self._background_music = data.filepath(music)
    2023
    2124    def draw(self, surface, engine):
     
    4346        super(CutScene, self).dispatch(ev)
    4447
     48    def enter(self):
     49        if self._background_music:
     50            pygame.mixer.music.load(self._background_music)
     51            pygame.mixer.music.play(-1)
     52
     53    def leave(self):
     54        if self._background_music:
     55            pygame.mixer.music.stop()
     56
    4557
    4658def opening_cutscene(game_state):
  • skaapsteker/level.py

    r127 r243  
    11import json
    22
    3 from pygame import Rect, Surface, Color
     3from pygame import Rect, Surface, Color, mixer
    44from pygame.sprite import LayeredUpdates
    55from pygame.locals import SRCALPHA, HWSURFACE
     
    6464        self.setup_enemies()
    6565        self.setup_player(player)
    66 
     66        self._background_music = None
     67        if 'music' in self.level_data and mixer.get_init():
     68            self._background_music = data.filepath('music/' + self.level_data['music'])
    6769
    6870    def build_backgrounds(self):
     
    7173            self.backgrounds.append(data.load_image('backgrounds/' + background))
    7274
     75
     76    def leave(self):
     77        if self._background_music:
     78            mixer.music.stop()
     79
     80
     81    def enter(self):
     82        if self._background_music:
     83            mixer.music.load(self._background_music)
     84            mixer.music.play(-1)
    7385
    7486    def build_tiles(self):
  • skaapsteker/levelscene.py

    r206 r243  
    7171        """Freeze the scene, for serialization"""
    7272        self._world.freeze()
     73        self._level.leave()
    7374
    7475    def enter(self):
    7576        """Unfreeze"""
    7677        self._world.thaw()
     78        self._level.enter()
    7779
    7880    def draw(self, screen_surface, engine):
Note: See TracChangeset for help on using the changeset viewer.