//--需要重构
    public void ShootBall()
    {
        int             randomIndex = Random.Range(0, _RandomPlayerCells.Count);
        SGridCoordinate coor        = _RandomPlayerCells[randomIndex];
        GridInfo        theCell     = BallGrid[coor.x, coor.z];

        if (theCell.IsEmpty())
        {
            _RandomPlayerCells.RemoveAt(randomIndex);
            Vector3 worldPosition = Definition.GridToWorld(coor.x, coor.z);
            sc.Show(coor);


            GameObject      ball   = GameObject.Instantiate(Ball, Boss.transform.position, Quaternion.identity) as GameObject;
            MotionParabolic motion = ball.AddMissingComponent <MotionParabolic>();
            motion.Go(Boss.transform.position, worldPosition, 30, 10);
            motion.SetCallBack(
                delegate()
            {
                ToolAutoDestory boom = ball.AddMissingComponent <ToolAutoDestory>();
                boom.SetCallBack(delegate {
                    theCell.CleanOccupant();
                    _RandomPlayerCells.Add(coor);
                });
                boom.Do(20);
            }

                );

            //网格准备被占领.
            theCell.BeginOccupy(ball);
            ball.AddMissingComponent <BallMoveHelper>().SetAim(theCell);
        }
    }
示例#2
0
    private void _NowKick()
    {
        EDirection      curDirection = MHeroController.CurDirection();
        SGridCoordinate forwardCoor  = Definition.GetNextCoorinate(MHeroController.MCurCoordinate, curDirection);

        MissionManager.I.KickBackBall(MHeroController.MCurCoordinate, forwardCoor);
    }
示例#3
0
    static public SGridCoordinate GetNextCoorinate(SGridCoordinate curCoor, EDirection nextDir)
    {
        SGridCoordinate nextCoor = curCoor;

        switch (nextDir)
        {
        case EDirection.Left:
            nextCoor.x -= 1;
            break;

        case EDirection.Right:
            nextCoor.x += 1;
            break;

        case EDirection.Up:
            nextCoor.z += 1;
            break;

        case EDirection.Down:
            nextCoor.z -= 1;
            break;
        }

        nextCoor.MAreaType = GetAreaType(nextCoor.x, nextCoor.z);

        return(nextCoor);
    }
示例#4
0
    void Init()
    {
        //-----初始化状态机----------

        MMachine = new BehaviourStateMachine();
        HeroIdleState idleState = new HeroIdleState(gameObject);

        MMachine.AddState(idleState);
        HeroMoveState moveState = new HeroMoveState(gameObject);

        MMachine.AddState(moveState);
        HeroKickState kickState = new HeroKickState(gameObject);

        MMachine.AddState(kickState);

        //-----end----------------

        //----初始化角色位置
        MCurCoordinate = new SGridCoordinate(4, 0);
        Vector3 heroPosition = Definition.GridToWorld(MCurCoordinate.x, MCurCoordinate.z);

        //heroPosition.y += MHeroHeight / 2f;
        transform.position = heroPosition;

        //---------------------
    }
示例#5
0
    public void Show(SGridCoordinate coor)
    {
        Vector3    showPosition = Definition.GridToWorld(coor.x, coor.z);
        GameObject theShow      = GameObject.Instantiate(PreShowBox, showPosition, Quaternion.identity) as GameObject;

        theShow.transform.localEulerAngles = new Vector3(90, 0, 0);
        theShow.transform.SetParent(transform, true);
        theShow.AddMissingComponent <ToolAutoDestory>().Do();
    }
示例#6
0
    /// <summary>
    /// Gets the next position.
    /// 还原当前位置的高度.
    /// </summary>
    /// <returns>The next position.</returns>
    /// <param name="curPosition">Current position.</param>
    /// <param name="curCoor">Current coor.</param>
    /// <param name="nextDir">Next dir.</param>
    static public Vector3 GetNextPosition(Vector3 curPosition, SGridCoordinate curCoor, EDirection nextDir)
    {
        SGridCoordinate nextCoor     = GetNextCoorinate(curCoor, nextDir);
        Vector3         nextPosition = GridToWorld(nextCoor.x, nextCoor.z);

        nextPosition.y = curPosition.y;

        return(nextPosition);
    }
    /// <summary>
    /// Determines whether this instance can move the specified curCoor nextDir.
    /// </summary>
    /// <returns><c>true</c> if this instance can move the specified curCoor nextDir; otherwise, <c>false</c>.</returns>
    /// <param name="curCoor">Current coor.</param>
    /// <param name="nextDir">Next dir.</param>
    public bool CanMove(SGridCoordinate curCoor, EDirection nextDir)
    {
        //---判断目标是不是一个好位置
        SGridCoordinate nextCoor = Definition.GetNextCoorinate(curCoor, nextDir);

        if (nextCoor.MAreaType != EAreaType.Player)
        {
            return(false);
        }
        GridInfo theGrid = BallGrid[nextCoor.x, nextCoor.z];
        bool     result  = theGrid.MCurState != GridInfo.EState.Occupation;

        return(result);
    }
    /// <summary>
    /// 踢回球.需要重构.
    /// </summary>
    /// <param name="oriCoor">角色坐标.</param>
    /// <param name="coor">球所在坐标</param>
    public void KickBackBall(SGridCoordinate oriCoor, SGridCoordinate coor)
    {
        GridInfo theGrid = BallGrid[coor.x, coor.z];

        if (theGrid.MCurState == GridInfo.EState.Occupation)
        {
            GameObject ball = theGrid.MOccupant;
            if (ball != null)
            {
                ToolAutoDestory boom = ball.AddMissingComponent <ToolAutoDestory>();
                boom.Stop();
                boom.Do(5);

                MotionParabolic motion = ball.AddMissingComponent <MotionParabolic>();
                motion.Go(ball.transform.position, Boss.transform.position, 30, 10);
                motion.SetCallBack(null);
            }

            theGrid.CleanOccupant();
        }
    }
 /// <summary>
 /// 初始化网格
 /// </summary>
 private void InitGrid()
 {
     _RandomPlayerCells.Clear();
     _RandomEnemyCells.Clear();
     for (int i = 0; i < Definition.GridWidthCount; i++)
     {
         for (int j = 0; j < Definition.GridHeightCount; j++)
         {
             SGridCoordinate coor  = new SGridCoordinate(i, j);
             GridInfo        gInfo = new GridInfo(coor);
             BallGrid[i, j] = gInfo;
             if (coor.MAreaType == EAreaType.Player)
             {
                 _RandomPlayerCells.Add(coor);
             }
             else if (coor.MAreaType == EAreaType.Enemy)
             {
                 _RandomEnemyCells.Add(coor);
             }
         }
     }
 }
示例#10
0
 public GridInfo(SGridCoordinate mCoordinate)
 {
     this.MCoordinate = mCoordinate;
 }
示例#11
0
 /// <summary>
 /// 坐标转移到下一个网格.
 /// </summary>
 public void SetCurToNext()
 {
     MCurCoordinate = Definition.GetNextCoorinate(MCurCoordinate, _NextDirection);
 }