Alguien sabe cual es mi error de codigo

import pygame
import sys

# Initialize Pygame
pygame.init()

# Set up some constants
WIDTH, HEIGHT = 640, 480
PACMAN_SIZE = 20
SPEED = 2
ANIMATION_FRAMES = 8
ANIMATION_DELAY = 50

# Set up the display
screen = pygame.display.set_mode((WIDTH, HEIGHT))

# Set up the Pac-Man character
pacman_x, pacman_y = WIDTH / 2, HEIGHT / 2
pacman_image = pygame.Surface((PACMAN_SIZE, PACMAN_SIZE))
pacman_image.fill((255, 255, 0)) # Yellow

# Load the sprite sheet
sprite_sheet = pygame.image.load('C:\Users\USER\Downloads\Daco.png')

# Set up the animation
current_frame = 0
animation_time = pygame.time.get_ticks()

# Set up the direction-specific animations
animations = {
'up': [(0, 0), (0, 20), (0, 40), (0, 60), (0, 80), (0, 100), (0, 120), (0, 140)],
'down': [(0, 160), (0, 180), (0, 200), (0, 220), (0, 240), (0, 260), (0, 280), (0, 300)],
'left': [(0, 320), (0, 340), (0, 360), (0, 380), (0, 400), (0, 420), (0, 440), (0, 460)],
'right': [(0, 480), (0, 500), (0, 520), (0, 540), (0, 560), (0, 580), (0, 600), (0, 620)]
}

# Set the initial animation direction
animation_direction = 'right'
animation_frames = animations[animation_direction]

# Game loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()

# Get the current key presses
keys = pygame.key.get_pressed()

# Move Pac-Man
if keys[pygame.K_UP] or keys[pygame.K_w]:
pacman_y -= SPEED
animation_direction = 'up'
animation_frames = animations[animation_direction]
if keys[pygame.K_DOWN] or keys[pygame.K_s]:
pacman_y += SPEED
animation_direction = 'down'
animation_frames = animations[animation_direction]
if keys[pygame.K_LEFT] or keys[pygame.K_a]:
pacman_x -= SPEED
animation_direction = 'left'
animation_frames = animations[animation_direction]
if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
pacman_x += SPEED
animation_direction = 'right'
animation_frames = animations[animation_direction]

# Ensure Pac-Man doesn't move off the screen
pacman_x = max(0, min(pacman_x, WIDTH - PACMAN_SIZE))
pacman_y = max(0, min(pacman_y, HEIGHT - PACMAN_SIZE))

# Update the animation
current_time = pygame.time.get_ticks()
if current_time - animation_time > ANIMATION_DELAY:
current_frame = (current_frame + 1) % ANIMATION_FRAMES
animation_time = current_time

# Draw the current frame of the animation
frame_rect = (animation_frames[current_frame][0], animation_frames[current_frame][1], PACMAN_SIZE, PACMAN_SIZE)
screen.fill((0, 0, 0)) # Clear the screen
screen.blit(sprite_sheet, (pacman_x, pacman_y), frame_rect) # Draw the current frame

# Update the display
pygame.display.flip()
pygame.time.Clock().tick(60) # Limit the frame rate to 60 FPS

Respuesta :

Respuesta:

no sé xd ni entendí yo jajajajajjaja

Otras preguntas