all repos — Legends-RPG @ 03e23956af527301293a4f59072dddf0e341df8b

A fantasy mini-RPG built with Python and Pygame.

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
commit

03e23956af527301293a4f59072dddf0e341df8b

parent

a5b828ace1209769c68ffed3ad2178da480599a4

3 files changed, 13 insertions(+), 1 deletions(-)

jump to
M data/states/levels.pydata/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/states/main_menu.pydata/states/main_menu.py

@@ -16,6 +16,7 @@ class Menu(tools._State):

def __init__(self): super(Menu, self).__init__() self.music = setup.MUSIC['kings_theme'] + self.music_title = 'kings_theme' self.volume = 0.4 self.next = c.INSTRUCTIONS self.tmx_map = setup.TMX['title']

@@ -109,6 +110,7 @@ def __init__(self):

super(Instructions, self).__init__() self.tmx_map = setup.TMX['title'] self.music = None + self.music_title = None def startup(self, *args): self.renderer = tilerender.Renderer(self.tmx_map)
M data/tools.pydata/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