def run_game():
    pygame.init()
    ai_settings = settings.Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    #screen=pygame.display.set_mode((1200,800))
    #bg_color=(200,200,222)
    pygame.display.set_caption("alien invasion")
    ship = Ship(ai_settings, screen)
    play_button = Button(ai_settings, screen, "play")
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    #存储子弹
    bullets = Group()
    aliens = Group()

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

    #开始游戏的主循环
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        bullets, aliens)
        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)
Beispiel #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)
    alien = Alien(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()
        #bullets.update()
        gf.update_bullets(bullets)
        gf.update_aliens(ai_settings, aliens)

        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        #print(len(bullets))
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
Beispiel #3
0
def run_game():
    pygame.init()
    ai_settings = Settings
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    alien = Alien(ai_settings, screen)
    pygame.display.set_caption("Invasion2.0")
    play_button = Button(ai_settings, screen, "Play")
    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)

    # main loop
    while True:
        gf.check_events(ai_settings, screen, stats, play_button, ship, aliens,
                        bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, ship, aliens, bullets,
                              stats)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
        gf.update_screen(ai_settings, screen, stats, ship, aliens, bullets,
                         play_button, sb)
Beispiel #4
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("邓明星大战外星人!")

    bg_color = ai_settings.bg_color

    ship = Ship(ai_settings, screen)

    aliens = Group()

    bullets = Group()

    # 创建外星人群
    gf.creat_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, aliens)

        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
Beispiel #5
0
def run():
    pygame.init()
    game_settings = Settings()
    screen = pygame.display.set_mode(
        (game_settings.screen_width, game_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    play_button = Button(game_settings, screen, "Play")
    stats = GameStats(game_settings)
    sb = Scoreboard(game_settings, screen, stats)
    ship = Ship(game_settings, screen)
    bullets = Group()
    aliens = Group()
    f.create_fleet(game_settings, screen, ship, aliens)
    while True:
        f.check_events(game_settings, screen, stats, sb, play_button, ship,
                       aliens, bullets)
        if stats.game_active:
            ship.update()
            f.update_bullets(game_settings, screen, stats, sb, play_button,
                             ship, aliens, bullets)
            f.update_aliens(game_settings, stats, sb, screen, ship, aliens,
                            bullets)

        f.update_screen(game_settings, screen, stats, sb, ship, aliens,
                        bullets, play_button)
Beispiel #6
0
def run_game():
    pygame.init()
    ai_setting = setting()
    scree = pygame.display.set_mode(
        (ai_setting.screen_width, ai_setting.screen_hight))
    aliens = Group()
    ship = Ship(scree, ai_setting)
    alien = Alien(ai_setting, scree)
    gf.create_fleet(ai_setting, scree, ship, aliens)
    bullets = Group()
    pygame.display.set_caption('New game')
    stats = GameStats(ai_setting)
    sb = Scoreboard(ai_setting, scree, stats)
    play_button = Button(ai_setting, scree, "Play")

    while True:
        gf.check_events(ship, ai_setting, scree, bullets, stats, play_button,
                        aliens)
        if stats.game_active:
            ship.update()
            gf.update_aliens(ai_setting, aliens, ship, stats, bullets, scree)
            gf.update_bullet(ai_setting, scree, ship, aliens, bullets, sb,
                             stats)
        gf.update_screen(ai_setting, scree, ship, bullets, aliens, play_button,
                         stats, sb)
Beispiel #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 War")
    play_button = Button(ai_settings, screen, "Play")
    stats = GameStats(ai_settings)
    sb = ScoreBoard(ai_settings, screen, stats)
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    f.create_fleet(ai_settings, screen, ship, aliens)
    # Назначение цвета фона
    bg_color = (100, 100, 100)
    alien = Alien(ai_settings, screen)
    while True:
        f.check_events(ai_settings, screen, stats, sb, play_button, ship,
                       aliens, bullets)
        if stats.game_active:
            ship.update()
            f.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                             bullets)
            f.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                            bullets)
        f.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                        play_button)
Beispiel #8
0
def game():
    pygame.init()
    game_settings = settings.Settings()
    screen = pygame.display.set_mode(
        (game_settings.width, game_settings.height))
    pygame.display.set_caption("Space Invaders")
    play_button = play.Button(settings, screen, "Play")
    stats = statistics.GameStats(game_settings)
    scoreboard = score.Score(game_settings, screen, stats)
    player_render = ship.Ship(screen, game_settings)
    bullets = pygame.sprite.Group()
    alien_group = pygame.sprite.Group()

    functions.alien_fleet(game_settings, screen, alien_group)

    while True:
        functions.check_events(game_settings, screen, player_render, bullets,
                               play_button, stats, alien_group, scoreboard)
        if stats.game_active:
            player_render.update()
            functions.update_bullets(alien_group, bullets, screen,
                                     game_settings, scoreboard, stats)
            functions.update_aliens(game_settings, stats, player_render,
                                    alien_group, screen, bullets, scoreboard)
        functions.update_screen(game_settings, screen, player_render,
                                alien_group, bullets, play_button, stats,
                                scoreboard)
