Python Forum

Full Version: Pygame Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, here is my code :
import pygame
pygame.init()

screen = pygame.display.set_mode((1000,750))

vie = True
clock = pygame.time.Clock()
x = 50
y = 50
points_x = [500]
points_y = [375]

clock = pygame.time.Clock()
color = (255, 100, 0)


def mouvement():
    screen.fill((0, 0, 0))
    for loop in range(len(points_x) - 1):
        points_x[len(points_x) - loop] = points_x[len(points_x) - loop - 1]
        points_y[len(points_y) - loop] = points_y[len(points_y) - loop - 1]
    for loop in range(len(points_x)):
        pygame.draw.rect(screen, color, pygame.Rect(points_x[loop], points_y[loop], 60, 60))
        
            
            
           

while True:
    pressed = pygame.key.get_pressed()

    ancien_x = points_x[0]
    ancien_y = points_y[0]
    
    if pressed[pygame.K_UP]:
        points_y[0] -= 3
        mouvement()
    elif pressed[pygame.K_DOWN]:
        points_y[0] += 3
        mouvement()
    elif pressed[pygame.K_LEFT]:
        points_x[0] -= 3
        mouvement()
    elif pressed[pygame.K_RIGHT]:
        points_x[0] += 3
        mouvement()

    pygame.draw.rect(screen, color, pygame.Rect(x, y, 60, 60))
    
    clock.tick(60)

But, the screen don't show anything. I don't know why ...
after clock.tick(60) add the following line
pygame.display.update()
This needs to be done once ever in the main game loop.