The code below is generally used to make a rectangle and move it in the pygame window. But it isn't working. The rectangle shows but it shows no sign of movement in it. Please tell me what's wrong in this code.
import pygame
pygame.init()
win = pygame.display.set_mode((800,800))
pygame.display.set_caption("nyumph")
x = 50
y = 50
width = 40
height = 60
vel = 5
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
x -= vel
if keys[pygame.K_RIGHT]:
x += vel
if keys[pygame.K_UP]:
y -= vel
if keys[pygame.K_DOWN]:
y += vel
win.fill((0, 0, 0))
pygame.draw.rect(win,(0, 0, 255), (x, y, width, height))
pygame.display.update()
pygame.quit()
This is the code I typed but only the rectangle appeared. It didn't move. Please tell me what's wrong in this.