import pygame import random # Initialize Pygame pygame.init() # Set up the game window WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Simple Fortnite-like Game") # Define colors WHITE = (255, 255, 255) RED = (255, 0, 0) BLUE = (0, 0, 255) # Define player class class Player(pygame.sprite.Sprite): def __init__(self): super().__init__() self.image = pygame.Surface((50, 50)) self.image.fill(RED) self.rect = self.image.get_rect() self.rect.center = (WIDTH // 2, HEIGHT // 2) def update(self): keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: self.rect.x -= 5 if keys[pygame.K_RIGHT]: self.rect.x += 5 if keys[pygame.K_UP]: self.rect.y -= 5 if keys[pygame.K_DOWN]: self.rect.y += 5 # Define enemy class class Enemy(pygame.sprite.Sprite): def __init__(self): super().__init__() self.image = pygame.Surface((30, 30)) self.image.fill(BLUE) self.rect = self.image.get_rect() self.rect.x = random.randint(0, WIDTH - self.rect.width) self.rect.y = random.randint(0, HEIGHT - self.rect.height) # Create sprite groups all_sprites = pygame.sprite.Group() enemies = pygame.sprite.Group() # Create player player = Player() all_sprites.add(player) # Create enemies for _ in range(10): enemy = Enemy() all_sprites.add(enemy) enemies.add(enemy) # Main game loop running = True while running: # Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Update all_sprites.update() # Draw screen.fill(WHITE) all_sprites.draw(screen) pygame.display.flip() # Cap the frame rate pygame.time.delay(30) pygame.quit()