def main_frame(self): done = False options = [Option(self.screen, "Play", (155, 300), self.color_manager), Option(self.screen, "Settings", (123, 340), self.color_manager), Option(self.screen, "Mute", (145, 380), self.color_manager), Option(self.screen, "Exit", (159, 420), self.color_manager)] while not done: self.screen.fill(color=self.color_manager.MENU_COLOR) logo = pygame.image.load("pictures/logo.png") self.screen.blit(logo, (50, 50)) background_logo = pygame.image.load("pictures/menu_background.png") self.screen.blit(background_logo, (0, 0)) for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): option.hovered = True else: option.hovered = False option.draw() for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): if option.text == "Play": self.effect_music.play("music/button_click.mp3") game(self.screen, self.color_manager, self.config_data, self) elif option.text == "Settings": self.effect_music.play("music/button_click.mp3") settings = Settings(self.screen, None, self, self.config_data, self.background_musik, self.effect_music, self.color_manager, "menu", 100, self.screen) th = Thread(target=settings.main) th.start() return elif option.text == "Mute": self.effect_music.play("music/button_click.mp3") self.background_musik.set_volume(0) self.effect_music.set_volume(0) self.config_data["Audio_Settings"]["muted"] = True option.text = "Unmute" option.pos = (122, 380) option.set_rect() elif option.text == "Unmute": self.effect_music.play("music/button_click.mp3") self.background_musik.set_volume(self.audio_settings["menu_background"]) self.effect_music.set_volume(self.audio_settings["effects"]) self.config_data["Audio_Settings"]["muted"] = False option.text = "Mute" option.pos = (145, 380) option.set_rect() elif option.text == "Exit": self.effect_music.play("music/button_click.mp3") done = True Close_Game(self.config_data) if event.type == pygame.QUIT: Close_Game(self.config_data) pygame.display.flip() self.clock.tick(self.fps)
def pause_menu(self): old_game = self.game old_fps = self.fps screen = self.screen self.fps = 0 self.color_manager.pale_frame(self.zoom, old_game, 7) done = False options = [Option(self.screen, "Resume", (123, 260), self.color_manager), Option(self.screen, "Retry", (145, 300), self.color_manager), Option(self.screen, "Settings", (123, 340), self.color_manager), Option(self.screen, "Menu", (145, 380), self.color_manager), Option(self.screen, "Exit", (159, 420), self.color_manager)] if self.config_data["Color_Mode"] == "NORMAL_MODE": background_image = pygame.image.load("pictures/normal_pause.png") else: background_image = pygame.image.load("pictures/dark_pause.png") while not done: screen.blit(background_image, ((380-background_image.get_width())/2, 125)) for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event == pygame.K_ESCAPE: done = True self.end_pause_menu(old_game, old_fps) if event.type == pygame.QUIT: Close_Game(self.config_data) if event.type == pygame.MOUSEBUTTONDOWN: for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): if option.text == "Resume": self.effect_music.play("music/button_click.mp3") done = True self.end_pause_menu(old_game, old_fps) elif option.text == "Retry": self.effect_music.play("music/button_click.mp3") game(self.screen, self.color_manager, self.config_data, self.menu) elif option.text == "Settings": Settings(self.screen, self.game, self.menu, self.config_data, self.background_musik, self.effect_music, self.color_manager, "game", -50, screen) elif option.text == "Menu": self.effect_music.play("music/button_click.mp3") done = True self.menu(screen) elif option.text == "Exit": self.effect_music.play("music/button_click.mp3") Close_Game(self.config_data) for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): option.hovered = True else: option.hovered = False option.draw() text_font = pygame.font.SysFont("Calibri", 40, True, False) text = text_font.render("PAUSE", True, self.color_manager.HEADLINE) screen.blit(text, [135, 160]) pygame.display.flip() break
def main(self): done = False self.screen.fill(color=self.color_manager.MENU_COLOR) options = [ Option(self.screen, "Audio", (141, 220 + self.displacement), self.color_manager), Option(self.screen, "Colors", (137, 260 + self.displacement), self.color_manager), Option(self.screen, "Back", (151, 300 + self.displacement), self.color_manager) ] self.screen.blit() while not done: """ if self.config_data["Color_Mode"] == "NORMAL_MODE": background_image = pygame.image.load("pictures/normal_pause.png") else: background_image = pygame.image.load("pictures/dark_pause.png") self.screen.blit(background_image, ((380 - background_image.get_width()) / 2, 175)) """ for event in pygame.event.get(): if event.type == pygame.QUIT: Close_Game(self.config_data) if event.type == pygame.MOUSEBUTTONDOWN: for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): if option.text == "Audio": self.effect_music.play( "music/button_click.mp3") self.audio() elif option.text == "Colors": self.effect_music.play( "music/button_click.mp3") done = True self.color_settings() elif option.text == "Back": self.effect_music.play( "music/button_click.mp3") done = True if type == "menu": self.menu(self.screen) elif type == "game": self.game(self.color_manager, self.config_data) for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): option.hovered = True else: option.hovered = False option.draw() text_font = pygame.font.SysFont('Calibri', 40, True, False) text = text_font.render("Settings", True, self.color_manager.HEADLINE) self.screen.blit(text, [123, 160 + self.displacement]) pygame.display.flip()
def color_settings(self): heading_font = pygame.font.SysFont('Calibri', 40, True, False) heading_text = heading_font.render("Color Settings", True, self.color_manager.HEADLINE) options = [ Option(self.screen, "Normal-Mode", (72, 200 + self.displacement), self.color_manager), Option(self.screen, "Dark-Mode", (96, 250 + self.displacement), self.color_manager), Option(self.screen, "BACK", (145, 290 + self.displacement), self.color_manager) ] if self.config_data["Color_Mode"] == "NORMAL_MODE": background_image = pygame.image.load("pictures/normal_pause.png") else: background_image = pygame.image.load("pictures/dark_pause.png") done = False while not done: self.screen.blit(background_image, ((380 - background_image.get_width()) / 2, 75 + self.displacement)) self.screen.blit(heading_text, (80, 110 + self.displacement)) for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): option.hovered = True else: option.hovered = False option.draw() for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): if option.text == "Normal-Mode": self.effect_music.play( "music/button_click.mp3") self.color_manager.set_normalmode() self.config_data['Color_Mode'] = "NORMAL_MODE" self.color_settings() elif option.text == "Dark-Mode": self.effect_music.play( "music/button_click.mp3") self.color_manager.set_darkmode() self.config_data['Color_Mode'] = "DARK_MODE" self.color_settings() elif option.text == "BACK": self.effect_music.play( "music/button_click.mp3") done = True if event.type == pygame.QUIT: Close_Game(self.config_data) pygame.display.flip() self.clock.tick(30)
def loop(self): ticks = 0 while not self.done: ticks += 1 if ticks * self.fps >= 60: ticks = 0 if self.game.state == "start": self.game.go_down(self.effect_music) for event in pygame.event.get(): if event.type == pygame.QUIT: Close_Game(self.config_data) if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP or event.key == pygame.K_w: self.game.rotate(self.effect_music) if event.key == pygame.K_DOWN or event.key == pygame.K_s: self.pressing_down = True self.fps += 14 if event.key == pygame.K_LEFT or event.key == pygame.K_a: self.pressing_left = True if event.key == pygame.K_RIGHT or event.key == pygame.K_d: self.pressing_right = True if event.key == pygame.K_ESCAPE: self.pause_menu() if event.type == pygame.KEYUP: if event.key == pygame.K_DOWN or event.key == pygame.K_s: self.pressing_down = False self.fps -= 14 if event.key == pygame.K_LEFT or event.key == pygame.K_a: self.pressing_left = False if event.key == pygame.K_RIGHT or event.key == pygame.K_d: self.pressing_right = False if self.pressing_down: self.game.go_down(self.effect_music) if self.pressing_left: self.game.left() if self.pressing_right: self.game.right() self.screen.fill(color=self.color_manager.MENU_COLOR) for i in range(self.game.height): for j in range(self.game.width): if self.game.field[i][j] == 0: color = self.color_manager.LINE_COLOR just_border = 1 else: color = colors[self.game.field[i][j]] just_border = 0 pygame.draw.rect(self.screen, color, [40 + j * self.zoom, 30 + i * self.zoom, self.zoom, self.zoom], just_border) # update the figures if self.game.Figure is not None: for i in range(4): for j in range(4): p = i * 4 + j if p in self.game.Figure.image(): pygame.draw.rect(self.screen, self.game.Figure.color, [40 + (j + self.game.Figure.x) * self.zoom, 30 + (i + self.game.Figure.y) * self.zoom, self.zoom, self.zoom]) if ((self.game.score / 50) / self.game.level) > 1: self.effect_music.play("music/level_up.mp3") self.fps += 1 self.game.level += 1 if self.game.state == "gameover": Loose_menu(self.screen, self.game, self.color_manager, self.config_data) self.done = True # update the score and the level level_font = pygame.font.SysFont('Calibri', 25, True, False) text_level = level_font.render("Level " + str(self.game.level), True, self.color_manager.SCORE) self.screen.blit(text_level, [0, 0]) score_font = pygame.font.SysFont('Calibri', 25, True, False) text_score = score_font.render("Score " + str(self.game.score), True, self.color_manager.SCORE) self.screen.blit(text_score, [text_score.get_width(), 0]) pygame.display.flip() self.clock.tick(60) # call the Loose_menu Loose_menu(self.screen, self.game, self.color_manager, self.config_data)
def loop(self): done = False clock = pygame.time.Clock() score_font = pygame.font.SysFont('Calibri', 1 * self.zoom, True, False) if self.game.score > self.config_data['Highscore']: self.config_data['Highscore'] = self.game.score highscore_font = pygame.font.SysFont('Calibri', 1 * self.zoom, True, False) text_congratulation = highscore_font.render( "!!!NEW HIGHSCORE!!!: ", True, self.color_manager.HIGHSCORE) self.screen.blit( text_congratulation, [self.get_width(text_congratulation), int(8.25 * self.zoom)]) text_score = score_font.render("Score: " + str(self.game.score), True, self.color_manager.HIGHSCORE) self.screen.blit(text_score, [self.get_width(text_score), int(12 * self.zoom)]) else: text_score = score_font.render("Level " + str(self.game.level), True, self.color_manager.HIGHSCORE) self.screen.blit( text_score, [self.get_width(text_score), int(10.2 * self.zoom)]) text_score = score_font.render("Score " + str(self.game.score), True, self.color_manager.HIGHSCORE) self.screen.blit( text_score, [self.get_width(text_score), int(11.4 * self.zoom)]) text_highscore = score_font.render( "Highscore: " + str(self.config_data["Highscore"]), True, self.color_manager.SCORE) self.screen.blit( text_highscore, [self.get_width(text_highscore), int(7.8 * self.zoom)]) gameover_font = pygame.font.SysFont('Calibri', 2 * self.zoom, True, False) text_gameover = gameover_font.render("Game Over!", True, self.color_manager.GAME_OVER) self.screen.blit(text_gameover, [self.get_width(text_gameover), int(6 * self.zoom)]) menu_font = pygame.font.SysFont('Calibri', 1 * self.zoom, True, False) menu_text = menu_font.render("Retry", True, self.color_manager.HIGHSCORE) option = Option(self.screen, "Retry", (self.get_width(menu_text), int(13.2 * self.zoom)), self.color_manager) pygame.display.flip() pygame.mixer.music.load('music/failure.mp3') pygame.mixer.music.play(False, 0.5) while not done: pygame.display.flip() clock.tick(2) for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.game(self.color_manager, self.config_data) done = True if option.rect.collidepoint(pygame.mouse.get_pos()): self.effect_music.play("music/button_click.mp3") self.game.start_new_game() if event.type == pygame.QUIT: Close_Game(self.config_data) if option.rect.collidepoint(pygame.mouse.get_pos()): option.hovered = True else: option.hovered = False option.draw()
def audio(self): if self.config_data["Color_Mode"] == "NORMAL_MODE": background_image = pygame.image.load("pictures/normal_pause.png") else: background_image = pygame.image.load("pictures/dark_pause.png") done = False manager = pygame_gui.UIManager((380, 650)) heading_font = pygame.font.SysFont("Calibri", 40, True, False) heading_text = heading_font.render("Audio", True, self.color_manager.HEADLINE) menu_background_audio_value = Slider( self.screen, "Menu-Music: ", 80, 150 + self.displacement, Color_Manager.DARKEST_GRAY, manager, self.config_data["Audio_Settings"]["menu_background"], (1, 100)) game_backgorund_audio_value = Slider( self.screen, "Background-Music: ", 80, 210 + self.displacement, Color_Manager.DARKEST_GRAY, manager, self.config_data["Audio_Settings"]["game_background"], (1, 100)) effects_audio_value = Slider( self.screen, "Game-Effects: ", 80, 270 + self.displacement, Color_Manager.DARKEST_GRAY, manager, self.config_data["Audio_Settings"]["effects"], (1, 100)) if self.type == "menu": main_ref = menu_background_audio_value elif self.type == "game": main_ref = game_backgorund_audio_value else: main_ref = menu_background_audio_value if self.config_data["Audio_Settings"]["muted"]: text = "Unmute" position = (122, 330 + self.displacement) else: text = "Mute" position = (145, 330 + self.displacement) options = [ Option(self.screen, text, position, self.color_manager), Option(self.screen, "Back", (145, 370 + self.displacement), self.color_manager) ] while not done: self.screen.blit(background_image, ((380 - background_image.get_width()) / 2, 75 + self.displacement)) self.screen.blit(heading_text, (141, 110 + self.displacement)) time_delta = self.clock.tick(30) menu_background_audio_value.draw() game_backgorund_audio_value.draw() effects_audio_value.draw() if not self.config_data["Audio_Settings"]["muted"]: self.background_music.set_volume(main_ref.get_current_value()) self.effect_music.set_volume( effects_audio_value.get_current_value()) self.config_data["Audio_Settings"][ "menu_background"] = menu_background_audio_value.get_current_value( ) self.config_data["Audio_Settings"][ "game_background"] = game_backgorund_audio_value.get_current_value( ) self.config_data["Audio_Settings"][ "effects"] = effects_audio_value.get_current_value() for event in pygame.event.get(): if event.type == pygame.QUIT: Close_Game(self.config_data) if event.type == pygame.MOUSEBUTTONDOWN: for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): if option.text == "Mute": self.effect_music.play( "music/button_click.mp3") self.background_music.set_volume(0) self.effect_music.set_volume(0) self.config_data["Audio_Settings"][ "muted"] = True option.text = "Unmute" option.pos = (122, 330 + self.displacement) option.set_rect() elif option.text == "Unmute": self.effect_music.play( "music/button_click.mp3") self.background_music.set_volume( self.config_data["Audio_Settings"] ["menu_background"]) self.effect_music.set_volume( self.config_data["Audio_Settings"] ["effects"]) self.config_data["Audio_Settings"][ "muted"] = False option.text = "Mute" option.pos = (145, 330 + self.displacement) option.set_rect() elif option.text == "Back": done = True self.main() manager.process_events(event) for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): option.hovered = True else: option.hovered = False option.draw() if menu_background_audio_value.is_pressed(): self.effect_music.play("music/button_click_down.mp3") if menu_background_audio_value.is_released(): self.effect_music.play("music/button_click_up.mp3") if game_backgorund_audio_value.is_pressed(): self.effect_music.play("music/button_click_down.mp3") if game_backgorund_audio_value.is_released(): self.effect_music.play("music/button_click_up.mp3") if effects_audio_value.is_pressed(): self.effect_music.play("music/button_click_down.mp3") if effects_audio_value.is_released(): self.effect_music.play("music/button_click_up.mp3") manager.draw_ui(self.screen) manager.update(time_delta=time_delta) pygame.display.flip() self.clock.tick(30)