Пример #1
0
def run_game():
    # 初始化游戏并创建一个屏幕对象
    pygame.init()
    pygame.display.set_caption('Alien Invasion')

    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    ship = Ship(ai_settings, screen)
    play_button = Button(ai_settings, screen, 'Play')

    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_events(ai_settings, screen, ship, bullets, stats, play_button,
                        aliens, sb)
        if not stats.game_over:
            ship.update()
            gf.update_bullets(ai_settings, screen, bullets, aliens, ship,
                              stats, sb)
            gf.update_aliens(ai_settings, screen, aliens, bullets, ship, stats,
                             sb)
        gf.update_screen(ai_settings, screen, ship, bullets, aliens, stats,
                         play_button, sb)
Пример #2
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)

    # 创建一个用于存储子弹的编组
    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(ai_settings, screen, ship, aliens, bullets)
        gf.update_aliens(ai_settings, ship, aliens)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
        time.sleep(0.01)
Пример #3
0
def run_game():
    pygame.init()
    screen_settings = Settings()
    stats = GameStats(screen_settings)

    screen = pygame.display.set_mode(
        (screen_settings.screen_width, screen_settings.screen_height))
    ship = Ship(screen)
    pygame.display.set_caption('Alien Inv')
    screen_y = 0
    background = Background(screen_settings.bg_image, [0, 0])
    play_button = Button(screen_settings, screen, "Play")
    bullets = Group()
    enemies = Group()

    while True:  # Game Loop
        gf.check_events(
            screen_settings,
            screen,
            ship,
            bullets,
            stats,
            play_button,
            enemies,
        )
        if stats.game_active:
            ship.update()
            gf.update_bullets(bullets, enemies)
            gf.update_enemies(enemies, ship, screen_settings, stats, screen,
                              bullets)
        gf.update_screen(screen_settings, screen, ship, screen_y, background,
                         bullets, enemies, play_button, stats)
        screen_y += screen_settings.bg_speed
Пример #4
0
def run_game():
    pygame.init()
    ai_settings = Mysettings()
    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)

    while True:

        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)
        gf.update_screen(ai_settings, screen, ship, alien, bullets)
def run_game():
    """The function opens the game and creates a screen"""
    # Initialize pygame, settings, and screen object.
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.display_width, ai_settings.display_height))
    pygame.display.set_caption("Alien Invasion")

    # Make a rocket ship
    rocket_ship = RocketShip(screen, ai_settings)

    # Make a group to store bullets in.
    bullets = Group()

    # Make a group of Aliens and the fleet.
    aliens = Group()
    game_functions.create_fleet(ai_settings, screen, rocket_ship, aliens)

    # Create an instance to store game statistics.# Create an instance to store game statistics and create a scoreboard
    stats = GameStats(ai_settings)
    empty_ship = EmptyShip(ai_settings, screen)
    sb = Scoreboard(ai_settings, screen, stats)

    # Make the Play button.
    play_button = Button(ai_settings, screen)

    # Start the main loop for the game.
    while True:
        game_functions.check_events(ai_settings, screen, stats, sb,
                                    play_button, rocket_ship, aliens, bullets)

        if stats.game_active:
            rocket_ship.update()
            game_functions.update_bullets(ai_settings, screen, stats, sb,
                                          rocket_ship, aliens, bullets)
            game_functions.update_aliens(ai_settings, stats, sb, screen,
                                         rocket_ship, aliens, bullets)

        game_functions.update_screen(ai_settings, screen, stats, sb,
                                     rocket_ship, aliens, bullets, play_button,
                                     empty_ship)
Пример #6
0
def run_game():
    """Initialize game, settings and create a screen object"""
    pygame.init()
    sounds = Sounds()
    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')

    # Make a ship, a group of aliens and a group of bullets
    ship = Ship(ai_settings, screen)
    aliens = Group()
    bullets = Group()

    # Create a fleet of aliens
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # Create an instance to store the game statistics and scoreboard
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        sounds, aliens, bullets)

        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, sounds,
                              aliens, bullets)
            gf.update_aliens(ai_settings, stats, sb, screen, ship, aliens,
                             bullets)
            gf.update_screen(ai_settings, screen, sb, ship, aliens, bullets)
        else:
            gf.display_menu_screen(ai_settings, screen, play_button)
Пример #7
0
def rungame():
    # Initialize game,settings and create screen object.
    pygame.init()
    sett = Settings()
    screen = pygame.display.set_mode((sett.screen_width, sett.screen_height))
    pygame.display.set_caption("Alien Invasion")
    """"Instance initialization"""
    # Make instance of game stats.
    stats = GameStats(sett)
    # Make instance of scoreboard.
    sb = ScoreBoard(sett, screen, stats)
    # Make the play button.
    b_play = Button(sett, screen, "PLAY")

    # Make instance of ship.
    ship = Ship(sett, screen)
    # Make a group to store bullets and aliens.
    aliens = Group()
    bullets = Group()
    # Make instance of alien.
    alien = Alien(sett, screen)
    gf.create_fleet(sett, screen, ship, aliens)

    # Start the main loop for the game.
    while True:
        # Watch for keyboard and mouse events.
        gf.check_events(sett, screen, stats, sb, b_play, ship, aliens, bullets)

        if stats.game_active:
            ship.update()
            gf.update_bullets(sett, screen, stats, sb, ship, aliens, bullets)
            gf.update_aliens(sett, stats, sb, screen, ship, aliens, bullets)

        # Redraw the screen during each pass through the loop.
        gf.update_screen(sett, screen, stats, sb, ship, aliens, bullets,
                         b_play)