当前位置: 首页>>代码示例>>Python>>正文


Python font.Font类代码示例

本文整理汇总了Python中pygame.font.Font的典型用法代码示例。如果您正苦于以下问题:Python Font类的具体用法?Python Font怎么用?Python Font使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Font类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    """Main program loop"""
    
    pygame.init()
    screen = pygame.display.set_mode(opt.window_size)
    
    sys_font = Font(get_default_font(), opt.font_size)
    clock = Clock()
    
    manager = YarsManager()

    running = True
    
    while running:
        #limit framerate and prepare FPS display text
        clock.tick(opt.max_framerate)
        fps = clock.get_fps()
        fps_text = sys_font.render("FPS: {0:.1f}".format(fps), False, opt.white)
        
        if event.get(pygame.QUIT):
            sys.exit()

        running = manager.handle_events(event.get(), key.get_pressed())
        manager.update()

        screen.fill(opt.black)
        manager.draw(screen)
        screen.blit(fps_text, fps_text.get_rect(top = 0, right = opt.width))
        pygame.display.update()
		
    sys.exit()
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:31,代码来源:game.py

示例2: LcarsText

class LcarsText(LcarsWidget):
    def __init__(self, colour, pos, message, size=1.0,
                 background=None, resolution=(480, 320)):
        self.colour = colour
        self.message = message
        self.background = background
        script_dir = dirname(__file__)
        ipath = join(script_dir, '../../assets/swiss911.ttf')
        self.font = Font(ipath, int(19.0 * size))

        self.renderText(message)
        # center the text if needed
        if (pos[1] < 0):
            # Screen specific magic number below! 240 = half width
            pos = (pos[0], resolution[0]/2 - self.image.get_rect().width/2)

        LcarsWidget.__init__(self, colour, pos, None)

    def renderText(self, message):
        if (self.background is None):
            self.image = self.font.render(message, True, self.colour)
        else:
            self.image = self.font.render(message, True,
                                          self.colour, self.background)

    def setText(self, newText):
        self.message = newText
        self.renderText(newText)

    def changeColour(self, colour):
        self.colour = colour
        self.renderText(self.message)
开发者ID:astrobokonon,项目名称:rpi_lcars,代码行数:32,代码来源:lcars_widgets.py

示例3: __init__

    def __init__(self, manager, score, lives, next_state):
        GameState.__init__(self, manager)

        sys_font = Font(get_default_font(), options.font_size)
        self.score_text = sys_font.render(str(score), True, options.white)
        self.lives_text = sys_font.render(str(lives), True, options.white)

        self.next_state = next_state
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:8,代码来源:infoscreen.py

示例4: __init__

    def __init__(self, manager):
        GameState.__init__(self, manager)

        sys_font = Font(get_default_font(), options.font_size)
        self.message1 = sys_font.render("Andrew's Bitchin' Yars' Revenge Clone",
                                        True, options.white)
        self.message2 = sys_font.render("Press shoot button (space) to start.",
                                        True, options.white)
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:8,代码来源:title.py

示例5: find_font_size

 def find_font_size(self):
     size = 100
     while size >= 1:
         f = Font(FONT, size)
         w, h = f.size('8')
         if w < self.w and h < self.h:
             return size
         size = size -1
     return size
开发者ID:sumpfgottheit,项目名称:pdu1800,代码行数:9,代码来源:widgets.py

示例6: TextBar

class TextBar(Sprite):
    def __init__(self, text, rect, fontSize):
        Sprite.__init__(self)
        self.font = Font(None, fontSize)
        self.rect = Rect(rect)
        self.image = pygame.surface.Surface((rect[2],
                                             rect[3]))
        self.image = self.font.render(text, 0, TEXTCOLOR)
    def setText(self, text):
        self.image = self.font.render(text, 0, TEXTCOLOR)
开发者ID:bry,项目名称:pybomber2,代码行数:10,代码来源:windows.py

示例7: display_message

	def display_message(screen, msg, x_center_delta=0, y_center_delta=0):
		center_x = (Helpers.const["size"]["display_width"] / 2) + x_center_delta
		center_y = (Helpers.const["size"]["display_height"] / 2) + y_center_delta
		msg_font =  Font(None, 30)

		screen_text = msg_font.render(msg, True, Helpers.const["color"]["white"])
		text_rect = screen_text.get_rect()
		text_rect.center = (center_x, center_y)
		
		screen.blit(screen_text, text_rect)
		pygame.display.update(text_rect)
		return text_rect