Beispiel #9
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")

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

    #创建一个用于储存游戏统计信息的实例
    stats = GameStats(ai_settings)

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

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

    #开始游戏的主循环
    while True:

        func.check_events(ai_settings, screen, stats, play_button, ship,
                          aliens, bullets)

        if stats.game_active:
            ship.update()
            #bullets.update()
            func.update_bullet(ai_settings, screen, ship, aliens, bullets)
            func.update_aliens(ai_settings, screen, stats, ship, aliens,
                               bullets)
            # #删除以消失子弹(优化主循环,将此放入function中)
            # for bullet in bullets.copy():
            #     if bullet.rect.bottom <= 0:
            #         bullets.remove(bullet)
            # print(len(bullets))

        #每次循环时都重绘屏幕
        func.update_screen(ai_settings, screen, stats, ship, bullets, aliens,
                           play_button)
Beispiel #10
0
def run_game():

    pygame.init()  # Initialize game and create a screen object.

    game_settings = Settings()  # Make it constructor.Make an instance.

    screen = pygame.display.set_mode(
        (game_settings.screen_width,
         game_settings.screen_height))  # Set screen size
    alien = Alien(game_settings, screen)  # Make Alien.
    pygame.display.set_caption("Alien Shooter")

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

    ship = Ship(screen, game_settings)  # Make a a ship.

    stats = GameStats(
        game_settings)  # Create an instance to store game statistics.

    sb = ScoreBoard(game_settings, screen, stats)
    bullets = Group()  # Make a group of bullets.
    aliens = Group()  # # Make a group of aliens.

    # Create the fleet of aliens.
    gf.create_fleet(game_settings, screen, aliens, ship)

    # Start main loop for the game.
    while True:
        # Watch Keyboard and Mouse events.
        gf.check_events(ship, game_settings, screen, bullets, play_button,
                        stats, aliens, sb)
        if stats.game_active:
            ship.update()
            gf.update_bullets(bullets, aliens, game_settings, screen, ship,
                              stats, sb)  # Updating bullets.
            gf.update_aliens(game_settings, aliens, ship, stats, screen,
                             bullets, sb)  # Update aliens.
        # Updating or loading the screen.
        gf.update_screen(game_settings, screen, ship, bullets, aliens,
                         play_button, stats, sb)
Beispiel #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")
    play_button = Button(screen, "Play", ai_settings.screen_width / 2, 300,
                         200, 50)
    reset_button = Button(screen, "Reset", ai_settings.screen_width / 2, 400,
                          200, 50)
    high_score_button = Button(screen, "High Score",
                               ai_settings.screen_width / 2, 500, 200, 50)
    pause_button = Button(screen, "Pause", 160, 30, 100, 40)
    back_button = Button(screen, "Back", 160, 30, 100, 40)
    ship = Ship(ai_settings, screen)
    Alien(ai_settings, screen)
    bullets = Group()
    alien_bullets = Group()
    arches = Group()
    # Explode(ai_settings, screen)
    explosio = Group()
    aliens = Group()  # Alien(ai_settings, screen)
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    gf.create_fleet(ai_settings, screen, ship, aliens, arches)

    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button,
                        pause_button, high_score_button, reset_button,
                        back_button, ship, aliens, bullets, arches)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets, alien_bullets, explosio, arches)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets, alien_bullets, arches)

        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         alien_bullets, play_button, pause_button,
                         high_score_button, reset_button, back_button,
                         explosio, arches)
Beispiel #12
0
def run_game():
	# 初始化游戏并创建一个屏幕对象
	pygame.init()

	# 获取配置对象
	ai_settings = Settings();

	screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
	print(screen)
	pygame.display.set_caption(ai_settings.title)


	# 创建飞船
	ship = Ship(ai_settings, screen)

	# 创建外星人
	# alien = Alien(ai_settings, screen)

	# 创建一个用于存储子弹的组
	bullets = Group()
	aliens = Group()

	# 创建外星人群
	funcs.create_alien_fleet(ai_settings, screen, aliens)


	#开始游戏主体
	while True:
		
		funcs.check_events(ai_settings, screen, ship, bullets)

		# 更新飞船绘制
		ship.update()

		funcs.update_bullets(bullets, aliens)

		funcs.update_aliens(ai_settings, aliens)

		# 绘制屏幕
		funcs.update_screen(ai_settings, screen, ship, bullets, aliens)
