def __init__(self, display_w, display_h): pygame.init() mixer.init() font.init() # check if the mixer was successfully initialized if mixer.get_init() is None: print("Failed to initialize the audio mixer module.") if font.get_init() is None: print("Failed to initialize the font module.") self.fps = 120 self.world = None self.gui = Gui(self) # Create screen display with 32 bits per pixel, no flags set self.display = pygame.display.set_mode((display_w, display_h), pygame.HWSURFACE, 32) self.delta_time = 0.0 self.debug = False self.paused = False self.print_fps = False self.worlds = list() self.game = None
def __init__(self, text, location, color=(0, 0, 0)): if not font.get_init(): font.init() self.fnt = font.Font(ui_enums.DEFAULT_FONT, ui_enums.DEFAULT_FONT_SIZE) self.srf = self.fnt.render(text, 1, color) self.color = color self.location = location self.update()
def load_font(name, size): """ Load pygame.font.Font() object :param name: Font file name :param size: font size :return: pygame.font.Font() """ # In case of loading error class NoneFont: def play(self): pass if not pyfont or not pyfont.get_init(): return NoneFont() fullname = os.path.join(font_dir, name) try: font = pyfont.Font(fullname, size) except error: print('Cannot load font: %s' % fullname) raise SystemExit(str(geterror())) return font
def __init__(self, text, loc, color=(0, 0, 0), bg_color=None, callback=None, fnt=DEFAULT_FONT, size=DEFAULT_FONT_SIZE, bold=False, underline=False, italics=False): if not font.get_init(): font.init() self.fnt = font.Font(fnt, size) self.fnt.set_bold(bold) self.fnt.set_underline(underline) self.fnt.set_italic(italics) if bg_color is not None: self.srf = self.fnt.render(text, 1, color, bg_color) else: self.srf = self.fnt.render(text, 1, color) self.width = self.srf.get_width() self.height = self.srf.get_height() self.location = loc self.callback = callback
def test_get_init(self): self.failUnless(pygame_font.get_init()) pygame_font.quit() self.failIf(pygame_font.get_init())
def __init__(self): if not font.get_init(): font.init()
def test_get_init(self): self.assertTrue(pygame_font.get_init()) pygame_font.quit() self.assertFalse(pygame_font.get_init())
# creature_puppeteer.py # Dumfing # Entry point for user to control the muscles of a creature #"Puppeteering" more like Dance Dance Revolution from pygame.locals import * from pygame import key, draw, font from lib import game_object from lib import colour_constants as colour if font.get_init(): KEY_FONT = font.Font("assets/Montserrat-Regular.otf", 25) class CreaturePuppeteer(game_object.GameObject): USABLE_KEYS = (K_q, K_w, K_o, K_p) def __init__(self, creature): self.creature = creature self.creature.set_colour_scheme(2) self.keybinds = {} self.keyStates = {} self.oldKeysDown = [] self.auto_assign_keys() self.triggerClock = 0 def set_creature(self, creature): self.creature = creature self.auto_assign_keys()
def test_get_init(self): self.failUnless(pygame_font.get_init()) pygame_font.quit() self.assertFalse(pygame_font.get_init())
def init(self): if not f.get_init(): f.init() _ = self.font