开发者ID:tsvetelina-aleksandrova,项目名称:Spacekatz,代码行数:12,代码来源:helpers.py

示例8: __init__

    def __init__(self, x, y, width, height, msg, size=32, 
            text_colour=base.BLACK, bg_colour=base.WHITE, 
            highlight_text=base.WHITE, highlight_bg=base.BLACK):

        font = Font(None, size)
        self.normal = pygame.Surface((width, height))
        self.normal.fill(bg_colour)
        self.normal.blit(font.render(msg, False, text_colour), (0, 0))
    
        self.highlighted = pygame.Surface((width, height))
        self.highlighted.fill(highlight_bg)
        self.highlighted.blit(font.render(msg, False, highlight_text), (0, 0))
        PicassoAsset.__init__(self, self.normal, x, y)
开发者ID:B-Lock,项目名称:risk,代码行数:13,代码来源:clickable.py

示例9: draw_mouse_info

 def draw_mouse_info(self, message, drawing=False):
     # Empty mouse canvas
     self.mouse_info_canvas.fill(self.background_color)
     
     # Create font and blit onto canvas
     font = Font(None, 22)
     mouse_info = font.render(message, 1, Colour.CHOCOLATE, Colour.BLACK)
     self.mouse_info_canvas.blit(mouse_info, (self.mouse_info_x, self.mouse_info_y))
     
     # If Mouse is dragging, notify
     if drawing:
         ti = Font(None, 30).render("DRAWING",1,Colour.CHOCOLATE, Colour.BLACK)
         self.mouse_info_canvas.blit(ti, (self.mouse_info_x, self.mouse_info_y+20))
开发者ID:parhamfh,项目名称:muscovaudio,代码行数:13,代码来源:canvas.py

示例10: gameover

def gameover():
    """The gameover loop
    Shows static image until the window is closed
    """
    
    sys_font = Font(get_default_font(), font_size)
    message = sys_font.render("GAME OVER", False, white)
    screen = pygame.display.get_surface()
    screen.blit(message, message.get_rect(centerx = width/2, top = 20))
    pygame.display.update()
    while 1:
        keyboard()
        for event in pygame.event.get():
            if event.type == pygame.QUIT: sys.exit()
开发者ID:rubiximus,项目名称:invader-shootan,代码行数:14,代码来源:game.py

示例11: main

def main():
    """The main function of the game.
    Initializes PyGame objects and then enters the game loop
    """
    
    pygame.init()
    screen = pygame.display.set_mode(window_size)
    
    sys_font = Font(get_default_font(), font_size)
    clock = Clock()
    
    #now that pygame is initialized, initialize inherited classes properly
    global enemy_wave, player
    enemy_wave = EnemyGroup(evil_bullets)
    
    player = Player(window_size, ship_filename, ship_speed)
    
    while 1:
        #limit framerate and prepare FPS display text
        clock.tick(max_framerate)
        fps = clock.get_fps()
        fps_text = sys_font.render("FPS: {0:.1f}".format(fps), False, white)
        
        score_text = sys_font.render("SCORE: {}".format(score), False, white)
        lives_text = sys_font.render("MANS: {}".format(lives), False, white)
    
        #check for QUIT event to prevent endless loopage
        for event in pygame.event.get():
            if event.type == pygame.QUIT: sys.exit()
            
        #call the game's thinking functions
        check_gameover()
        keyboard()
        evil_bullets.update()
        good_bullets.update()
        enemy_wave.update()
        collisions()
            
        #draw the stuff
        screen.fill(black)
        good_bullets.draw(screen)
        evil_bullets.draw(screen)
        enemy_wave.draw(screen)
        screen.blit(player.image, player.rect)
        screen.blit(score_text, score_text.get_rect(top = 0, left = 0))
        screen.blit(lives_text, lives_text.get_rect(top = 0, centerx = width / 2))
        screen.blit(fps_text, fps_text.get_rect(top = 0, right = width))
        pygame.display.update()
开发者ID:rubiximus,项目名称:invader-shootan,代码行数:48,代码来源:game.py

