pygame飞机大战7

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))

显示最高分


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值