if me_destroy_index == 0:
life_num -= 1
me.reset()
pygame.time.set_timer(INVINCIBLE_TIME, 3 * 1000)
if enemies_down and not me.invincible:
me.active = False
for e in enemies_down:e.active = False
elif event.type == INVINCIBLE_TIME:
me.invincible = False
pygame.time.set_timer(INVINCIBLE_TIME, 0)
在飞机一条命被撞了之后,我们设置一个3秒的无敌状态
在reset后,调用计时器,就不会调用
if enemies_down and not me.invincible:里面的 me.active = False
则飞机无敌,然后3秒后调用elif event.type == INVINCIBLE_TIME:
me.invincible = False,关闭计时器
然后调用if enemies_down and not me.invincible:
recorded = False
if not recorded:
recorded = True
with open("record.txt", "r") as f:
record_score = int(f.read())
if score > record_score:
with open("record.txt", "w") as f:
f.write(str(score))
先把recored设置为False,这样不用一局游戏疯狂读档存档
节省资源,然后再把recored设置为True
打开文件record.text
如果此局分数比以往高,则存档入record.txt文件
record_score_text = score_font.render("Best : %d" % record_score, True, (255, 255, 255))
screen.blit(record_score_text, (50, 50))
显示最高分