INNER CODE UNIT · Python
collide
metafy-social/python-scripts · scripts/Brick-Breaker-Python/main.py:74
def collide(self, ball):
if not (ball.x <= self.x + self.width and ball.x >= self.x):
return False
if not (ball.y - ball.radius <= self.y + self.height):
return False
self.hit()
ball.set_vel(ball.x_vel, ball.y_vel * -1)
return True
def hit(self):
self.health -= 1
self.color = self.interpolate(
*self.colors, self.health/self.max_health)
@staticmethod
def interpolate(color_a, color_b, t):
# 'color_a' and 'color_b' are RGB tuples