So i jsut started learning python but right now when i run this and try to jump it loads this error and also the rectangle dont move if i hold it it only moves onces i just started and i really dont know what the problem is
This is what it showed: keys = pygame.key.get_pressed() pygame.error: video system not initialized
import pygame
pygame.init()
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("Hello")
x = 100
y = 100
width = 50
height = 50
vel = 10
jump_count = 10
jump = False
run = True
while run:
pygame.draw.rect(win, (255, 255, 255), (x, y, width, height))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT] and x < 450:
x += vel
if keys[pygame.K_LEFT] and x > 0:
x -= vel
if not jump:
if keys[pygame.K_DOWN] and y < 450:
y += vel
if keys[pygame.K_UP] and y > 0:
y -= vel
if keys[pygame.K_SPACE]:
jump = True
else:
if jump_count >= -10:
neg = 1
if jump_count < 0:
neg = -1
y -= (jump_count ** 2) /2 * neg
jump_count = -1
else:
jump = False
jump_count = 10
win.fill((0, 0, 0))