我有精灵从屏幕的末端到另一个,但现在我希望它永远来回。有什么想法吗?
u = 1 #u is the x coordinate
if u < 430: #480 is the window siz, i want it to stop at 430
u += 5 # Move up by 5
我应该添加整个代码以便更容易吗?
答案 0 :(得分:1)
您可以使用delta变量:
delta = 5
u = 1
并将其调整为切换方向:
u += delta
if u >= 430:
delta = -5
elif u < 50:
delta = 5