예제 #1
0
 public static void ballEnterPocket(string id, PoolBall ball)
 {
     if (onBallEnterPocket != null)
     {
         onBallEnterPocket(id, ball);
     }
 }
예제 #2
0
 public static void whiteBallHitBall(bool hitBall, PoolBall ball)
 {
     if (onWhiteBallHitBall != null)
     {
         onWhiteBallHitBall(hitBall, ball);
     }
 }
예제 #3
0
 public void onBallEnterPocket(string pocketID, PoolBall ball)
 {
     if (GetComponent <AudioSource>())
     {
         GetComponent <AudioSource>().PlayOneShot(onBallEnterPocketAC);
     }
 }
예제 #4
0
        public override bool isBallOkay(PoolBall ball)
        {
            bool isOkay = true;

            if (areAllBallsDown == false)
            {
                if (greaterThen8 == 0)
                {
                    isOkay = m_targetBall.ballType != PoolBall.BallType.BLACK;
                }
                if (greaterThen8 == 1)
                {
                    isOkay = m_targetBall.ballType == PoolBall.BallType.STRIPE;
                }
                else if (greaterThen8 == -1)
                {
                    isOkay = m_targetBall.ballType == PoolBall.BallType.SOLID;
                }
            }
            else
            {
                isOkay = m_targetBall.ballType == PoolBall.BallType.BLACK;
            }
            return(isOkay);
        }
예제 #5
0
        public override void enterPocket(PoolBall ball)
        {
            if (ball && ball == m_whiteBall)
            {
                m_whiteEnteredPocket = true;
            }
            else
            {
                m_totalBallsPocketed++;
                m_ballsPocketed++;
            }
            //we sunk the 8 ball
            if (ball.ballIndex == 9)
            {
                m_gameover = true;
                if (m_totalBallsPocketed == 9)
                {
                    PoolKit.BaseGameManager.gameover(m_players[m_playerTurn].playerName + " Wins!");
                }
                else
                {
                    PoolKit.BaseGameManager.gameover(m_players[m_playerTurn].playerName + " Loses!");
                }
            }


            Debug.Log("enterPocket" + ball.ballIndex + "  m_totalBallsPocketed " + m_totalBallsPocketed);
        }
예제 #6
0
        public override bool canUseBall(PoolBall ball)
        {
            bool useBall = m_greaterThen8 == 0;

            bool allBallsDown = areAllBallsDown();

            PoolBall[] balls = (PoolBall[])GameObject.FindObjectsOfType(typeof(PoolKit.PoolBall));
            if (m_greaterThen8 == 0)
            {
                useBall = ball.ballType != PoolBall.BallType.BLACK;
            }
            if (m_greaterThen8 == 1)
            {
                useBall = ball.ballType == PoolBall.BallType.STRIPE;
            }
            if (m_greaterThen8 == -1)
            {
                useBall = ball.ballType == PoolBall.BallType.SOLID;
            }
            if (m_greaterThen8 != 0 && ball.ballType == PoolBall.BallType.BLACK &&
                (allBallsDown))
            {
                useBall = true;
            }
            if (balls.Length == 2 && ball.ballType == PoolBall.BallType.BLACK)
            {
                useBall = true;
            }
            return(useBall);
        }
예제 #7
0
 void onWhiteBallHitWall(bool hitBall, PoolBall ball)
 {
     //its our first hit
     if (hitBall == false)
     {
         handleFirstBallHitByWhiteBall(ball);
     }
 }
예제 #8
0
 public void setTarget(PoolBall ball, Vector3 targetPos)
 {
     if (ball)
     {
         m_targetBall  = ball;
         m_targetPos   = targetPos;
         m_targetPos.y = transform.position.y;
     }
 }
예제 #9
0
 //a ball lands in the pocket lets gray out the texture.
 public virtual void enterPocket(PoolBall ball)
 {
     if (ball.ballType != PoolBall.BallType.WHITE)
     {
         int ballIndex = ball.ballIndex;
         ballIndex--;
         m_ballIcons[ballIndex].color = Color.gray * .2f;
     }
 }
예제 #10
0
        //our ball has landed in the water, lets call the ball bowling pit
        void OnTriggerEnter(Collider col)
        {
            PoolBall pb = col.GetComponent <PoolBall>();

            if (col.name.Contains("Ball"))
            {
                BaseGameManager.ballEnterPocket(triggerID, pb);
                pb.enterPocket();
            }
        }
