为什么在这段代码中,触摸线时圆圈不会停止?如果有人知道如何在接触地面时停下来,请写信。
import pygame
pygame.init()
FPS = 30
x = 300
y = 200
xL = 200
xL2 = 400
yL = 300
sc = pygame.display.set_mode((600, 400))
clock = pygame.time.Clock()
pygame.display.update()
speedDown = 0
while True:
sc.fill((255,255,255))
clock.tick(FPS)
pygame.draw.circle(sc,(0,0,255),(x,y), 20, 0)
pygame.draw.line(sc,(0,0,0),(xL,yL),(xL2,yL),5)
for i in pygame.event.get():
if i.type == pygame.QUIT:
exit()
keys = pygame.key.get_pressed()
if y == yL:
speedDown = 0
y += 5
else:
speedDown += 1
y += speedDown
pygame.display.update()
因为你检查了一次是否相等,然后圆圈向下,在下一次迭代中,检查再次进入它
else,圆圈继续向下。要让它在线上“冻结”,你可以这样写:测试https://repl.it/repls/VirtuousThirstyLint