Beispiel #1
0
        public void createLine(Point a, Point b, int radius, ref Area area)
        {
            Queue<Point> points = new Queue<Point>();
            HashSet<Point> expandPoints = new HashSet<Point>();
            //PagedArray2D<bool> tiles = new PagedArray2D<bool>(false);

            Point[] expandDirections = new Point[]
            {
                new Point(1, 0),
                new Point(-1, 0),
                new Point(0, 1),
                new Point(0, -1)
            };

            bool steep = (Math.Abs(b.Y - a.Y) > Math.Abs(b.X - a.X));
            if (steep)
            {
                a = new Point(a.Y, a.X);
                b = new Point(b.Y, b.X);
            }
            if (a.X > b.X)
            {
                Point temp = a;
                a = b;
                b = temp;
            }

            Point delta = new Point(b.X - a.X, Math.Abs(b.Y - a.Y));

            float error = delta.X / 2f;
            int yStep = (a.Y < b.Y) ? 1 : -1;
            int y = a.Y;

            for (int x = a.X; x < b.X; ++x)
            {
                Point point;
                if (steep)
                    point = new Point(y, x);
                else
                    point = new Point(x, y);

                points.Enqueue(point);
                expandPoints.Add(point);

                error -= delta.Y;
                if (error < 0)
                {
                    y += yStep;
                    error += delta.X;
                }
            }

            for (int i = 0; i < radius; ++i)
            {
                int size = points.Count;
                for (int j = 0; j < size; ++j)
                {
                    Point point = points.Dequeue();
                    area[point.X, point.Y] = true;
                    expandPoints.Remove(point);

                    foreach(Point p in expandDirections)
                    {
                        Point newPoint = point + p;
                        if (p.X < 0 || p.Y < 0 || p.X >= tileMap.Size.x || p.Y >= tileMap.Size.y)
                            continue;

                        if (expandPoints.Contains(newPoint))
                            continue;

                        points.Enqueue(newPoint);
                        expandPoints.Add(newPoint);
                    }
                }
            }
        }
Beispiel #2
0
 public void replaceArea(Area area, UInt16 TileIDA, UInt16 TileIDB)
 {
     foreach (Point p in area)
     {
         if (tileMap.getTileID(p.X, p.Y) == TileIDA)
             tileMap.setTile(p.X, p.Y, TileIDB);
     }
 }
Beispiel #3
0
 public void fillArea(Area area, UInt16 tileID)
 {
     foreach (Point p in area)
         tileMap.setTile(p.X, p.Y, tileID);
 }
Beispiel #4
0
        public Area generateArea(int2 pos, float minRadius, float maxRadius)
        {
            Area area = new Area();

            Rectangle rect = new Rectangle(pos.x - (int)maxRadius, pos.y - (int)maxRadius, (int)(2 * maxRadius), (int)(2 * maxRadius));
            Land land = new Land();

            float noiseRadius = maxRadius - minRadius;

            Graphics.Tools.Noise.Primitive.BevinsGradient noise = new Graphics.Tools.Noise.Primitive.BevinsGradient(random.Next(), NoiseQuality.Best);

            for (int y = rect.Y; y < rect.Y + rect.Height; ++y)
            {
                for (int x = rect.X; x < rect.X + rect.Width; ++x)
                {
                    if (x < 0 || y < 0 || x >= tileMap.Size.x || y >= tileMap.Size.y)
                        continue;

                    float dis = new Vector2(x - pos.x, y - pos.y).Length() / maxRadius;
                    float nvalue = Math.Abs(noise.GetValue((float)x / 64f, (float)y / 64f, 0f));

                    if (dis + noiseRadius / maxRadius * (nvalue) < 1f)
                    {
                        area[x, y] = true;
                    }

                }
            }

            return area;
        }
Beispiel #5
0
        public Area createPath(Point p1, Point p2, int radius, float curliness)
        {
            List<Point> points = new List<Point>();

            points.Add(p1);
            points.Add(p2);
            {
                int i = 0;
                while (i + 1 < points.Count)//for (int i = 0; i < points.Count-1; ++i)
                {
                    for (int j = 0; j < 100; ++j )
                    {
                        Point a = points[i];
                        Point b = points[i + 1];
                        float distance = (a - b).ToVector2().Length();
                        if (distance <= 8f)
                            break;

                        Point c = (a + b) / new Point(2, 2);
                        c.X += random.Next(-(int)(0.5f * distance * curliness), (int)(0.5f * distance * curliness));
                        c.Y += random.Next(-(int)(0.5f * distance * curliness), (int)(0.5f * distance * curliness));

                        c.X = Math.Min(Math.Max(c.X, 0), tileMap.Size.x - 1);
                        c.Y = Math.Min(Math.Max(c.Y, 0), tileMap.Size.y - 1);

                        points.Insert(i + 1, c);
                    }
                    ++i;
                }
            }

            Area area = new Area();
            for (int i = 0; i < points.Count - 1; ++i)
            {
                Point a = points[i];
                Point b = points[i + 1];
                createLine(a, b, radius, ref area);
            }

            return area;
        }