예제 #11
0
        public override void Start()
        {
            base.Start();
            sphereCollider       = gameObject.GetComponent <SphereCollider>();
            ball                 = gameObject.GetComponent <PoolBall>();
            m_constraint         = gameObject.GetComponent <Constraint>();
            m_constraint.enabled = false;

            //m_cue = (PoolCue)GameObject.FindObjectOfType(typeof(PoolCue));
            stopBall();
        }
예제 #12
0
 public override void handleFirstBallHitByWhiteBall(PoolBall ball)
 {
     if (ball)
     {
         m_ballIndex = ball.ballIndex;
         Debug.Log("m_ballIndex" + m_ballIndex + " getLowesBall() + " + getLowestPoolBall());
         m_foul = m_ballIndex != getLowestPoolBall();
     }
     else
     {
         Debug.Log("NUllball");
     }
 }
예제 #13
0
        public void setTarget(PoolBall ball, Vector3 p2)
        {
            poolCueGO.SetActive(true);
            lineRenderer.SetColors(Color.green, Color.green);
            m_lr2.SetColors(Color.blue, Color.blue);
            lineRenderer.SetPosition(0, m_whiteBall.transform.position);
            lineRenderer.SetPosition(1, ball.transform.position);


            if (m_lr2)
            {
                m_lr2.gameObject.SetActive(true);
                m_lr2.SetPosition(0, ball.transform.position);
                m_lr2.SetPosition(1, p2);
            }
        }
예제 #14
0
        public Vector3 findClosestPocketToBall(PoolBall pb,
                                               ref float d0)
        {
            Vector3 rc = Vector3.zero;

            for (int j = 0; j < m_pockets.Length; j++)
            {
                float d1 = (m_pockets[j].getPosition() - pb.transform.position).magnitude;
                if (d1 < d0)
                {
                    rc = m_pockets[j].getPosition();
                    d0 = d1;
                }
            }
            return(rc);
        }
예제 #15
0
        public void findClosestBall()
        {
            float d0 = 1000000f;

            for (int i = 0; i < m_balls.Length; i++)
            {
                if (m_balls[i])
                {
                    float d1 = (m_whiteBall.transform.position - m_balls[i].transform.position).magnitude;
                    if (d1 < d0 && m_balls[i] != m_whiteBall && m_ball.pocketed == false)
                    {
                        m_targetBall = m_balls[i];
                        d0           = d1;
                    }
                }
            }
        }
예제 #16
0
        public int getNomBallsInPath(PoolBall whiteBall,
                                     PoolBall targetBall,
                                     Vector3 pocketPos,
                                     float radius)
        {
            RaycastHit[] hits  = null;
            int          count = getNomBallsInWay(whiteBall.transform.position,
                                                  targetBall.transform.position,
                                                  radius,
                                                  ref hits);

            count = getNomBallsInWay(targetBall.transform.position,
                                     pocketPos,
                                     radius,
                                     ref hits);
            return(count);
        }
예제 #17
0
        public override void enterPocket(PoolBall ball)
        {
            if (ball.ballType != PoolBall.BallType.WHITE)
            {
                if (ball.ballType != PoolBall.BallType.BLACK)
                {
                    int ballIndex = ball.ballIndex;

                    bool greater8 = (ballIndex > 8);
                    if (m_setEvenOdd == false)
                    {
                        setEvenOdd(greater8);
                        m_setEvenOdd = true;
                    }
                }
                base.enterPocket(ball);
            }
        }
        void enterPocketRPC(string name, int playerTurn)
        {
            m_playerTurn = playerTurn;
            GameObject go   = GameObject.Find(name);
            PoolBall   ball = null;

            if (go)
            {
                ball = go.GetComponent <PoolBall>();
            }


            //we sunk the 8 ball
            if (ball &&
                ball.ballType == PoolBall.BallType.BLACK)
            {
                m_gameover = true;

                //we got all the balls down.
                if (m_players[m_playerTurn].areAllBallsDown() == false)
                {
                    PoolKit.BaseGameManager.gameover(m_players[m_playerTurn].playerName + " Loses!");
                }
                else
                {
                    PoolKit.BaseGameManager.gameover(m_players[m_playerTurn].playerName + " Wins!");
                }
            }

            if (ball && ball == m_whiteBall)
            {
                m_whiteEnteredPocket = true;
            }
            else if (ball && ball.pocketed == false)
            {
                m_ballsPocketed++;
            }
        }
