Exemplo n.º 1
0
 void OnMouseUp()
 {
     Dragging = false;
     if (StrigerThrow)
     {
         StrigerThrow = false;
         PhotonView.RPC("ThrowStrigerRPC", RpcTarget.All, ThrowDirection, DragLength);
         StrigerRayCast.toggleLine(false);
         StrigerMoving = true;
         GameStatusScript.getInstance().StrigerMoving = true;
     }
 }
Exemplo n.º 2
0
 void OnMouseUp()
 {
     Dragging = false;
     if (StrigerThrow)
     {
         StrigerThrow = false;
         ThrowStrigerRPC(ThrowDirection, DragLength);
         StrigerRayCast.toggleLine(false);
         StrigerMoving = true;
         GameStatusScript.getInstance().StrigerMoving = true;
     }
 }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (!photonView.IsMine)
        {
            GetComponent <Rigidbody>().position = Vector3.MoveTowards(GetComponent <Rigidbody>().position, NetworkPosition, Time.fixedDeltaTime);
            GetComponent <Rigidbody>().rotation = Quaternion.RotateTowards(GetComponent <Rigidbody>().rotation, NetworkRotation, Time.fixedDeltaTime * 100.0f);

            /* //Lag compensation
             * double timeToReachGoal = LagCurrentPacketTime - LagLastPacketTime;
             * LagCurrentTime += Time.deltaTime;
             *
             * //Update remote player
             * transform.position = Vector3.Lerp(PositionAtLastPacket, LagLatestPos, (float)(LagCurrentTime / timeToReachGoal));
             * transform.rotation = Quaternion.Lerp(RotationAtLastPacket, LagLatestRot, (float)(LagCurrentTime / timeToReachGoal));*/
        }
        if (GameStatusScript.getInstance() != null)
        {
            Turn = GameStatusScript.getInstance().Turn;
            if (!PlayersSet && GameStatusScript.getInstance().MatchStatus == MatchStatus.INGAME)
            {
                PlayerOne  = PhotonNetwork.PlayerList[0];
                PlayerTwo  = PhotonNetwork.PlayerList[1];
                PlayersSet = true;
            }
        }

        /*  if (!Input.GetMouseButtonDown(0))
         * {
         *    return;
         * }*/
        if (Turn == PlayerType.Player1)
        {
            if (PlayerOne.IsLocal)
            {
                if (GetComponent <PhotonView>().Owner != PlayerOne)
                {
                    GetComponent <PhotonView>().RequestOwnership();
                }
                if (StrigerMoving)
                {
                    StrigerMoveTime += Time.deltaTime;
                    if (StrigerMoveTime > 7)
                    {
                        PhotonView.RPC("UnfreezeAllYRPC", RpcTarget.All);
                        if (CoinController.GetInstance().AllSleeping() && GetComponent <Rigidbody>().IsSleeping())
                        {
                            StrigerMoveTime = 0;
                            StrigerMoving   = false;
                            // Toggle turn here.
                            if (GameSetupScript.GetInstance() != null)
                            {
                                //GameSetupScript.GetInstance().ToggleTurn();
                                PhotonNetwork.RaiseEvent(RaiseEventCodes.ToggleTurnEvent, null, new RaiseEventOptions()
                                {
                                    Receivers = ReceiverGroup.MasterClient
                                }, SendOptions.SendReliable);
                                GameStatusScript.getInstance().StrigerMoving = false;
                            }
                        }
                    }
                }
            }
            if (Dragging && PlayerOne.IsLocal)
            {
                Vector3 rayPoint = getRayPoint();
                if ((rayPoint.x >= -7.5 && rayPoint.x <= 7.5) && (rayPoint.z <= -10 && rayPoint.z >= -14))
                {
                    var point = rayPoint;
                    point.y            = transform.position.y;
                    point.z            = transform.position.z;
                    transform.position = point;
                    StrigerThrow       = false;

                    // Toggle Ray cast off here
                    StrigerRayCast.toggleLine(false);
                }
                if (rayPoint.z < -13)
                {
                    StrigerThrow = true;
                    // Toggle Ray cast on here
                    StrigerRayCast.toggleLine(false);
                    DragAngle  = AngleBetween(new Vector2(transform.position.x, transform.position.z), new Vector2(rayPoint.x, rayPoint.z));
                    DragLength = Vector3.Distance(transform.position, rayPoint);
                    ThrowAngle = 90 + DragAngle;
                    var x = 100 * Math.Cos(ThrowAngle * Mathf.Deg2Rad);
                    var z = 100 * Math.Sin(ThrowAngle * Mathf.Deg2Rad);
                    ThrowDirection = new Vector3((float)x, 0, (float)z);
                    Debug.DrawRay(transform.position, ThrowDirection, Color.green, 0.2f, false);
                    //  cast line
                    StrigerRayCast.castLine(transform.position, ThrowDirection);
                }
            }
        }
        else if (Turn == PlayerType.Player2)
        {
            if (PlayerTwo.IsLocal)
            {
                if (GetComponent <PhotonView>().Owner != PlayerTwo)
                {
                    GetComponent <PhotonView>().RequestOwnership();
                }
                if (StrigerMoving)
                {
                    StrigerMoveTime += Time.deltaTime;
                    if (StrigerMoveTime > 7)
                    {
                        PhotonView.RPC("UnfreezeAllYRPC", RpcTarget.All);
                        if (CoinController.GetInstance().AllSleeping() && GetComponent <Rigidbody>().IsSleeping())
                        {
                            StrigerMoveTime = 0;
                            StrigerMoving   = false;
                            GameStatusScript.getInstance().StrigerMoving = false;
                            // Toggle turn here.
                            if (GameSetupScript.GetInstance() != null)
                            {
                                PhotonNetwork.RaiseEvent(RaiseEventCodes.ToggleTurnEvent, null, new RaiseEventOptions()
                                {
                                    Receivers = ReceiverGroup.MasterClient
                                }, SendOptions.SendReliable);
                            }
                        }
                    }
                }
            }
            if (Dragging && PlayerTwo.IsLocal)
            {
                Vector3 rayPoint = getRayPoint();
                if ((rayPoint.x >= -7.5 && rayPoint.x <= 7.5) && (rayPoint.z >= 10 && rayPoint.z <= 12))
                {
                    var point = rayPoint;
                    point.y            = transform.position.y;
                    point.z            = transform.position.z;
                    transform.position = point;
                    StrigerThrow       = false;

                    // Toggle Ray cast off here
                    StrigerRayCast.toggleLine(false);
                }
                if (rayPoint.z > 12)
                {
                    StrigerThrow = true;
                    // Toggle Ray cast onn here
                    StrigerRayCast.toggleLine(true);
                    DragAngle  = AngleBetween(new Vector2(transform.position.x, transform.position.z), new Vector2(rayPoint.x, rayPoint.z));
                    DragLength = Vector3.Distance(transform.position, rayPoint);
                    ThrowAngle = DragAngle - 90;
                    var x = 100 * Math.Cos(ThrowAngle * Mathf.Deg2Rad);
                    var z = 100 * Math.Sin(ThrowAngle * Mathf.Deg2Rad);
                    ThrowDirection = new Vector3((float)x, 0, (float)z);
                    Debug.DrawRay(transform.position, ThrowDirection, Color.green, 0.2f, false);
                    //  cast line
                    StrigerRayCast.castLine(transform.position, ThrowDirection);
                }
            }
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (GameStatusScript.getInstance() != null)
        {
            Turn = GameStatusScript.getInstance().Turn;
        }
        if (Turn == PlayerType.Player1)
        {
            if (Dragging)
            {
                Vector3 rayPoint = getRayPoint();
                if ((rayPoint.x >= -7.5 && rayPoint.x <= 7.5) && (rayPoint.z <= -10 && rayPoint.z >= -14))
                {
                    var point = rayPoint;
                    point.y            = transform.position.y;
                    point.z            = transform.position.z;
                    transform.position = point;
                    StrigerThrow       = false;

                    // Toggle Ray cast off here
                    StrigerRayCast.toggleLine(false);
                }
                if (rayPoint.z < -13)
                {
                    StrigerThrow = true;
                    // Toggle Ray cast on here
                    StrigerRayCast.toggleLine(false);
                    DragAngle  = AngleBetween(new Vector2(transform.position.x, transform.position.z), new Vector2(rayPoint.x, rayPoint.z));
                    DragLength = Vector3.Distance(transform.position, rayPoint);
                    ThrowAngle = 90 + DragAngle;
                    var x = 100 * Math.Cos(ThrowAngle * Mathf.Deg2Rad);
                    var z = 100 * Math.Sin(ThrowAngle * Mathf.Deg2Rad);
                    ThrowDirection = new Vector3((float)x, 0, (float)z);
                    Debug.DrawRay(transform.position, ThrowDirection, Color.green, 0.2f, false);
                    //  cast line
                    StrigerRayCast.castLine(transform.position, ThrowDirection);
                }
            }
        }
        if (StrigerMoving)
        {
            StrigerMoveTime += Time.deltaTime;
            if (StrigerMoveTime > 7)
            {
                //Unfreeze all y here
                UnfreezeAllYRPC();
                //PhotonView.RPC("UnfreezeAllYRPC", RpcTarget.All);
                if (CoinController.GetInstance().AllSleeping() && GetComponent <Rigidbody>().IsSleeping())
                {
                    StrigerMoveTime = 0;

                    if (GameSetupSingle.GetInstance() != null)
                    {
                        // Toggle turn here
                        GameSetupSingle.GetInstance().ToggleTurn();
                        //PhotonNetwork.RaiseEvent(RaiseEventCodes.ToggleTurnEvent, null, new RaiseEventOptions() { Receivers = ReceiverGroup.MasterClient }, SendOptions.SendReliable);
                        GameStatusScript.getInstance().StrigerMoving = false;
                        StrigerMoving = false;
                    }
                }
            }
        }
    }
