python--飞机大战
发布时间:2023-02-16 14:09:11 所属栏目:Python 来源:互联网
导读:实现功能: 1:飞机的移动,发射子弹,手雷,生命值,生命条 2:敌飞机有3种形态(小,中,大)不同的飞机大小不一样,生命值不一样,爆炸动画也不一样 3:背景音乐,子弹击中敌机会发生碰撞的爆炸动画和音效 4:随机产生补给(双射子弹和全屏炸弹) 5:难度
each.active = False # 绘制我方飞机 if me.active: if switch_plane: screen.blit(me.image1,me.rect) else: screen.blit(me.image2,me.rect) else: # 毁灭 if me_destroy_index == 0: me_down_sound.play() if not(delay % 2): screen.blit(me.destroy_images[me_destroy_index],me.rect) me_destroy_index = (me_destroy_index + 1) % 4 if me_destroy_index == 0: life_num -= 1 me.reset() pygame.time.set_timer(INVINCIBLE_TIME,3 * 1000) # 绘制全屏炸弹数量 bomb_text = bomb_font.render("× %d" % bomb_num,True,WHITE) text_rect = bomb_text.get_rect() screen.blit(bomb_image,(10,height - 10 - bomb_rect.height)) screen.blit(bomb_text,(20 + bomb_rect.width,height - 5 - text_rect.height)) # 绘制剩余生命数量 if life_num: for i in range(life_num): screen.blit(life_image,((width - 10 - (i + 1) * life_rect.width),height - 10 - life_rect.height)) # 绘制得分 score_text = score_font.render('score : %d' % score,WHITE) screen.blit(score_text,5)) # 绘制游戏结束画面 elif life_num == 0: # 背景音乐停止 pygame.mixer.music.stop() pygame.mixer.stop() # 停止发放补给 pygame.time.set_timer(SUPPLY_TIME,0) 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)) # 绘制结束界面 record_score_text = score_font.render("Best : %d" % record_score,(255,255)) screen.blit(record_score_text,45)) gameover_text1 = gameover_font.render("Your score",255)) gameover_text1_rect = gameover_text1.get_rect() gameover_text1_rect.left,gameover_text1_rect.top = (width - gameover_text1_rect.width) // 2,height // 3 screen.blit(gameover_text1,gameover_text1_rect) gameover_text2 = gameover_font.render(str(score),255)) gameover_text2_rect = gameover_text2.get_rect() gameover_text2_rect.left,gameover_text2_rect.top =(width - gameover_text2_rect.width) // 2,gameover_text1_rect.bottom + 10 screen.blit(gameover_text2,gameover_text2_rect) again_rect.left,again_rect.top = (width - again_rect.width) // 2,gameover_text2_rect.bottom + 50 screen.blit(again_image,again_rect) gameover_rect.left,gameover_rect.top = (width - again_rect.width) // 2,again_rect.bottom + 10 screen.blit(gameover_image,gameover_rect) # 如果用户按下鼠标左键 (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |