加入收藏 | 设为首页 | 会员中心 | 我要投稿 甘南站长网 (https://www.0941zz.com/)- 科技、行业物联网、开发、云计算、云管理!
当前位置: 首页 > 编程开发 > Python > 正文

python--飞机大战

发布时间:2023-02-16 14:09:11 所属栏目:Python 来源:互联网
导读:实现功能: 1:飞机的移动,发射子弹,手雷,生命值,生命条 2:敌飞机有3种形态(小,中,大)不同的飞机大小不一样,生命值不一样,爆炸动画也不一样 3:背景音乐,子弹击中敌机会发生碰撞的爆炸动画和音效 4:随机产生补给(双射子弹和全屏炸弹) 5:难度

  
          elif level == 2 and score > 30000:
              level = 3
              upgrade_sound.play()
              # 增加5架小型敌机,3架中型敌机和2架大型敌机
              add_small_enemies(small_enemies,5)
              add_mid_enemies(mid_enemies,3)
              add_big_enemies(big_enemies,2)
              # 提升小型敌机的速度
              inc_speed(target=small_enemies,inc=1)
              inc_speed(target=mid_enemies,inc=1)
  
          elif level == 3 and score > 60000:
              level = 4
              upgrade_sound.play()
              # 增加5架小型敌机,2)
  
              # 提升小型敌机的速度
              inc_speed(target=small_enemies,inc=1)
  
          elif level == 4 and score > 100000:
              level = 5
              upgrade_sound.play()
              # 增加5架小型敌机,inc=1)
              inc_speed(target=big_enemies,inc=1)
          screen.blit(background,(0,0))
  
          if life_num and not paused:
              # 检测键盘按键操作
              key_pressed = pygame.key.get_pressed()
              if key_pressed[K_w] or key_pressed[K_UP]:
                  me.moveUp()
              if key_pressed[K_s] or key_pressed[K_DOWN]:
                  me.moveDown()
              if key_pressed[K_a] or key_pressed[K_LEFT]:
                  me.moveLeft()
              if key_pressed[K_d] or key_pressed[K_RIGHT]:
                  me.moveRight()
  
              # 绘制全屏炸弹补给
              if bomb_supply.active:
                  bomb_supply.move()
                  screen.blit(bomb_supply.image,bomb_supply.rect)
                  if pygame.sprite.collide_mask(me,bomb_supply):
                      get_bomb_sound.play()
                      if bomb_num < 3:
                          bomb_num += 1
                      bomb_supply.active = False
  
              # 绘制超级子弹补给
              if bullet_supply.active:
                  bullet_supply.move()
                  screen.blit(bullet_supply.image,bullet_supply.rect)
                  if pygame.sprite.collide_mask(me,bullet_supply):
                      get_bullet_sound.play()
                      # 发射超级子弹
                      is_double_bullet = True
                      pygame.time.set_timer(DOUBLE_BULLTET_TIME,18 * 1000)
                      bullet_supply.active = False
  
              # 发射子弹
              if not(delay % 10):
                  bullet_sound.play()
                  if is_double_bullet:
                      bullets = bullet2
                      bullets[bullet2_index].reset(
                          (me.rect.centerx - 40,me.rect.centery))
                      bullets[bullet2_index +
                              1].reset((me.rect.centerx + 20,me.rect.centery))
                      bullet2_index = (bullet2_index + 2) % BULLET2_NUM
                  else:
                      bullets = bullet1
                      bullets[bullet1_index].reset((me.rect.centerx-10,me.rect.centery-10))
                      bullet1_index = (bullet1_index + 1) % BULLET1_NUM

(编辑:甘南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读