def __init__(self): self.start_ticks = pygame.time.get_ticks() self.start_text = text_format("RACE STARTS", MENU_FONT, 25, colors.white) self.start_text_rect = self.start_text.get_rect() self.countdown_text = text_format(str(self.countdown), MENU_FONT, 25, colors.white) self.countdown_text_rect = self.countdown_text.get_rect()
def leaderboard_menu(screen, menu_logos): in_leaderboard_menu = True # Load background_image = load_image(background_file) menu_line = load_image(menu_line_file) leaderboard_list = load_leaderboard() while in_leaderboard_menu: for event in pygame.event.get(): if event.type == pygame.QUIT or \ (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): return # Draw Background background_rect = background_image.get_rect() background_rect.left, background_rect.top = [0, 0] screen.fill([255, 255, 255]) screen.blit(background_image, background_rect) # Draw Logos menu_logos.draw(screen) title = text_format(TITLE_TEXT, MENU_FONT, 50, colors.white) screen.blit(title, (150, 220)) position_header_text = text_format("POSITION", MENU_FONT, 16, colors.white) screen.blit(position_header_text, (150, 300)) time_header_text = text_format("TIME (seconds)", MENU_FONT, 16, colors.white) screen.blit(time_header_text, (300, 300)) name_header_text = text_format("NAME", MENU_FONT, 16, colors.white) screen.blit(name_header_text, (500, 300)) screen.blit(menu_line, (150, 320)) for place in range(10): y_position = 330 + place * 16 place_text = text_format( str(place + 1) + ".", MENU_FONT, 16, colors.white) time_text = text_format(leaderboard_list[place][0], MENU_FONT, 16, colors.white) name_text = text_format(leaderboard_list[place][1], MENU_FONT, 16, colors.white) screen.blit(place_text, (150, y_position)) screen.blit(time_text, (300, y_position)) screen.blit(name_text, (500, y_position)) screen.blit(menu_line, (150, 500)) press_escape_text = text_format( "Press 'Escape' key to return to the Main Menu", MENU_FONT, 16, colors.white) screen.blit(press_escape_text, (150, 520)) pygame.display.update() clock.tick(30)
def title_screen(screen, screen_rect): in_title_screen = True # Load background_image = load_image(background_file) main_title_image = load_image('ccc_pumptrack_attack_title.png') # Main Theme load_music(main_theme) pygame.mixer.music.play(-1) while in_title_screen: for event in pygame.event.get(): if event.type == pygame.QUIT or event.type == pygame.KEYDOWN: return # Draw Background background_rect = background_image.get_rect() background_rect.left, background_rect.top = [0, 0] screen.fill(colors.white) screen.blit(background_image, background_rect) main_title_image_rect = main_title_image.get_rect() main_title_image_rect.center = (screen_rect.size[0] / 2 + 20, screen_rect.size[1] / 2 - 80) screen.blit(main_title_image, main_title_image_rect) press_any_key = text_format("Press any key to continue", MENU_FONT, 18, colors.white) press_any_key_rect = press_any_key.get_rect() press_any_key_rect.center = (screen_rect.size[0] / 2, 500) screen.blit(press_any_key, press_any_key_rect) pygame.display.update() clock.tick(30)
def draw(self, screen, screen_rect, background, background_in_alpha): screen.blit(background, screen_rect) screen.blit(background_in_alpha, screen_rect) title = text_format(TITLE_TEXT, MENU_FONT, 50, colors.white) if self.selected == 0: text_start = text_format(MENU_START, MENU_FONT, 25, colors.white) else: text_start = text_format(MENU_START, MENU_FONT, 25, colors.light_gray) if self.selected == 1: text_quit = text_format(MENU_QUIT, MENU_FONT, 25, colors.white) else: text_quit = text_format(MENU_QUIT, MENU_FONT, 25, colors.light_gray) screen.blit(title, (150, 220)) screen.blit(self.menu_line, (150, 350)) screen.blit(text_start, (150, 370)) screen.blit(text_quit, (150, 400)) screen.blit(self.menu_line, (150, 500))
def draw(self, screen, screen_rect, background, background_in_alpha): self.countdown_text = text_format(str(self.countdown), MENU_FONT, 25, colors.white) self.countdown_text_rect = self.countdown_text.get_rect() screen.blit(background, screen_rect) screen.blit(background_in_alpha, screen_rect) screen.blit( self.start_text, (screen_rect.size[0] / 2 - self.start_text_rect.size[0] / 2, screen_rect.size[1] / 2)) screen.blit( self.countdown_text, (screen_rect.size[0] / 2 - self.countdown_text_rect.size[0] / 2, screen_rect.size[1] / 2 + 50))
def draw(self, screen, screen_rect, background, background_in_alpha): screen.blit(background, screen_rect) screen.blit(background_in_alpha, screen_rect) msg = "Your final Time: %ss" % datetime.datetime.fromtimestamp( self.final_time / 1000.0).strftime('%S.%f')[:-3] final_time_text = text_format(msg, MENU_FONT, 20, colors.white) screen.blit( final_time_text, (screen_rect.size[0] / 2 + 150, screen_rect.size[1] / 2 - 100)) for place in range(10): y_position = 330 + place * 16 place_text = text_format( str(place + 1) + ".", MENU_FONT, 16, colors.white) time_text = text_format(self.leaderboard_list[place][0], MENU_FONT, 16, colors.white) name_text = text_format(self.leaderboard_list[place][1], MENU_FONT, 16, colors.white) screen.blit(place_text, (screen_rect.size[0] / 2 + 150, y_position)) screen.blit(time_text, (screen_rect.size[0] / 2 + 180, y_position)) screen.blit(name_text, (screen_rect.size[0] / 2 + 240, y_position)) title = text_format(GAME_OVER_TITLE, MENU_FONT, 50, colors.white) if self.selected == 0: text_start = text_format(MENU_START, MENU_FONT, 25, colors.white) else: text_start = text_format(MENU_START, MENU_FONT, 25, colors.light_gray) if self.selected == 1: text_quit = text_format(MENU_QUIT, MENU_FONT, 25, colors.white) else: text_quit = text_format(MENU_QUIT, MENU_FONT, 25, colors.light_gray) screen.blit(title, (150, 220)) screen.blit(self.menu_line, (150, 350)) screen.blit(text_start, (150, 370)) screen.blit(text_quit, (150, 400)) screen.blit(self.menu_line, (150, 500))
def settings_menu(menu_logos): menu = True selected = 0 # Load background_image = load_image(background_file) menu_line = load_image(menu_line_file) while menu: for event in pygame.event.get(): if event.type == pygame.QUIT or \ (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): return if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: if selected <= 0: selected = len(menu_options) - 1 else: selected -= 1 elif event.key == pygame.K_DOWN: if selected == len(menu_options) - 1: selected = 0 else: selected += 1 if event.key == pygame.K_RETURN: if selected == 0: change_sound_volume() if selected == 1: change_music_volume() if selected == 2: toggle_full_screen() if selected == 3: menu = False # Draw Background background_rect = background_image.get_rect() background_rect.left, background_rect.top = [0, 0] screen = pygame.display.get_surface() screen.fill([255, 255, 255]) screen.blit(background_image, background_rect) # Draw Logos menu_logos.draw(screen) # Main Menu UI # screen.fill(colors.light_blue) title = text_format(TITLE_TEXT, MENU_FONT, 50, colors.white) sfx_volume = MENU_SFX_VOLUME + str(int(pygame.mixer.Channel(0).get_volume() * 10)) music_volume = MENU_MUSIC_VOLUME + str(int(pygame.mixer.music.get_volume()*10)) full_screen_mode = MENU_FULL_SCREEN_MODE + is_full_screen() if selected == 0: text_start = text_format(sfx_volume, MENU_FONT, 25, colors.white) else: text_start = text_format(sfx_volume, MENU_FONT, 25, colors.light_gray) if selected == 1: text_settings = text_format(music_volume, MENU_FONT, 25, colors.white) else: text_settings = text_format(music_volume, MENU_FONT, 25, colors.light_gray) if selected == 2: text_credits = text_format(full_screen_mode, MENU_FONT, 25, colors.white) else: text_credits = text_format(full_screen_mode, MENU_FONT, 25, colors.light_gray) if selected == 3: text_quit = text_format(MENU_RETURN, MENU_FONT, 25, colors.white) else: text_quit = text_format(MENU_RETURN, MENU_FONT, 25, colors.light_gray) text_option_description = text_format(menu_options_descriptions[selected], MENU_FONT, 16, colors.white) # Main Menu Text screen.blit(title, (150, 220)) screen.blit(menu_line, (150, 320)) screen.blit(text_start, (150, 340)) screen.blit(text_settings, (150, 370)) screen.blit(text_credits, (150, 400)) screen.blit(text_quit, (150, 460)) screen.blit(menu_line, (150, 500)) screen.blit(text_option_description, (150, 520)) pygame.display.update() clock.tick(30)
def main_menu(screen, screen_rect): menu = True selected = 0 menu_logos = MenuLogos() # Load background_image = load_image(background_file) menu_line = load_image(menu_line_file) menu_logos.load() while menu: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: if selected <= 0: selected = len(menu_options) - 1 else: selected -= 1 elif event.key == pygame.K_DOWN: if selected == len(menu_options) - 1: selected = 0 else: selected += 1 if event.key == pygame.K_RETURN: if selected == 0: game_play(screen, screen_rect) if selected == 1: settings_menu(menu_logos) if selected == 2: leaderboard_menu(screen, menu_logos) if selected == 3: credits_menu(screen, menu_logos) if selected == 4: pygame.quit() quit() # Draw Background background_rect = background_image.get_rect() background_rect.left, background_rect.top = [0, 0] screen.fill([255, 255, 255]) screen.blit(background_image, background_rect) # Draw Logos menu_logos.draw(screen) # Main Menu UI title = text_format(TITLE_TEXT, MENU_FONT, 50, colors.white) if selected == 0: text_start = text_format(MENU_START, MENU_FONT, 25, colors.white) else: text_start = text_format(MENU_START, MENU_FONT, 25, colors.light_gray) if selected == 1: text_settings = text_format(MENU_SETTINGS, MENU_FONT, 25, colors.white) else: text_settings = text_format(MENU_SETTINGS, MENU_FONT, 25, colors.light_gray) if selected == 2: text_leaderboard = text_format(MENU_LEADERBOARD, MENU_FONT, 25, colors.white) else: text_leaderboard = text_format(MENU_LEADERBOARD, MENU_FONT, 25, colors.light_gray) if selected == 3: text_credits = text_format(MENU_CREDITS, MENU_FONT, 25, colors.white) else: text_credits = text_format(MENU_CREDITS, MENU_FONT, 25, colors.light_gray) if selected == 4: text_quit = text_format(MENU_QUIT, MENU_FONT, 25, colors.white) else: text_quit = text_format(MENU_QUIT, MENU_FONT, 25, colors.light_gray) text_option_description = text_format( menu_options_descriptions[selected], MENU_FONT, 16, colors.white) # Main Menu Text screen.blit(title, (150, 220)) screen.blit(menu_line, (150, 320)) screen.blit(text_start, (150, 340)) screen.blit(text_settings, (150, 370)) screen.blit(text_leaderboard, (150, 400)) screen.blit(text_credits, (150, 430)) screen.blit(text_quit, (150, 460)) screen.blit(menu_line, (150, 500)) screen.blit(text_option_description, (150, 520)) pygame.display.update() clock.tick(30)
def credits_menu(screen, menu_logos): in_credits_menu = True selected = 0 # Load background_image = load_image(background_file) menu_line = load_image(menu_line_file) while in_credits_menu: for event in pygame.event.get(): if event.type == pygame.QUIT or \ (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): return if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: if selected <= 0: selected = len(menu_options) - 1 else: selected -= 1 elif event.key == pygame.K_DOWN: if selected == len(menu_options) - 1: selected = 0 else: selected += 1 if event.key == pygame.K_RETURN: if selected == 0: go_to_web(CCC_URL) if selected == 1: go_to_web(CCC_FACEBOOK_URL) if selected == 2: return # Draw Background background_rect = background_image.get_rect() background_rect.left, background_rect.top = [0, 0] screen.fill([255, 255, 255]) screen.blit(background_image, background_rect) # Draw Logos menu_logos.draw(screen) title = text_format(TITLE_TEXT, MENU_FONT, 50, colors.white) screen.blit(title, (150, 220)) developed_by = text_format( "DEVELOPED BY FERRAN PONS (PROGRAMMING AND GRAPHICS)", MENU_FONT, 16, colors.white) screen.blit(developed_by, (150, 300)) screen.blit(menu_line, (150, 320)) if selected == 0: text_ccc_about = text_format(MENU_ABOUT_CCC, MENU_FONT, 25, colors.white) else: text_ccc_about = text_format(MENU_ABOUT_CCC, MENU_FONT, 25, colors.light_gray) if selected == 1: text_ccc_facebook = text_format(MENU_GO_TO_WEB, MENU_FONT, 25, colors.white) else: text_ccc_facebook = text_format(MENU_GO_TO_WEB, MENU_FONT, 25, colors.light_gray) if selected == 2: text_quit = text_format(MENU_RETURN, MENU_FONT, 25, colors.white) else: text_quit = text_format(MENU_RETURN, MENU_FONT, 25, colors.light_gray) text_option_description = text_format( menu_options_descriptions[selected], MENU_FONT, 16, colors.white) screen.blit(text_ccc_about, (150, 340)) screen.blit(text_ccc_facebook, (150, 370)) screen.blit(text_quit, (150, 460)) screen.blit(menu_line, (150, 500)) screen.blit(text_option_description, (150, 520)) music_title_text = text_format("MUSIC", MENU_FONT, 18, colors.white) screen.blit(music_title_text, (800, 300)) screw_wave = text_format("Screw Wave by Windom Earle", MENU_FONT, 16, colors.white) screen.blit(screw_wave, (800, 330)) screw_wave_license = \ text_format("licensed under a Attribution-NonCommercial-ShareAlike 3.0 International License.", MENU_FONT, 10, colors.white) screen.blit(screw_wave_license, (800, 350)) pygame.display.update() clock.tick(30)