You are on page 1of 2

import pygame,sys,time

from pygame.locals import *


import pyautogui
import random

pygame.init()
DISPLAYSURF=pygame.display.set_mode((400,300))
pygame.display.set_caption(' world')
a=10
b=200
WHITE=(255,255,255)
PURPLE=(255,0,255)
RED=(255,0,0)
BLACK=(0,255,0)
DISPLAYSURF.fill(WHITE)
fpsClock=pygame.time.Clock()
k=1
u=0
x=[0,0,0,0]
y=[0,0,0,0]
f=2
xf=random.randrange(20,380,10)
yf=random.randrange(20,280,10)
while True:

DISPLAYSURF.fill(WHITE)
for event in pygame.event.get():
if event.type== pygame.KEYDOWN:

if event.key == ord("a"):
k=-10
u=0
elif event.key == ord("s"):
k=0
u=10
elif event.key == ord("w"):
k=0
u=-10
elif event.key == ord("d"):
k=10
u=0

elif event.type==QUIT:
pygame.quit()
sys.exit()

x[1]=a
y[1]=b
for i in range(f,0,-1):
x[i+1]=x[i]
y[i+1]=y[i]

#q=c
#z=d
#c=a
#d=b
a=a+k
b=b+u
#h=[q,c,a]
#j=[z,d,b]

for i in range(1,f):
pygame.draw.rect(DISPLAYSURF, RED, (x[i], y[i], 10, 10))
#pygame.draw.rect(DISPLAYSURF, RED, (a, b, 10, 10))
#pygame.draw.rect(DISPLAYSURF, RED, (q, z, 10, 10))
pygame.draw.rect(DISPLAYSURF, PURPLE, (xf, yf, 10, 10))

if a in range(xf-5,xf+5) and b in range(yf-5,yf+5):

#pygame.draw.rect(DISPLAYSURF, BLACK, (40, 40, 10, 10))


f=f+1
x.append(0)
y.append(0)
print(f)
xf=random.randrange(20,380,10)
yf=random.randrange(20,280,10)

#time.sleep(10)
#pygame.quit()
#sys.exit()

pygame.display.update()
fpsClock.tick(8)

You might also like