示例12: __init__

    def __init__(self, colour, pos, text, handler=None):
        self.handler = handler
        image = pygame.image.load("assets/button.png").convert()
        size = (image.get_rect().width, image.get_rect().height)
        font = Font("assets/swiss911.ttf", 19)
        textImage = font.render(text, False, colours.BLACK)
        image.blit(textImage, 
                   (image.get_rect().width - textImage.get_rect().width - 10,
                    image.get_rect().height - textImage.get_rect().height - 5))

        self.image = image
        self.colour = colour
        LcarsWidget.__init__(self, colour, pos, size)
        self.applyColour(colour)
        self.highlighted = False
        self.beep = Sound("assets/audio/panel/202.wav")
开发者ID:elijaheac,项目名称:rpi_lcars,代码行数:16,代码来源:lcars_widgets.py

示例13: __init__

    def __init__(self, em, text, events_attrs={}, rect=None,
                 txtcolor=(255, 0, 0), bgcolor=None):
        """ When receiving an event containing text, 
        replace self.text by that event's text.
        events_attrs maps event classes to event text attributes. 
        Usage: TextLabelWidget(em, 'start text', {EventName: 'evt_attr'})  
        """
        Widget.__init__(self, em)

        self.events_attrs = events_attrs
        for evtClass in events_attrs:
            self._em.subscribe(evtClass, self.on_textevent)

        # gfx
        self.font = Font(None, font_size)
        if rect:
            self.rect = rect
        else:
            self.rect = Rect((0, 0), (100, font_size + 4))
            #default width = 100px,
            # 4px from 1px each of border bottom,
            # padding bottom, padding top, and border top 

        self.txtcolor = txtcolor
        self.bgcolor = bgcolor

        self.text = text
        #self.image = Surface(self.rect.size) # needed?

        self.dirty = 1 # added [tho] 
开发者ID:gentimouton,项目名称:smofac,代码行数:30,代码来源:widgets.py

示例14: __init__

    def __init__(self, id, status):
        """
            Link object with its sprite
        """
        self.__images_cash = defaultdict(dict)
        self.id = id
        self.status = status

        layer = int(self.status.layer)
        if layer > theme.MAX_LAYERS:
            layer = theme.MAX_LAYERS
        if layer < 0:
            layer = 0
        super(RoboSprite, self).__init__(UserInterface.sprites_all, UserInterface.sprites_by_layer[layer])

        self.image = self.images[0].copy()
        self.rect = self.image.get_rect()
        self._debug_color = (
            random.randint(200, 255),
            random.randint(50, 255),
            0
        )
        self._id_font = Font(theme.FONT_FILE_NAME, 20)
        self._selected = False
        # for animated sprites
        self._animcycle = 3
        self._drawed_count = 0
开发者ID:suguby,项目名称:robogame_engine,代码行数:27,代码来源:user_interface.py

示例15: __init__

 def __init__(self, fruit, interp_step):
     """ Prepare the fruit's spr: a square diamond 
     with a number in the center.
     interp_step determines where to position the sprite, 
     based on the view's current sprite step. 
     """
     DirtySprite.__init__(self)
     self.fruit = fruit
     
     # make the square
     sq_surf = Surface((cell_size / 1.414, cell_size / 1.414))
     sq_surf.set_colorkey((255, 0, 255))  # magenta = color key
     sq_surf.fill(FRUIT_COLORS[fruit.fruit_type])
     # rotate for a diamond
     dm_surf = rotate(sq_surf, 45)
     blit_rect = Rect(0, 0, cell_size * 1.414, cell_size * 1.414)
     # blit the diamond as the fruit's image
     img = Surface((cell_size, cell_size))
     img.set_colorkey((255, 0, 255))  # magenta = color key
     img.fill((255, 0, 255))
     img.blit(dm_surf, blit_rect)
     
     # add text at the center
     self.font = Font(None, font_size) 
     txtsurf = self.font.render(str(fruit.fruit_num), True, (0, 0, 0))
     textpos = txtsurf.get_rect(center=(cell_size / 2, cell_size / 2))
     img.blit(txtsurf, textpos)
     
     # prepare rect to blit on screen
     self.resync(interp_step)
     
     self.image = img
开发者ID:gentimouton,项目名称:smofac,代码行数:32,代码来源:fruitspr.py


注:本文中的pygame.font.Font类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。