class SplashScreen(GameState): def __init__(self): super(SplashScreen, self).__init__() self.font = pygame.font.Font(MAIN_TITLE_FONT[0], 54) self.title = self.font.render(GAME_TITLE, True, (229, 22, 22)) self.title_rect = self.title.get_rect(x=(SCREEN_SIZE[0] / 2) - 220, y=80) self.persist["screen_color"] = "black" self.next_state = "GAMEPLAY" self.menu = Menu([ Button("Start", ((SCREEN_SIZE[0] / 2) - 125, 300, 250, 40)), Button("Credits", ((SCREEN_SIZE[0] / 2) - 125, 350, 250, 40)) ]) self.sound = Sound("assets/sound/MainTheme.wav") self.sound.play() def startup(self, persistent): self.sound.play() self.menu.select_option(0) def get_event(self, event): if event.type == pygame.QUIT: self.quit = True elif event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: self.menu.select_option(-1) elif event.key == pygame.K_DOWN: self.menu.select_option(1) elif event.key == pygame.K_RETURN: self.next_state = "GAMEPLAY" if self.menu.selected_option == 0 else "CREDITS" self.persist["selected_option"] = self.menu.selected_option self.done = True self.sound.stop() def draw(self, surface): surface.fill(Color("black")) background = pygame.image.load("assets/images/nave.png").convert() background.set_colorkey((255, 255, 255)) surface.blit(background, [(SCREEN_SIZE[0] / 2) - 250, (SCREEN_SIZE[1] / 2) - 140]) surface.blit(self.title, self.title_rect) self.menu.draw(surface) def update(self, surface): self.menu.update()
# Update tab if inventory is open if show_inv: tab.update(font) display.blit(tab, (0, height // 2 - (attributes.height // 2))) # Update XP bar if inventory is open if show_inv: xp_bar.update(font) display.blit(xp_bar, (width // 2 - (inv.width // 2), height // 2 - (inv.height // 2) - xp_bar.height)) # Update skill tree surface if show_st: st.update(font, data) display.blit(st, (0, height // 2 - (st.height // 2))) # Pause menu if show_menu: menu.update(font, *pygame.mouse.get_pos()) display.blit(menu, (menu.x, menu.y)) # Draw fps counter fps_txt = font.render(str(round(clock.get_fps(), 0)), True, (0, 255, 0)) display.blit(fps_txt, (0, 0)) # Update whole screen pygame.display.update() pygame.quit()