import pygame
import random
import math
WIDTH = 500
HEIGHT = 500
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
running = True
x = 0
y = random.randint(0,475)
x2 = random.randint(200,500)
move = 0
state = 0
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
move = 1
if event.key == pygame.K_LEFT:
move = 2
x = 0
x2 = random.randint(200,500)
state = 0
screen.fill((0, 0, 0))
pygame.draw.rect(screen, (255, 255, 255), (x, y, 25, 25))
pygame.draw.line(screen, (255, 255, 255), [x2, 0], [x2, 500], 5)
if move == 1:
x += 1
if x == x2-25:
state = 1
if state == 0:
pygame.display.flip()
pygame.quit()
|