import pygame
import random
import sys
FPS = 60
W = 500
H = 500
WHITE = (255, 255, 255)
BLUE = (0, 70, 225)
sc = pygame.display.set_mode((W, H))
clock = pygame.time.Clock()
sc.fill(WHITE)
x = 10
y = 10
r = 1
sc.fill((200, 255, 200))
direction = 0
movevar = 0
while 1:
for i in pygame.event.get():
if i.type == pygame.QUIT:
sys.exit()
elif i.type == pygame.KEYUP:
if i.key == pygame.K_RIGHT:
movevar = 0
elif i.key == pygame.K_LEFT:
movevar = 0
elif i.key == pygame.K_DOWN:
movevar = 0
elif i.key == pygame.K_UP:
movevar = 0
elif i.type == pygame.KEYDOWN:
if i.key == pygame.K_RIGHT:
direction = 0
movevar = 1
elif i.key == pygame.K_LEFT:
direction = 1
movevar = 1
elif i.key == pygame.K_DOWN:
direction = 2
movevar = 1
elif i.key == pygame.K_UP:
direction = 3
movevar = 1
if (x < 10): x = 10
if (x > 400): x = 400
if (y < 10): y = 10
if (y > 400): y = 400
if movevar == 1:
r = r + 1
if r == 10: r = 1
if direction == 0: x = x + 10
if direction == 1: x = x - 10
if direction == 2: y = y + 10
if direction == 3: y = y - 10
pygame.draw.circle(sc, BLUE, (x, y), r)
pygame.display.update()
clock.tick(FPS)
|