示例#1
0
    private void TryMove()
    {
        if (Constance.RUNNING == false)
        {
            return;
        }

        if (this.running == false)
        {
            return;
        }

        this.nextPosition = GetNextPosition();

        Vector2 nextPoint = BattleUtils.PositionToGrid(this.nextPosition.x, this.nextPosition.y);


        if (BattleControllor.IsMoveable(nextPoint) == false)
        {
            if (this.currentDirection != this.direction)
            {
                this.currentDirection = this.direction;

                if (this.follower != null)
                {
                    follower.SetNextPosition(this._transform.localPosition);
                }
            }
            return;
        }

        //下个格子中的物体
        ArrayList monsterList = BattleControllor.GetMonstersByPoint(nextPoint);

        if (this.position != nextPoint && monsterList.Count > 0)
        {
            //前方有障碍物 需要停止

            if (this.currentDirection != this.direction)
            {
                this.currentDirection = this.direction;

                if (this.follower != null)
                {
                    follower.SetNextPosition(this._transform.localPosition);
                }
            }

            return;
        }


        float moveDistance = Time.deltaTime * speed;

        if (this.currentDirection != this.direction)
        {
            this.currentDirection = this.direction;

            if (this.follower != null)
            {
                follower.SetNextPosition(this._transform.localPosition);
            }
        }


        Move(moveDistance);


        if (follower != null)
        {
            follower.Move(moveDistance);
        }
    }