Esempio n. 1
0
    //public IEnumerator RunToTarget (Vector3 target, bool selfRemoved, int factor)
    //{
    //    m_IsRunningToTarget = true;
    //    //m_TargetPosition = target;
    //    DelegateManager.CanHandleTouch(false);

    //    while (m_Transform.position != m_TargetPosition)
    //    {
    //        Vector3 pos = Vector3.SmoothDamp(m_Transform.position, m_TargetPosition, ref m_Velocity, Constant.SMOOTH_TIME);
    //        UpdatePositionInWorld(pos);
    //        yield return null;
    //    }

    //    m_Velocity = Vector3.zero;
    //    m_IsRunningToTarget = false;

    //    if (selfRemoved)
    //    {
    //        //Handle current and other baseobject
    //        DelegateManager.NotifyOtherObjectState(this, ObjectState.CanMoved);
    //        UpdateObjectState(ObjectState.Sleeping);
    //        UnLinkFoodAndPetIcon();

    //        //Remove this from list
    //        DelegateManager.RemoveObjectFromList(this);

    //        //Update other game stat
    //        DelegateManager.UpdateStatWithFactor(factor);
    //    }
    //    else
    //        DelegateManager.NotifyOtherObjectState(null, ObjectState.CanMoved);

    //    DelegateManager.ShouldUpdateTime(true);
    //    DelegateManager.ShouldKeepMoving(true);
    //    DelegateManager.CanHandleTouch(true);

    //    yield break;

    //}

    void UpdateGame(float deltaTime)
    {
        if (m_IsRunningToTarget)
        {
            if (m_Transform.position == m_TargetPosition)
            {
                m_IsRunningToTarget = false;

                if (m_TargetPosition == m_CachedPosition)
                {
                    DelegateManager.NotifyOtherObjectState(null, ObjectState.CanMoved);
                }

                /*else
                 *  DelegateManager.NotifyOtherObjectState(this, ObjectState.CanMoved);*/

                m_Velocity       = Vector3.zero;
                m_TargetPosition = Vector3.zero;

                /////////////////////Try to change for level uo///////////////////////
                //DelegateManager.ShouldUpdateTime(true);
                //if (m_SelfRemoved)
                //{
                //    m_SelfRemoved = false;
                //    UpdateObjectState(ObjectState.Sleeping);
                //    UnLinkFoodAndPetIcon();
                //    DelegateManager.ResetFood();
                //

                //    DelegateManager.UpdateStatWithFactor(1);
                //}

                //DelegateManager.ShouldKeepMoving(true);

                if (m_SelfRemoved)
                {
                    m_SelfRemoved = false;
                    UpdateObjectState(ObjectState.Sleeping);
                    UnLinkFoodAndPetIcon();

                    DelegateManager.RemoveObjectFromList(this);
                    DelegateManager.UpdateStatWithFactor(1);
                }
                else
                {
                    DelegateManager.ShouldUpdateTime(true);
                    DelegateManager.ShouldKeepMoving(true);
                }
                ////////////////////////////////////////////////////////////////////////////
            }
            else
            {
                Vector3 pos = Vector3.SmoothDamp(m_Transform.position, m_TargetPosition, ref m_Velocity, Constant.SMOOTH_TIME);
                UpdatePositionInWorld(pos);
            }
        }
    }
Esempio n. 2
0
 void TouchBegin(GameObject obj, Vector3 pos)
 {
     if (m_State == ObjectState.CanMoved && m_CanHandleTouch && this.gameObject == obj)
     {
         UpdateObjectState(ObjectState.Moving);
         //m_Transform.position = pos;
         UpdatePositionInWorld(pos);
         DelegateManager.NotifyOtherObjectState(this, ObjectState.None);
         DelegateManager.ShouldKeepMoving(false);
     }
 }
Esempio n. 3
0
 void OnPause(bool pausedStatus)
 {
     if (pausedStatus)
     {
         if (m_State == ObjectState.Moving)
         {
             UpdatePositionInWorld(m_CachedPosition);
             m_State = ObjectState.CanMoved;
             DelegateManager.NotifyOtherObjectState(this, ObjectState.CanMoved);
             DelegateManager.ShouldKeepMoving(true);
         }
     }
 }
