def __init__(self, manager): super().__init__(manager) # PyDis logo self.image = ImageObject( self, (0, 0), Paths.splash / "pydis_logo.png", ) # Center the image image_width = self.image.surface.get_rect().width image_height = self.image.surface.get_rect().height center = ( (Window.width / 2) - (image_width / 2), (Window.height / 2) - (image_height / 2), ) # Move the logo to the right position, based on screen size. self.image.move_absolute(center) # What scene should be loaded after this finishes? self.next_scene = "jetbrains" # PyDis SFX self.sound = pygame.mixer.Sound(str(Paths.sfx / "pydis_desu.ogg")) self.sound.play()
def __init__(self, manager): super().__init__(manager) self.max_bombs = 8 self.game_over_screen = None self.accuracy = None self.timer = None self.speed_multiplier = 3 self.explosions: List[Explosion] = [] self.texts: List[TextShootObject] = [] self.new_missile_timer = 200 self.new_jet_timer = random.randint(450, 1200) self.start_ticks = pygame.time.get_ticks() self.game_running = True self.sent_scores = False self.lock = None self.wpm = None self.letters_typed = 0 self.letters_missed = 0 self.pyjet = None self.restart_game_text = TextObject( self, (0, 0), "Play again", font_path=Paths.fonts / "ObelixPro-cyr.ttf", font_size=60 ) self.high_scores_text = TextObject( self, (0, 0), "High scores", font_path=Paths.fonts / "ObelixPro-cyr.ttf", font_size=60 ) self.restart_game_text.move_absolute(( (Window.width / 2) - (self.restart_game_text.size[0] / 2), 450 )) self.high_scores_text.move_absolute(( (Window.width / 2) - (self.high_scores_text.size[0] / 2), 550 )) self.wpm_text = None self.accuracy_text = None # Background image background_path = Paths.levels / random.choice(["level_bg.png", "level_bg_2.png"]) self.background = ImageObject( self, (0, 0), background_path, ) # SFX self.gunshot = pygame.mixer.Sound(str(Paths.sfx / "gunshot.ogg")) self.gunshot.set_volume(0.4) self.wrong = pygame.mixer.Sound(str(Paths.sfx / "wrong_letter.ogg")) self.you_lose_sfx = pygame.mixer.Sound(str(Paths.sfx / "you_lose.ogg")) self.you_win_sfx = pygame.mixer.Sound(str(Paths.sfx / "you_win.ogg")) # Some random NPCs number_of_npcs = 7 npc_slots = [ (123, 550), (211, 550), (284, 550), (450, 550), (570, 550), (800, 550), (990, 550), ] random.shuffle(npc_slots) self.npcs = [] for _ in range(number_of_npcs): self.npcs.append( NPC(self, npc_slots.pop(-1)) ) # Enemies self.flutterdude = Flutterdude( self, (0, 75), 1.5 ) # Play some music self.manager.play_music("pskov_loop.ogg", loop=True)
def _build_game_over_screen(self): """ Builds a screen that can be displayed when the game is over, showing WINNER or YOU LOSE graphics, score, a retry button and playing sfx. """ # Calculate WPM total_letters = self.letters_typed + self.letters_missed self.wpm = int((total_letters / 5) / self.timer.minutes_passed) self.wpm_text = TextObject( self, (1045, 15), f"WPM: {self.wpm}", font_path=Paths.fonts / "ObelixPro-cyr.ttf", font_size=35 ) # Calculate accuracy total_letters = self.letters_typed + self.letters_missed if total_letters: self.accuracy = int( 100 - ((self.letters_missed / total_letters) * 100) ) else: self.accuracy = 0 self.accuracy_text = TextObject( self, (938, 70), f"Accuracy: {self.accuracy}%", font_path=Paths.fonts / "ObelixPro-cyr.ttf", font_size=35 ) # Display the right images and play SFX if not self.npcs: self.game_over_screen = ImageObject( self, (0, 0), Paths.ui / "you_lose.png" ) move_height = 220 self.you_lose_sfx.play() else: self.game_over_screen = ImageObject( self, (0, 0), Paths.ui / "winner.png" ) move_height = 100 self.you_win_sfx.play() image_width = self.game_over_screen.size[0] center_x = (Window.width / 2) - (image_width / 2) self.game_over_screen.move_absolute((center_x, move_height)) # Play game over music self.manager.play_music("code_jam_full.ogg")
def __init__(self, manager): super().__init__(manager) # Main game logo self.logo = ImageObject( self, (0, 0), Paths.ui / "logo.png", ) # Move the logo to the right position, based on screen size. image_width = self.logo.size[0] logo_location = ( (Window.width / 2) - (image_width / 2), 40, ) self.logo.move_absolute(logo_location) # How to play self.how_to_play_open = False self.how_to_play = ImageObject(self, (0, 0), Paths.ui / "how_to_play.png") self.close_how_to_play = ImageObject(self, (1060, 300), Paths.ui / "close_window.png") # Background image self.background = ImageObject( self, (0, 0), Paths.ui / "background.png", ) # Floaty dudes self.flutterdude = FloatingObject( self, (980, 260), Paths.enemies / "flutterdude.png", float_range=(260, 280), float_speed=4, ) self.brainmon = FloatingObject( self, (900, 400), Paths.enemies / "brainmon_firing.png", float_range=(390, 400), float_speed=3, ) # Text init self.start_game_text = TextObject( self, (90, 400), "Start game", font_path=Paths.fonts / "NANDA.TTF", font_size=60, ) self.how_to_play_text = TextObject( self, (90, 480), "How to play", font_path=Paths.fonts / "NANDA.TTF", font_size=60, ) self.high_scores_text = TextObject( self, (90, 560), "High scores", font_path=Paths.fonts / "NANDA.TTF", font_size=60, ) self.quit_text = TextObject( self, (90, 640), "Quit game", font_path=Paths.fonts / "NANDA.TTF", font_size=60, ) self.menu_items = { "start": self.start_game_text, "how_to_play": self.how_to_play_text, "high_scores": self.high_scores_text, "quit": self.quit_text, "close": self.close_how_to_play, } # SFX if self.manager.previous_scene.name == "jetbrains": self.sound = pygame.mixer.Sound(str(Paths.sfx / "megalomaniac.ogg")) self.sound.play() # Music self.manager.play_music("code_jam_loop.ogg", loop=True)
def __init__(self, manager): super().__init__(manager) # Background image self.background = ImageObject( self, (0, 0), Paths.ui / "background.png", ) # High score overlay self.high_scores = ImageObject(self, (0, 0), Paths.ui / "high_scores.png") # High scores headline self.headline_text = TextObject(self, (0, 0), "High scores", font_path=Paths.fonts / "ObelixPro-cyr.ttf", font_size=50) self.headline_text.move_absolute( ((Window.width / 2) - (self.headline_text.size[0] / 2), 75)) # The icons that explain what each row is for self.score_headline = TextObject(self, (600, 200), "Score") self.wpm_headline = TextObject(self, (850, 200), "WPM") self.accuracy_headline = TextObject(self, (1000, 200), "Accuracy") # Add the close button self.close_button = ImageObject(self, (1120, 90), Paths.ui / "close_window.png") # Score attributes self.high_score_y = 270 self.high_score_number = 1 self.high_score_texts = [] # Get the scores r = requests.get(URLs.scores_api) high_scorers = r.json() # Sort by score and limit to 5 high_scorers = [{ "username": name, "wpm": data['wpm'], "accuracy": data['accuracy'], "score": data['score'] } for name, data in high_scorers.items()] high_scorers = sorted(high_scorers, key=itemgetter('score'), reverse=True)[:5] # Build the score text objects for score in high_scorers: points = score['score'] name = score['username'] accuracy = score['accuracy'] wpm = score['wpm'] self.high_score_texts.append(( TextObject(self, (180, self.high_score_y), f"{self.high_score_number}.", font_path=Paths.fonts / "NANDA.TTF", font_size=60), TextObject(self, (230, self.high_score_y), name, font_path=Paths.fonts / "NANDA.TTF", font_size=60), TextObject(self, (600, self.high_score_y), str(points), font_path=Paths.fonts / "NANDA.TTF", font_size=60), TextObject(self, (850, self.high_score_y), str(wpm), font_path=Paths.fonts / "NANDA.TTF", font_size=60), TextObject(self, (1000, self.high_score_y), f"{accuracy}%", font_path=Paths.fonts / "NANDA.TTF", font_size=60), )) self.high_score_y += 80 self.high_score_number += 1 self.start_game_text = TextObject( self, (90, 400), "Start game", font_path=Paths.fonts / "NANDA.TTF", font_size=60, ) # Music if self.manager.previous_scene and not self.manager.previous_scene.name == "main_menu": self.manager.play_music("code_jam_full.ogg")
def __init__(self, manager): super().__init__(manager) # Background image self.background = ImageObject( self, (0, 0), Paths.ui / "background.png", ) # Box overlay self.enter_name_box = ImageObject(self, (0, 0), Paths.ui / "enter_name_box.png") self.enter_name_box.move_absolute( ((Window.width / 2) - (self.enter_name_box.size[0] / 2), (Window.height / 2) - (self.enter_name_box.size[1] / 2))) # Instructions self.please_enter_name = TextObject(self, (0, 0), "Who are you?", font_path=Paths.fonts / "ObelixPro-cyr.ttf", font_size=50) self.please_enter_name.move_absolute( ((Window.width / 2) - (self.please_enter_name.size[0] / 2), 200)) # InputBox self.input_field = TextInputObject( self, (450, 315), font_path=Paths.fonts / "FiraMono-Regular.ttf", font_size=40, max_length=15, text_color=Colors.white, cursor_color=Colors.white, ) # Explanation text below input self.explanation_line_1 = TextObject( self, (0, 0), "We need this information for high scores.", font_path=Paths.fonts / "FiraMono-Regular.ttf", font_size=20) self.explanation_line_1.move_absolute( ((Window.width / 2) - (self.explanation_line_1.size[0] / 2), 400)) self.explanation_line_2 = TextObject( self, (0, 0), "Feel free to input a nickname, or a made-up name.", font_path=Paths.fonts / "FiraMono-Regular.ttf", font_size=20) self.explanation_line_2.move_absolute( ((Window.width / 2) - (self.explanation_line_2.size[0] / 2), 440)) # OK Button self.ok_button = TextObject(self, (880, 530), "OK", font_path=Paths.fonts / "ObelixPro-cyr.ttf", font_size=50, disabled=True) # Music self.manager.play_music("code_jam_loop.ogg", loop=True)