Exemplo n.º 5
0
    public IEnumerator ComputerMovePossibleShot()
    {
        List <PossibleShot> possibles = new List <PossibleShot>();
        double transformLocationStart = -7.5;
        double transformLocationEnd   = 7.5;

        for (double transformLocationX = transformLocationStart; transformLocationX < transformLocationEnd; transformLocationX += 0.1)
        {
            for (int theta = -10; theta > -170; theta--)
            {
                Vector3 ThrowDirection = StrigerRayCast.GetLocation(theta, 10);

                RaycastHit hit;
                //Debug.DrawRay(new Vector3((float)transformLocationX, transform.position.y, transform.position.z), ThrowDirection* 1000, Color.yellow, 20);
                // Does the ray intersect any objects excluding the player layer
                if (Physics.Raycast(new Vector3((float)transformLocationX, transform.position.y, transform.position.z), ThrowDirection * 1000, out hit, Mathf.Infinity))
                {
                    //Debug.DrawRay(transform.position, ThrowDirection.normalized * hit.distance, Color.yellow, 5);

                    PossibleShot shot = new PossibleShot
                    {
                        ThrowDirection    = ThrowDirection.normalized,
                        TransformLocation = new Vector3((float)transformLocationX, transform.position.y, transform.position.z),
                        HitCoinType       = ScoreCoinType.NOTSET,
                        HitDistance       = hit.distance
                    };
                    if (hit.collider.gameObject.transform.parent != null)
                    {
                        if (hit.collider.gameObject.transform.parent.name == "WhiteCoins")
                        {
                            shot.HitCoinType = ScoreCoinType.White;
                        }
                        if (hit.collider.gameObject.transform.parent.name == "BlackCoins")
                        {
                            shot.HitCoinType = ScoreCoinType.Black;
                        }
                    }
                    if (hit.collider.gameObject.name == "Queen")
                    {
                        shot.HitCoinType = ScoreCoinType.Queen;
                    }
                    if (shot.HitCoinType != ScoreCoinType.NOTSET)
                    {
                        possibles.Add(shot);
                    }
                }
                else
                {
                    //Debug.DrawRay(transform.position, ThrowDirection.normalized * 1000, Color.white, 15);
                }
            }
            yield return(null);
        }

        if (possibles.Count != 0)
        {
            ThrowStrigerRPC(possibles[possibles.Count / 2].ThrowDirection * possibles[possibles.Count / 2].HitDistance * 5, possibles[possibles.Count / 2].HitDistance);
            StrigerMoving = true;
        }
        yield break;
        //GetComponent<Rigidbody>().AddForce(possibles[possibles.Count/2].ThrowDirection* possibles[possibles.Count / 2].HitDistance);
    }