Пример #1
0
    private void WayBypass(HexagonControl hexagonFinish, IMove EnemyTarget, IMove Collision)
    {
        List <HexagonControl> Way;

        Way = new List <HexagonControl>()
        {
            Control.HexagonMain(), hexagonFinish
        };

        if (Way != null)
        {
            Way = NavStatic.PathCheckBypassFly(Way, Collision, EnemyTarget, this);

            if (Way.Count > 0)
            {
                _wayList.Clear();

                _wayList.AddRange(Way);
                _isMove = true;
            }
            else
            {
                StartCoroutine(StopBypass());
            }
        }
    }
Пример #2
0
    private void CollisionMain(Vector2 NextPos)
    {
        HexagonControl hex = MapControl.FieldPosition(gameObject.layer, NextPos);

        if (_hexagonMain != hex)
        {
            if (!hex.IsFree)
            {
                if ((EnemyTarget != null) && hex.ObjAbove == EnemyTarget.IMoveMain)
                {
                    IMoveMain.StopMoveTarget();
                }
                else
                {
                    IMoveMain.StopMove(hex);
                }
            }
            else
            {
                if (hex.TypeHexagon == 1)
                {
                    Debug.LogError("da");
                }

                _hexagonMain.Gap();
                _hexagonMain = hex;
                _hexagonMain.Contact(IMoveMain);
                RecordApproac();
                TravelMessage();
            }
        }
    }
Пример #3
0
    public static HexagonControl FieldPositionFly(int layer, Vector2 position)//гексагон к которому принадлежит герой
    {
        Vector2        difference = layer == 8 ? Vector2.zero : new Vector2(X, Y);
        HexagonControl hexagon    = GetPositionOnTheMapFly(position - difference);

        return(hexagon.GetHexagonMain());//нужный 6-ти угольник
    }
Пример #4
0
    public async void StartWay(HexagonControl hexagonFinish, IMove EnemyTarget)
    {
        _wayList.Clear();

        await Task.Run(() =>
                       Way(hexagonFinish, EnemyTarget));
    }
Пример #5
0
    private static HexagonControl OwnershipCheckFly(int _row, int _column, Vector2 pos)
    {
        List <HexagonControl> hexagons = new List <HexagonControl>();
        int _columbias = (_row % 2) == 0 ? 1 : -1;

        if ((MapNav[_row, _column].position - pos).magnitude <= 1.8f)
        {
            return(MapNav[_row, _column]);
        }

        #region AddToList
        hexagons.Add(MapNav[_row, _column]);
        if (_column < MapNav.GetLength(1) - 1)
        {
            hexagons.Add(MapNav[_row, _column + 1]);
        }

        if (_column > 0)
        {
            hexagons.Add(MapNav[_row, _column - 1]);
        }

        if (_row < MapNav.GetLength(0) - 1)
        {
            hexagons.Add(MapNav[_row + 1, _column]);

            if (_column + _columbias > 0 && _column + _columbias < MapNav.GetLength(1) - 1)
            {
                hexagons.Add(MapNav[_row + 1, _column + _columbias]);
            }
        }

        if (_row > 0)
        {
            hexagons.Add(MapNav[_row - 1, _column]);
            if (_column + _columbias > 0 && _column + _columbias < MapNav.GetLength(1) - 1)
            {
                hexagons.Add(MapNav[_row - 1, _column + _columbias]);
            }
        }
        #endregion

        float          mag     = float.PositiveInfinity;
        HexagonControl hexagon = null;
        for (int i = 0; i < hexagons.Count; i++)
        {
            if (mag > (hexagons[i].position - pos).magnitude)
            {
                mag     = (hexagons[i].position - pos).magnitude;
                hexagon = hexagons[i];
                if (mag <= 1.8f)
                {
                    return(hexagons[i]);
                }
            }
        }

        return(hexagon);
    }
Пример #6
0
 public void AddNodeFirst(HexagonControl newNode)
 {
     nodes.Insert(0, new Node(0, newNode));
     for (int i = 1; i < nodes.Count; i++)
     {
         nodes[i].NodeNumber += 1;
     }
 }
Пример #7
0
    public void SaveTheWay(HexagonControl endWay, List <HexagonControl> way)
    {
        List <HexagonControl> NewWayList = new List <HexagonControl>();

        NewWayList.AddRange(way);
        EndWay.Add(endWay);
        Way.AddRange(NewWayList);
        Way.Add(null);
    }
Пример #8
0
    private void Start()
    {
        //временно
        _hexagonMain = MapControl.FieldPosition(gameObject.layer, transform.position);
        _hexagonMain.Contact(IMoveMain);
        //незабудь удалить
        transform.position = (Vector2)_hexagonMain.transform.position;

        RecordApproac();
    }
Пример #9
0
    public static HexagonControl FieldPosition(int layer, Vector2 position)//гексагон к которому принадлежит герой
    {
        Vector2        difference = layer == 8 ? Vector2.zero : new Vector2(X, Y);
        int            layerHex   = layer == 8 ? 9 : 12;
        HexagonControl hexagon    = GetPositionOnTheMap(position - difference, layerHex);

        if (hexagon == null)
        {
            Debug.Log(layerHex);
        }

        return(hexagon.GetHexagonMain());//нужный 6-ти угольник
    }
Пример #10
0
 public List <HexagonControl> GetWay(HexagonControl where)
 {
     if (ShortWay.ContainsKey(where))
     {
         List <HexagonControl> hexagonControls = new List <HexagonControl>();
         hexagonControls.AddRange(ShortWay[where]);
         return(hexagonControls);
     }
     else
     {
         Debug.Log("Unknown hexagon");
         return(null);
     }
 }
Пример #11
0
    private void Way(HexagonControl hexagonFinish, IMove EnemyTarget)
    {
        List <HexagonControl> Way;

        Way = new List <HexagonControl>()
        {
            hexagonFinish
        };

        if (Way != null)
        {
            _wayList.AddRange(Way);
            _isMove = true;
        }
    }
Пример #12
0
    public static HexagonControl[,] MapNav = new HexagonControl[9, 20]; //масив содержащий все 6-ти угольники

    void Awake()                                                        //измени
    {
        //enemyManager.InitializationList(_heroControls);
        _mapPos = transform.position;
        for (int i = 0; i < hexagons.Length; i++)
        {
            hexagons[i].name = i.ToString();
            for (int j = 0; j < hexagons[i].childCount; j++)
            {
                HexagonControl hexagon = hexagons[i].GetChild(j).GetComponent <HexagonControl>();
                MapNav[i, j] = hexagon;
                hexagons[i].GetChild(j).name = j.ToString();
                hexagon.NamberHex();
            }
        }
    }
Пример #13
0
    private static Graph CreatingEdgeBendingFly(List <HexagonControl> listHexagons, IMove EnemyTarget, List <IMove> EnemyList)//выстраивает ребра в графе
    {
        var graph = new Graph(listHexagons);

        for (int i = 0; i < graph.Length - 1; i++)
        {
            for (int j = i + 1; j < graph.Length; j++)
            {
                bool IsElevation;

                Vector2 StartPosition = graph[i].NodeHexagon.GetArrayElement().position;
                Vector2 direction     = graph[j].NodeHexagon.GetArrayElement().position;

                bool           NoRibs = false;
                HexagonControl node   = graph[j].NodeHexagon.GetHexagonMain();

                if (!CollisionCheckElevationFly(StartPosition, direction, listHexagons[0], EnemyTarget, EnemyList))
                {
                    NoRibs = true;
                }

                if (i == 0 && graph[j].NodeHexagon == listHexagons[listHexagons.Count - 1] && !NoRibs)
                {
                    graph[i].NodeHexagon.Flag();
                    graph[j].NodeHexagon.Flag();
                    Debug.Log(EnemyList.Count);
                }

                if (!NoRibs)
                {
                    float magnitude = (graph[i].NodeHexagon.position - graph[j].NodeHexagon.position).magnitude;
                    graph[i].Connect(graph[j], magnitude, null);
                }
            }
        }
        //List<Node> f = graph[0].IncidentNodes();
        //foreach (var item in f)
        //{
        //    if (item.NodeHexagon == listHexagons[listHexagons.Count - 1])
        //    {
        //        item.NodeHexagon.Flag();
        //        graph[0].NodeHexagon.Flag();
        //        Debug.Log(123456);
        //    }
        //}
        return(graph);
    }
