以下是我程序中的代码除外。第一个区块涉及射击+敌人碰撞,第二个区块涉及我的+敌人碰撞,第三个区块实际产生新的波浪。目前,初始波浪大小会产生10个敌人,并且游戏循环在第一波之后不会产生新的敌人。
# baddie and shot collision
removed = False
for a in baddies[:]:
for b in shots[:]:
if a.imgRect.colliderect(b.imgRect):
shots.remove(b)
a.toughness -= 1
if a.toughness < 1:
baddies.remove(a)
removed = True
print str(wavesize)
break
# baddie and mine collision
removed = False
for a in baddies[:]:
for b in mines[:]:
if a.imgRect.colliderect(b.imgRect):
mines.remove(b)
a.toughness -= 1
if a.toughness < 1:
baddies.remove(a)
removed = True
break
if removed:
wavesize -= 1
if wavesize < 1:
loopcount += 1
wavesize = 10+(loopcount*5)
baddies = createNewWave(wavesize)
答案 0 :(得分:1)
每次通过循环并且删除坏人时,你只会将wavesize
减少一个,但你很可能一次删除多个坏人。此外,您在第一组循环后重置了removed
变量,因此如果它们被镜头破坏,您可能会丢失坏人。你应该做的是跟踪你移除了多少坏人,然后减少波浪大小。
removed = 0
for a in baddies[:]:
for b in shots[:]:
...
baddies.remove(a)
removed += 1
for a in baddies[:]:
for b in mines[:]:
...
baddies.remove(a)
removed += 1
wavesize -= removed
if wavesize < 1:
loopcount += 1
wavesize = 10+(loopcount*5)
baddies = createNewWave(wavesize)