Esempio n. 4
0
    public void CabllbackForHealthBar()
    {
        if (m_IsLevelUp)
        {
        }
        else
        {
            ResetFoodType();

            RefreshTime();

            m_IsActivePet = false;

            DelegateManager.ShouldKeepMoving(true);
            DelegateManager.ShouldUpdateTime(true);
            DelegateManager.NotifyOtherObjectState(null, BaseObject.ObjectState.CanMoved);
        }
    }
Esempio n. 5
0
    void OnMouseDown()
    {
        if (m_CanHandleTouch && Input.GetMouseButtonDown(0))
        {
            var input = Input.mousePosition;

            if (Constant.IsDebug)
            {
                Debug.Log("Input Position: " + input);
            }

            if (m_State == ObjectState.CanMoved)
            {
                //var worldPoint = Camera.main.ScreenToWorldPoint (input);
                var worldPoint = m_Camera.ScreenToWorldPoint(input);
                worldPoint.z = 0;

                if (Constant.IsDebug)
                {
                    Debug.Log("world point: " + worldPoint);
                }

                RaycastHit2D hit = Physics2D.Raycast(worldPoint, m_Camera.transform.forward);
                if (hit)
                {
                    GameObject obj = hit.collider.gameObject;
                    if (obj == this.gameObject)
                    {
                        //Debug.Log ("GameObject get touched with position: " + obj.transform.position);
                        UpdateObjectState(ObjectState.Moving);
                        worldPoint.z = 0;
                        //m_Transform.position = worldPoint;
                        UpdatePositionInWorld(worldPoint);
                        DelegateManager.NotifyOtherObjectState(this, ObjectState.None);
                        DelegateManager.ShouldKeepMoving(false);
                    }
                }
            }
        }
    }
Esempio n. 6
0
    void NotifyBaseObjectDeselection(BaseObject caller)
    {
        //Stop timing
        DelegateManager.ShouldUpdateTime(false);

        //Reset Animated Object
        m_AnimatedObject = null;

        // a lot of logic will be done in here
        Transform trans = caller.GetTransformation();

        if (CheckValidPosition(trans.position.x, trans.position.y))
        {
            int column = ConvertToColumnIndex(trans.position.x);
            int row    = ConvertToRowIndex(trans.position.y);

            if (Constant.IsDebug)
            {
                Debug.Log("Row index: " + row + " and Column index: " + column);
            }

            if (m_Array[row, column] == null)
            {
                m_Array[row, column] = caller;

                //Update Object in Matrix and world then freeze this object
                UpdateObjectInMatrixAndWorld(caller, row, column);
                caller.UpdateObjectState(BaseObject.ObjectState.Frozen);

                //Update matching logic
                HandleNewObject(caller);

                //Notify to remove current object and create new object in the list
                //DelegateManager.RemoveObjectFromList(caller);

                ClearBaseObjectsFromList();

                //Update other objects' state
                if (m_AnimatedObject == null)
                {
                    DelegateManager.NotifyOtherObjectState(caller, BaseObject.ObjectState.CanMoved);
                    DelegateManager.RemoveObjectFromList(caller);
                    DelegateManager.ShouldUpdateTime(true);
                }
                //else
                //{
                //    DelegateManager.MakeBaseObjectMoveToPet(m_AnimatedObject);
                //}

                //Check should refresh quests if that has been complete
                //DelegateManager.ShouldRefreshQuests();
            }
            else
            {
                //caller.SetTarget(caller.GetCachedPosition());
                //StartCoroutine(caller.RunToTarget(caller.GetCachedPosition(), false, 0));
                caller.SetUpForwardAnimation(caller.GetCachedPosition(), false);
                //caller.ReturnToCachedPosition();
                //DelegateManager.NotifyOtherObjectState(null, BaseObject.ObjectState.CanMoved);
            }
        }
        else
        {
            //caller.SetTarget(caller.GetCachedPosition());
            //StartCoroutine(caller.RunToTarget(caller.GetCachedPosition(), false, 0));
            caller.SetUpForwardAnimation(caller.GetCachedPosition(), false);
            //caller.ReturnToCachedPosition();
            //DelegateManager.NotifyOtherObjectState(null, BaseObject.ObjectState.CanMoved);
            //caller.UpdateObjectState (BaseObject.ObjectState.CanMoved);
        }

        //Check if the board is full --> broadcast endgame
        CheckBoardIsFull();
    }