Пример #14
0
    private void CollisionMain(Vector2 NextPos)
    {
        HexagonControl hex;

        if (IMoveMain.IsFlight())
        {
            hex = MapControl.FieldPositionFly(gameObject.layer, NextPos);
        }
        else
        {
            hex = MapControl.FieldPosition(gameObject.layer, NextPos);
        }

        if (_hexagonMain != hex)
        {
            if (!hex.GetFree(IMoveMain.IsFlight()))
            {
                if ((HeroTarget != null) && hex.ObjAbove == HeroTarget.IMoveMain)
                {
                    IMoveMain.StopMoveTarget();
                }
                else
                {
                    IMoveMain.StopMove(hex);
                }
            }
            else
            {
                if (IMoveMain.IsFlight())
                {
                    _hexagonMain.GapFly();
                    _hexagonMain = hex;
                    _hexagonMain.ContactFly(IMoveMain);
                }
                else
                {
                    _hexagonMain.Gap();
                    _hexagonMain = hex;
                    _hexagonMain.Contact(IMoveMain);
                }

                RecordApproac();
                TravelMessage();
            }
        }
    }
Пример #15
0
 public void DataRecords()
 {
     _mapPos = transform.position;
     for (int i = 0; i < hexagons.Length; i++)
     {
         hexagons[i].name = i.ToString();
         for (int j = 0; j < hexagons[i].childCount; j++)
         {
             HexagonControl hexagon = hexagons[i].GetChild(j).GetComponent <HexagonControl>();
             MapNav[i, j] = hexagon;
             hexagons[i].GetChild(j).name = j.ToString();
             hexagon.NamberHex();
             if (hexagon.GetHexagonMain().TypeHexagon != 1)
             {
                 _navSurface.ListHexagonControls.Add(hexagon.GetHexagonMain());
             }
         }
     }
 }
Пример #16
0
    private HeroControl GetNearestHeroMag(HexagonControl hexagon)
    {
        HeroControl heroControl = null;
        float       Magnitude   = float.PositiveInfinity;

        for (int i = 0; i < _listHero.Count; i++)
        {
            float magnitude = 0;

            magnitude += (hexagon.position - (Vector2)_listHero[i].transform.position).magnitude;

            if (Magnitude > magnitude)
            {
                Magnitude   = magnitude;
                heroControl = _listHero[i];
            }
        }
        return(heroControl);
    }
Пример #17
0
    private static Graph CreatingEdgeBending(List <HexagonControl> listHexagons, IMove EnemyTarget, List <IMove> EnemyList)//выстраивает ребра в графе
    {
        var graph = new Graph(listHexagons);

        for (int i = 0; i < graph.Length - 1; i++)
        {
            for (int j = i + 1; j < graph.Length; j++)
            {
                bool IsElevation;

                Vector2 StartPosition = graph[i].NodeHexagon.GetArrayElement().position;
                Vector2 direction     = graph[j].NodeHexagon.GetArrayElement().position;

                bool           NoRibs = false;
                HexagonControl node   = graph[j].NodeHexagon.Elevation != null ?
                                        graph[j].NodeHexagon.Elevation : graph[j].NodeHexagon;

                if (listHexagons[i].TypeHexagon <= 0 || (listHexagons[i].TypeHexagon == 3 && node.layer != 10))
                {
                    IsElevation = false;
                    if (!CollisionCheck(StartPosition, direction, IsElevation, listHexagons[0], EnemyTarget, EnemyList))
                    {
                        NoRibs = true;
                    }
                }
                else
                {
                    IsElevation = true;
                    if (!CollisionCheckElevation(StartPosition, direction, IsElevation, listHexagons[0], EnemyTarget, EnemyList))
                    {
                        NoRibs = true;
                    }
                }

                if (!NoRibs)
                {
                    float magnitude = (graph[i].NodeHexagon.position - graph[j].NodeHexagon.position).magnitude;
                    graph[i].Connect(graph[j], magnitude, null);
                }
            }
        }
        return(graph);
    }
Пример #18
0
    private void Way(HexagonControl hexagonFinish, IMove EnemyTarget)
    {
        List <HexagonControl> Way;

        Way = Control.HexagonMain().GetWay(hexagonFinish);

        if (Way != null)
        {
            if (_isClever)
            {
                Way = NavStatic.PathCheck(Way, EnemyTarget, this);
            }
            else
            {
                Way.Remove(Way[0]);
            }

            _wayList.AddRange(Way);
            _isMove = true;
        }
    }
