From: Andrew J. <an...@la...> - 2001-11-26 01:36:21
|
Cool nuts people. Fábio Dias drooped me a mail with instructions on how to patch pyzzle so it can run without pygame mixer being installed. This could become useful for people who have no SDL sound support on linux or other platform but still want to work with Pyzzle. His original mail is below and is fairly self explanatory. So thanks Fabio for the code or rather commented out code. (-: ----- Original Message ----- From: "Fábio Dias" <fab...@ie...> To: <th...@us...> Sent: Sunday, November 25, 2001 7:04 AM Subject: Pyzzle -- Protection against pygame.mixer is None > Hi Andrew, > > I have downloaded your library (Pyzzle), and have played around a bit with > it. I was installing pyGame at the time, so left pygame.mixer out of my > installation. When trying to run the Pyzzle example, however, it crashed, > because pygame.mixer was not available. > > Since pygame.mixer is None when not available, the refences to pygame.mixer > failed, because they involved calling methods of pygame.mixer, obviously > inexistents on None. I have patched myself all occurences of it, so the game > ignores sounds when sound is unavailable. > > Lines involved on the change are prefixed with an exclamation mark. > > > > On gamelogic.py, around lines 41--50: > pygame.mixer.pre_init(11025) > except: > pygame.mixer = None > > def playsound(a_sound): > ! if pygame.mixer is None: > ! return > global Asound > soundfile = os.path.join('data', a_sound+'.wav') > Asound = pygame.mixer.Sound(soundfile) > Asound.play() > > > > On pyzzle.py, around lines 214--225: > menubuttonport.fill(BACKGROUNDCOLOUR) > screen.blit(menubuttonport, MENU_BUTTON_RECT) > pygame.display.update(MENU_BUTTON_RECT) > > def play_ambiant(a_ambiant): > ! if pygame.mixer is None: > ! return > music = os.path.join('data', a_ambiant) > #print 'amb', a_ambiant > pygame.mixer.music.load(music) > pygame.mixer.music.play(-1) > > > > On pyzzle.py, around lines 546--560: > #mainloop > while not quit: > #if pyzzle is not reciving mouse focus this stops the game > if not pygame.mouse.get_focused(): > #print 'not reciving focus' > ! if pygame.mixer is not None: > ! pygame.mixer.music.pause() # stops music/ambiant sounds when > window is not reciving focus > ! event = pygame.event.wait() > ! pygame.mixer.music.unpause() # restarts music/ ambients > > # Gather Events, check for exit signal needs work > pygame.event.pump() > keystate = pygame.key.get_pressed() > > Hope it helps =) > > Truly, > > Fabio Dias > |