【发布时间】:2019-12-13 13:22:30
【问题描述】:
所以,基本上我希望两个圆圈以加速度 1 彼此加速。我想在圆圈碰撞时停下来。 但是,代码在它们碰撞之前停止。这是因为它计算出在下一次迭代中,它们会直接通过。所以它停止了。如何改进它,以便它给出所需的结果。 我已经要求它打印圆的位置和速度,以便你可以在它运行时查看数据。 提前致谢。
import pygame
pygame.init()
w=1000
h=500
dis=pygame.display.set_mode((w,h))
pygame.display.set_caption("test2")
t=10
x1=50
x2=w-50
y1=250
y2=y1
v=0
r=True
def circles():
pygame.draw.circle(dis,(0,200,0),(x1,y1),25)
pygame.draw.circle(dis,(0,0,200),(x2,y2),25)
run=True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type==pygame.QUIT:
run=False
while r:
pygame.time.delay(t)
dis.fill((255,255,255))
circles()
print(x2,x1,(x2-x1),v,t)
x1+=v
x2-=v
v+=1
if x2-x1<=50: # THIS LINE STOPS THE CIRCLES
r=False
pygame.display.update()
pygame.quit()
【问题讨论】:
标签: python pygame collision-detection