本文整理汇总了Python中pygame.font.Font类的典型用法代码示例。如果您正苦于以下问题:Python Font类的具体用法?Python Font怎么用?Python Font使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Font类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: __init__
def __init__(
self, evManager, text, rect=None, onDownClickEvent=None, onUpClickEvent=None, onMouseMoveOutEvent=None
):
Widget.__init__(self, evManager)
# Widget init sets dirty to true, hence the actual text rendering
# will be done in ButtonWidget.update(), called by the view renderer.
self._em.reg_cb(DownClickEvent, self.on_downclick)
self._em.reg_cb(UpClickEvent, self.on_upclick)
self._em.reg_cb(MoveMouseEvent, self.on_mousemove)
# the events to be triggered when the button is clicked or mouse moved
self.onDownClickEvent = onDownClickEvent
self.onUpClickEvent = onUpClickEvent
self.onMouseMoveOutEvent = onMouseMoveOutEvent
self.text = text
self.font = Font(None, config_get_fontsize()) # default font, 40 pixels high
if rect:
self.rect = rect
self.image = Surface(self.rect.size) # container size from specified rect
# if txtimg does not fit in rect, it'll get cut (good thing)
else:
txtimg = self.font.render(self.text, True, (0, 0, 0))
self.rect = txtimg.get_rect()
self.image = Surface(self.rect.size) # container size from rendered text
开发者ID:gentimouton,项目名称:crowd-control,代码行数:27,代码来源:widgets.py
示例17: MenuScreen
class MenuScreen(BaseScreen):
def init_entities_before(self, surface):
self.font = Font(None, 30)
self.textImg = self.font.render(
'Press SPACE to BEGIN !',
1,
(255,255,255)
)
surface.blit(self.textImg, (200,200))
def execute(self, surface):
if pygame.key.get_pressed()[SPACE] == 1:
raise ChangeScreenException(1, 'Launch the game!')
def erase_all_map(self):
pass
def draw(self, surface):
pass
def game_over(self, text, number=None):
BaseScreen.erase_all_map(self)
font = Font(None, 30)
textImg = font.render(text, 1, (255,255,255))
self.surface.blit(textImg, (200,100))
开发者ID:Bobbyshow,项目名称:Avoid,代码行数:26,代码来源:menu.py
示例18: __init__
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)
开发者ID:ceronman,项目名称:twsitemall,代码行数:16,代码来源:application.py
示例19: draw
def draw(self, surface):
h = surface.get_height()
w = surface.get_width()
board = self.board
if not self.pos:
return
(x, y) = self.pos
x *= (board.bw / board.width)
y *= (board.bh / board.height)
self.radius = ((board.bh if board.bh < board.bw else board.bw) / board.width) / 4
self.apos = (int(x+(self.radius*2)+board.offset[0]), int(y+(self.radius*2)+board.offset[1]))
if self.selected and board.highlight_selected:
color = (255, 80, 0)
halo(surface, self.apos, self.radius, color, self.radius/2)
elif self.possible_move and board.highlight_moves:
color = (128, 255, 255)
halo(surface, self.apos, self.radius, color, self.radius/2, False)
elif self.empty:
color = (128, 255, 255)
circle(surface, self.apos, self.radius, color, 1)
if not self.empty:
color = (128, 255, 255)
circle(surface, self.apos, self.radius, color)
#draw links to other nodes
if board.show_grid:
from pygame.font import Font
vera = Font('Resources\\fonts\\Vera.ttf',10)
text_surface = vera.render(str(self.cord), True, (255, 255, 255))
surface.blit(text_surface, (self.apos[0]+self.radius, self.apos[1]+self.radius))
for n in self.links:
if self.links[n].apos:
self.draw_link(surface, self.links[n])
return self
开发者ID:AnnanFay,项目名称:pyge-solitaire,代码行数:47,代码来源:hole.py
示例20: init_entities_before
def init_entities_before(self, surface):
self.font = Font(None, 30)
self.textImg = self.font.render(
'Press SPACE to BEGIN !',
1,
(255,255,255)
)
surface.blit(self.textImg, (200,200))
开发者ID:Bobbyshow,项目名称:Avoid,代码行数:8,代码来源:menu.py
注:本文中的pygame.font.Font类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论