I started to make a game with pygame and i am only at that point, where i should have 10*10 grey squares. When I start the program, the squares appear but the program is not responding. Is there anything wrong with the script or is it about my laptop performance?
import pygame
pygame.init()
win=pygame.display.set_mode((768,768))
left=50
up=50
difx=20
dify=20
sx=50
sy=50
grey=(90,90,90)
black=(0,0,0)
blue=(0,0,250)
def draw():
pygame.Surface.fill(win,black)
for x in range(0,100):
pygame.draw.rect(win,grey,(left+x%10*(sx+difx),up+round((x-x%10)/10)*(sy+dify),sx,sy))
pygame.display.update()
while True:
pygame.time.delay(100)
draw()
Python 3.7 Windows 10
You can try this.
import pygame
def main():
pygame.init()
win=pygame.display.set_mode((768,768))
left=50
up=50
difx=20
dify=20
sx=50
sy=50
grey=(90,90,90)
black=(0,0,0)
blue=(0,0,250)
def draw():
pygame.Surface.fill(win,black)
for x in range(0,100):
pygame.draw.rect(win,grey,(left+x%10*(sx+difx),up+round((x-x%10)/10)*(sy+dify),sx,sy))
while True:
for e in pygame.event.get():
if e.type == pygame.QUIT:
return
pygame.display.update()
draw()
if __name__ == '__main__':
main()
You are missing a for e in pygame.event.get():