Пример #19
0
    private HeroControl GetNearestHero(HexagonControl hexagon)
    {
        HeroControl heroControl = null;
        float       Magnitude   = float.PositiveInfinity;

        for (int i = 0; i < _listHero.Count; i++)
        {
            List <HexagonControl> listHex = new List <HexagonControl>();
            listHex.AddRange(hexagon.GetWay(_listHero[i].HexagonMain()));
            float magnitude = 0;

            for (int j = 0; j < listHex.Count - 1; j++)
            {
                magnitude += (listHex[j].position - listHex[j + 1].position).magnitude;
            }

            if (Magnitude > magnitude)
            {
                Magnitude   = magnitude;
                heroControl = _listHero[i];
            }
        }
        return(heroControl);
    }
Пример #20
0
    public void First(EnemyManager manager)
    {
        //_navigationBot.Control = this;
        _enemyManager = manager;

        if (IMoveMain.IsFlight())
        {
            _hexagonMain = MapControl.FieldPositionFly(gameObject.layer, transform.position);
        }
        else
        {
            _hexagonMain = MapControl.FieldPosition(gameObject.layer, transform.position);
        }

        if (IMoveMain.IsFlight())
        {
            _hexagonMain.ContactFly(IMoveMain);
        }
        else
        {
            _hexagonMain.Contact(IMoveMain);
        }
        RecordApproac();
    }
Пример #21
0
    private static void OwnershipCheck(int _row, int _column, out float Row, out int Column, Vector2 pos)
    {
        if (_row > MapNav.GetLength(0) - 1)
        {
            _row = MapNav.GetLength(0) - 1;
        }
        else if (_row < 0)
        {
            _row = 0;
        }

        if (_column > MapNav.GetLength(1) - 1)
        {
            _column = MapNav.GetLength(1) - 1;
        }
        List <HexagonControl> hexagons = new List <HexagonControl>();
        int _columbias = (_row % 2) == 0 ? 1 : -1;

        if ((MapNav[_row, _column].position - pos).magnitude <= 1.8f)
        {
            Row    = _row;
            Column = _column;
            return;
        }

        #region AddToList
        hexagons.Add(MapNav[_row, _column]);
        if (_column < MapNav.GetLength(1) - 1)
        {
            hexagons.Add(MapNav[_row, _column + 1]);
        }

        if (_column > 0)
        {
            hexagons.Add(MapNav[_row, _column - 1]);
        }

        if (_row < MapNav.GetLength(0) - 1)
        {
            hexagons.Add(MapNav[_row + 1, _column]);

            if (_column + _columbias > 0 && _column + _columbias < MapNav.GetLength(1) - 1)
            {
                hexagons.Add(MapNav[_row + 1, _column + _columbias]);
            }
        }

        if (_row > 0)
        {
            hexagons.Add(MapNav[_row - 1, _column]);
            if (_column + _columbias > 0 && _column + _columbias < MapNav.GetLength(1) - 1)
            {
                hexagons.Add(MapNav[_row - 1, _column + _columbias]);
            }
        }
        #endregion

        float          mag     = float.PositiveInfinity;
        HexagonControl hexagon = null;
        for (int i = 0; i < hexagons.Count; i++)
        {
            if (mag > (hexagons[i].position - pos).magnitude)
            {
                mag     = (hexagons[i].position - pos).magnitude;
                hexagon = hexagons[i];
                if (mag <= 1.8f)
                {
                    Row    = hexagons[i].Row;
                    Column = hexagons[i].Column;
                    return;
                }
            }
        }
        Row    = hexagon.Row;
        Column = hexagon.Column;
        return;
    }
