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.create_fleet(ai_settings, screen, ship, aliens) # 创建play按钮 play_button = Buttom(ai_settings, screen, "Play") # 创建记分牌 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, aliens, bullets) gf.update_aliens(ai_settings, stats, sb, screen, ship, aliens, bullets) gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def __init__(self, director, background_name, continue_scene): ''' Constructor ''' Scene.__init__(self, director, background_name) for buttom in self.common_buttoms.itervalues(): buttom.is_visible = True self.continue_scene = continue_scene self.next_btn = Buttom((config.width/2, (config.height/2 + 150)), config.b_size, 'continue_pressed'+PNG_EXT, 'continue_release'+PNG_EXT, True)
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 Invation") #创建play按钮 play_buttom = Buttom(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_buttom, 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_buttom)
def run_game(): pygame.init() screen = pygame.display.set_mode((ai_setting.screen_width, ai_setting.screen_height)) pygame.display.set_caption(ai_setting.title) bg_color = ai_setting.bg_color ship = Ship(screen, ai_setting) bullet: Group = pygame.sprite.Group() aliens = Group() state = GameState(ai_setting) gf.create_fleet(screen, aliens, ai_setting, ship) play_buttom = Buttom(screen,"Play") while True: gf.check_events(ship,ai_setting,screen,bullet,play_buttom,state,aliens) if state.game_active is True: ship.update_ship() gf.update_bullet(bullet,aliens,screen,ai_setting,ship) gf.update_aliens(aliens,ai_setting,ship,state,bullet,screen) gf.update_screen(bg_color, screen, ship, bullet, aliens,state,play_buttom)
class Sce_Winner(Scene): ''' classdocs ''' def __init__(self, director, background_name, continue_scene): ''' Constructor ''' Scene.__init__(self, director, background_name) for buttom in self.common_buttoms.itervalues(): buttom.is_visible = True self.continue_scene = continue_scene self.next_btn = Buttom((config.width/2, (config.height/2 + 150)), config.b_size, 'continue_pressed'+PNG_EXT, 'continue_release'+PNG_EXT, True) def on_update(self): self.time = self.director.time self.update() self.next_btn.updater() if self.next_btn.is_pressed: self.go_scene = self.continue_scene def on_event(self, event): self.event(event) if event.type == pygame.MOUSEMOTION: mouse_pos = pygame.mouse.get_pos() self.next_btn.mouse_over(mouse_pos) if event.type == pygame.MOUSEBUTTONUP: mouse_pos = pygame.mouse.get_pos() self.next_btn.pressed(mouse_pos) def on_draw(self, screen): self.draw(screen) self.next_btn.draw(screen)