def render(self, render_screen): draw_text(render_screen, self.cached_fonts['large'], color_normal, True, "Please select your preferred", ( self.window_width // 2, self.window_height // 8)) draw_text(render_screen, self.cached_fonts['large'], color_normal, True, "input device", ( self.window_width // 2, self.window_height // 4)) for _, value in self.menu_items.items(): value.render(render_screen)
def display(self, worksheet, sorted_contours): contours = sorted_contours for i, contour in enumerate(contours): app = Helpers.approx(contour, 0.05) rect = Helpers.get_rectangle_corners(app) font_face = Helpers.font("Hershey") font_scale = 1.5 thickness = 3 text_size = Helpers.text_size(str(self.answer_key[i]), font_face, font_scale, thickness) text_x = int(rect[0][0] - text_size[0][0]) - 20 text_y = int(rect[3][1]) - 10 if self.marks[i] == "correct": contour_color = Helpers.BGR_COLORS["GREEN"] text_color = Helpers.BGR_COLORS["DARK GREEN"] elif self.marks[i] == "unknown": contour_color = Helpers.BGR_COLORS["YELLOW"] text_color = Helpers.BGR_COLORS["BLACK"] else: contour_color = Helpers.BGR_COLORS["RED"] text_color = Helpers.BGR_COLORS["DARK RED"] Helpers.draw_text(worksheet, str(self.answer_key[i]), (text_x, text_y), font_face, font_scale, \ text_color, thickness) Helpers.draw_contour(worksheet, contour, contour_color) Helpers.show(worksheet, 'graded') return worksheet
def render(self, render_screen, score, highest_score): x = self.x y = self.y # Show lose menu render_screen.blit(self.score_menu_img, (x, y)) # show bird score draw_text(render_screen, 'Score', self.cached_fonts['retro_20'], (255, 134, 45), True, pygame.Rect( x, y, self.score_menu_img.get_width(), self.score_menu_img.get_height() // 4), 'center', 'center') y = y + self.score_menu_img.get_height() // 4 draw_text(render_screen, str(score), self.cached_fonts['retro_20'], (255, 134, 45), True, pygame.Rect( x, y, self.score_menu_img.get_width(), self.score_menu_img.get_height() // 4), 'center', 'center') # show bird high score y = y + self.score_menu_img.get_height() // 4 draw_text(render_screen, 'Best', self.cached_fonts['retro_20'], (255, 134, 45), True, pygame.Rect( x, y, self.score_menu_img.get_width(), self.score_menu_img.get_height() // 4), 'center', 'center') y = y + self.score_menu_img.get_height() // 4 draw_text(render_screen, str(highest_score), self.cached_fonts['retro_20'], (255, 134, 45), True, pygame.Rect( x, y, self.score_menu_img.get_width(), self.score_menu_img.get_height() // 4), 'center', 'center') # Show Restart button self.restart_button.render(render_screen) # Show Highscores button self.save_score_button.render(render_screen)
def render(self, render_screen): draw_text(render_screen, self.cached_fonts['large'], (255, 255, 255), True, f'Player {self.winner} Won!', (self.window_width // 2, self.window_height // 5)) draw_text(render_screen, self.cached_fonts['small'], (255, 255, 255), True, "Press Enter to go back to the main menu", (self.window_width // 2, self.window_height // 3)) # print score draw_text(render_screen, self.cached_fonts['huge'], (255, 255, 255), True, str(self.player1_score), (self.window_width // 4, self.window_height // 4)) draw_text(render_screen, self.cached_fonts['huge'], (255, 255, 255), True, str(self.player2_score), (self.window_width * 3 // 4, self.window_height // 4))
def _draw(self): GL.glColor3f(*DARK_GREY) draw_line(*self.x_axis) draw_line(*self.y_axis) GL.glColor3f(*LIGHT_GREY) for line in chain(self.horizontal_grid, self.vertical_grid): draw_line(*line) GL.glColor3f(*DARK_GREY) GL.glLineWidth(2) draw_line(self.mark + (0, 5), self.mark + (0, -5)) GL.glLineWidth(1) draw_text(self.origin + (2, -10), "0") draw_text(self.mark + (2, -10), "20") draw_text(self.x_axis[1] + (2, -10), "X") draw_text(self.y_axis[1] + (2, -10), "Y")
def render(self, render_screen): # Draw scrolling top background self.background_top.render(render_screen) # Draw Pipes for pipe_pair in self.pipe_pairs: pipe_pair.render(render_screen) # Draw bird self.bird.render(render_screen) # Draw scrolling bottom background self.background_bottom.render(render_screen) if not self.play and not self.lose: # Draw welcome message draw_text( render_screen, 'Welcome to Flappy Yos!', self.cached_fonts['retro_70'], (255, 255, 255), True, pygame.Rect(0, self.window_height // 9, self.window_width, self.window_height - self.window_height // 9), 'center', 'top') draw_text( render_screen, 'Press Spacebar to start playing', self.cached_fonts['retro_40'], (255, 255, 255), True, pygame.Rect(0, self.window_height // 4, self.window_width, self.window_height - self.window_height // 4), 'center', 'top') if self.play: # Draw score draw_text( render_screen, str(self.bird.score), self.cached_fonts['retro_70'], (255, 255, 255), True, pygame.Rect(0, self.window_height // 8, self.window_width, self.window_height - self.window_height // 8), 'center', 'top') if self.lose: self.end_game_menu.render(render_screen, self.bird.score, self.bird.highest_score)
def render(self, render_screen): start_pos = self.window_height // 5 gap = 40 if self.num_players == 1: draw_text(render_screen, self.cached_fonts['medium'], (255, 255, 255), True, "Player 1 instructions", (self.window_width // 2, start_pos)) start_pos += gap draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, f"You have chosen to use the {self.input_device}. ", (self.window_width // 2, start_pos)) start_pos += gap draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, f"You have selected {self.difficulty} difficulty. ", (self.window_width // 2, start_pos)) if self.input_device == 'mouse': start_pos += gap * 2 draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, "Control the paddle on the left hand side of the screen", (self.window_width // 8, start_pos), 'left') start_pos += gap draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, "using your mouse. the paddle can be moved up or down.", (self.window_width // 8, start_pos), 'left') if self.input_device == 'keyboard': draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, "Control the paddle on the left hand side of the screen", (self.window_width // 8, start_pos), 'left') start_pos += gap draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, 'using your keyboard. use "W" to move the paddle up', (self.window_width // 8, start_pos), 'left') start_pos += gap draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, 'and "S" to move the paddle down.', (self.window_width // 8, start_pos), 'left') else: draw_text(render_screen, self.cached_fonts['medium'], (255, 255, 255), True, "Two players instructions", (self.window_width // 2, start_pos)) start_pos += gap * 2 draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, 'Player 1 controls the left hand paddle using the', (self.window_width // 8, start_pos), 'left') start_pos += gap draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, '"W" (up) and "Z" (down) keys.', (self.window_width // 8, start_pos), 'left') start_pos += gap * 2 draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, 'Player 2 controls the right hand paddle using the', (self.window_width // 8, start_pos), 'left') start_pos += gap draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, 'up arrow and down arrow keys.', (self.window_width // 8, start_pos), 'left') start_pos += gap * 2 draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, "Points are scored when your opponent misses the ball.", (self.window_width // 8, start_pos), 'left') start_pos += gap draw_text(render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, f"First player to reach {self.win_score} points wins the game.", (self.window_width // 8, start_pos), 'left') start_pos = self.window_height - gap * 2 draw_text(render_screen, self.cached_fonts['medium'], (255, 255, 255), True, "Press Spacebar to Play!", (self.window_width // 2, start_pos)) for _, value in self.menu_items.items(): value.render(render_screen)
def render(self, render_screen): # draw the net self.draw_net(render_screen) # draw the score draw_text(render_screen, self.cached_fonts['huge'], (255, 255, 255), True, str(self.player1.score), (self.window_width // 4, self.window_height // 4)) draw_text(render_screen, self.cached_fonts['huge'], (255, 255, 255), True, str(self.player2.score), (self.window_width * 3 // 4, self.window_height // 4)) # Draw special hit prompt time = int(pygame.time.get_ticks() / 500) if self.player1.ball_hits == self.paddle_special_hit_threshold: if not self.player1.going_to_hit_special: if time % 2 == 0: draw_text( render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, 'Press Left Ctrl for a special hit!', (self.window_width * 1 // 4, self.window_height // 10)) else: if time % 2 == 0: draw_text( render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, 'Hitting special!', (self.window_width * 1 // 4, self.window_height // 10)) if self.num_players == 2 and self.player2.ball_hits == self.paddle_special_hit_threshold: if not self.player2.going_to_hit_special: if time % 2 == 0: draw_text( render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, 'Press Right Ctrl for a special hit!', (self.window_width * 3 // 4, self.window_height // 10)) else: if time % 2 == 0: draw_text( render_screen, self.cached_fonts['small_medium'], (255, 255, 255), True, 'Hitting special!', (self.window_width * 3 // 4, self.window_height // 10)) # Draw the ball self.ball.draw(render_screen) # Draw the paddles self.player1.draw(render_screen) self.player2.draw(render_screen) self.particle_system.render(render_screen)
def render(self, render_screen): draw_text(render_screen, self.cached_fonts['title'], color_normal, True, "PONG", (self.window_width // 2, self.window_height // 4)) for _, value in self.menu_items.items(): value.render(render_screen)
def render(self, render_screen): draw_text(render_screen, self.cached_fonts['large'], color_normal, True, "Choose your difficulty level:", ( self.window_width // 2, self.window_height // 8)) for _, value in self.menu_items.items(): value.render(render_screen)
def render(self, render_screen): draw_text(render_screen, self.font, self.color, True, self.text, self.position, 'left')