a youtube video told me to put what I've already put.
https://www.youtube.com/watch?v=bVx2nhB0t1o&feature=youtu.be
My window opens, but just stays at a black screen. When I close the window, then I get the error message:
Traceback (most recent call last):
File "./invaders.py", line 23, in <module>
keys = pygame.key.get_pressed()
pygame.error: video system not initialized
I don't really understand why this is happening and any help would be much appreciated.
import pygame
pygame.init()
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("Space Invaders")
x = 50
y = 50
width = 30
height = 30
vel = 5
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.quit()
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)
pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))
pygame.display.update()