import pygame
import random
WIDTH = 500
HEIGHT = 700
FPS = 60
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
f1 = pygame.font.Font(None, 36)
running = True
x = 0
y = 0
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
for it_1 in range(0,500,50):
for it_2 in range(0,500,50):
pygame.draw.rect(screen,WHITE, (it_1,it_2,49,49))
if (x < 0): x = 0
if (x > 450): x = 450
if (y > 500): y = 500
if (y < 100): y = 100
direction = random.randint(0,4)
if (direction == 0):
x = x + 50
if (direction == 1):
x = x - 50
if (direction == 2):
y = y + 50
if (direction == 3):
y = y - 50
pygame.draw.rect(screen,GREEN, (x,y,49,49))
pygame.display.update()
pygame.time.delay(250)
pygame.quit()
|