Я делаю понг 4 человека со всех сторон квадрата, но не знаю, как добавить столкновение между отдельными веслами, чтобы они не переходили друг в друга по углам
import pygame
pygame.init()
### Colors
WHITE = (255, 255, 255)
BLACK = (0,0,0)
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("GNOP")
x = 485
y = 75
x2 = 5
y2 = 75
x3 = 250
y3 = 5
y4 = 485
x4 = 250
width = 10
height = 90
vel = 5
run = True
while run:
print(x4,y4)
pygame.time.delay(10)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
key= pygame.key.get_pressed()
if key [pygame.K_UP] and y>0:
y -= vel
if key [pygame.K_DOWN]and y<420:
y += vel
if key [pygame.K_w] and y2>0:
y2 -= vel
if key [pygame.K_s]and y2<420:
y2 += vel
if key [pygame.K_c] and x3>0:
x3 -= vel
if key [pygame.K_v] and x3<420:
print(1)
x3 += vel
if key [pygame.K_n] and x4>0:
x4 -= vel
if key [pygame.K_m] and x4<420:
x4 += vel
def ball (self):
# Create the image of the ball
self.image = pygame.Surface([10, 10])
# Color the ball
self.image.fill(BLACK)
# Get a rectangle object that shows where our image is
self.rect = self.image.get_rect()
# Get attributes for the height/width of the screen
self.screenheight = pygame.display.get_surface().get_height()
self.screenwidth = pygame.display.get_surface().get_width()
# Speed in pixels per cycle
self.speed = 0
# Floating point representation of where the ball is
self.x = 0
self.y = 0
# Direction of ball in degrees
self.direction = 0
# Height and width of the ball
self.width = 10
self.height = 10
# Set the initial ball speed and position
self.reset()
win.fill((230,230,230))
pygame.draw.rect(win,(0, 0, 0), (x, y, width, height))
pygame.draw.rect(win,(255,50,0), (x2, y2, width, height))
pygame.draw.rect(win,(150,15,200), (x3, y3, height, width))
pygame.draw.rect(win,(0,100,255), (x4, y4, height, width))
pygame.display.update()
pygame.quit()
ball()
Мне нужны весла, чтобы обнаруживать друг друга и сталкиваться, а не фазировать друг друга, но я просмотрел несколько кодов, и мне еще предстоит узнать, как это сделать для каждого из них в отдельности, это очень важно, потому что я не могу получить мяч работать без него