Python doesn't respond when I play it. No syntax error appears either. Not sure what is wrong. I tried running another game I made which worked fine so I don't think it's my computer. error message
This is my code:
import pygame
pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("Draft")
icon = pygame.image.load("doctor.png")
pygame.display.set_icon(icon)
white = (255,255,255)
black = (0,0,0) red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
def draw_ground():
groundx = 20
groundy = 30
Ground = pygame.Rect(groundx,groundy,width = 800,height = 20)
pygame.draw.rect(screen,green,Ground)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
draw_ground()
It isn't complete yet, I'm trying to test it first before moving ahead.
There is a typo in your code:
black = (0,0,0) red = (255,0,0)
It has to be
black = (0,0,0)
red = (255,0,0)
However, there is more.
pygame.Rect
does not accept keyword arguments:
Ground = pygame.Rect(groundx,groundy,width = 800,height = 20)
Ground = pygame.Rect(groundx,groundy,800,20)
You have to update the display by calling either pygame.display.update()
or pygame.display.flip()
:
clock = pygame.time.Clock()
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# clear dispaly
screen.fill(0)
# draw objects
draw_ground()
# update dispaly
pygame.display.flip()
The typical PyGame application loop has to:
pygame.time.Clock.tick
pygame.event.pump()
or pygame.event.get()
.blit
all the objects)pygame.display.update()
or pygame.display.flip()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments