本文整理汇总了Python中pygame.font.Font.set_bold方法的典型用法代码示例。如果您正苦于以下问题:Python Font.set_bold方法的具体用法?Python Font.set_bold怎么用?Python Font.set_bold使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.font.Font
的用法示例。
在下文中一共展示了Font.set_bold方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import set_bold [as 别名]
def __init__(self, x, y, width, height, msg, size=16,
text_colour=base.BLACK, bg_colour=base.WHITE,
highlight_text=base.WHITE, highlight_bg=base.BLACK,
offset_x=0, offset_y=0, bold=False):
self.normal = pygame.Surface((width, height))
self.normal.fill(bg_colour)
font = Font(_FONT, size)
font.set_bold(bold)
font_width, font_height = font.size(msg)
font_x = (width - font_width) / 2
font_y = (height - font_height) / 2
self.normal.blit(font.render(msg, False, text_colour),
(font_x, font_y))
self.highlighted = pygame.Surface((width, height))
self.highlighted.fill(highlight_bg)
self.highlighted.blit(font.render(msg, False, highlight_text),
(font_x, font_y))
self.offset_x = offset_x
self.offset_y = offset_y
self.force_highlight = False
self.disabled = False
PicassoAsset.__init__(self, self.normal, x, y)
示例2: initFont
# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import set_bold [as 别名]
def initFont(name, ttfFile, size, bold = 0, italic = 0, underline = 0):
global fontFaces
if name in fontFaces:
del fontFaces[name]
font = Font(ttfFile, size)
font.set_bold(bold)
font.set_italic(italic)
font.set_underline(underline)
fontFaces[name] = font
示例3: __init__
# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import set_bold [as 别名]
class Menu:
def __init__(self, x, y, fontsize, space, color_fg, color_bg, background, titles):
self.titles = titles
self.images = []
self.rects = []
self.himages = []
self.color_fg = color_fg
self.color_bg = color_bg
self.space = space
self.background = data.load_image(background)
self.index = 0
self.x = x
self.y = y
self.font = Font(data.filepath('fonts', 'vera.ttf'), fontsize)
self.font.set_bold(True)
self.fonth = Font(data.filepath('fonts', 'vera.ttf'), fontsize+5)
self.fonth.set_bold(True)
def init(self):
dy = 0
for title in self.titles:
image = self.font.render(title, True, self.color_bg)
himage = self.fonth.render(title, True, self.color_fg)
rect = image.get_rect()
rect.move_ip(self.x, self.y + dy)
dy += rect.height + self.space
self.images.append(image)
self.himages.append(himage)
self.rects.append(rect)
def run(self, screen):
def blit(screen):
screen.blit(self.background, (0,0))
for image, rect in zip(self.images, self.rects):
if image != self.images[self.index]:
screen.blit(image, rect)
screen.blit(self.himages[self.index], self.rects[self.index])
pygame.display.update()
done = False
blit(screen)
while not done:
for event in pygame.event.get():
if event.type == QUIT:
sys.quit()
if event.type == KEYDOWN:
if event.key == K_DOWN:
self.index = min(self.index+1, len(self.images)-1)
blit(screen)
if event.key == K_UP:
self.index = max(self.index-1, 0)
blit(screen)
if event.key == K_RETURN:
done = True
return self.index
示例4: render_text
# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import set_bold [as 别名]
def render_text(self, msg):
font = Font(_FONT, self.size)
font.set_bold(self.bold)
new_surface = pygame.Surface((self.width, self.height),
pygame.SRCALPHA, 32)
msg = msg.strip("\n")
lines = msg.split("\n")
longest = max(lines, key=lambda x: len(x))
#new_surface = pygame.Surface((self.width, self.height))
temp_surface = font.render(longest, False, self.colour)
msg_width = temp_surface.get_size()[0]
msg_height = font.get_height() * len(lines)
msg_x = (new_surface.get_width() - msg_width) / 2
msg_y = (new_surface.get_height() - msg_height) / 2
for index, line in enumerate(lines):
font_surface = font.render(line, False, self.colour)
new_surface.blit(font_surface, (msg_x,
msg_y + (font.get_height() * index)))
self.surface = new_surface
示例5: init
# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import set_bold [as 别名]
class Application:
def init(self):
pygame.init()
self.screen = pygame.display.set_mode((SCREEN_W, SCREEN_H))
self.clock = pygame.time.Clock()
pygame.display.set_caption("Twist'em All !")
pygame.time.set_timer(USEREVENT, 1000)
self.font = Font(data.filepath('fonts', 'vera.ttf'), 48)
self.font.set_bold(True)
def run(self):
option = 0
items = ['Play', 'Quit', 'Help']
menu = Menu(400, 200, 25, 40, (255,0,0), (0, 0,0), 'title-background.png', items)
menu.init()
map_number = 0
won = False
while option != 1 and map_number < 4:
self.screen.set_clip(Rect(0, 0, SCREEN_W, SCREEN_H))
if not won:
option = menu.run(self.screen)
if option == 0:
w_map = Map((640, 440))
w_map.load(maps[map_number])
panel = Panel(w_map)
won = self.run_map(w_map, panel)
if won:
map_number += 1
if map_number >= 4:
menu = Menu(300, 200, 18, 40, (255,0,0), (0, 0,0), 'title-background.png', ['You finished the game', 'More levels comming soon...'])
menu.init()
menu.run(self.screen)
def run_map(self, world_map, panel):
panel.draw_background(self.screen)
while not world_map.finish:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
return False
if event.type == USEREVENT:
print 'Frames per second:', self.clock.get_fps()
keys = pygame.key.get_pressed()
world_map.update(keys)
world_map.draw(self.screen, (0, 40))
panel.draw(self.screen)
pygame.display.update(world_map.update_rects)
pygame.display.update(panel.rect)
self.clock.tick(FPS)
if world_map.won:
aditional = ''
if world_map.main_character.life == world_map.main_character.life_max:
aditional = ' (Perfect)'
text = self.font.render('You Won !%s' % aditional , True, (0, 170, 0))
else:
text = self.font.render('You Lost !', True, (170, 0, 0))
rect = text.get_rect()
rect.centerx = SCREEN_W / 2
rect.centery = SCREEN_H / 2
self.screen.set_clip(Rect(0, 0, SCREEN_W, SCREEN_H))
self.screen.blit(text, rect)
pygame.display.update()
done = False
pygame.time.wait(2000)
return world_map.won