Пример #22
0
    private void FixedUpdate()
    {
        if (_wayList.Count <= 0)
        {
            _isMove = false;
        }

        if (StaticLevelManager.IsGameFlove)
        {
            if (_isMove)
            {
                _targetHexagon = _wayList[0];

                if (_targetHexagon.TypeHexagon == 2 && gameObject.layer == 8)
                {
                    gameObject.layer = 11;
                }
                else if (_targetHexagon.TypeHexagon == 0 && gameObject.layer == 11)
                {
                    gameObject.layer = 8;
                }

                transform.position = Vector2.MoveTowards(transform.position, _targetHexagon.transform.position, _speedMove);

                Vector2 NextPos = (Vector2)transform.position + (Vector2)(_targetHexagon.transform.position - transform.position).normalized * 1.8f;

                Control.Collision(NextPos);

                if (_wayList.Count > 0)
                {
                    if (((Vector2)transform.position - (Vector2)_wayList[0].transform.position).magnitude <= 0.01f)
                    {
                        _wayList.Remove(_wayList[0]);
                    }
                }
            }
            else
            {
                if (((Vector2)transform.position - Control.HexagonMain().position).magnitude >= 0.01f)
                {
                    transform.position = Vector2.MoveTowards(transform.position, Control.HexagonMain().position, _speed);
                }

                if (_isBypass)
                {
                    if (_wayList.Count > 0)
                    {
                        IMove move = _currentPos.ObjAbove;
                        if ((move == null))
                        {
                            if (_currentPos.IsFree)
                            {
                                _isMove = true;
                            }
                        }
                        else if (!move.IsGo())
                        {
                            IMove enemy = Control.Target() != null?Control.Target() : null;

                            WayBypass(_wayList[_wayList.Count - 1], enemy, _currentPos.ObjAbove);
                        }
                    }
                }
            }
        }
        else
        {
            if (((Vector2)transform.position - Control.HexagonMain().position).magnitude >= 0.01f)
            {
                transform.position = Vector2.MoveTowards(transform.position, Control.HexagonMain().position, _speed);
            }
        }
    }
Пример #23
0
 public void StartWay(HexagonControl hexagonFinish)
 {
     IMoveMain.StartWay(hexagonFinish, null);
 }
Пример #24
0
    private void RecordApproac()
    {
        bool           elevation = gameObject.layer != 8;
        HexagonControl Hex       = _hexagonMain;
        HexagonControl hexagon   = Hex.Floor != null ? Hex.Floor : Hex;

        AnApproac.Clear();

        //hexagon.Flag();

        if (hexagon.Row != 0)
        {
            HexagonControl hexagonCon = MapControl.MapNav[hexagon.Row - 1, hexagon.Column].GetHexagonMain(elevation);

            if (hexagonCon != null)
            {
                AnApproac.Add(hexagonCon);
            }

            if ((hexagon.Row % 2) == 0)                                  //1
            {
                if (hexagon.Column < MapControl.MapNav.GetLength(1) - 1) //2
                {
                    HexagonControl hexagonControl = MapControl.MapNav[hexagon.Row - 1, hexagon.Column + 1].GetHexagonMain(elevation);
                    if (hexagonControl != null)
                    {
                        AnApproac.Add(hexagonControl);
                    }
                }
            }
            else
            {
                if (hexagon.Column > 0)//2
                {
                    HexagonControl hexagonControl = MapControl.MapNav[hexagon.Row - 1, hexagon.Column - 1].GetHexagonMain(elevation);
                    if (hexagonControl != null)
                    {
                        AnApproac.Add(hexagonControl);
                    }
                }
            }
        }

        if (hexagon.Column > 0)
        {
            HexagonControl hexagonControl = MapControl.MapNav[hexagon.Row, hexagon.Column - 1].GetHexagonMain(elevation);
            if (hexagonControl != null)
            {
                AnApproac.Add(hexagonControl);
            }
        }

        if (hexagon.Column < MapControl.MapNav.GetLength(1) - 1)
        {
            HexagonControl hexagonControl = MapControl.MapNav[hexagon.Row, hexagon.Column + 1].GetHexagonMain(elevation);
            if (hexagonControl != null)
            {
                AnApproac.Add(hexagonControl);
            }
        }

        if (hexagon.Row < MapControl.MapNav.GetLength(0) - 1)
        {
            HexagonControl hexagonCon = MapControl.MapNav[hexagon.Row + 1, hexagon.Column].GetHexagonMain(elevation);
            if (hexagonCon != null)
            {
                AnApproac.Add(hexagonCon);
            }

            if ((hexagon.Row % 2) == 0)
            {
                if (hexagon.Column < MapControl.MapNav.GetLength(1) - 1)//2
                {
                    HexagonControl hexagonControl = MapControl.MapNav[hexagon.Row + 1, hexagon.Column + 1].GetHexagonMain(elevation);
                    if (hexagonControl != null)
                    {
                        AnApproac.Add(hexagonControl);
                    }
                }
            }
            else
            {
                if (hexagon.Column > 0)//2
                {
                    HexagonControl hexagonControl = MapControl.MapNav[hexagon.Row + 1, hexagon.Column - 1].GetHexagonMain(elevation);
                    if (hexagonControl != null)
                    {
                        AnApproac.Add(hexagonControl);
                    }
                }
            }
        }
    }
