def update(self): pressed_keys = pygame.key.get_pressed() if pressed_keys[pygame.K_DOWN]: self.move_down() elif pressed_keys[pygame.K_UP]: self.move_up() elif pressed_keys[pygame.K_LEFT]: self.move_left() elif pressed_keys[pygame.K_RIGHT]: self.move_right() elif pressed_keys[pygame.K_ESCAPE]: pygame.quit() sys.exit() super().update() #warping collision = False for warp in game.current_screen.warps: if self.x + 8 >= warp[0][0] * 20 and \ self.x + 8 < warp[0][0] * 20 + 20 and \ self.y + 12 + 8 >= warp[0][1] * 20 and \ self.y + 12 + 8 < warp[0][1] * 20 + 20: if not self.has_warped: game.load_screen(warp[1]) self.x = self.x - warp[0][0] * 20 + warp[2][0] * 20 self.y = self.y - warp[0][1] * 20 + warp[2][1] * 20 game.checkpoint = (self.x, self.y, warp[1]) collision = True break if collision: self.has_warped = True else: self.has_warped = False
import pygame, game, sys # Game initialization game.init() game.load_screen(0) clock = pygame.time.Clock() # Gameloop while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() game.update() game.draw() pygame.display.flip() clock.tick(30)