def on_draw(self): """Draw and update text.""" super().on_draw() x = WIDTH / 2 y = HEIGHT / 2 + 102.5 colour = (255, 255, 255) arcade.draw_text('Settings', x, y, colour, 30, anchor_x='center', anchor_y='center', font_name=FONT.format(type='b')) y -= 40 sfx_vol = self.sfx_slider.value * 100 arcade.draw_text(f'SFX Volume - {sfx_vol:.0f}%', x, y, colour, 20, anchor_x='center', anchor_y='center', font_name=FONT.format(type='r')) y -= 70 music_vol = self.music_slider.value * 100 arcade.draw_text(f'Music Volume - {music_vol:.0f}%', x, y, colour, 20, anchor_x='center', anchor_y='center', font_name=FONT.format(type='r'))
def make_grid(window, chosenSymbol): window.fill(colors['white']) p1 = chosenSymbol p2 = 'X' if p1 == 'O' else 'O' p1Text = FONT.render(f"Player 1 : {p1}", 1, colors['green'] if p1 == 'O' else colors['red']) p2Text = FONT.render(f"Computer : {p2}", 1, colors['green'] if p2 == 'O' else colors['red']) totalWidth = p1Text.get_width() + p2Text.get_width() window.blit(p1Text, ((WIN_DIM - totalWidth) // 2, 0)) window.blit(p2Text, (p1Text.get_width() + (WIN_DIM - totalWidth) // 2 + 10, 0)) # draw a 3x3 grid of 300 x 300 pixels # got 200 pixels left on either side, start from 100, 100 pygame.display.flip() for i in range(0, 4): pygame.draw.line(window, colors['black'], (100, (i + 1) * 100), (400, (i + 1) * 100)) for j in range(0, 4): pygame.draw.line(window, colors['black'], ((j + 1) * 100, 100), ((j + 1) * 100, 400)) pygame.display.update()
def on_draw(self): """Draw all the sprites and UI elements.""" arcade.start_render() self.pauseplay.center_x = self.left + WIDTH - 40 super().on_draw() for n, player in enumerate(self.players): center_x = n * (WIDTH / 4) + self.left + 136.5 arcade.draw_text(text=f'Player {n + 1}', start_x=center_x, start_y=HEIGHT - 5, color=arcade.color.WHITE, font_size=20, anchor_x='center', anchor_y='top', font_name=FONT.format(type='b')) if player.death_message: message = ( f'{player.death_message}, {player.revive_after // 60}') colour = (255, 0, 0) else: message = f'Score: {player.score:3d}' colour = (255, 255, 255) arcade.draw_text(text=message, start_x=center_x, start_y=HEIGHT - TOP + 21, color=colour, font_size=20, anchor_x='center', font_name=FONT.format(type='r')) arcade.draw_text(text=f'{int(self.time_left):02d}s', start_x=self.left + WIDTH - 35, start_y=HEIGHT - (TOP - self.blocks[0].height // 2) // 2 - 15, color=arcade.color.WHITE, font_size=20, anchor_x='center', anchor_y='center', font_name=FONT.format(type='b')) for sprite_list in self.sprite_lists: sprite_list.draw() for player in self.players: player.draw() if self.paused: arcade.draw_lrtb_rectangle_filled(left=self.left, right=WIDTH + self.left, top=HEIGHT, bottom=0, color=(255, 255, 255, 100)) super().on_draw(start_render=False) if not self.pause_screen: self.pause_screen = views.Paused( self, lambda: MultiplayerGame(len(self.players))) self.window.show_view(self.pause_screen)
def show_end_screen(window, winner): window.fill(colors['white']) if winner != 'Draw': t = f'{winner} wins' text = FONT.render(t, 1, colors['green'] if winner == 'O' else colors['red']) else: text = FONT.render('Draw', 1, colors['black']) window.blit(text, ((WIN_DIM - text.get_width()) // 2, 10)) pygame.display.update()
def create_tooltip(self) -> arcade.Texture: """Create an arcade texture for the tooltip.""" gap = 5 name_font = ImageFont.truetype(FONT.format(type='r'), 20) desc_font = ImageFont.truetype(FONT.format(type='ri'), 15) name_width, name_height = name_font.getsize(self.name) desc_width, desc_height = desc_font.getsize(self.desc) width = max(name_width, desc_width) + gap * 2 height = name_height + gap * 3 + desc_height im = Image.new('RGB', (width, height), color=(255, 255, 255)) draw = ImageDraw.Draw(im) draw.text((gap, gap), self.name, (0, 0, 0), name_font) draw.text((gap, name_height + gap * 2), self.desc, (0, 0, 0), desc_font) return arcade.Texture(self.name + '\n' + self.desc, im)
def on_draw(self): """Draw text.""" global restarts arcade.start_render() restarts = 0 # won't work without this for some reason arcade.set_viewport(0, WIDTH, 0, HEIGHT) y = HEIGHT / 2 + 80 arcade.draw_text('Game Over:', WIDTH / 2, y, (255, 0, 0), font_size=50, anchor_x='center', font_name=FONT.format(type='b')) y -= 50 arcade.draw_text(self.message, WIDTH / 2, y, (255, 0, 0), font_size=30, anchor_x='center', font_name=FONT.format(type='m')) y -= 60 if len(self.scores) == 1: arcade.draw_text(f'Score: {self.scores[0]}', WIDTH / 2, y, (255, 255, 255), font_size=30, anchor_x='center', font_name=FONT.format(type='m')) y -= 30 else: for n, score in enumerate(self.scores): arcade.draw_text(f'Player {n + 1}: {score}', WIDTH / 2, y, (255, 255, 255), font_size=30, anchor_x='center', font_name=FONT.format(type='m')) y -= 40 y -= 10 arcade.draw_text('Click anywhere to continue', WIDTH / 2, y, arcade.color.GRAY, font_size=20, anchor_x='center', font_name=FONT.format(type='ri'))
def on_draw(self): """Draw the text and buttons to the screen.""" super().on_draw() arcade.draw_text('Achievements', WIDTH / 2, HEIGHT / 2 + 225, arcade.color.WHITE, font_size=30, anchor_x='center', font_name=FONT.format(type='b'))
def on_draw(self): """Draw text and back button.""" super().on_draw() arcade.draw_text('Multiplayer', WIDTH / 2, HEIGHT / 2 + 100, arcade.color.WHITE, font_size=50, anchor_x='center', font_name=FONT.format(type='b')) arcade.draw_text(MULTIPLAYER_HELP, WIDTH / 2, HEIGHT / 2, arcade.color.WHITE, font_size=20, anchor_x='center', anchor_y='center', align='center', font_name=FONT.format(type='r'))
def on_draw(self): """Draw text and back button.""" arcade.start_render() super().on_draw() arcade.draw_text('About', WIDTH / 2, HEIGHT / 2 + 100, arcade.color.WHITE, font_size=50, anchor_x='center', font_name=FONT.format(type='b')) arcade.draw_text(ABOUT, WIDTH / 2, HEIGHT / 2, arcade.color.WHITE, font_size=20, anchor_x='center', anchor_y='center', align='center', font_name=FONT.format(type='r'))
def on_draw(self): """Draw buttons, game and title.""" arcade.start_render() self.game.on_draw() arcade.draw_text('Paused', self.game.left + WIDTH / 2, HEIGHT / 2 + 50, (0, 0, 0), font_size=50, anchor_x='center', font_name=FONT.format(type='b')) super().on_draw(start_render=False)
def on_draw(self): """Display the buttons and title.""" arcade.start_render() super().on_draw() arcade.draw_text('Multiplayer', WIDTH / 2, HEIGHT / 2, arcade.color.WHITE, font_size=50, anchor_x='center', anchor_y='bottom', font_name=FONT.format(type='b')) arcade.draw_text( 'Multiplayer physics is still a little broken, apologies.', WIDTH / 2, HEIGHT / 2 - 160, (255, 255, 255), 20, anchor_x='center', anchor_y='top', font_name=FONT.format(type='li'))
def create_tooltip(self) -> arcade.Texture: """Create an arcade texture for the tooltip.""" padding = 5 font = ImageFont.truetype(FONT.format(type='ri'), 20) text_width, text_height = font.getsize(self.tooltip_text) width = text_width + padding * 2 height = text_height + padding * 2 im = Image.new('RGB', (width, height), color=(255, 255, 255)) draw = ImageDraw.Draw(im) draw.text((padding, padding), self.tooltip_text, (0, 0, 0), font) return arcade.Texture(str(self.tooltip_text), im)
def on_draw(self): """Display the buttons and title.""" arcade.start_render() super().on_draw() arcade.draw_text('Artemis: Gem Matcher', WIDTH / 2, HEIGHT / 2, arcade.color.WHITE, font_size=50, anchor_x='center', anchor_y='bottom', font_name=FONT.format(type='b'))
def on_draw(self): """Draw all the sprites and UI elements.""" arcade.start_render() self.pauseplay.center_x = self.left + WIDTH - 40 super().on_draw() arcade.draw_text(text=f'High Score: {self.hiscore:03d}', start_x=self.left + WIDTH - 100, start_y=HEIGHT - (TOP - self.blocks[0].height // 2) // 2 + 15, color=arcade.color.WHITE, font_size=20, anchor_x='right', anchor_y='center', font_name=FONT.format(type='b')) arcade.draw_text(text=f'Score: {self.player.score:03d}', start_x=self.left + WIDTH - 100, start_y=HEIGHT - (TOP - self.blocks[0].height // 2) // 2 - 15, color=arcade.color.WHITE, font_size=20, anchor_x='right', anchor_y='center', font_name=FONT.format(type='b')) for sprite_list in self.sprite_lists: sprite_list.draw() self.player.draw() if self.paused: arcade.draw_lrtb_rectangle_filled(left=self.left, right=WIDTH + self.left, top=HEIGHT, bottom=0, color=(255, 255, 255, 100)) super().on_draw(start_render=False) if not self.pause_screen: self.pause_screen = views.Paused(self, Game) self.window.show_view(self.pause_screen)
def main_screen(window): text = FONT.render("Choose your Symbol", 1, colors['black']) textWidth = text.get_width() window.blit(text, ((WIN_DIM - textWidth) // 2, 0)) pygame.draw.rect(window, colors['black'], (0, 200, WIN_DIM, 100)) zero = BIG_FONT.render("O", 1, colors['green']) cross = BIG_FONT.render("X", 1, colors['red']) # print(f'zero = {zero.get_width(), zero.get_height()}') window.blit(zero, ((90, 200))) window.blit(cross, ((270, 200))) pygame.display.update()