【发布时间】:2020-05-18 03:18:13
【问题描述】:
在我的 pygame 游戏中,我的玩家射击“子弹”,当它们到达屏幕边缘时,它们是“pop()”-ed,但如果只有 1 颗子弹到达末端,而数组中没有其他东西,游戏立即崩溃。
for i in reversed(range(len(shots))):
shots[i].shoot()
shots[i].drawBullet()
if shots[i].x > swidth or shots[i].x < 0:
shots.pop(i)
if shots[i].y > sheight or shots[i].y < 0:
shots.pop(i)
【问题讨论】:
-
我认为这是格式错误,并且所有其余的行都应该在 fr 循环内?
-
请格式化您的代码。您的问题的答案可能取决于缩进。
标签: python-3.x pygame