python--飞机大战
发布时间:2023-02-16 14:09:11 所属栏目:Python 来源:互联网
导读:实现功能: 1:飞机的移动,发射子弹,手雷,生命值,生命条 2:敌飞机有3种形态(小,中,大)不同的飞机大小不一样,生命值不一样,爆炸动画也不一样 3:背景音乐,子弹击中敌机会发生碰撞的爆炸动画和音效 4:随机产生补给(双射子弹和全屏炸弹) 5:难度
again_rect = again_image.get_rect() gameover_image = pygame.image.load("images/gameover.png").convert_alpha() gameover_rect = gameover_image.get_rect() # 用于延迟切换 delay = 100 recorded = False clock = pygame.time.Clock() running = True while running: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == MOUSEBUTTONDOWN: if event.button == 1 and paused_rect.collidepoint(event.pos): paused = not paused if paused: pygame.time.set_timer(SUPPLY_TIME,0) pygame.mixer.music.pause() pygame.mixer.pause() else: pygame.time.set_timer(SUPPLY_TIME,20 * 1000) pygame.mixer.music.unpause() pygame.mixer.unpause() elif event.type == MOUSEMOTION: if paused_rect.collidepoint(event.pos): if paused: paused_image = resume_pressed_image else: paused_image = paused_pressed_image else: if paused: paused_image = resume_nor_image else: paused_image = paused_nor_image elif event.type == KEYDOWN: if event.key == K_SPACE: if bomb_num: bomb_num -= 1 bomb_sound.play() for each in enemies: if each.rect.bottom > 0: each.active = False elif event.type == SUPPLY_TIME: supply_sound.play() if choice([True,False]): bomb_supply.reset() else: bullet_supply.reset() elif event.type == DOUBLE_BULLTET_TIME: is_double_bullet = False pygame.time.set_timer(DOUBLE_BULLTET_TIME,0) elif event.type == INVINCIBLE_TIME: me.invincible = False pygame.time.set_timer(INVINCIBLE_TIME,0) # 根据用户得分增加难度 if level == 1 and score > 5000: level = 2 upgrade_sound.play() # 增加3架小型敌机,2架中型敌机和1架大型敌机 add_small_enemies(small_enemies,3) add_mid_enemies(mid_enemies,2) add_big_enemies(big_enemies,1) # 提升小型敌机的速度 inc_speed(target=small_enemies,inc=1) (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |