Выполнение задания по программированию Pygame Python
import pygame as pg
import random
pg.init()
SIZE = W, H = 500, 500
screen = pg.display.set_mode((SIZE))
pg.display.set_caption('Кружки')
FPS = 35
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (225, 0, 0)
GREEN = (0, 225, 0)
BLUE = (0, 0, 225)
YELLOW = (225, 225, 0)
clock = pg.time.Clock()
list_colot = [BLACK, WHITE, RED, GREEN, BLUE, YELLOW]
class Circle:
def __init__(self, x, y, rad, color):
self.x = x
self.y = y
self.rad = rad
self.color = color
def horizontal_movement(self):
if self.dir == 'right':
self.x += 1
if self.x > W:
self.dir = 'left'
else:
self.x -= 1
if self.x < 0:
self.dir = 'right'
s_c = []
for i in range(100):
s_c.append(Circle(i * 10, i * 5, 30, tuple(random.choices(range(256), k=3))))
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
quit()
screen.fill(WHITE)
clock.tick(FPS)
pg.display.flip()
pg.display.update()
Надо сделать передвижение как на картинке
Тобиш с центра его догоняют остальные и отталкиваются поочереди от левой до правой части и обратно. Вообще не понимаю как это сделать
Источник: Stack Overflow на русском