def run_game(): # Initialise game and create a screen object pygame.init() informpy_settings = settings() screen = pygame.display.set_mode((informpy_settings.screen_width, informpy_settings.screen_height)) pygame.display.set_caption("Invaders from Python") #Make play button play_button = Button(informpy_settings, screen, "Play") #Create an instance to store game stats and create scoreboard stats = GameStats(informpy_settings) sb = Scoreboard(informpy_settings, screen, stats) #Make a ship, a group of bullets and a group of bullets ship = Ship(informpy_settings, screen) bullets = Group() aliens = Group() #Create a fleet of aliens gf.create_fleet(informpy_settings, screen, ship, aliens) # Start main loop of game while True: # Watch for keyboard and mouse events: gf.check_events(informpy_settings, screen, stats, sb, play_button, ship, aliens, bullets) # Refactoring gf.update_screen(informpy_settings, screen, stats, sb, ship, aliens, bullets, play_button) if stats.game_active: ship.update() gf.update_bullets(informpy_settings, screen, stats, sb, ship, aliens, bullets) gf.update_aliens(informpy_settings, screen, stats, sb, ship, aliens, bullets)
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(ai_settings.game_title) # 设置背景图片 back_ground_image = pygame.image.load(ai_settings.image).convert() # 创建一个用于存储游戏统计信息的实例 stats = GameStats(ai_settings) # 创建一艘飞船 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) if stats.game_active: ship.update() bullets.update() gf.update_screen(ai_settings, screen, ship, back_ground_image, aliens, bullets) gf.update_bulltes(ai_settings, screen, ship, aliens, bullets) gf.update_aliens(ai_settings, stats, 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') #创建一艘飞船 ship = Ship(ai_settings, screen) #创建一个用于存储子弹的编组 bullets = Group() #创建一个外星人 群组 # alien = Alien(ai_settings,screen) #创建一个play按键 play_button = Button(ai_settings, screen, "Play") aliens = Group() gf.create_fleet(ai_settings, screen, ship, aliens) #创建一个用于存储有系统及信息的实例 stats = GameStats(ai_settings) # 开始游戏的主循环 while True: gf.check_events(ai_settings, screen, ship, 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, screen, ship, aliens, bullets, play_button)
def run_game(): # Initialise game and create a screen object pygame.init() informpy_settings = settings() screen = pygame.display.set_mode( (informpy_settings.screen_width, informpy_settings.screen_height)) pygame.display.set_caption("Invaders from Python") # Create a ship ship = Ship(informpy_settings, screen) #Make a group to store bullets in bullets = Group() # Start main loop of game while True: # Watch for keyboard and mouse events: gf.check_events(informpy_settings, screen, ship, bullets) # Refactoring ship.update() gf.update_bullets(bullets) # print(len(bullets)) #Shows that bullets are actually removed gf.update_screen(informpy_settings, screen, ship, bullets)
def run_game(): # Initialise game and create a screen object pygame.init() informpy_settings = settings() screen = pygame.display.set_mode( (informpy_settings.screen_width, informpy_settings.screen_height)) pygame.display.set_caption("Invaders from Python") # Create a ship ship = Ship(screen) # Start main loop of game while True: # Watch for keyboard and mouse events: gf.check_events() # Refactoring gf.update_screen(informpy_settings, screen, ship)
def run_game(): #Initialise game and create a screen object pygame.init() imformpy_settings = settings() screen = pygame.display.set_mode( (imformpy_settings.screen_width, imformpy_settings.screen_height)) pygame.display.set_caption("Invaders from Python") #Start main loop of game while True: #Watch for keyboard and mouse events: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() #redraw the screen during each pass through the loop screen.fill(imformpy_settings.bg_colour) #make the most recently drawn screen visable pygame.display.flip()