Example #1
0
 /// <summary>
 /// ユニット追加
 /// </summary>
 /// <param name="unit"></param>
 public void AddUnit(Unit.BaseAvator unit)
 {
     unit.ControlId = unitNums;
     if (unit.CurrentUnitType == Unit.UnitType.playerTower)
     {
         playerTower = unit;
     }
     else if (unit.CurrentUnitType == Unit.UnitType.enemyTower)
     {
         enemyTower = unit;
     }
     unitList.Add(unit);
     unitNums++;
 }
Example #2
0
        /// <summary>
        /// 目標検索
        /// </summary>
        /// <param name="baseUnit"></param>
        /// <returns></returns>
        private BaseAvator SearchTarget(BaseAvator baseUnit)
        {
            BaseAvator target = null;

            var targetDist = 10;              //baseUnit.MaxRenge //一旦仮で索敵範囲設定

            var basePosX = baseUnit.CurrentX; //現在位置を初期設定
            var basePosY = baseUnit.CurrentY;

            foreach (Unit.BaseAvator unit in unitList)//リストからユニットを全検索
            {
                if (baseUnit.ControlId == unit.ControlId || unit.CurrentUnitType == baseUnit.CurrentUnitType)
                {
                    continue;
                }

                if (unit.CurrentUnitType == UnitType.playerTower && baseUnit.CurrentUnitType == UnitType.player)
                {
                    continue;
                }

                if (unit.CurrentUnitType == UnitType.enemyTower && baseUnit.CurrentUnitType == UnitType.enemy)
                {
                    continue;
                }

                //目標対象を特定 対象距離を計算
                var pos      = unit.transform.localPosition;
                var distX    = unit.CurrentX - basePosX;
                var distY    = unit.CurrentY - basePosY;
                var distance = Math.Abs(distX) + Math.Abs(distY);

                //索敵距離以下なら対象と索敵距離を更新
                if (targetDist > distance)
                {
                    target     = unit;
                    targetDist = distance;
                }
            }

            if (target == null)//対象がいない場合はタワーを対象とする
            {
                target = GetTower(baseUnit.CurrentUnitType);
            }

            return(target);
        }
Example #3
0
        /// <summary>
        /// 目標位置の周囲でもっとも近いマスを取得
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        private CheckerSquare GetNearSquare(BaseAvator from, BaseAvator to)
        {
            var posx  = to.NextX;
            var posy  = to.NextY;
            var distX = posx - from.CurrentX;
            var distY = posy - from.CurrentY;

            if (Math.Abs(distX) >= Math.Abs(distY))
            {
                if (distX > 0)
                {
                    posx -= 1;
                }
                else
                {
                    posx += 1;
                }
            }
            else
            {
                if (distY > 0)
                {
                    posy -= 1;
                }
                else
                {
                    posy += 1;
                }
            }

            if (CheckPossession(posx, posy))
            {
                posx = to.NextX;
                posy = to.NextY;

                if (Math.Abs(distY) >= Math.Abs(distX))
                {
                    if (distY > 0)
                    {
                        posy -= 1;
                    }
                    else
                    {
                        posy += 1;
                    }
                }
                else
                {
                    if (distX > 0)
                    {
                        posx -= 1;
                    }
                    else
                    {
                        posx += 1;
                    }
                }
            }

            return(GetSquare(posx, posy));
        }
Example #4
0
        /// <summary>
        /// 目標に最も近いマスまでのルートを返します
        /// </summary>
        /// <param name="unit"></param>
        /// <param name="target"></param>
        public CheckerSquare[] GetRouteCells(BaseAvator unit, BaseAvator target)
        {
            var square = GetNearSquare(unit, target);

            return(CalculateRouteCells(unit.CurrentX, unit.CurrentY, unit.MovePoint, square));
        }