for bullet in hero_plane.bullet_list: for enemy_plane in enemy_plane_list: if enemy_plane.shoot_by(bullet): enemy_plane.boom = True
for enemy_plane in enemy_plane_list: for bullet in enemy_plane.bullet_list: if hero_plane.shoot_by(bullet): hero_plane.boom = True if hero_plane.boom == True: gameover = pygame.image.load('image/gameover.jpg') screen.blit(gameover, (50, 300))
for enemy_plane in enemy_plane_list: enemy_plane.display()
remove_enemy_plane(screen)
# 通过键盘获取游戏事件 for event in pygame.event.get(): # 如果点击了退出按钮,则退出游戏 if event.type == QUIT: print('exit') exit()
# 判断键盘是否按下了键 elif event.type == KEYDOWN: # 如果按键是a或者是<-键,则控制飞机向左移动 if event.key == K_a or event.key == K_LEFT: hero_plane.move_left() print('left') if event.key == K_w or event.key == K_UP: hero_plane.move_up() print('up') if event.key == K_s or event.key == K_DOWN: hero_plane.move_down() print('down') # 如果按键是d或者是->键,则控制飞机向右移动 elif event.key == K_d or event.key == K_RIGHT: hero_plane.move_right() print('right') # 如果按键是Esc则停止移动 elif event.key == K_ESCAPE: hero_plane.stop() # 如果按键是空格键,则飞机发射子弹 elif event.key == K_SPACE: hero_plane.shoot() print('space')