def winFunction(): DISPLAYSURF.fill(BLACK) helper.outputText('YOU WIN!!',WIN_WIDTH//2, WIN_HEIGHT//2, WHITE, size = 64, centered=True) pygame.display.update() pygame.time.wait(1500) WORLD.pop()
def pause(self): # Huge hack done here to render the screen and then copy it. # This allows us to have a 'screenshoot' of the actual game state for # displaying the pause creen on top of that. render_system = RenderSystem() render_system.bindToEntityManager(self.entity_manager) render_system.bindToGroupManager(self.group_manager) render_system.update() render_system = None freezed_surface = DISPLAYSURF.copy() # Load images dark_img = pygame.image.load('Images\\dark.png') # Lower the sound pygame.mixer.music.set_volume(0.4) # Initialise variables paused = True caught_events = list() i = 0 while paused: # Copy the surface to modify it copied_surface = freezed_surface.copy() # Darken the image copied_surface.blit(dark_img, (0,0)) # Output text helper.outputText('PAUSE', WIN_WIDTH//2, WIN_HEIGHT//2, centered=True, size = 200, surface = copied_surface) helper.outputText('Press Q to return to level screen', WIN_WIDTH//2, WIN_HEIGHT//2+150, centered=True, size = 50, surface = copied_surface) helper.outputText('Press ESC to resume the game', WIN_WIDTH//2, WIN_HEIGHT//2+215, centered=True, size = 50, surface = copied_surface) # Process events for event in pygame.event.get(): if event.type == QUIT: helper.terminate() elif event.type == KEYDOWN: # If we press escape, return to the level to play it if event.key == K_ESCAPE: paused = False elif event.key == K_q: WORLD.change(Engines.LevelMenuEngine().engine) paused = False # Add the keyup events onto the caught events list to add them # later to the stack. This avoids free running after pause. elif event.type == KEYUP: if event not in caught_events: caught_events.append(event) # Finally, we blit the copied surface into the original surface DISPLAYSURF.blit(copied_surface, (0,0)) FPS_CLOCK.tick() pygame.display.update() # Readd the caught events onto the event stack for event in caught_events: pygame.event.post(event) # Increase sound volume pygame.mixer.music.set_volume(0.8)