예제 #19
0
        public override void OnCollisionEnter(Collision col)
        {
            float vel = Mathf.Max(GetComponent <Rigidbody>().velocity.x, GetComponent <Rigidbody>().velocity.z);

            if (col.gameObject.name.Contains("Ball"))
            {
                PoolBall ball = col.gameObject.GetComponent <PoolBall>();
//				Debug.Log ("whiteBallHit"+ ball.name + m_hitBall);

                if (ball && m_hitBall == false)
                {
                    PoolKit.BaseGameManager.whiteBallHitBall(m_hitBall, ball);
                    m_hitBall = true;
                }
                //we hit our target, lets set it to the target position
                if (ball && ball == m_targetBall)
                {
                    PoolKit.BaseGameManager.ballHitBall(GetComponent <Rigidbody>().velocity);
                    m_targetBall.pointAtTarget(m_targetPos);
                    m_targetBall = null;
                }
            }
        }
예제 #20
0
 void onEnterPocket(string pocketIndex, PoolBall ball)
 {
     enterPocket(ball);
 }
예제 #21
0
        void handleRotate()
        {
            if (m_whiteBall && m_whiteBall.sphereCollider)
            {
                poolCueGO.SetActive(true);
                SphereCollider sc  = m_whiteBall.sphereCollider;
                Ray            ray = new Ray(m_whiteBall.transform.position + new Vector3(0, sc.radius * ballScalarRadius, 0), sc.transform.forward);
                RaycastHit     rch;
                if (Physics.SphereCast(ray, sc.radius * ballScalarRadius, out rch, 1000f, layerMask.value))
                {
                    Vector3 pos = rch.point;
                    lineRenderer.SetPosition(0, m_whiteBall.transform.position);
                    float radius = sc.radius * ballScalarRadius;

                    Vector3 vec = pos - sc.transform.position;

                    pos = sc.transform.position + vec.normalized * (vec.magnitude - radius);

                    if (lineRenderer)
                    {
                        lineRenderer.SetPosition(1, pos);
                    }
                    Vector3 nrm = rch.normal;
                    nrm.y = 0;
                    if (m_lr2)
                    {
                        m_lr2.gameObject.SetActive(false);
                    }
                    m_targetBall = null;


                    lineRenderer.SetColors(Color.yellow, Color.yellow);


                    if (rch.collider.name.Contains("Ball"))
                    {
                        m_targetBall = rch.collider.GetComponent <PoolBall>();
                        bool isOkay = isBallOkay(m_targetBall);

                        if (isOkay)
                        {
                            lineRenderer.SetColors(Color.green, Color.green);
                            m_lr2.SetColors(Color.blue, Color.blue);
                        }
                        else
                        {
                            lineRenderer.SetColors(Color.red, Color.red);
                            m_lr2.SetColors(Color.magenta, Color.magenta);
                        }
                        if (m_lr2)
                        {
                            m_lr2.gameObject.SetActive(true);
                        }
                        Vector3 otherBallPos = rch.point;

                        Vector3 incomingVec = rch.point - sc.transform.position;
                        Vector3 reflectVec  = Vector3.Reflect(-incomingVec, rch.normal);
                        Debug.DrawLine(sc.transform.position, rch.point, Color.red);
                        Debug.DrawRay(rch.point, reflectVec, Color.green);


                        Vector3 dir = Vector3.Reflect(m_whiteBall.transform.forward, nrm).normalized;
                        m_lr2.SetPosition(0, rch.point);

                        Vector3 mirrorPos = rch.point + Quaternion.AngleAxis(angleReflect, Vector3.up) * dir.normalized * reflectDistance;
                        m_lr2.SetPosition(1, mirrorPos);

                        m_targetPos = mirrorPos;

                        mirrorPos = pos - Quaternion.AngleAxis(angleReflect, Vector3.up) * dir.normalized * reflectDistance;
                    }
                }
            }
        }
예제 #22
0
 public virtual bool isBallOkay(PoolBall ball)
 {
     return(true);
 }
예제 #23
0
 //can we use the ball
 public virtual bool canUseBall(PoolBall ball)
 {
     return(true);
 }
예제 #24
0
 public override bool isBallOkay(PoolBall ball)
 {
     return((ball.ballIndex) == getLowestPoolBall());
 }
예제 #25
0
 public virtual void handleFirstBallHitByWhiteBall(PoolBall ball)
 {
 }
 public override void handleFirstBallHitByWhiteBall(PoolBall ball)
 {
     m_foul = false;
 }
예제 #27
0
 public virtual void enterPocket(PoolBall ball)
 {
 }
 public override void enterPocket(PoolBall ball)
 {
     enterPocketRPC(ball.name, m_playerTurn);
 }