def game(): pygame.init() ai_setting = Setting() screen = pygame.display.set_mode( (ai_setting.screen_width, ai_setting.screen_height)) pygame.display.set_caption('Alien invasion') play_button = Button(ai_setting, screen, "Play") stats = GameStats(ai_setting) sb = Scoreboard(ai_setting, screen, stats) bg_color = (220, 220, 220) alian = Alian(ai_setting, screen) ship = Ship(screen, ai_setting) bullets = Group() alians = Group() gf.create_fleet(ai_setting, screen, ship, alians) while True: gf.check_event(ai_setting, screen, stats, sb, play_button, ship, alians, bullets) gf.screen(ai_setting, screen, stats, sb, ship, bullets, alians, play_button) if stats.game_active: ship.update() gf.update_bullets(ai_setting, screen, stats, sb, ship, alians, bullets) gf.update_alians(ai_setting, screen, stats, sb, ship, alians, bullets) pygame.display.flip() gf.screen(ai_setting, screen, stats, sb, ship, bullets, alians, play_button)
def run_game(): # 初始化游戏并创建一个屏幕对象 pygame.init() ai_setting = Settings() screen = pygame.display.set_mode( (ai_setting.screen_width, ai_setting.screen_height)) pygame.display.set_caption("Alien Invasion") # 创建Play按钮 play_button = Button(ai_setting, screen, 'Play') # 创建一个用于存储游戏统计信息的实例 stats = GameStats(ai_setting) # 创建一艘飞船 ship = Ship(ai_setting, screen) # 创建一个用于存储子弹的编组 bullets = Group() # 创建一群外星人 aliens = Group() # 创建外星人群 gf.create_fleet(ai_setting, screen, ship, aliens) # 开始游戏的主循环 while True: # 监视键盘和鼠标事件 gf.check_events(ai_setting, screen, stats, play_button, ship, aliens, bullets) if stats.game_active: ship.update() gf.update_bullets(ai_setting, screen, ship, aliens, bullets) gf.update_aliens(ai_setting, stats, screen, ship, aliens, bullets) # 每次循环时都会重绘屏幕 gf.update_screen(ai_setting, screen, stats, ship, aliens, bullets, play_button)
def 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_button = Button(ai_settings, screen, "Play") stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) ship = Ship(ai_settings, screen) aliens = Group() #创建外星人编组 bullets = Group() #创建子弹编组 gf.create_fleet(ai_settings, screen, ship, aliens) while True: gf.check_events(ai_settings, screen, stats, sb, 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, screen, stats, sb, ship, aliens, bullets) #更新外星人 gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button) #更新屏幕
def run_game(): #初始化 pygame.init() ai_setting = Setting() screen = pygame.display.set_mode( (ai_setting.screen_width, ai_setting.screen_hight)) #创建窗口 ship = Ship(ai_setting, screen) #实例化飞船 stats = Gamestats(ai_setting) #统计信息 sb = Scoreboard(ai_setting, screen, stats) #scoreboard记分牌 bullets = Group() #创建子弹的一个列表 aliens = Group() #同上 gf.create_fleet(ai_setting, screen, ship, aliens) play_button = Button(ai_setting, screen, "Play") # 检测操作->game_function while True: gf.check_event(ai_setting, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() gf.update_bullets(ai_setting, screen, stats, sb, ship, aliens, bullets) gf.update_aliens(ai_setting, screen, stats, sb, ship, aliens, bullets) gf.upgrade_screen(ai_setting, screen, stats, sb, ship, aliens, bullets, play_button) #更新屏幕函数
def run_game(): pygame.init() ai_setting = Setting() screen = pygame.display.set_mode( (ai_setting.screen_width, ai_setting.screen_height)) pygame.display.set_caption('MO') ship = Ship(screen, ai_setting) bullets = Group() aliens = Group() gf.create_aliens(ai_setting, screen, aliens, ship) stats = GameStats(ai_setting) score = Scoreboard(ai_setting, screen, stats) play_button = Button(ai_setting, screen, 'PLAY') while True: gf.check_event(ai_setting, screen, ship, bullets, stats, play_button, score) if stats.game_active: ship.update() gf.update_bullets(ai_setting, screen, ship, aliens, bullets, stats, score) gf.update_aliens(ai_setting, screen, ship, aliens, bullets, stats, score) gf.update_screen(ai_setting, screen, ship, aliens, bullets, stats, play_button, score)
def run_game(): #初始化游戏并创建一个屏幕对象 pygame.init() my_setting = Settings() screen = pygame.display.set_mode( (my_setting.screen_width, my_setting.screen_height), pygame.RESIZABLE) pygame.display.set_caption("外星人入侵") ship = Ship(my_setting, screen) bullets = Group() aliens = Group() #开始游戏循环 while True: # start = time.clock() #监视键盘和鼠标事件 gf.check_events(ship, my_setting, screen, bullets) ship.update() # print(ship.rect.centery) # print(ship.moving_right) gf.update_bullets(bullets) gf.create_fleet(screen, my_setting, aliens, ship) # screen.fill(my_setting.bg_color) # for bullet in bullets.sprites(): # bullet.draw_bullet() # ship.blitme() # alien.blitme() #让最近绘制的屏幕可见 # pygame.display.flip() # print(len(bullets)) gf.screen_update(my_setting, screen, ship, bullets, aliens)
def 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") # Создание экземпляра для хранения игровой статистики. stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) play_button = Button(ai_settings, screen, "Play") 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, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() # bullets.update() gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets) gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets) gf.update_screen( ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def 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") #创建一个用于存储游戏统计信息的实例 stats=GameStats(ai_settings) #创建一艘飞船,一个子弹编组和一个外星人编组 ship=Ship(screen,ai_settings) bullets=Group() aliens=Group() #创建外星人群 gf.creat_fleet(ai_settings,screen,ship,aliens) #开始游戏的主循环 while True: gf.check_events(ai_settings,screen,ship,bullets) ship.update() gf.update_bullets(ai_settings,screen,ship,aliens,bullets) gf.update_aliens(ai_settings,stats,screen,ship,aliens,bullets) gf.update_screen(ai_settings,screen,ship,aliens,bullets)
def run_game(): pygame.init() ai_setting = Settings() screen = pygame.display.set_mode( (ai_setting.screen_width, ai_setting.screen_height)) pygame.display.set_caption("Alien Invasion") player1 = Player1(ai_setting, screen) bullets = Group() aliens = Group() gf.create_fleet(ai_setting, screen, player1, aliens) stats = GameStats(ai_setting) gf.load_high_score(ai_setting, stats) sb = Scoreboard(ai_setting, screen, stats) play_button = Button(ai_setting, screen, 'Play') # Запуск основного цикла while True: gf.check_events(ai_setting, screen, stats, sb, player1, aliens, bullets, play_button) gf.update_screen(ai_setting, screen, sb, stats, player1, aliens, bullets, play_button) if stats.game_active: player1.update() gf.update_bullets(ai_setting, screen, stats, sb, player1, aliens, bullets) gf.update_aliens(ai_setting, stats, sb, screen, player1, aliens, bullets)
def run_game(): pygame.init() ai_settings = Settings() screen_size = (ai_settings.screen_width, ai_settings.screen_height) screen = pygame.display.set_mode(screen_size) pygame.display.set_caption("Alien Invasion") play_button = Button(ai_settings, screen, "Play") stats = GameStats(ai_settings) ship = Ship(ai_settings, screen) bullets = Group() aliens = Group() # Alien(ai_settings, screen) # 创建外星人群 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, ship, aliens, bullets) gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets) gf.update_screen(ai_settings, stats, screen, ship, aliens, bullets, play_button)
def 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") # 创建一艘飞船 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, ship, bullets) ship.update() gf.update_bullets(bullets) # 每次循环时都重绘屏幕 gf.update_screen(ai_settings, screen, ship, bullets, aliens)
def run_game(): #Initialize pygame,settings, and screen object pygame.display.init() ai_settings = Settings() print ai_settings.screen_height print ai_settings.screen_width screen = pygame.display.set_mode( (ai_settings.screen_height, ai_settings.screen_width)) pygame.display.set_caption("Alien Invasion") #Make a ship, a group of bullets and a group of aliens ship = Ship(ai_settings, screen) bullets = Group() aliens = Group() #Create the fleet of aliens gf.create_fleet(ai_settings, screen, aliens) #Start the main loop for the game while True: gf.check_events(ai_settings, screen, ship, bullets) ship.update() gf.update_bullets(bullets) gf.update_screen(ai_settings, screen, ship, aliens, bullets) #Make the most recently drawn screen visible pygame.display.flip()
def run_game(): # 初始化pygame、设置和屏幕对象 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, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets) # print(len(bullets)) gf.update_aliens(ai_settings, stats, screen, sb, ship, aliens, bullets) gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def run_game(): # 初始化游戏,并创建一个屏幕对象 pygame.init() ai_settings = Setting() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Alien Invasion") ship = Ship(ai_settings, screen) bullets = Group() aliens = Group() gf.create_fleet(ai_settings, screen, aliens) # 设置背景色 bg_color = (230, 230, 230) # 开始游戏的主循环 while True: # 监视键盘和鼠标事件 gf.check_events(ai_settings, screen, ship, bullets) ship.update() gf.update_bullets(bullets) gf.update_screen(ai_settings, screen, ship, aliens, bullets)
def run_game(): #初始化游戏并且创建一个游戏对象 pygame.init() #初始化屏幕宽高颜色 ai_setting = Settings() screen =pygame.display.set_mode((ai_setting.screen_width,ai_setting.screen_width)) pygame.display.set_caption("Alien Invasion") #创建play按钮 play_button = Button(ai_setting,screen,"Play") stats = GameStats(ai_setting) # bg_color = {230,230,230} #创建一个ship的实例,在while前面,避免创建很多飞船 ship = Ship(ai_setting,screen) #创建一个用于存储子弹的编组 bullets = Group() aliens = Group() gf.create_fleet(ai_setting,screen,ship,aliens) alien = Alien(ai_setting,screen) pygame.display.flip() #开始游戏的主循环 while True: #监听键盘和鼠标事件 gf.check_events(ai_setting,screen,stats,play_button,ship,aliens,bullets) if stats.game_active: ship.update() gf.update_bullets(ai_setting,screen,ship,aliens,bullets) gf.update_aliens(ai_setting,stats,screen,ship,aliens,bullets) gf.update_screen(ai_setting,screen,stats,ship,aliens,bullets,play_button)
def 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") stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) #Play按钮 play_button = Button(ai_settings, screen, "Play") #创建一艘飞船 ship = Ship(ai_settings, screen) #创建用于存储子弹的编组 bullets = Group() #创建一个外星人编组 aliens = Group() gf.creat_fleet(ai_settings, screen, ship, aliens) #游戏主循环 while True: gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets) #监视键盘和鼠标事件 if stats.game_active: ship.update() gf.update_bullets(ai_settings, stats, sb, screen, ship, aliens, bullets) gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets) gf.update_screen(ai_settings, screen, sb, stats, ship, aliens, bullets, play_button) #更新屏幕
def run_game(): pygame.init() ai_settings = Settings() stats = GameStats(ai_settings) screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) sb = Scoreboard(ai_settings, screen, stats) pygame.display.set_caption("Alien") ship = Ship(ai_settings, screen) bullets = Group() alien = Alien(ai_settings, screen) aliens = Group() gf.creat_fleet(ai_settings, screen, ship, aliens) play_button = Button(ai_settings, screen, "Go") while True: gf.check_events(ai_settings, screen, stats, sb, 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, screen, stats, sb, ship, aliens, bullets) gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def run_game(): # 初始化游戏 pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Fight") #创建一个存储游戏信息的实例 state = GameState(ai_settings) #创建飞机 plane = Plane(screen, ai_settings) bullets = Group() enemiesB = Group() enemiesG = Group() enemiesR = Group() # 开始游戏的主循环 while True: # 监视键鼠 gf.check_events(plane) if state.game_active: # 每次循环都重绘屏幕 gf.update_screen(ai_settings, screen, plane, enemiesB, enemiesG, enemiesR, bullets) plane.update() gf.update_bullets(bullets, enemiesB, enemiesG, enemiesR) gf.update_enemy(ai_settings, plane, enemiesB, enemiesG, enemiesR, bullets, state, screen)
def run_game(): # Initialize game and create screen object pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Alien Invasion") # Start backgound music ai_settings.set_music_background() # Make a ship, a group of bullets, and a group of aliens. ship = Ship(ai_settings, screen) bullets = Group() aliens = Group() # Create a fleet of aliens. gf.create_fleet(ai_settings, screen, ship, aliens) # Start the main loop for the game. while True: gf.check_events(ai_settings, screen, ship, bullets) ship.update() gf.update_bullets(bullets) gf.update_screen(ai_settings, screen, ship, aliens, bullets)
def run_game(): # init game and create a screen pygame.init() # create game settings object settings = Settings() screen = pygame.display.set_mode( (settings.screen_width, settings.screen_height)) pygame.display.set_caption("Alien Invation") # create a ship object ship = Ship(settings, screen) # create group of bullets bullets = Group() # create a group of aliens aliens = Group() # create fleet gf.create_fleet(settings, screen, aliens) # start the main loop for the game while True: # watch for keyboard event and mouse event gf.check_events(settings, screen, ship, bullets) # update ship position ship.update() # update bullets gf.update_bullets(bullets) # update screen gf.update_screen(settings, screen, ship, aliens, bullets)
def run_game(): #pygame init pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) #set title pygame.display.set_caption("Alien Invasion") #创建一个飞船,一个用于存储子弹的编组,一个用于存储外星人的编组 ship = Ship(ai_settings, screen) bullets = Group() aliens = Group() #创建外星人群 gf.create_fleet(ai_settings, screen, aliens) #cycle for game while True: gf.check_events(ai_settings, screen, ship, bullets) ship.update() bullets.update() gf.update_bullets(bullets) gf.update_screen(ai_settings, screen, ship, aliens, bullets)
def 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) #创建一艘飞船 ship = Ship(ai_settings, screen) #创建一个用于存储子弹的编组 bullets = Group() #创建一个外星人编组 aliens = Group() #创建外星人群 gf.create_fleet(ai_settings, screen, ship, aliens) #创建存储游戏统计信息的实例,并创建几分牌 sb = Scoreboard(ai_settings, screen, stats) while True: gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() gf.update_bullets(ai_settings, screen, stats, sb, ship, bullets, aliens) gf.update_aliens(ai_settings, stats, sb, screen, ship, bullets, aliens) gf.update_screen(ai_settings, stats, screen, ship, bullets, aliens, play_button, sb)
def 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") # Создание корабля, группы пуль и группы пришельцев ship = Ship(ai_settings, screen) bullets = Group() aliens = Group() # Созданиефлота пришельцев. gf.create_fleet(ai_settings, screen, ship, aliens) stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) play_button = Button(ai_settings, screen, "Play") # Создание пришельца #alien = Alien(ai_settings, screen) # Запуск основного цикла игры while True: # Отслеживание событий клавиатуры и мыши gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() bullets.update() gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets) gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets) gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def main(): pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) #,RESIZABLE) pygame.display.set_caption("Alien Invasion") play_button = Button(ai_settings, screen, "Play") stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) ship = Ship(ai_settings, screen) moon = Moon(ai_settings, screen) earth = Earth(ai_settings, screen) stars = Group() bullets = Group() aliens = Group() gf.create_fleet(ai_settings, screen, ship, aliens) gf.create_multilayer_star(ai_settings, screen, stars) while True: gf.check_events(ai_settings, screen, stats, sb, 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, sb, screen, ship, aliens, bullets) stats.update_highscore() gf.update_screen(ai_settings, screen, stats, stars, sb, [moon, earth], [ship], play_button, aliens, bullets)
def run_game(): #初始化游戏并创建一个屏幕对象 pygame.init() #初始化背景设置,让pygame能够正确的工作 alien_settings = Settings() screen = pygame.display.set_mode((alien_settings.screen_width,alien_settings.screen_height)) #创建显示窗口,实参(1200,800)是一个元组,指定窗口的显示尺寸 pygame.display.set_caption("小飞船大战外星人") #创建Play按钮 play_button = Button(alien_settings,screen,"Play") #创建存储游戏统计信息的实例,并创建记分牌 stats = GameStats(alien_settings) sb = Scoreboard(alien_settings,screen,stats) #创建一艘飞船、一个用于存储子弹的编组、一个外星人编组 ship = Ship(screen,alien_settings) bullets = Group() aliens = Group() #创建外星人群 game_function.create_aliens_group(alien_settings,screen,aliens,ship) #开始游戏的循环 while True: game_function.check_events(alien_settings,screen,stats,play_button,ship,aliens,bullets,sb) if stats.game_active: ship.update() game_function.update_bullets(alien_settings,screen,ship,aliens,bullets,stats,sb) game_function.update_aliens(alien_settings,stats,screen,ship,aliens,bullets,sb) game_function.update_screen(alien_settings,screen,ship,bullets,aliens,stats,play_button,sb)
def run_game(): #初始化Pygame,设置和屏幕对象 pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Alien Invasion") stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) #创建Play按钮 play_button = Button(ai_settings, screen, "Play") 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, sb, 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) #2 每次循 环时都重绘屏幕 gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def 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 by Mr.yang") #创建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 ,sb ,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 ,screen ,stats ,sb ,ship ,aliens ,bullets) gf.update_screen(ai_settings ,screen ,stats ,sb ,ship ,aliens, bullets ,play_button)
def 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 v1.1") ship = Ship(ai_settings, screen) bullets = Group() aliens = Group() stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) play_button = Button(ai_settings, screen, "Play") while True: gf.check_events(ai_settings, screen, ship, bullets, stats, play_button, aliens, sb) if stats.game_active: ship.update() gf.update_bullets(ai_settings, screen, bullets, aliens, ship, stats, sb) gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets, sb) gf.update_screen(ai_settings, screen, ship, bullets, aliens, play_button, stats, sb)
def run_game(): # initialize game and create a screen object pygame.init() f_settings = Setting() screen = pygame.display.set_mode((f_settings.screen_width, f_settings.screen_height)) pygame.display.set_caption("Alien Attack!") # Make a fighter, a group of bullets and a group of aliens fighter = Fighter(f_settings, screen) aliens = Group() bullets = Group() # Create play button play_button = Button(f_settings, screen, "Play") # Create an instance to store game stats stats = GamesStats(f_settings) # Create the fleet of aliens gf.create_fleet(f_settings, screen, aliens, fighter) # Create scoreboard sb = Scoreboard(f_settings, screen, stats, fighter) # Start the main loop for the game. while True: gf.check_events(f_settings, screen, aliens, fighter, bullets, play_button, stats, sb) if stats.game_active: fighter.position() gf.update_bullets(f_settings, screen, stats, fighter, bullets, aliens, sb) gf.update_aliens(f_settings, screen, aliens, fighter, bullets, stats, sb) gf.screen_update(f_settings, screen, fighter, bullets, aliens, stats, play_button, sb)
def run_game(): pg.init() sett = Settings() screen = pg.display.set_mode((sett.screen_width, sett.screen_height)) pg.display.set_caption("Super Hijacker") #创建hero hero = Hero(screen, sett) #创建存储敌机的编组 enemies = Group() #创建存储子弹的编组 #bullets[0],bullets[1],bullets[2]分别为存储hero发射的普通子弹、多核弹、导弹的编组, #bullets[3],bullets[4],bullets[5]分别为存储enemies发射的普通子弹、多核弹、导弹的编组 bullets = [] for i in range(6): bullet = Group() bullets.append(bullet) #游戏主循环 while True: gf.handle_events(sett, screen, hero, enemies, bullets) if sett.game_active: hero.update() gf.update_bullets(sett, bullets, hero, enemies) gf.update_enemies(enemies, hero) gf.update_screen(sett, screen, hero, enemies, bullets)
def run_game(): pygame.init() ai_setting = Setting() screen = pygame.display.set_mode( (ai_setting.screen_width, ai_setting.screen_height)) pygame.display.set_caption("外星人大战") ship = Ship(ai_setting, screen) # 创建存储子弹的编组 bullets = Group() #创建一个外星人 aliens = Group() gameState = GameState(ai_setting) sb = ScoreBoard(ai_setting, screen, gameState) play_button = Button(ai_setting, screen, 'Play') gf.create_fleet(ai_setting, screen, ship, aliens) while True: gf.check_events(ai_setting, gameState, aliens, screen, ship, bullets, play_button, sb) if gameState.game_active: ship.update() gf.update_bullets(ai_setting, screen, gameState, sb, ship, aliens, bullets) gf.update_aliens(ai_setting, gameState, sb, screen, ship, aliens, bullets) gf.update_screen(ai_setting, gameState, screen, ship, aliens, bullets, play_button, sb)
def run_game(): # 初始化pygame、设置和屏幕对象 pygame.init() ai_settings = Settings() # 定义类 screen = pygame.display.set_mode(( ai_settings.screen_width, ai_settings.screen_height)) # screen = pygame.display.set_mode()#创建和屏幕一样大的 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() # 创建一个外星人 alien = Alien(ai_settings, screen) gf.create_fleet(ai_settings, screen, ship, aliens) # 开始游戏的主循环 while True: gf.check_events(ai_settings, screen, stats, sb, 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, screen, stats, sb, ship, aliens, bullets) gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)