Esempio n. 1
0
    /// <summary>
    /// Moves the piece on the local.
    /// </summary>
    /// <returns><c>true</c>, if the piece was moved, <c>false</c> otherwise.</returns>
    /// <param name="fromXIndex">From X index.</param>
    /// <param name="fromZIndex">From Z index.</param>
    /// <param name="toXIndex">To X index.</param>
    /// <param name="toZIndex">To Z index.</param>
    public bool MovePieceLocal(int fromXIndex, int fromZIndex, int toXIndex, int toZIndex, bool pFromLocal)
    {
        NavTileAgent selectedAgent = LevelArray.currentLevelArray.GetAgentInCell(fromXIndex, fromZIndex);
        NavTileAgent agent         = LevelArray.currentLevelArray.GetAgentInCell(toXIndex, toZIndex);

        if (agent == null)
        {
            selectedAgent.MoveAgentToPos(toXIndex, toZIndex);
            if (pFromLocal)
            {
                if (selectedAgent.GetComponent <Tower>())
                {
                    TowerMoves.Instance.OneTowerMoved();
                }
                GameController.Instance.OnMoveableObjectMoved();
            }
            return(true);
        }
        else
        {
            if (agent.isLocalAgent == pFromLocal)
            {
                if (selectedAgent == agent)
                {
                    if (pFromLocal)
                    {
                        GameController.Instance.OnMoveableObjectMoved();
                    }
                }
                else
                {
                    Notification.Instance.ShowNotification("Prohibited move");
                }
                return(false);
            }
            else
            {
                selectedAgent.GetComponent <GridObjectBase>().AttackTarget(agent.GetComponent <GridObjectBase>());
                if (pFromLocal)
                {
                    if (selectedAgent.GetComponent <Tower>())
                    {
                        TowerMoves.Instance.OneTowerMoved();
                    }
                    GameController.Instance.OnMoveableObjectMoved();
                }
                return(true);
            }
        }
        return(false);
    }
Esempio n. 2
0
    private IEnumerator ShowCubesForAgentMovement()
    {
        //wait for 2 frames till all cubes deactivate removed from rendering queue
        yield return(new WaitForEndOfFrame());

        yield return(new WaitForEndOfFrame());

        GridLightsController.Instance.ShowCubesForAgentAttack(selectedAgent.GetComponent <GridObjectBase>());
        //wait for 2 frames till all the attack cubes are added to the rendering queue
        yield return(new WaitForEndOfFrame());

        yield return(new WaitForEndOfFrame());

        GridLightsController.Instance.ShowCubesForAgentMovement(selectedAgent);
    }
Esempio n. 3
0
    public override void excuteState()
    {
        if (Input.GetMouseButtonDown(0))
        {
            touchStartPos  = Input.mousePosition;
            touchStartTime = Time.timeSinceLevelLoad;
        }
        if (Input.GetMouseButtonUp(0))
        {
            float timeDiffrence = Time.timeSinceLevelLoad - touchStartTime;
            //the time diffrence when we consider this a tap or swipe, otherwise do nothing
            const float TAP_SWIPE_MAX_TIME = 0.5f;
            //the max distance to consider this a tap
            const float MAX_TAP_DISTANCE = 3f;
            if (timeDiffrence <= TAP_SWIPE_MAX_TIME)
            {
                //if true, it's a tap
                if (Vector2.Distance(touchStartPos, Input.mousePosition) <= MAX_TAP_DISTANCE)
                {
                    LayerMask  gridsLayer = 1 << LayerMask.NameToLayer("BlueLightCube");
                    RaycastHit vHit       = new RaycastHit();
                    Ray        vRay       = gameCamera.ScreenPointToRay(Input.mousePosition);
                    if (Physics.Raycast(vRay, out vHit, 1000, gridsLayer))
                    {
                        Debug.Log("OK " + vHit.collider.gameObject.name);
                        NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInPos(vHit.collider.transform.position.x, vHit.collider.transform.position.z);
                        if (agent == null)
                        {
                            Notification.Instance.ShowNotification("Selected cell is empty");
                            return;
                        }

                        if (!agent.isLocalAgent)
                        {
                            Notification.Instance.ShowNotification("You may only select objects deployed by you!");
                            return;
                        }

                        if (agent.GetComponent <GridObjectBase>().IsFrozen)
                        {
                            Notification.Instance.ShowNotification("Selection is frozen!");
                            return;
                        }


                        if (agent.GetComponent <Tower>())
                        {
                            if (!TowerMoves.Instance.IsTowerMoveAllowed)
                            {
                                Notification.Instance.ShowNotification("Not enough moves!");
                                return;
                            }
                        }

                        //raise the event that a moveable object have been selected
                        GameController.Instance.OnMoveableObjectSelect(agent);
                    }
                }
            }
        }
    }