import pygame import sys # Initialize Pygame pygame.init() # Set up the screen SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_caption("Portal Game") # Colors DARK_GREY = (20, 20, 20) NEON_RED = (255, 0, 0) NEON_BLUE = (0, 0, 255) WHITE = (255, 255, 255) WHITE_TRANSPARENT = (255, 255, 255, 100) # Player player_size = 50 player_radius = 20 player = pygame.Rect(SCREEN_WIDTH // 2 - player_size // 2, SCREEN_HEIGHT // 2 - player_size // 2, player_size, player_size) # Portals portal_width = 20 portal_height = 100 portal_red = pygame.Rect(100, 100, portal_width, portal_height) portal_blue = pygame.Rect(600, 400, portal_width, portal_height) # Glow effect portal_glow_radius = 40 portal_glow_red = pygame.Rect(portal_red.x - portal_glow_radius, portal_red.y - portal_glow_radius, portal_red.width + portal_glow_radius * 2, portal_red.height + portal_glow_radius * 2) portal_glow_blue = pygame.Rect(portal_blue.x - portal_glow_radius, portal_blue.y - portal_glow_radius, portal_blue.width + portal_glow_radius * 2, portal_blue.height + portal_glow_radius * 2) # Game loop while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() # Player movement keys = pygame.key.get_pressed() player_speed = 2 if keys[pygame.K_LEFT]: player.x -= player_speed if keys[pygame.K_RIGHT]: player.x += player_speed if keys[pygame.K_UP]: player.y -= player_speed if keys[pygame.K_DOWN]: player.y += player_speed # Teleport player if collides with portals if player.colliderect(portal_red): player.x = portal_blue.x player.y = portal_blue.y elif player.colliderect(portal_blue): player.x = portal_red.x player.y = portal_red.y # Clear screen screen.fill(DARK_GREY) # Draw glow effect around portals pygame.draw.ellipse(screen, WHITE_TRANSPARENT, portal_glow_red) pygame.draw.ellipse(screen, WHITE_TRANSPARENT, portal_glow_blue) # Draw portals pygame.draw.rect(screen, NEON_RED, portal_red, border_radius=10) pygame.draw.rect(screen, NEON_BLUE, portal_blue, border_radius=10) # Draw player pygame.draw.rect(screen, WHITE, player, border_radius=player_radius) # Update display pygame.display.flip()