import pygame
import sys
# Initialize Pygame
pygame.init()
# Set up the game window
screen_width, screen_height = 640, 480
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("2D Puzzle Game")
# Define colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
# Define game variables
tile_size = 32
player_pos = [0, 0]
gems_collected = 0
# Define the game map
game_map = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 0, 1, 1, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 1, 0, 1, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 1, 1, 1, 1, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 0, 0, 1, 1, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
]
# Load images
player_img = pygame.image.load("player.png").convert_alpha()
gem_img = pygame.image.load("gem.png").convert_alpha()
wall_img = pygame.image.load("wall.png").convert()
# Game loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
sys.exit()
# Handle player movement
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
if game_map[player_pos[1] - 1][player_pos[0]] == 0:
player_pos[1] -= 1
elif event.key == pygame.K_DOWN:
if game_map[player_pos[1] + 1][player_pos[0]] == 0:
player_pos[1] += 1
elif event.key == pygame.K_LEFT:
if game_map[player_pos[1]][player_pos[0] - 1] == 0:
player_pos[0] -= 1
elif event.key == pygame.K_RIGHT:
if game_map[player_pos[1]][player_pos[0] + 1] ==