Exemplo n.º 1
0
def run_game():

    pygame.init()

    bullets = Group()
    aliens = Group()

    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)
    play_button = Button(ai_settings, screen, "Play")

    ship = Ship(ai_settings, screen, bullets)

    gf.create_fleet(ai_settings, screen, ship, aliens)

    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, stats, ship, aliens, bullets,
                         play_button)
Exemplo n.º 2
0
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")

    # 创建一艘飞船,子弹,外星人的编组
    ship = Ship(screen)
    bullets = Group()
    aliens = Group()

    # 创建外星人群
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # 设置背景色
    bg_color = (230, 230, 230)

    # 开始游戏的主循环
    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, ship, aliens)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
Exemplo n.º 3
0
def run_game():
    
    #引入导入的模块
    ai_settings = Settings()
    
    #初始化游戏并创建一个屏幕对象
    pygame.init()
    screen =pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
    pygame.display.set_caption("Alien Invision") #设置标题
    # bg_color = ai_settings.bg_color #这里表示的是一个RGB色值
    
    # 创建play按钮
    play_button = Button(ai_settings,screen,'PLAY')
    
     
    ship = Ship(ai_settings,screen)
    
    
    #创建一个存储子弹的编组
    bullets = Group()
    
    #创建一个存储外星人的编组
    aliens = Group()
    
    #创建外星人群
    gf.create_fleet(ai_settings,screen,aliens,ship)
    
    
    
    #创建一个用于统计游戏存储信息的实例
    stats = GameStats(ai_settings)
    
    
    # 创建记分牌
    sb = Scoreboard(ai_settings,screen,stats)
    
    # 开始游戏的主循环
    while True:
        #监视键盘和鼠标事件
        gf.check_envents(ai_settings,screen,ship,bullets,stats,play_button,aliens,sb)
        gf.update_screen(ai_settings,screen,ship,bullets,aliens,stats,play_button,sb)

        if  stats.game_active:
            # 每次循环都调用飞船的更新方法
            ship.update() 

            gf.update_bullets(bullets,aliens,ai_settings,ship,screen,stats,sb)
            
            
            #不断地 更新外星人的位置
            
            gf.update_alien(ai_settings,aliens,ship,screen,stats,bullets,sb)
Exemplo n.º 4
0
def run():
    # Setup pygame, display and settings
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Space_Invader")
    clock = pygame.time.Clock()

    # Stats
    stats = GameStats(ai_settings)

    # Scoreboard
    sb = Scoreboard(ai_settings, screen, stats)

    # Ship, bullets, aliens, beam
    ship = Ship(ai_settings, screen)
    bullets = pygame.sprite.Group()
    aliens = pygame.sprite.Group()
    beams = pygame.sprite.Group()
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # UFO, bunker
    ufo = pygame.sprite.Group()
    bunkers = pygame.sprite.Group(create_bunker(ai_settings, screen, 0),
                                  create_bunker(ai_settings, screen, 1),
                                  create_bunker(ai_settings, screen, 2),
                                  create_bunker(ai_settings, screen, 3))

    while True:
        # fps
        clock.tick(60)
        if not stats.game_active:
            quit_game = not gf.startup(ai_settings, stats, screen)
            if quit_game:
                pygame.quit()
                break
            gf.new_game(ai_settings, screen, stats, sb, ship, aliens, beams, bullets)
        gf.check_events(ai_settings, screen, stats, ship, bullets)
        if stats.game_active:
            ship.update()
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, beams, bullets, ufo)
            gf.update_bullets_beams(ai_settings, screen, stats, sb, ship, aliens, beams, bullets, ufo)

        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, beams, bullets, bunkers, ufo)
        gf.bg_music(ai_settings, stats)
Exemplo n.º 5
0
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)

    # 创建一艘飞船、一个子弹编组和一个外星人编组
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

    # 创建外星人群
    game_fuctions.create_fleet(ai_settings, screen, ship, aliens)

    # 开始游戏主循环
    while True:
        game_fuctions.check_events(ai_settings, screen, stats, play_button,
                                   ship, bullets)
        if stats.game_active:
            ship.update()
            game_fuctions.update_bullets(ai_settings, screen, ship, aliens,
                                         bullets)
            game_fuctions.update_aliens(ai_settings, stats, screen, ship,
                                        aliens, bullets)

        game_fuctions.update_screen(ai_settings, screen, stats, ship, aliens,
                                    bullets, play_button)
Exemplo n.º 6
0
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)
    #创建一艘飞船
    ship = Ship(ai_settings, screen)
    #创建一个用于存储子弹的编组
    bullets = Group()
    #创建一个用于存储外星人的编组
    aliens = Group()

    #创建外星人群
    gf.create_fleet(ai_settings, screen, ship, aliens)

    #创建play按钮
    play_button = Button(ai_settings, screen, "Play")

    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)
Exemplo n.º 7
0
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")
    pause_button = Pause(ai_settings,screen,"Pause")
    
    # 创建一艘飞船、一个子弹编组和一个外星人编组
    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,pause_button,
            ship,aliens,bullets)
        
        if stats.game_active and not stats.pause_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,pause_button)
Exemplo n.º 8
0
def run_game():
    # Initializes the game and crete a screen obj
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    # Make the play button
    play_button = Button(ai_settings, screen, "Play")
    # Create an instances to start game stats and create Scoreboard
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    # Make a ship, a group of bullets, and a group of aliens
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    lasers = Group()
    explodes = Group()
    shields = Group()
    # Create the fleet of aliens
    gf.create_fleet(ai_settings, screen, aliens)
    gf.create_walls(ai_settings=ai_settings, screen=screen, shields=shields)
    # Start the main loop for the game
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets)
        if stats.game_active:
            ship.update()
            gf.fire_laser(ai_settings, screen, aliens, lasers)
            gf.update_laser(ai_settings=ai_settings,
                            screen=screen,
                            stats=stats,
                            sb=sb,
                            ship=ship,
                            aliens=aliens,
                            bullets=bullets,
                            lasers=lasers,
                            shields=shields)
            gf.update_bullets(ai_settings=ai_settings,
                              screen=screen,
                              stats=stats,
                              sb=sb,
                              aliens=aliens,
                              bullets=bullets,
                              explosions=explodes,
                              shields=shields)
            gf.update_aliens(ai_settings=ai_settings,
                             screen=screen,
                             stats=stats,
                             sb=sb,
                             ship=ship,
                             aliens=aliens,
                             bullets=bullets,
                             lasers=lasers,
                             explosions=explodes,
                             shields=shields)
            gf.update_explosions(explodes)

        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         lasers, play_button, explodes, shields)