if event.type == pygame.QUIT: # If user clicked close done = True # Flag that we are done so we exit this loop if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: player.go_right() test_map.left() if event.key == pygame.K_LEFT: player.go_left() test_map.right() if event.key == pygame.K_UP: player.go_up() if event.key == pygame.K_DOWN: player.go_down() if event.key == pygame.K_m: open_phone() if event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: player.stop("R") test_map.stop() if event.key == pygame.K_LEFT: player.stop("L") test_map.stop() if event.key == pygame.K_UP: player.stop("U") if event.key == pygame.K_DOWN: player.stop("D") test_map.update(player) player.update()
def play_scene(self): pygame.init() size= [constants.SCREEN_WIDTH,constants.SCREEN_HEIGHT] screen = pygame.display.set_mode(size) pygame.display.set_caption("Punks R Us - "+self.scene_name) clock = pygame.time.Clock() while not self.done: for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close pygame.quit()# Flag that we are done so we exit this loop if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: self.player.go_right() self.current_map.left() if event.key == pygame.K_LEFT: self.player.go_left() self.current_map.right() if event.key == pygame.K_UP: self.player.go_up() self.current_map.stop() if event.key == pygame.K_DOWN: self.player.go_down() self.current_map.stop() if event.key == pygame.K_m: open_phone() if event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: self.player.stop("R") self.current_map.stop() if event.key == pygame.K_LEFT: self.player.stop("L") self.current_map.stop() if event.key == pygame.K_UP: self.player.stop("U") if event.key == pygame.K_DOWN: self.player.stop("D") # Update all things that need updating self.current_map.update(self.player) self.player.update() # Draw map self.current_map.draw(screen,self.player) # Draw sprites # Draw text # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT # Limit to 60 frames per second clock.tick(60) # Go ahead and update the screen with what we've drawn. pygame.display.flip()