public static void ballEnterPocket(string id, PoolBall ball) { if (onBallEnterPocket != null) { onBallEnterPocket(id, ball); } }
public static void whiteBallHitBall(bool hitBall, PoolBall ball) { if (onWhiteBallHitBall != null) { onWhiteBallHitBall(hitBall, ball); } }
public void onBallEnterPocket(string pocketID, PoolBall ball) { if (GetComponent <AudioSource>()) { GetComponent <AudioSource>().PlayOneShot(onBallEnterPocketAC); } }
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); }
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); }
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); }
void onWhiteBallHitWall(bool hitBall, PoolBall ball) { //its our first hit if (hitBall == false) { handleFirstBallHitByWhiteBall(ball); } }
public void setTarget(PoolBall ball, Vector3 targetPos) { if (ball) { m_targetBall = ball; m_targetPos = targetPos; m_targetPos.y = transform.position.y; } }
//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; } }
//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(); } }
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(); }
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"); } }
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); } }
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); }
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; } } } }
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); }
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++; } }
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; } } }
void onEnterPocket(string pocketIndex, PoolBall ball) { enterPocket(ball); }
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; } } } }
public virtual bool isBallOkay(PoolBall ball) { return(true); }
//can we use the ball public virtual bool canUseBall(PoolBall ball) { return(true); }
public override bool isBallOkay(PoolBall ball) { return((ball.ballIndex) == getLowestPoolBall()); }
public virtual void handleFirstBallHitByWhiteBall(PoolBall ball) { }
public override void handleFirstBallHitByWhiteBall(PoolBall ball) { m_foul = false; }
public virtual void enterPocket(PoolBall ball) { }
public override void enterPocket(PoolBall ball) { enterPocketRPC(ball.name, m_playerTurn); }