If music is the same as previous state, music will just continue rather than start again.
Justin Armstrong justinmeister@gmail.com
Mon, 16 Jun 2014 11:11:05 -0700
3 files changed,
13 insertions(+),
1 deletions(-)
M
data/states/levels.py
→
data/states/levels.py
@@ -26,6 +26,8 @@ super(LevelState, self).__init__()
self.name = name self.tmx_map = setup.TMX[name] self.allow_battles = battles + self.music_title = None + self.previous_music = None self.music, self.volume = self.set_music() def set_music(self):@@ -43,9 +45,11 @@ c.DUNGEON5: ('dungeon_theme', .4),
c.HOUSE: ('pleasant_creek', .1), c.BROTHER_HOUSE: ('pleasant_creek', .1)} + if self.name in music_dict: music = music_dict[self.name][0] volume = music_dict[self.name][1] + self.music_title = music return setup.MUSIC[music], volume else: return None, None
M
data/tools.py
→
data/tools.py
@@ -39,9 +39,11 @@ self.state.update(self.screen, self.keys, self.current_time)
def flip_state(self): previous, self.state_name = self.state_name, self.state.next + previous_music = self.state.music_title persist = self.state.cleanup() self.state = self.state_dict[self.state_name] self.state.previous = previous + self.state.previous_music = previous_music self.state.startup(self.current_time, persist) self.set_music()@@ -49,7 +51,9 @@ def set_music(self):
""" Set music for the new state. """ - if self.state.music: + if self.state.music_title == self.state.previous_music: + pass + elif self.state.music: pg.mixer.music.load(self.state.music) pg.mixer.music.set_volume(self.state.volume) pg.mixer.music.play(-1)@@ -100,6 +104,8 @@ self.next = None
self.previous = None self.game_data = {} self.music = None + self.music_title = None + self.previous_music = None def get_event(self, event): pass