I am trying to make code to move a rectangle by pressing a key. In my code I made a while loop to keep drawing a rectangle that moves to the right in steps of 10 pixels but my progrem only shows the drawing execution of the end of the while loop.
Does anybody knows what I am doing wrong or how to fix it.
See my code below:
x=10
pygame.draw.rect(DISPLAYSURF, GREEN, (0, 10, 10,10))
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
while x<=380:
pygame.time.wait(100)
x = x + 20
print(x)
DISPLAYSURF.fill(BLACK)
pygame.draw.rect(DISPLAYSURF, GREEN, (x, 10, 10,10))
pygame.display.update()