Ejemplo n.º 1
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("CXK VS Ball")
    #创建飞船
    ship=Ship(ai_settings,screen)
    #创建存储子弹的群
    bullet_always=Bullet(ai_settings,screen,ship)
    bullets=Group()
    #创建alien群
    aliens=Group()
    gf.create_aliens(ai_settings,screen,ship,aliens)
    #创建存储游戏统计信息的实例,并创建记分牌
    stats=GameStats(ai_settings)
    sb=Scoreboard(ai_settings,screen,stats)
    #创建Play按钮
    play_button=Button(ai_settings,screen,"Fighting")
    
    #开始游戏的主循环
    while True:
        gf.check_events(ai_settings,screen,stats,sb,play_button,ship,aliens,bullets,bullet_always)
        if stats.game_active:     
            Ship.update(ship)
            gf.update_bullets(ai_settings,screen,stats,sb,ship,aliens,bullets,bullet_always)
            gf.update_aliens(ai_settings,stats,screen,sb,ship,aliens,bullets)
        gf.update_screen(ai_settings,screen,stats,sb,ship,aliens,bullets,play_button)
Ejemplo 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)
Ejemplo n.º 3
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")

    #  创建一艘飞船
    ship = Ship(ai_settings, screen)
    # 创建Doraemon
    #doraemon = Doraemon(ai_settings,screen)
    # 创建背景
    background = pygame.image.load('images/doraemon.jpg').convert()
    # 创建一个存储子弹的编组
    bullets = Group()
    #  背景色
    bg_color = (ai_settings.bg_color)

    # 游戏主循环
    while True:

        gf.check_event(ai_settings, screen, ship, bullets)
        #doraemon.update()
        ship.update()
        gf.update_bullets(bullets)
        gf.update_screen(ai_settings, screen, ship, bullets, background)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
def run_game():
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("s41_blizzard invasion")
    ship = Ship(screen)
    while True:
        gf.check_events(ship)
        gf.update_screen(ai_settings, screen, ship)
        ship.update()
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
def run_game():
    ''''''
    pygame.init()
    ai_setting = Setting()
    screen = pygame.display.set_mode((ai_setting.width,ai_setting.height))
    pygame.display.set_caption('外星人大战')
    ship = Ship(ai_setting,screen)
    bullets = Group()

    while True:
        check_event(ai_setting,screen,ship,bullets)
        ship.update()
        bullets.update()
        update_screen(ai_setting,screen,ship,bullets)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
def run_game():
    """初始化游戏并创建一个窗口对象"""
    pygame.init()  # 初始化背景
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_height,
         ai_settings.screen_width))  # 创建一个显示窗口,使用实参创建一个窗口。
    pygame.display.set_caption("Alien Invasion")

    #设置北京颜色
    bg_color = (230, 230, 230)

    # 创建一艘飞船
    ship = Ship(ai_settings, screen)
    # 创建一个用于存储子弹的编组
    bullets = Group()

    while True:  # 使用while循环来循环一个事件
        # 监听键盘鼠标事件
        # for event in pygame.event.get(
        # ):  # for循环做事件的循环。pygame.event.get()所有键盘鼠标事件豆浆促使for循环运行。
        #     if event.type == pygame.QUIT:  # 在for循环中,判断如果发生窗口关闭事件,则调用sys.exit()来退出游戏。
        #         sys.exit()  # 退出时,使用sys模块退出。
        gf.check_events(ai_settings, screen, ship, bullets)

        ship.update()

        gf.update_bullets(bullets)

        # 每次循环重新绘制屏幕ÒÒ
        # screen.fill(ai_settings.bg_color)
        # ship.blitme()
        #
        # # 让最新的屏幕可见。
        # pygame.display.flip()  # 绘制一个空屏幕,并擦去旧屏幕。可以理解为刷新屏幕。
        gf.update_screen(ai_settings, screen, ship, bullets)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)