1 回答

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊
關(guān)于滯后部分,有幾件事:
正如@Kingsley 所提到的,你是雙循環(huán),對(duì)碰撞檢查的數(shù)量進(jìn)行平方
您正在檢查不在屏幕上的對(duì)象
您在迭代對(duì)象時(shí)刪除對(duì)象(可能解釋了 -1-1-1)
試試這段代碼。它移動(dòng)得更快:
# LIVES AND SPIKE
lstdel = []
for i,spk in enumerate(spikes):
if spk.rect.left > 500 or spk.rect.left < 0: continue # off screen
if player1.rect.colliderect(spk.rect):
if deaths > 0:
deaths -= 1
talk = font.render("LIVES = "+str(deaths),True,(255,255,255))
talkRect.center = ((100,90))
lstdel.append(i)
for i in lstdel[::-1]:
del spikes[i] #delete from end
lstdel = []
for i,pk in enumerate(pikes):
if pk.rect.left > 500 or pk.rect.left < 0: continue # off screen
if player1.rect.colliderect(pk.rect):
if deaths > 0:
deaths -= 1
talk = font.render("LIVES = "+str(deaths),True,(255,255,255))
talkRect.center = ((100,90))
lstdel.append(i)
for i in lstdel[::-1]:
del pikes[i] #delete from end
lstdel = []
for i, lv in enumerate(lives):
if lv.rect.left > 500 or lv.rect.left < 0: continue # off screen
if player1.rect.colliderect(lv.rect):
if deaths > 0:
deaths += 1
talkRect.center = ((100,90))
lstdel.append(i)
for i in lstdel[::-1]:
del lives[i] #delete from end
添加回答
舉報(bào)