Пример #1
0
    void BallsRewindingUpdate()
    {
        if (Time.time > rewindStartTime)
        {
            clockTime -= Time.deltaTime;
            if (clockTime < 0)
            {
                clockTime = 0;
            }

            for (int i = 0; i < balls.Count; ++i)
            {
                PoolLoopBall ball = (PoolLoopBall)balls[i];
                ball.UpdateScrubTime(clockTime);
            }

            if (clockTime == 0)
            {
                state = State.BEFORE_PREPARING_SHOT;
                for (int i = 0; i < balls.Count; ++i)
                {
                    PoolLoopBall ball = (PoolLoopBall)balls[i];
                    ball.EnterActiveState();
                }
            }
        }
    }
Пример #2
0
    void BallsActiveUpdate()
    {
        clockTime += Time.deltaTime;

        bool allSleeping = true;

        for (int i = 0; i < balls.Count; ++i)
        {
            PoolLoopBall ball     = (PoolLoopBall)balls[i];
            Rigidbody2D  ballBody = ball.gameObject.GetComponent <Rigidbody2D>();
            if (!ballBody.IsSleeping())
            {
                allSleeping = false;
                break;
            }
        }

        if (allSleeping)
        {
            state           = State.BALLS_REWINDING;
            rewindStartTime = Time.time + 1.5f;
            for (int i = 0; i < balls.Count; ++i)
            {
                PoolLoopBall ball = (PoolLoopBall)balls[i];
                ball.EnterScrubbingState();
            }
        }
    }
Пример #3
0
    void Start()
    {
        state   = State.BEFORE_PREPARING_SHOT;
        cueBall = null;

        shotCamera = GameObject.Find("ShotCamera").GetComponent <Camera>();
        poolStick  = GameObject.Find("PoolStick");

        clockTime = 0.0f;

        debugText = gameObject.GetComponentInChildren <Text>();
    }
Пример #4
0
    void EnterPreparingShotState(PoolLoopBall cueBallToHit)
    {
        cueBall = cueBallToHit;
        state   = State.PREPARING_SHOT;

        MeshRenderer poolStickRenderer = poolStick.GetComponent <MeshRenderer>();

        poolStickRenderer.enabled = true;

        cueBallScreenPosition = shotCamera.WorldToScreenPoint(cueBall.transform.position);

        shotAngle    = 0;
        shotDistance = 0.01f;
    }
Пример #5
0
 void BeforePreparingShotUpdate()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         Ray          testRay = shotCamera.ScreenPointToRay(Input.mousePosition);
         RaycastHit2D hit     = Physics2D.GetRayIntersection(testRay);
         if (hit)
         {
             PoolLoopBall ball = hit.collider.gameObject.GetComponent <PoolLoopBall>();
             if (ball != null)
             {
                 if (ball.ballName == "CueBall")
                 {
                     EnterPreparingShotState(ball);
                 }
             }
         }
     }
 }
Пример #6
0
    void EnterBallsActiveState()
    {
        state = State.BALLS_ACTIVE;
        MeshRenderer poolStickRenderer = poolStick.GetComponent <MeshRenderer>();

        poolStickRenderer.enabled = false;

        Rigidbody2D body           = cueBall.GetComponent <Rigidbody2D>();
        Vector2     forceDirection = new Vector3(-Mathf.Cos(shotAngle), -Mathf.Sin(shotAngle), 0);

        Vector2 cueBallPos2d  = new Vector2(cueBall.transform.position.x, cueBall.transform.position.y);
        Vector2 forcePosition = cueBallPos2d - forceDirection * cueBall.transform.localScale.x;

        body.AddForceAtPosition(forceDirection * Mathf.Pow(25, 1 + shotDistance), forcePosition);

        clockStart = Time.fixedTime;

        for (int i = 0; i < balls.Count; ++i)
        {
            PoolLoopBall ball = (PoolLoopBall)balls[i];
            ball.EnterActiveState();
        }
    }
Пример #7
0
 public void OnPoolLoopBallStart(PoolLoopBall ball)
 {
     balls.Add(ball);
 }