Пример #25
0
    public static HexagonControl[] GetPositionOnTheMap(Vector2 Target, Vector2 Position) // возвращает гексагон через позицию (может определить два блока)
    {
        Vector2 Normalized = (Target - Position).normalized;
        float   XTarget    = (float)System.Math.Round(Normalized.x, 1);
        float   YTarget    = (float)System.Math.Round(Normalized.y, 1);
        float   Y          = (Position.y - _mapPos.y) / -3f;
        float   YOld       = (Position.y - _mapPos.y) / -3f;

        int   YMax       = Mathf.Abs(Mathf.RoundToInt(Y));
        float Difference = 0;
        float f          = ((Position.x - (_mapPos.x - 3.46f)) / 1.73f);
        float R          = Mathf.Floor(f) * 1.73f - (Position.x - (_mapPos.x - 3.46f));
        int   G          = (int)f % 2 == 0 ? 0 : 1;

        if (Mathf.Abs(YMax - Mathf.Abs(Y)) < Mathf.Abs(G - ((0.333f + ((0.333f / 1.73f) * Mathf.Abs(R))))))
        {
            Y = Mathf.Round(Mathf.Abs(Y));
        }
        else
        {
            if (YMax - Mathf.Abs(Y) > 0)
            {
                Y = Mathf.Floor(Mathf.Abs(Y));
            }
            else
            {
                Y = Mathf.Ceil(Mathf.Abs(Y));
            }
        }

        if ((Y % 2) != 0)
        {
            Difference = 0.5f;
        }

        float factor = (MapNav[0, 1].position.x - MapNav[0, 0].position.x);
        float X      = ((Position.x - _mapPos.x) / factor) + Difference;

        X = X > 0 ? X : 0;
        int XInt;

        if (X == 0.5)
        {
            XInt = 1;
        }
        else
        {
            XInt = Mathf.RoundToInt(X);
        }

        OwnershipCheck((int)Y, XInt, out Y, out XInt, Position);

        List <HexagonControl> hexagonsList = new List <HexagonControl>();

        if (Mathf.Abs((float)System.Math.Round((XInt - X), 2)) == 0.5f && XTarget == 0)
        {
            if (XInt <= 19)
            {
                hexagonsList.Add(MapNav[(int)Y, XInt]);
            }
            if (XInt > 0 && (Position - MapNav[(int)Y, XInt - 1].position).magnitude <= 1.8f)
            {
                hexagonsList.Add(MapNav[(int)Y, XInt - 1]);
            }

            HexagonControl[] hexagons = new HexagonControl[hexagonsList.Count];

            for (int i = 0; i < hexagonsList.Count; i++)
            {
                hexagons[i] = hexagonsList[i];
            }

            return(hexagons);
        }
        else if (Mathf.Abs((float)System.Math.Round((XInt - X), 3)) < 0.5f && (Mathf.Abs((float)System.Math.Round((YMax - YOld), 3)) < 0.51 && Mathf.Abs((float)System.Math.Round((YMax - YOld), 3)) > 0.33) && ((Mathf.Abs(XTarget) == 0.9f) && (Mathf.Abs(YTarget) == 0.5f)))
        {
            hexagonsList.Add(OwnershipCheckadditional((int)Y, XInt, Position));
            hexagonsList.Add(MapNav[(int)Y, XInt]);

            HexagonControl[] hexagons = new HexagonControl[hexagonsList.Count];

            for (int i = 0; i < hexagonsList.Count; i++)
            {
                hexagons[i] = hexagonsList[i];
            }

            return(hexagons);
        }
        else
        {
            HexagonControl[] hexagons = new HexagonControl[1];
            hexagons[0] = MapNav[(int)Y, XInt];

            return(hexagons);
        }
    }
