import sys import pygame from character import Character from portal import Portal from wall import Wall # Define some colours BLACK = (0, 0, 0) WHITE = (255, 255, 255) # Height of the screen (in pixels) W = 1200 # Width of the screen (in pixels) H = 800 pygame.init() pygame.display.set_caption("Python Platformer!") screen = pygame.display.set_mode([W, H]) clock = pygame.time.Clock() c = Character() p = Portal(1000, 200) w = Wall(969, 250, 40, 200) # Game Loop while True: clock.tick(60) # Handle events for event in pygame.event.get(): # If the user presses the X button, close the game if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: # If the user presses d, the character should move right if event.unicode == 'd': c.xSpeed = c.xSpeed + 5 # If the user presses a, the chracter should move shouldMoveRight if event.unicode == 'a' : c.xSpeed = c.xSpeed - 5 # If the user presses w or space, the chracter should move shouldMoveRight if event.unicode == 'w' or event.unicode == ' ': c.ySpeed = c.ySpeed - 20 if event.type == pygame.KEYUP: # If the user releases d, the character should stop if event.unicode == 'd': c.xSpeed = c.xSpeed - 5 # If the user releases a, the chracter should stop if event.unicode == 'a' : c.xSpeed = c.xSpeed + 5 # Draw the background screen.fill(WHITE) pygame.draw.rect(screen, BLACK, (0, 600, W, 200)) # Update character position c.updatePosition() # If position of character # Apply Gravity c.ySpeed = c.ySpeed + 1 if c.y >= 600: c.y = 600 c.ySpeed = 0 if c.x > 1200: c.x = 0 if c.x < 0: c.x = 1200 # Draw the character w.draw(screen) p.draw(screen) c.draw(screen) # Check if the player reached the portal if p.isPointOnPortal(c.x, c.y): print("You win!!!!!!") # Apply the changes pygame.display.flip()