def __init__(self): super(WinningScreen, self).__init__() reset_lists() # Reset player player.reset() # Make sure the background image is the good one window.modify_background_image("pictures/sky_1024x768.jpg") # Mouse invisible pygame.mouse.set_visible(True) # Create the buttons self.exit_button = Button(window.screen, SCREEN_WIDTH / 4 + -50, 400, 100, 30, (WHITE, LIGHT_GREY), "Exit", action=self.change_scene_exit) self.next_level = Button(window.screen, SCREEN_WIDTH / 4 * 3 + -50, 400, 100, 30, (WHITE, LIGHT_GREY), "Next level", action=self.change_scene_next_level)
class WinningScreenFinal(object): """ Scene: The screen displayed when player win. """ def __init__(self): super(WinningScreenFinal, self).__init__() reset_lists() # Reset player player.reset() # Make sure the background image is the good one window.modify_background_image("pictures/sky_1024x768.jpg") # Mouse invisible pygame.mouse.set_visible(True) # Create the buttons self.exit_button = Button(window.screen, SCREEN_WIDTH / 2 + -50, 400, 100, 30, (WHITE, LIGHT_GREY), "Exit", action=self.change_scene_exit) def render(self, the_window): the_window.prepare_draw() # Draw button self.exit_button.draw() # Display score font = pygame.font.SysFont('Agency FB', 100, True, False) loose_text = font.render("Congratulations", True, WHITE) the_window.screen.blit(loose_text, [(SCREEN_WIDTH / 2) - (loose_text.get_width() / 2), 50]) def update(self): pass def handle_events(self, events): pass @staticmethod def change_scene_exit(): # Reset score before exiting score.score = "0" score.lives = str(PLAYER_STARTING_LIVES) # Go back to startup screen manager.go_to(StartupScreen())
def __init__(self): """ init pygame screen, maze object for gameplay and all preset button and message to be display on screen""" # Initialize Pygame basics pygame.init() self.width = (constant.MAZE_SIZE + constant.OPTIONAL_W) * constant.SPRITE_W self.height = (constant.MAZE_SIZE + constant.OPTIONAL_H) * constant.SPRITE_H self.screen = pygame.display.set_mode((self.width, self.height)) pygame.display.set_caption("Mac Gyver Escape") self.clock = pygame.time.Clock() # Initialize Button and Message self.start_button = Button( (constant.MAZE_SIZE // 5, constant.MAZE_SIZE * 2 // 3), constant.GREEN, constant.BRIGHT_GREEN, "Start", ) self.quit_button = Button( (constant.MAZE_SIZE * 3 // 5, constant.MAZE_SIZE * 2 // 3), constant.RED, constant.BRIGHT_RED, "Quit", ) self.menu_message = Message( (self.width // 2, self.height // 4), "Mac Gyver Escape", constant.BIG_SIZE, constant.BIG_FONT, constant.BLACK, ) self.status = constant.MENU # If Maze object instance goes bad # it is impossible to play the game # so Exit with error message try: self.maze = Maze() except RuntimeError: print("Error during initialization of Game") self.status = constant.EXIT return
def __init__(self): super(LoosingScreen, self).__init__() self.max_score = None reset_lists() # Make sure the background image is the good one window.modify_background_image("pictures/sky_1024x768.jpg") # Mouse invisible pygame.mouse.set_visible(True) # Create the button to go back to startup screen self.go_back_button = Button(window.screen, SCREEN_WIDTH / 2 + -50, 400, 100, 30, (WHITE, LIGHT_GREY), "Continue", action=self.change_scene)
def __init__(self): super(StartupScreen, self).__init__() # Create buttons for start screen self.buttons_list = [ Button(window.screen, 100, 600, 100, 30, (WHITE, LIGHT_GREY), "Start", action=self.change_scene), Button(window.screen, 100, 640, 100, 30, (WHITE, LIGHT_GREY), "Exit", action=quit_game) ] # Be sure the background image is the good one window.modify_background_image("pictures/interface_bg_v1_800x800.png")
class WinningScreen(object): """ Scene: The screen displayed when player win. """ def __init__(self): super(WinningScreen, self).__init__() reset_lists() # Reset player player.reset() # Make sure the background image is the good one window.modify_background_image("pictures/sky_1024x768.jpg") # Mouse invisible pygame.mouse.set_visible(True) # Create the buttons self.exit_button = Button(window.screen, SCREEN_WIDTH / 4 + -50, 400, 100, 30, (WHITE, LIGHT_GREY), "Exit", action=self.change_scene_exit) self.next_level = Button(window.screen, SCREEN_WIDTH / 4 * 3 + -50, 400, 100, 30, (WHITE, LIGHT_GREY), "Next level", action=self.change_scene_next_level) def render(self, the_window): the_window.prepare_draw() # Draw button self.exit_button.draw() self.next_level.draw() # Display score font = pygame.font.SysFont('Agency FB', 100, True, False) loose_text = font.render("YOU WIN", True, WHITE) font = pygame.font.SysFont('Agency FB', 50, True, False) if int(score.score) < 0: # Score can't be negative score.score = "0" loose_text_score = font.render("Score :%s pts." % score.score, True, WHITE) the_window.screen.blit(loose_text, [(SCREEN_WIDTH / 2) - (loose_text.get_width() / 2), 50]) the_window.screen.blit(loose_text_score, [(SCREEN_WIDTH / 2) - (loose_text_score.get_width() / 2), 180]) def update(self): pass def handle_events(self, events): pass @staticmethod def change_scene_exit(): # Reset score before exiting score.score = "0" score.lives = str(PLAYER_STARTING_LIVES) # Go back to startup screen manager.go_to(StartupScreen()) @staticmethod def change_scene_next_level(): global LEVEL LEVEL = LEVEL # Reset score before exiting # FIXME: Must have function to reset score. score.score = "0" # Find next level if LEVEL == 1: manager.go_to(Level2()) elif LEVEL == 2: manager.go_to(Level3()) elif LEVEL == 3: manager.go_to(Level4())
class LoosingScreen(object): """ Scene: The screen displayed when player loose. """ def __init__(self): super(LoosingScreen, self).__init__() self.max_score = None reset_lists() # Make sure the background image is the good one window.modify_background_image("pictures/sky_1024x768.jpg") # Mouse invisible pygame.mouse.set_visible(True) # Create the button to go back to startup screen self.go_back_button = Button(window.screen, SCREEN_WIDTH / 2 + -50, 400, 100, 30, (WHITE, LIGHT_GREY), "Continue", action=self.change_scene) def render(self, the_window): the_window.prepare_draw() # Draw button self.go_back_button.draw() # Display score font = pygame.font.SysFont('Agency FB', 100, True, False) loose_text = font.render("YOU LOOSE", True, WHITE) font = pygame.font.SysFont('Agency FB', 50, True, False) if int(score.score) < 0: # Score can't be negative score.score = "0" loose_text_score = font.render("Your score is %s pts." % score.score, True, WHITE) the_window.screen.blit(loose_text, [(SCREEN_WIDTH / 2) - (loose_text.get_width() / 2), 50]) the_window.screen.blit(loose_text_score, [(SCREEN_WIDTH / 2) - (loose_text_score.get_width() / 2), 180]) def update(self): pass def handle_events(self, events): pass @staticmethod def change_scene(): global LOOSE # Reset player player.reset() # Reset score before exiting score.score = "0" score.lives = str(PLAYER_STARTING_LIVES) LOOSE = False # Go back to startup screen manager.go_to(StartupScreen())
class Game: """ Class managing the state machine and general information of the Game""" def __init__(self): """ init pygame screen, maze object for gameplay and all preset button and message to be display on screen""" # Initialize Pygame basics pygame.init() self.width = (constant.MAZE_SIZE + constant.OPTIONAL_W) * constant.SPRITE_W self.height = (constant.MAZE_SIZE + constant.OPTIONAL_H) * constant.SPRITE_H self.screen = pygame.display.set_mode((self.width, self.height)) pygame.display.set_caption("Mac Gyver Escape") self.clock = pygame.time.Clock() # Initialize Button and Message self.start_button = Button( (constant.MAZE_SIZE // 5, constant.MAZE_SIZE * 2 // 3), constant.GREEN, constant.BRIGHT_GREEN, "Start", ) self.quit_button = Button( (constant.MAZE_SIZE * 3 // 5, constant.MAZE_SIZE * 2 // 3), constant.RED, constant.BRIGHT_RED, "Quit", ) self.menu_message = Message( (self.width // 2, self.height // 4), "Mac Gyver Escape", constant.BIG_SIZE, constant.BIG_FONT, constant.BLACK, ) self.status = constant.MENU # If Maze object instance goes bad # it is impossible to play the game # so Exit with error message try: self.maze = Maze() except RuntimeError: print("Error during initialization of Game") self.status = constant.EXIT return def run(self): """function used to mange the game display and behavior""" while self.status: # Keep loop running at the right speed self.clock.tick(constant.FPS) # Process input (events) for event in pygame.event.get(): # check exit condition if event.type == pygame.QUIT: self.status = constant.EXIT if self.status == constant.MENU: self._menu() elif self.status == constant.PLAY: self._play() elif self.status == constant.FINISH: self._finish() elif self.status == constant.RESTART: self.maze.restart() self.status = constant.MENU pygame.quit() def _menu(self): """ Display for Menu status of game """ self.screen.fill(constant.WHITE) if self.start_button.display(self.screen): self.status = constant.PLAY if self.quit_button.display(self.screen): self.status = constant.EXIT self.menu_message.display(self.screen) # Apply changes pygame.display.flip() def _play(self): """ Display during Play status of game """ # status keep play until maze.update # return constant.FINISH state self.status = self.maze.update() self.screen.fill(constant.BLACK) # Display maze and component on screen self.maze.display(self.screen) # Apply changes pygame.display.flip() def _finish(self): """ Display during Finish status of game """ self.screen.fill(constant.WHITE) # Create a message depending of result of game result = self.maze.final_result() end_message = Message( (self.width // 2, self.height // 2), result, constant.BIG_SIZE, constant.BIG_FONT, constant.BLACK, ) end_message.display(self.screen) # Apply changes pygame.display.flip() # Wait some time to display message then restart to menu time.sleep(1) self.status = constant.RESTART