python开发飞机大战外星人游戏怎么弄双人模式
1个回答
展开全部
主函数
import pygamefrom settings import Settingsfrom ship import Shipimport game_function as gffrom pygame.sprite import Groupfrom alien import Alienfrom game_stats import GameStatsfrom button import Buttonfrom scoreboard import Scoreboarddef run_game():"""初始化游戏并创建一个屏幕对象"""pygame.init()ai_settings = Settings()screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))pygame.display.set_caption("Alien Invasion")# 创建Play按钮play_button = Button(ai_settings, screen, "Play")# 创建一个用于存储游戏统计信息的实例, 并创建记分牌stats = GameStats(ai_settings)sb = Scoreboard(ai_settings, screen, stats)# 创建一艘飞船ship = Ship(ai_settings, screen)# 创建一个用于存储子弹的数组bullets = Group()aliens = Group()# 创建外星人群gf.create_fleet(ai_settings, screen, ship, aliens)# 开始游戏主循环while True:gf.check_events(ai_settings, screen, stats, play_button, ship, aliens, bullets)if stats.game_active:ship.update()gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)run_game()
import pygamefrom settings import Settingsfrom ship import Shipimport game_function as gffrom pygame.sprite import Groupfrom alien import Alienfrom game_stats import GameStatsfrom button import Buttonfrom scoreboard import Scoreboarddef run_game():"""初始化游戏并创建一个屏幕对象"""pygame.init()ai_settings = Settings()screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))pygame.display.set_caption("Alien Invasion")# 创建Play按钮play_button = Button(ai_settings, screen, "Play")# 创建一个用于存储游戏统计信息的实例, 并创建记分牌stats = GameStats(ai_settings)sb = Scoreboard(ai_settings, screen, stats)# 创建一艘飞船ship = Ship(ai_settings, screen)# 创建一个用于存储子弹的数组bullets = Group()aliens = Group()# 创建外星人群gf.create_fleet(ai_settings, screen, ship, aliens)# 开始游戏主循环while True:gf.check_events(ai_settings, screen, stats, play_button, ship, aliens, bullets)if stats.game_active:ship.update()gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)run_game()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询