Пример #26
0
    private static HexagonControl OwnershipCheck(int _row, int _column, Vector2 pos, int Layer)
    {
        List <HexagonControl> hexagons = new List <HexagonControl>();
        int _columbias = (_row % 2) == 0 ? 1 : -1;

        if (((Vector2)MapNav[_row, _column].position - pos).magnitude <= 1.8f)
        {
            if (MapNav[_row, _column].gameObject.layer == Layer && (MapNav[_row, _column].TypeHexagon != 1 || Layer == 12) || (Layer == 12 && MapNav[_row, _column].TypeHexagon == 3))
            {
                return(MapNav[_row, _column]);
            }
        }

        #region AddToList
        hexagons.Add(MapNav[_row, _column]);
        if (_column < MapNav.GetLength(1) - 1)
        {
            hexagons.Add(MapNav[_row, _column + 1]);
        }

        if (_column > 0)
        {
            hexagons.Add(MapNav[_row, _column - 1]);
        }

        if (_row < MapNav.GetLength(0) - 1)
        {
            hexagons.Add(MapNav[_row + 1, _column]);

            if (_column + _columbias > 0 && _column + _columbias < MapNav.GetLength(1) - 1)
            {
                hexagons.Add(MapNav[_row + 1, _column + _columbias]);
            }
        }

        if (_row > 0)
        {
            hexagons.Add(MapNav[_row - 1, _column]);
            if (_column + _columbias > 0 && _column + _columbias < MapNav.GetLength(1) - 1)
            {
                hexagons.Add(MapNav[_row - 1, _column + _columbias]);
            }
        }
        #endregion

        float          mag     = float.PositiveInfinity;
        HexagonControl hexagon = null;
        for (int i = 0; i < hexagons.Count; i++)
        {
            if (hexagons[i].gameObject.layer == Layer && (hexagons[i].TypeHexagon != 1 || Layer == 12) || (Layer == 12 && hexagons[i].TypeHexagon == 3))
            {
                if (mag > ((Vector2)hexagons[i].position - pos).magnitude)
                {
                    mag     = ((Vector2)hexagons[i].position - pos).magnitude;
                    hexagon = hexagons[i];
                    if (mag <= 1.8f)
                    {
                        return(hexagons[i]);
                    }
                }
            }
            else
            {
                if (Layer == 12 && hexagons[i].gameObject.layer == 12)
                {
                    hexagons[i].Flag();
                }
            }
        }

        return(hexagon);
    }
Пример #27
0
    public static bool CollisionCheck(Vector2 StartPos, Vector2 TargetPos, bool elevation, HexagonControl StartHex, IMove EnemyTarget, List <IMove> EnemyList)//возыращет true если на пути нет припятсвий не все враги препятсвие (пол)
    {
        HexagonControl[] controls;
        Vector2          currentVector = StartPos;

        while ((TargetPos - currentVector).magnitude > 0.1f)
        {
            controls = MapControl.GetPositionOnTheMap(TargetPos, currentVector);
            for (int i = 0; i < controls.Length; i++)
            {
                if (controls[i] == StartHex || (EnemyTarget != null && controls[i].ObjAbove == EnemyTarget))
                {
                    continue;
                }

                if ((!controls[i].FreedomTestType(elevation)) ||
                    (!controls[i].IsFree) && (EnemyList.Contains(controls[i].ObjAbove)) && !controls[i].ObjAbove.IsGo())
                {
                    return(false);
                }
            }
            currentVector = Vector2.MoveTowards(currentVector, TargetPos, 0.4f);
        }
        return(true);
    }
Пример #28
0
 public void StopMove(HexagonControl CollcionHex)
 {
     _currentPos = CollcionHex;
     _isMove     = false;
 }
Пример #29
0
 public void Ban()
 {
     hexagon = null;
     busy    = false;
 }
Пример #30
0
    public static bool CollisionCheckElevation(Vector2 StartPos, Vector2 TargetPos, bool elevation, HexagonControl StartHex, IMove EnemyTarget)//возыращет true если на пути нет припятсвий (возвышанность)
    {
        HexagonControl[] controls;

        Vector2 currentVector = StartPos;

        while ((TargetPos - currentVector).magnitude > 0.1f)
        {
            controls = MapControl.GetPositionOnTheMap(TargetPos, currentVector);
            for (int i = 0; i < controls.Length; i++)
            {
                if (controls[i].GetHexagonMain() == StartHex || (EnemyTarget != null && controls[i].GetHexagonMain().ObjAbove == EnemyTarget))
                {
                    continue;
                }

                if (!controls[i].GetHexagonMain().FreedomTestType(elevation) || (!controls[i].GetHexagonMain().IsFree) && !controls[i].GetHexagonMain().ObjAbove.IsGo())
                {
                    return(false);
                }
            }
            currentVector = Vector2.MoveTowards(currentVector, TargetPos, 0.4f);
        }

        return(true);
    }