У меня возникли проблемы с тем, чтобы детектор столкновений работал для моей игры в понг без необходимости изменять все классы (спрайт, рендеринг).
Я видел несколько полезных тем здесь, на StackOverflow, но не могу заставить их работать.
#Create a class named sprite to use for the paddles and the ball.
class Sprite():
def __init__(self,x,y,width,height,color):
self.x = x
self.y = y
self.width = width
self.height = height
self.color= (255,255,255)
#attirbute for drawing the sprite(s) to the screen
def render(self):
pygame.draw.rect(screen,self.color,(self.x,self.y,self.width,self.height))
#Create the sprites
Paddle1 = Sprite(50,175,25,150,color[0])
Paddle2 = Sprite(650,175,25,150,color[1])
Ball = Sprite(300,250,25,25, color[2])
#Set the Sprite's color(s)
Paddle1.color = color[0]
Paddle2.color = color[1]
Ball.color = color[2]
#Variables used for moving the paddles
moveY1,moveY2=0,0
#### Spot where my collision detector goes####
#### Code for drawing and moving the paddles####
Paddle1.y += moveY1
Paddle1.render()
Paddle2.y += moveY2
Paddle2.render()
#Draw the Ball
Ball.render()