我玩了一会儿,但我简直无法理解.
我制造了一个发射导弹的坦克,当导弹击中墙壁时,我希望它们反弹,但我希望它们能够以正确的角度反弹.
现在我没有任何障碍,当导弹越过viewportRectangle我制造的时候导弹就会反弹.
我正在寻找的解决方案是否相当先进?
有相对简单的方法吗?
我正在制作一个游戏,其中球在一个更大的圆圈内部反弹.较大的圆圈不会移动.
这是我目前用于这些冲突的代码:
def collideCircle(circle, ball):
"""Check for collision between a ball and a circle"""
dx = circle.x - ball.x
dy = circle.y - ball.y
distance = math.hypot(dx, dy)
if distance >= circle.size + ball.size:
# We don't need to change anything about the circle, just the ball
tangent = math.atan2(dy, dx)
ball.angle = 2 * tangent - ball.angle
ball.speed *= elasticity + 0.251
angle = 0.5 * math.pi + tangent
ball.x -= math.sin(angle)
ball.y += math.cos(angle) …Run Code Online (Sandbox Code Playgroud)