#!/bin/python
import pygame, sys
import random
green = (0, 255, 0)
blue = (0, 0, 128)
red = (255, 0, 0)
pygame.init()
sc = pygame.display.set_mode((500, 500))
pygame.display.set_caption("Юркин танк поехал")
clock = pygame.time.Clock()
pygame.time.set_timer(pygame.USEREVENT, 100)
x = 250
y = 250
counter_1 = 0
random_selecting = random.randint(0,3)
while True:
sc.fill((125,125,125))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.USEREVENT:
counter_1 = counter_1 + 5
if counter_1 == 50:
random_selecting = random.randint(0,3)
counter_1 = 0
if random_selecting == 0:
x = x + 5
if random_selecting == 1:
x = x - 5
if random_selecting == 2:
y = y + 5
if random_selecting == 3:
y = y - 5
if x < 0:
x = 0
if x > 450:
x = 450
if y < 0:
y = 0
if y > 450:
y = 450
pygame.draw.rect(sc, (255, 255, 255), (x, y, 50, 50))
pygame.display.flip()
|