pygame飛機大戰7

2021-08-17 15:49:02 字數 1177 閱讀 3731

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

顯示最高分

pygame飛機大戰3

self.destroy images.extend pygame.image.load images enemy1 down1.png convert alpha pygame.image.load images enemy1 down2.png convert alpha pygame.imag...

pygame飛機大戰4

pygame.mask.from su ce self,image 對的非透明部分做標記 pygame.sprite.spritecollide b,enemies,false,pygame.sprite.collide mask 完美檢測碰撞 me.rect.midtop,子彈生成在飛機的中間的頂...

pygame飛機大戰5

score font.render score s str score true,white render函式把字元字串轉換為su ce物件 true拒絕鋸齒 paused rect.collidepoint event.pos 在paused rect矩形類裡有collidepoint event...