import pygame import random # 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("Medieval Quest: Lake of Peril") # Load images player_img = pygame.image.load("knight.png").convert_alpha() monster_img = pygame.image.load("monster.png").convert_alpha() lake_img = pygame.image.load("lake.png").convert_alpha() # Set up the player player_rect = player_img.get_rect() player_rect.centerx = screen_width // 2 player_rect.bottom = screen_height - 20 player_speed = 5 # Set up the monster monster_rect = monster_img.get_rect() monster_rect.center = (random.randint(0, screen_width), random.randint(50, screen_height // 2)) monster_speed = 3 # Set up the lake lake_rect = lake_img.get_rect() lake_rect.center = (screen_width // 2, screen_height // 2) # Game loop running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Player movement keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: player_rect.x -= player_speed if keys[pygame.K_RIGHT]: player_rect.x += player_speed if keys[pygame.K_UP]: player_rect.y -= player_speed if keys[pygame.K_DOWN]: player_rect.y += player_speed # Keep player within screen bounds player_rect.x = max(0, min(player_rect.x, screen_width - player_rect.width)) player_rect.y = max(0, min(player_rect.y, screen_height - player_rect.height)) # Monster movement if monster_rect.x < player_rect.x: monster_rect.x += monster_speed elif monster_rect.x > player_rect.x: monster_rect.x -= monster_speed if monster_rect.y < player_rect.y: monster_rect.y += monster_speed elif monster_rect.y > player_rect.y: monster_rect.y -= monster_speed # Collision detection if player_rect.colliderect(monster_rect): print("Collision!") # Draw everything screen.fill((255, 255, 255)) screen.blit(player_img, player_rect) screen.blit(monster_img, monster_rect) screen.blit(lake_img, lake_rect) pygame.display.flip() # Cap the frame rate pygame.time.Clock().tick(60) # Quit Pygame pygame.quit()