Fiddling around with pygame and I'm not sure what's happening. code is just supposed to make a red box and bounce it around a gray screen. It works, but only when I quit the display.
I've checked out questions that are similar but none seem to have an answer that applies to me (might be wrong about that). Does anyone know how this code could be improved?
import pygame
from pygame.locals import *
from rect import *
##from pygame.font import *
RED = (255, 0, 0)
GRAY = (150, 150, 150)
width = 500
height = 200
pygame.init()
screen = pygame.display.set_mode((width, height))
rect = Rect(100, 50, 50, 50)
v = [2, 2]
##moving = False
running = True
while running:
for event in pygame.event.get():
if event.type == QUIT:
running = False
rect.move_ip(v)
if rect.left < 0 or rect.right > width:
v[0] *= -1
if rect.top < 0 or rect.bottom > height:
v[1] *= -1
screen.fill(GRAY)
pygame.draw.rect(screen, RED, rect)
pygame.display.flip()
pygame.quit()