я очень рад,что написал ту хрень,которую хотел.хотя возможно я уже это реализовал.
import pygame
import random
import math
WIDTH = 500
HEIGHT = 500
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
running = True
x = 50
y = 50
counter = 0
direct = random.randint(0,3)
stop = 0
varstop = 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_RETURN:
if stop == 0:
stop = 1
print("stop 1")
else:
print("stop 0")
stop = 0
screen.fill(WHITE)
print(stop)
direct = -1
if stop == 0:
direct = random.randint(0,3)
if direct == 0 and x < 450:
x = x + 1
if direct == 1 and x > 50:
x = x - 1
if direct == 2 and y > 50:
y = y - 1
if direct == 3 and y < 450:
y = y + 1
pygame.draw.rect(screen, (255,255,0), (x,y, 25,25))
pygame.display.flip()
counter = counter + 1
pygame.quit()
|