1 回答

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊
導(dǎo)致此問(wèn)題的原因Lives是每次滿足條件時(shí)都會(huì)遞減。如果連續(xù)幀中滿足條件,Lives則每幀遞減一次。您必須避免Lives連續(xù)多次遞減。
當(dāng)Lives遞減時(shí),設(shè)置狀態(tài) ( self.hit)。設(shè)置Lives時(shí)不要遞減。當(dāng)條件不再滿足時(shí)self.hit重置:self.hit
class Balloon:
def __init__(self, x,y,health, dests, speed):
# [...]
self.hit = False
def Check_Health(self, pos):
global Lives
if self.x == pos[0] and self.y == pos[1]:
if not self.hit:
Lives -= self.health
self.hit = True
else:
self.hit = False
添加回答
舉報(bào)