Пример #1
0
def run_game():
    #初始化游戏并创建一个屏幕对象
    pygame.init()
    my_setting = Settings()

    screen = pygame.display.set_mode(
        (my_setting.screen_width, my_setting.screen_height), pygame.RESIZABLE)
    pygame.display.set_caption("外星人入侵")
    ship = Ship(my_setting, screen)
    bullets = Group()

    aliens = Group()

    #开始游戏循环
    while True:
        #		start = time.clock()
        #监视键盘和鼠标事件
        gf.check_events(ship, my_setting, screen, bullets)
        ship.update()

        # print(ship.rect.centery)
        # print(ship.moving_right)
        gf.update_bullets(bullets)
        gf.create_fleet(screen, my_setting, aliens, ship)
        # screen.fill(my_setting.bg_color)
        # for bullet in bullets.sprites():
        # bullet.draw_bullet()
        # ship.blitme()
        # alien.blitme()
        #让最近绘制的屏幕可见
        #		pygame.display.flip()
        #		print(len(bullets))
        gf.screen_update(my_setting, screen, ship, bullets, aliens)
Пример #2
0
def run_game():
    ai_setting = Setting()
    screen = pygame.display.set_mode(
        (ai_setting.screen_width, ai_setting.screen_height))
    pygame.display.set_caption('Alien Invasi   on')
    ship = Ship(screen)
    bullets = Group()
    aliens = Group()
    gf.create_alien_fleet(ai_setting, aliens, screen)
    stats = GameStats(ai_setting)
    play_botton = Botton(screen, 'Play')
    sb = ScoreBoard(screen, ai_setting, stats)

    while True:
        screen.fill(ai_setting.bg_color)
        gf.check_events(ship, bullets, screen, ai_setting, play_botton, stats,
                        aliens, sb)

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

        gf.screen_update(screen, ai_setting, ship, bullets, aliens,
                         play_botton, stats, sb)
Пример #3
0
def run_game():
    # initialize game and create a screen object
    pygame.init()
    f_settings = Setting()
    screen = pygame.display.set_mode((f_settings.screen_width, f_settings.screen_height))
    pygame.display.set_caption("Alien Attack!")
    # Make a fighter, a group of bullets and a group of aliens
    fighter = Fighter(f_settings, screen)
    aliens = Group()
    bullets = Group()

    # Create play button
    play_button = Button(f_settings, screen, "Play")

    # Create an instance to store game stats
    stats = GamesStats(f_settings)

    # Create the fleet of aliens
    gf.create_fleet(f_settings, screen, aliens, fighter)

    # Create scoreboard
    sb = Scoreboard(f_settings, screen, stats, fighter)

    # Start the main loop for the game.
    while True:
        gf.check_events(f_settings, screen, aliens, fighter, bullets, play_button, stats, sb)
        if stats.game_active:
            fighter.position()
            gf.update_bullets(f_settings, screen, stats, fighter, bullets, aliens, sb)
            gf.update_aliens(f_settings, screen, aliens, fighter, bullets, stats, sb)
        gf.screen_update(f_settings, screen, fighter, bullets, aliens, stats, play_button, sb)
Пример #4
0
def run_game():
    pygame.init()
    setting=Setting()
    screen=pygame.display.set_mode((setting.screen_w, setting.screen_h))
    pygame.display.set_caption("Alien War!")
    ship=Ship(screen)
    alien=Alien(screen,setting)
    bullets=Group()
    while True:
        game_f.check_event(ship,screen,setting,bullets)
        for bullet in bullets:
            bullet.bullet_move()
            if bullet.bullet_rect.top<=0:
                bullets.remove(bullet)
        game_f.screen_update(setting,screen,ship,bullets,alien)
def run_game():
    # pygame初始化
    pygame.init()
    ai_setting = Setting()
    screen = pygame.display.set_mode(ai_setting.window_size)

    gf.game_init(screen, ai_setting)
    ship = Ship(screen, ai_setting)
    bullets = Group()
    while True:
        # 监测鼠标键盘操作
        gf.check_event(screen, ai_setting, ship, bullets)
        # 更新飞船位置
        ship.update()
        gf.bullets_update(bullets)
        # 重绘屏幕
        gf.screen_update(screen, ai_setting, ship, bullets)
Пример #6
0
def run_game():
    pygame.init()

    settings = Settings()
    screen = pygame.display.set_mode(settings.screen_mode)
    pygame.display.set_caption(settings.game_name)
    bodys = Group()
    variables = Variables(screen, settings)
    egg = Egg(screen, settings)
    play_button = Buttons("play", screen, settings)
    score = Score(settings, screen, variables)
    #set the parametre of the screen
    while True:

        gf.event_check(variables, play_button)
        if variables.game_active:
            gf.create_bodys(bodys, settings, screen, variables, score)
            bodys.update()
            gf.update_egg(bodys, variables, egg, settings, score)
        gf.screen_update(settings, screen, bodys, egg, play_button, variables,
                         score)