def run_game():
    """ Initialize game and create a screen object."""
    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 a ship
    ship = Ship(ai_settings, screen)
    #Make a group to store bullets in
    bullets = Group()
    aliens = Group()
    #Make an alien
    gf.create_fleet(ai_settings, screen, ship, aliens)
    # Start the main loop for the game.
    while True:
        # Watch for keyboard and mouse events.
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)
        gf.update_aliens(ai_settings, aliens)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
Beispiel #14
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("外星人")

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

    # 创建外星人
    alien = Alien(ai_settings, screen)

    # 创建一艘飞船
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

    # 创建用于储存数据的实例
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

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

    # 开始游戏的主循环
    while True:
        fun.check_events(ai_settings, screen, stats, play_button, ship, aliens,
                         bullets)
        if stats.game:
            ship.update()
            fun.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                               bullets)
            fun.update_aliens(ai_settings, stats, screen, ship, aliens,
                              bullets)
        fun.update_screen(ai_settings, screen, stats, sb, ship, aliens,
                          bullets, play_button)
def run_game():
        #Initialze and create a screen object
        pygame.init()
        ai_set = Settings()
        screen = pygame.display.set_mode((ai_set.screen_width, ai_set.screen_height))
        pygame.display.set_caption("Alien Invasion")

        #play button
        play_button = Button(ai_set, screen, "PLAY")

        #create game stats
        stats = GameStats(ai_set)
        sb = Scoreboard(ai_set, screen, stats)

        #create the Ship
        ship = Ship(ai_set, screen)
        bullets = Group()
        #alien group
        aliens = Group()

        # setting background color
        bg_color = (26, 48, 85)

        #make an alien
        # alien = Alien(ai_set, screen)
        #make fleet of aliens
        fu.create_fleet(ai_set, screen, ship, aliens)

        while True:
            fu.check_events(ai_set, screen, stats, sb, play_button, ship, aliens, bullets)
            if stats.game_active:
                ship.update()
                fu.update_bullets(ai_set, screen, stats, sb, ship, aliens, bullets)
                fu.update_aliens(ai_set, stats, screen, sb, ship, aliens, bullets)
            #Redraw screen during each pass of loop
            fu.update_screen(ai_set, screen, stats, sb, ship, aliens, bullets, play_button)
Beispiel #16
0
def game_run():
    file = r'activation.mp3'
    # Initialize
    pygame.mixer.init()
    # Load the file pf music
    pygame.mixer.music.load(file)
    pygame.mixer.music.play()

    # Initialize and create screen.
    pygame.init()
    setting = Setting()
    screen = pygame.display.set_mode(
        (setting.screen_width, setting.screen_height))
    pygame.display.set_caption("Aircraft war")

    # Create play button
    play_button = Button(setting, screen, 'Play', 200)
    help_button = Button(setting, screen, 'Help', 400)

    # Draw a rocket.
    rocket = Rocket(setting, screen)

    # Set a Group for bullets.
    bullets = Group()

    # Set a Group for alien bullets.
    alien_bullets = Group()

    # Set a Group for aliens.
    aliens = Group()

    # Create aliens.
    functions.create_aliens(setting, screen, rocket, aliens, alien_bullets)

    # Create States.
    states = States(setting)

    # Create Scoreboard.
    scoreboard = Scoreboard(setting, screen, states)

    # Create Textbox.
    textbox = Textbox(setting, screen)

    # Create Incidents.
    incidents = Group()

    # Create Background.
    BackGround = Background('background.jpg', [0, 0])

    # Main loop.
    while True:
        functions.respond_events(setting, screen, states, scoreboard, rocket,
                                 aliens, bullets, alien_bullets, play_button,
                                 help_button, textbox, incidents)
        if states.game_active:
            rocket.update_rocket()
            bullets.update(rocket)
            alien_bullets.update(setting)
            incidents.update(states)
            functions.update_bullets(setting, screen, states, scoreboard,
                                     rocket, aliens, bullets, alien_bullets)
            functions.update_aliens(setting, screen, states, scoreboard,
                                    rocket, aliens, bullets, alien_bullets,
                                    incidents)
            functions.update_alien_bullets(setting, screen, states, scoreboard,
                                           rocket, aliens, bullets,
                                           alien_bullets, incidents)
            functions.update_incidents(setting, screen, states, scoreboard,
                                       rocket, aliens, bullets, alien_bullets,
                                       incidents)
        functions.screen_update(setting, screen, states, scoreboard, rocket,
                                aliens, bullets, alien_bullets, play_button,
                                help_button, textbox, incidents)
        screen.fill([255, 255, 255])
        screen.blit(BackGround.image, BackGround.rect)