Ejemplo n.º 1
0
        void OnDrag(int2 p)
        {
            if (_draggedPoints.Contains(p))
            {
                return;
            }

            if (!_map.IsInBounds(p))
            {
                return;
            }

            int i = Grid2D.PosToIndex(p, _size.x);

            // Don't touch the path points
            if ((_start != null && _start.Value.Equals(p)) ||
                _end != null && _end.Value.Equals(p))
            {
                return;
            }

            Debug.Log($"OnDrag {p}");
            ClearPath();
            var existing = _map.GetTile(p.x, p.y);

            if (_draggedPoints.Count == 0)
            {
                _dragAdding = existing == 0;
            }

            _draggedPoints.Add(p);

            if (existing == 0)
            {
                if (_dragAdding)
                {
                    _map.SetTile(p.x, p.y, 1);
                }
            }
            if (existing == 1)
            {
                if (!_dragAdding)
                {
                    _map.SetTile(p.x, p.y, 0);
                }
            }

            _dirty = true;
        }
Ejemplo n.º 2
0
 public void Execute()
 {
     for (int i = 0; i < Map.Length; ++i)
     {
         int2  p     = Grid2D.IndexToPos(i, Size.x);
         float noise = SumOctave(p.x, p.y,
                                 Iterations, Persistence, Scale, Low, High);
         if (noise >= threshold)
         {
             Map.SetTile(p.x, p.y, 1);
         }
     }
 }
Ejemplo n.º 3
0
        public static (TestMapInt, int, int) GetMapWithObstacles(int w, int h, Allocator allocator)
        {
            var map = new TestMapInt(w, h, allocator);

            int x = w / 2;

            for (int y = 0; y < h - 2; ++y)
            {
                map.SetTile(x, y, 1);
            }


            int start = map.PosToIndex(0, 0);
            int end   = map.PosToIndex(w - 1, 0);

            return(map, start, end);
        }