def __init__(self, position=(0, 0), size=(120, 20), parent=None, style=None, enabled=True, text=""): if not style: if not defaultTextBoxStyle: import gui gui.defaultTextBoxStyle = { 'font': font.SysFont(None, 16), 'font-color': (0, 0, 0), 'bg-color-normal': (255, 255, 255), 'bg-color-focus': (230, 255, 255), 'border-color-normal': (0, 0, 0), 'border-color-focus': (0, 50, 50), 'border-width': 1, 'appearence': APP_3D, 'antialias': True, 'offset': (4, 4) } style = defaultTextBoxStyle self.text = text self.currpos = len(text) self._textStartX = 0 self.surf = None self.textWidth = 0 pygame.key.set_repeat(250, 40) self.dynamicAttributes.extend(["text", "currpos"]) Widget.__init__(self, position, size, parent, style, enabled)
def __init__(self): Sprite.__init__(self) self.font = font.SysFont("monospace", 15) self.score = 0 self.text = "Score: {}".format(self.score) self.color = (0, 0, 0) self.image = None
def __init__(self, ai_settings, screen, stats): """Initialize score keeping attributes.""" self.screen = screen self.screen_rect = screen.get_rect() self.ai_settings = ai_settings self.stats = stats # Font settings for scoring information. self.text_color = (30, 30, 30) self.font = font.SysFont(None, 48) # Prepare the initial score image. self.score_image = None self.score_rect = None self.high_score_image = None self.high_score_rect = None self.level_image = None self.level_rect = None self.ships = None # Prepare the initial score images. self.prep_score() self.prep_high_score() self.prep_level() self.prep_ships()
def configurarFuente() -> font: """ Configura y devuelve la fuente del texto. @return: Fuente @rtype: FontType """ return font.SysFont(name='arial', size=20)
def __init__(self, x, y, axis=True, grid=True): """ initialise a plot object, with an x-range from x[0] to x[1] and a y-range from y[0] to y[1]. optional arguments axis and grid to set wether or not the axis / grid should be shown by default. the attributes are free to be get or set. plot( (lower x, upper x), (lower y, upper y), axis = True, grid = True ) -> plot to show the axis, grid and legend, use plot.show() to show functions and DE phase space, use plot.draw_func( f(x) ) plot.draw_field( y'(x,y) ) """ self.lo_x, self.hi_x = x self.lo_y, self.hi_y = y self.screen = display.get_surface() self.axis_font = pgfont.SysFont('Cambria', 15, True) self.axis = axis self.grid = grid self.dragging = False
def renderText(image): dateFont = font.SysFont('arial', 20, bold=True, italic=False) addressFont = font.SysFont('arial', 14, bold=False, italic=True) date = datetime.datetime.now().strftime('%b %d, %Y %I:%M %p') srfDate = dateFont.render(date, True, (255, 255, 255)) srfDateShadow = dateFont.render(date, True, (0, 0, 0)) address = 'Boulevard East, Weehawken, NJ' srfAddress = addressFont.render(address, True, (255, 255, 255)) srfAddressShadow = addressFont.render(address, True, (0, 0, 0)) image.blit(srfDateShadow, (11, 11)) image.blit(srfDate, (10, 10)) image.blit(srfAddressShadow, (11, 36)) image.blit(srfAddress, (10, 35))
def button(width, height, caption): # line thickness thickness = Style.button.border.thickness # background surface = Surface((width, height)) surface.fill(Style.button.color) # border if thickness > 0: draw.lines(surface, Style.button.border.color, True, [(0, 0), (width - thickness, 0), (width - thickness, height - thickness), (0, height - thickness)], thickness) # label myfont = font.SysFont(Style.button.label.font, Style.button.label.size) size = myfont.size(caption) # center text ... offsetX = (width - size[0]) / 2 offsetY = (height - size[1]) / 2 # draw text on surface label = myfont.render(caption, True, Style.button.label.color) surface.blit(label, (offsetX, offsetY)) return surface
def io_screen(info): """Intro and outro screens""" pygame.init() screen_width = 700 screen_height = 800 play_width = 400 play_height = 600 screen = pygame.display.set_mode((screen_width, screen_height)) s_font = font.SysFont("comicsans", 93) label = s_font.render(info, 1, (252, 15, 204)) run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if info.startswith("P"): if event.type == pygame.KEYDOWN: run = False elif info.startswith("G"): time.sleep(2) run = False screen.fill((0, 0, 26)) screen.blit(label, (0 + (screen_width - label.get_width()) // 2, screen_height // 2 - label.get_height() // 2)) pygame.display.update()
def bar(self, surface, text, pos, w=300): rect = Rect(pos, (w, 60)) draw.rect(surface, (0, 200, 200), rect) sf = font.SysFont('blah', 60, bold=False, italic=False) txt = sf.render(text, True, (0, 0, 0)) surface.blit(txt, rect.inflate(-10, -10))
def main(): char = 0 mancount = 0 count = 0 font = f.SysFont("Cooper Black", 30) text = font.render("Hangman", True, (0, 0, 255)) t = font.render(fact, True, (255, 0, 0)) p = font.render('enter your guess', True, (255, 255, 0)) gameover = font.render('Sorry game over! :( ', True, (255, 255, 0)) gamewon = font.render('Correct guess, Hurray! :) ', True, (255, 255, 0)) for i in list_word: if i is not ' ': blanks.append("_") char += 1 update_choice() while not False: for event in py.event.get(): if event.type == py.QUIT: return elif event.type == py.KEYDOWN: mancount, count = get_char(event, mancount, count) if mancount == 6: scr.blit(gameover, (150, 450)) py.display.flip() return if count == len(word): scr.blit(gamewon, (150, 450)) py.display.flip() return scr.blit(text, (220, 20)) scr.blit(t, (80, 150)) scr.blit(p, (80, 250)) py.display.flip()
def DrawOptions(screen, pokemon): draw.rect(screen, (62, 73, 65), (0, 113, 240, 47)) draw.rect(screen, (205, 177, 80), (2, 115, 236, 43)) draw.rect(screen, (185, 196, 198), (5, 118, 230, 37)) draw.rect(screen, (48, 78, 102), (5, 119, 228, 35)) # Set the font my_font = font.SysFont(None, 15) # Draw first move level_label = my_font.render(pokemon.moves[0] if pokemon.moves[0] else "-", 1, (255, 255, 255)) screen.blit(level_label, (18, 124)) # Draw second move level_label = my_font.render(pokemon.moves[1] if pokemon.moves[1] else "-", 1, (255, 255, 255)) screen.blit(level_label, (90, 124)) # Draw third move level_label = my_font.render(pokemon.moves[2] if pokemon.moves[2] else "-", 1, (255, 255, 255)) screen.blit(level_label, (18, 138)) # Draw last move level_label = my_font.render(pokemon.moves[3] if pokemon.moves[3] else "-", 1, (255, 255, 255)) screen.blit(level_label, (90, 138))
def on_game_end(self, game: engine.ChainReactionAnimated): """ Game over screen """ # convert colors to grayscale global ORB_PL1, ORB_PL2 global COL_PL1, COL_PL2 global COL_GRD COL_PL1 = (30, 30, 30) COL_PL2 = (30, 30, 30) COL_GRD = (30, 30, 30) ORB_PL1 = [sprites.grayscale(x, 0.2) for x in ORB_PL1] ORB_PL2 = [sprites.grayscale(x, 0.2) for x in ORB_PL2] # save player player = game.player self.flight_steps = 20 # slow-mo # construct game over text font_instance = font.SysFont("Ubuntu Mono", 50, True, False) message = "GREEN WINS!" if game.winner else "RED WINS!" mscolor = (100, 255, 50) if game.winner else (255, 100, 50) game_over_text = font_instance.render(message, True, mscolor) text_w, text_h = game_over_text.get_size() text_dest = (W_DIMS[0] // 2 - text_w // 2, W_DIMS[1] // 2 - text_h // 2) blit_text = lambda: self.surface.blit(game_over_text, text_dest) # keep exploding for cool end-graphics while self.open and game.pending_moves: prev_board, explosions = game.get_next_step() if explosions: self.explode_gameover(prev_board, explosions, player, blit_text) self.clear() self.draw_grid() self.draw_orbs(game.board) self.surface.blit(game_over_text, text_dest) self.update() self.event_handler() # draw static if pending moves are over if not game.pending_moves: self.clear() self.draw_grid() self.draw_orbs(game.board) self.surface.blit(game_over_text, text_dest) self.update() while self.open: self.event_handler() self.clock.tick(self.fps) # voluntary close if not game.game_over and not self.open: print("Sorry to see you go :(") font.quit() pygame.quit()
def DrawOpponentPokemon(screen, pokemon): name = pokemon.name if pokemon.name else GetPokemon( pokemon.number)["name"].capitalize() image_index = pokemon.number level = pokemon.level percent_health = pokemon.hp / pokemon.max_hp # Draw the Pokemon's info background draw.rect(screen, (62, 73, 65), (14, 14, 108, 32)) # Outline draw.rect(screen, (251, 252, 218), (15, 15, 106, 30)) # Content # Draw the health bar draw.rect(screen, (62, 73, 65), (44, 34, 72, 4)) draw.rect(screen, (131, 213, 164), (44, 34, floor(percent_health * 72), 4)) # Set the font my_font = font.SysFont(None, 15) # Print the Pokemon's name name_label = my_font.render(name, 1, (0, 0, 0)) screen.blit(name_label, (18, 20)) # Print the Pokemon's level level_label = my_font.render("Lv: " + str(level), 1, (0, 0, 0)) screen.blit(level_label, (82, 20)) # Draw the Pokemon sprite_sheet = image.load("Images/Pokemon/pokemon.png") DrawPokemon(screen, sprite_sheet, 138, 12, image_index)
def renderCheatMode(self): """ Renders the cheatMode button on top of the minefield **Args**: None. **Preconditions**: CheatMode is accessed **Postconditions**: cheatMode button is rendered **Returns**: None. """ cheatMode_text = 'Cheat mode' (cheatMode_left, cheatMode_top) = self.cheatMode_element.get_abs_offset() (cheatMode_x, cheatMode_y) = self.cheatMode_element.get_size() cheatMode_fontsize = 20 cheatMode_font = font.SysFont('lucidaconsole', cheatMode_fontsize) self.drawButton(self.window._screen, (cheatMode_left, cheatMode_top), (cheatMode_x, cheatMode_y), ((128, 128, 128), (96, 96, 96)), cheatMode_text, cheatMode_fontsize, self.reset)
def __init__(self, text, tam, pos, color): _font = font.SysFont('Comic Sans MS', 30) self.text = _font.render(text, False, color) self.pos = pos self.sizeWidth = _font.size(text)[0] self.sizeHeight = _font.size(text)[1] self.rect = Rect(pos[0], pos[1], self.sizeWidth, self.sizeHeight)
def __init__(self): self._files = FileResolver() # Store keyboard keys and corresponded sounds self._key_sound = {} # Load keymap settings with open(self._files.keymap_path) as f: self._keymap = yaml.safe_load(f) # Lower buffer to lower sound delay mixer.init(44100, -16, 2, 256) # Set higher channels number, allows to play many sounds # at the same time without stopping previously started ones mixer.set_num_channels(20) # Get any mono font, if no mono fonts use system default fonts = tuple(filter(lambda txt: 'mono' in txt, font.get_fonts())) win_font = fonts[0] if fonts else None font.init() self._font = font.SysFont(win_font, self.FONT_SIZE) # Set up the window win_height = len(self._keymap) * self.FONT_SIZE + 2 * self.MARGIN self._screen = display.set_mode((self.WINDOW_WIDTH, win_height)) display.set_caption(self.WINDOW_CAPTION)
def __init__(self, x_size_init=9, y_size_init=9, numMines_init=10): init() #limits on board size selections self.min_size = 2 self.max_y = 20 self.max_x = 40 #initialize member variables with initial values self.x_size = x_size_init self.y_size = y_size_init self.numMines = numMines_init #create a new display window of size (x, y) self.window = display.set_mode((600, 500)) self.window_margin = 20 #define subsurfaces for rendering different menu components self.sizeSurface = self.window.subsurface( Rect(self.window_margin, self.window_margin, self.window.get_width() / 2 - 1.5 * self.window_margin - 1, self.window.get_height() - 2 * self.window_margin - 100)) self.mineSurface = self.window.subsurface( Rect((self.window.get_width() / 2) + .5 * self.window_margin, self.window_margin, self.window.get_width() / 2 - 1.5 * self.window_margin, self.window.get_height() - 2 * self.window_margin - 100)) self.startSurface = self.window.subsurface( Rect(self.window_margin, 400, self.window.get_width() - 2 * self.window_margin, 100 - self.window_margin)) #initialize colors of the surfaces self.window.fill(Color('light grey')) self.sizeSurface.fill(Color('dark grey')) self.mineSurface.fill(Color('dark gray')) #intialize different font sizes self.title = font.SysFont('lucidaconsole', 30) self.subtitle = font.SysFont('lucidaconsole', 25) #initialize the Drawer self.drawer = Drawer() #initialize the ready flag self.gameReady = False
def __init__(self, x, y, texto, action=None): self.f = font.SysFont('Verdana', 16) imagen = self.crear(texto) rect = imagen.get_rect(topleft=(x, y)) super().__init__(imagen, rect) Renderer.add_widget(self, 1) WidgetHandler.add_widget(self, 1) self.action = action
def attachText(self, body, font, size, colour, pos=(1, 1)): self.font = pyfont.SysFont(font, size) self.fontName = font self.fontSize = size self.body = body self.textColour = colour self.textDimensions = self.font.size(body) self.textPos = tuple(pos)
def draw(self, surface): draw.rect(surface, self.color, self.rect) myfont = font.SysFont('Times New Roman', 24) textsurface = myfont.render(self.text, False, (0, 0, 0)) TextLeftRightCor = (self.rect.center[0] - textsurface.get_width() / 2, self.rect.center[1] - textsurface.get_height() / 2) surface.blit(textsurface, TextLeftRightCor)
def show_text(text_in, size_font, x, y): """ Генерируем текст с необходимыми параметрами и выводим его на экране """ x, y = int(x), int(y) game_font = font.SysFont(NAME_FONT, size_font) text_obj = game_font.render(text_in, 1, COLOR_TEXT) text_rect = text_obj.get_rect() text_rect.center = (x, y) window_surf.blit(text_obj, text_rect)
def test_SysFont(self): # Can only check that a font object is returned. fonts = pygame_font.get_fonts() if "arial" in fonts: # Try to use arial font if it is there, rather than a random font # which can be different depending on installed fonts on the system. font_name = "arial" else: font_name = sorted(fonts)[0] o = pygame_font.SysFont(font_name, 20) self.assertTrue(isinstance(o, pygame_font.FontType)) o = pygame_font.SysFont(font_name, 20, italic=True) self.assertTrue(isinstance(o, pygame_font.FontType)) o = pygame_font.SysFont(font_name, 20, bold=True) self.assertTrue(isinstance(o, pygame_font.FontType)) o = pygame_font.SysFont("thisisnotafont", 20) self.assertTrue(isinstance(o, pygame_font.FontType))
def __init__(self, gui, position, body, font, size, colour, z=0): self.z = 0 self.position = position self.font = pyfont.SysFont(font, size) self.body = body self.textColour = colour self.textDimensions = self.font.size(body) self.gui = gui
def menu(): global shiftDown textbox = TextBox() textbox.rect.center = [320, 240] run = True username = "" while run: WIN.blit(BACKGROUND, (0, 0)) WIN.blit(textbox.image, textbox.rect) pygame.display.flip() for e in pygame.event.get(): if e.type == pygame.QUIT: run = False if e.type == pygame.KEYUP: if e.key in [pygame.K_RSHIFT, pygame.K_LSHIFT]: shiftDown = False if e.type == pygame.KEYDOWN: textbox.add_chr(pygame.key.name(e.key)) if e.key == pygame.K_SPACE: textbox.text += " " textbox.update() if e.key in [pygame.K_RSHIFT, pygame.K_LSHIFT]: shiftDown = True if e.key == pygame.K_BACKSPACE: textbox.text = textbox.text[:-1] textbox.update() if e.key == pygame.K_RETURN: if len(textbox.text) > 0: username = textbox.text run = False run = True titlefont = font.SysFont("comicsans", 70) while run: WIN.blit(BACKGROUND, (0, 0)) titlelabel = titlefont.render("Press Spacebar to Begin...", True, (255, 255, 255)) WIN.blit(titlelabel, (WIDTH//2 - titlelabel.get_width()//2, HEIGHT//2)) update() for event in get(): if event.type == pygame.QUIT: run = False break keys = get_pressed() if keys[K_SPACE]: if main(username) == 1: WIN.blit(BACKGROUND, (0, 0)) titlelabel = titlefont.render("Game Over...", True, (255, 255, 255)) WIN.blit(titlelabel, (WIDTH//2 - titlelabel.get_width()//2, HEIGHT//2)) update() pygame.time.wait(2000) WIN.blit(BACKGROUND, (0, 0)) titlelabel = titlefont.render("Press Space To Restart/Escape To Quit...", True, (255, 255, 255)) WIN.blit(titlelabel, (WIDTH//2 - titlelabel.get_width()//2, HEIGHT//2)) update() if wait() == 1: run = False break display_scores() pygame.quit()
def __init__(self, ai_settings, screen, x, y, text='', color=(0, 0, 0)): self.x = x self.y = y self.screen = screen self.screen_rect = self.screen.get_rect() self.ai_settings = ai_settings self.message = text self.font = font.SysFont('Courier New', 48) self.text_color = color
def __init__(self, parent, text, method, x, y, w, h): super().__init__(parent) self.f = font.SysFont('Verdana', 16) self.rect = Rect(x, y, w, h) self.x, self.y, self.w, self.h = x, y, w, h self.img_uns = self.crear(text, self.f, w, h, COLOR_TEXT) self.img_sel = self.crear(text, self.f, w, h, COLOR_SELECTED) self.image = self.img_uns self.action = method
def initialize(self, name, size): init() # pygame.init() display.set_caption(name) # pygame.display self.screen = display.set_mode(size) self.window = Surface(self.screen.get_size(), SRCALPHA) self.uiScreen = Surface(self.screen.get_size(), SRCALPHA) self.font = font.SysFont("Arial", 18)
def __init__(self): super().__init__() self.f = font.SysFont('Verdana', 16) self.image = Surface((WIDTH, HEIGHT // 5)) self.image.fill(COLOR_BOX) self.rect = self.image.get_rect(bottomleft=(0, HEIGHT)) EventHandler.register(self.switch, 'ToggleTypeMode') WidgetHandler.add_widget(self) Renderer.add_widget(self)
def __draw_dist_numbers__(self, angle, r, r_display): f = font.SysFont('Lucida Console', int(WIDTH / 55)) text_angle = angle * pi / 180 margin = 0.007 * WIDTH text = f.render(str(r), False, WHITE) a = int(WIDTH / 2 + r_display * sin(text_angle) + margin) b = int(AP_POS - r_display * cos(text_angle)) self.gD.blit(text, [a, b]) return
def __init__(self, pos_x, pos_y, size, content="text", font_name="Consolas", color=(255, 255, 255, 255)): self.pos_x = pos_x self.pos_y = pos_y self.size = size self.content = content self.color = color self.font_name = font_name self.font = font.SysFont(font_name, size) self.text_alpha = 50