Problema pygame

di il
1 risposte

Problema pygame

Ciao a tutti!
Sto riscontrando alcuni problemi nella realizzazione di un codice
mi da errore presso la riga 44: File "c:\Users\pc\Desktop\snake_game\prova.py", line 44
if cube_pos[0] >= WIDTH or cube_pos[0] < 0 or cube_pos[1] >= HEIGHT or cube_pos[1] < 0:
IndentationError: unexpected indent
PS C:\Users\pc\Desktop\snake_game>

potreste dargli un occhiata?
import pygame
import sys

WIDTH = 800
HEIGHT = 600
WHITE = (255,255,255)
RED = (255,0,0)
cube_pos = [50, 50]
cube_vel = [0, 0]
cube_size = 30
FPS = 60

screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()

run = True

while run:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
        if event.type == pygame.KEYDOWN:
            # move on the x axis (WASD)
            if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                cube_vel[0] -= 10
            elif event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                cube_vel[0] += 10
            # move on the y axis (WASD)
            elif event.key == pygame.K_s or event.key == pygame.K_DOWN:
                cube_vel[1] += 10
            elif event.key == pygame.K_w or event.key == pygame.K_UP:
                cube_vel[1] -= 10
        
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_a or event.key == pygame.K_d:
                cube_vel[0] = 0
            if event.key == pygame.K_w or event.key == pygame.K_s:
                cube_vel[1] = 0 

    cube_pos[0] += cube_vel[0]
    cube_pos[1] += cube_vel[1]    
        
        #perdere toccando i bordi
        if cube_pos[0] >= WIDTH or cube_pos[0] < 0 or cube_pos[1] >= HEIGHT or cube_pos[1] < 0:
            run = False

    screen.fill(WHITE)
    pygame.draw.rect(screen, RED, (cube_pos[0], cube_pos[1], cube_size, cube_size))
    clock.tick(FPS)
    pygame.display.update()



pygame.quit()
sys.exit()

1 Risposte

  • Re: Problema pygame

    Il messaggio di errore è eloquente:

    [...] line 44 [...] IndentationError: unexpected indent [...]

    L'indentazione della linea linea 44, ed la successiva, ha tab di troppo.
Devi accedere o registrarti per scrivere nel forum
1 risposte