def load_image(filename, colorkey=IMAGE_COLORKEY): # get the path of the filename fullname = file_path(filename, constants.GRAPHICS_DIR) # try to load the image try: image = pygame.image.load(fullname) except: print ''.join(["Couldn't load image: ", fullname]) raise SystemExit # check the current alpha value of the surface if image.get_alpha() is None: image = image.convert() else: image = image.convert_alpha() # check for image's colorkey if colorkey: if colorkey is -1: colorkey = image.get_at((0, 0)) image.set_colorkey(colorkey, RLEACCEL) # return the image and its rectangle return image, image.get_rect()
def _credits_option(self): # get the path of the filename fullname = file_path( constants.FILES['texts']['menu']['credits']['text'][0], constants.TEXTS_DIR) # if credits text file exists and is readable if os.access(fullname, os.F_OK) and os.access(fullname, os.R_OK): if self.game_opts.verbose: print 'Go to the credits screen.' # create the credits screen c = Credits(self.screen, self.game_opts, self.window_frame, self.menu_settings_bg, self.select_option_snd, fullname) # run the credits screen if not c.run(): # quit if the close button is # pressed (inside the credits) self._quit_option() else: print ''.join(["Couldn't text file: ", fullname])
def _credits_option(self): fullname = file_path( constants.FILES['texts']['menu']['credits']['text'][0], constants.TEXTS_DIR) if os.access(fullname, os.F_OK) and os.access(fullname, os.R_OK): if self.game_opts.verbose: print('Go to the credits screen.') c = Credits(self.screen, self.game_opts, self.window_frame, self.menu_settings_bg, self.select_option_snd, fullname) if not c.run(): # quit if the close button is # pressed (inside the credits) self._quit_option() else: path = os.path.basename(__file__) print("{0}: couldn't read text file: {1}".format(path, fullname)) raise SystemExit
def load_sound(filename): fullname = file_path(filename, constants.SOUNDS_DIR) if not os.path.isfile(fullname): raise SystemExit('Not a file: {0}'.format(fullname)) sound = pygame.mixer.Sound(fullname) return sound
def play_music(filename, repeat=MUSIC_REPEAT): # get the path of the filename fullname = file_path(filename, constants.SOUNDS_DIR) # try to play the music theme try: sound = pygame.mixer.music.load(fullname) pygame.mixer.music.play(repeat) except: print((' '.join(("Couldn't play music:", fullname)))) raise SystemExit
def load_font(filename, size=FONT_SIZE): fullname = file_path(filename, constants.FONTS_DIR) try: font = pygame.font.Font(fullname, size) except IOError as err: import os path = os.path.basename(__file__) raise SystemExit("{0}: couldn't load font: {1}".format(path, fullname)) return font
def load_font(filename, size=FONT_SIZE): fullname = file_path(filename, constants.FONTS_DIR) try: font = pygame.font.Font(fullname, size) except: import os path = os.path.basename(__file__) print("{0}: couldn't load font: {1}".format(path, fullname)) raise SystemExit return font
def play_music(filename, repeat=MUSIC_REPEAT): '''Play a background audio theme''' fullname = file_path(filename, constants.SOUNDS_DIR) try: sound = pygame.mixer.music.load(fullname) pygame.mixer.music.play(repeat) except pygame.error as err: import os path = os.path.basename(__file__) raise SystemExit("{0}: couldn't load music: {1}".format( path, fullname))
def load_sound(filename): # get the path of the filename fullname = file_path(filename, constants.SOUNDS_DIR) # try to load the sound try: sound = pygame.mixer.Sound(fullname) except: print((' '.join(("Couldn't load sound:", fullname)))) raise SystemExit # return the loaded sound return sound
def load_font(filename, size=FONT_SIZE): # get the path of the filename fullname = file_path(filename, constants.FONTS_DIR) # try to create the font try: font = pygame.font.Font(fullname, size) except: print ''.join(["Couldn't load font: ", fullname]) raise SystemExit # return the font return font
def play_music(filename, repeat=MUSIC_REPEAT): class NoneSound: def play(self): pass if not pygame.mixer or not pygame.mixer.get_init(): return NoneSound() # get the path of the filename fullname = file_path(filename, constants.SOUNDS_DIR) # try to play the music theme try: sound = pygame.mixer.music.load(fullname) pygame.mixer.music.play(repeat) except: print ''.join(["Couldn't play music: ", fullname]) raise SystemExit
def load_sound(filename): class NoneSound: def play(self): pass if not pygame.mixer or not pygame.mixer.get_init(): return NoneSound() # get the path of the filename fullname = file_path(filename, constants.SOUNDS_DIR) # try to load the sound try: sound = pygame.mixer.Sound(fullname) except: print ''.join(["Couldn't load sound: ", fullname]) raise SystemExit # return the loaded sound return sound
def load_image(filename, colorkey=IMAGE_COLORKEY): fullname = file_path(filename, constants.GRAPHICS_DIR) try: image = pygame.image.load(fullname) except: import os path = os.path.basename(__file__) print("{0}: couldn't load image: {1}".format(path, fullname)) raise SystemExit if image.get_alpha() is None: image = image.convert() else: image = image.convert_alpha() if colorkey: if colorkey is -1: colorkey = image.get_at((0, 0)) image.set_colorkey(colorkey, RLEACCEL) return image, image.get_rect()
def _credits_option(self): # get the path of the filename fullname = file_path( constants.FILES['texts']['menu']['credits']['text'][0], constants.TEXTS_DIR) # if credits text file exists and is readable if os.access(fullname, os.F_OK) and os.access(fullname, os.R_OK): if self.game_opts.verbose: print('Go to the credits screen.') # create the credits screen c = Credits(self.screen, self.game_opts, self.window_frame, self.menu_settings_bg, self.select_option_snd, fullname) # run the credits screen if not c.run(): # quit if the close button is # pressed (inside the credits) self._quit_option() else: print((' '.join(("Couldn't read text file:", fullname))))