コード例 #1
0
        public void generateLake()
        {
            int lakeCount = sx % 5 + 1;
            int lakeRange = 12;

            int px = sx;
            int py = sy;

            int attempt          = 0;
            int CurrentLakeCount = 0;

            while (attempt < 100 && CurrentLakeCount < 1)
            {
                Point  Position      = new Point(buffer + (px % (useRegion)), buffer + (py % (useRegion)));
                double Oceandistance = MapUtil.GetDist((int)Position.X, (int)Position.Y, IslandMap.o, wx / 2);

                //Debug.WriteLine("Center: " + Position);
                if (Oceandistance > lakeRange * 2 || Oceandistance == -1)
                {
                    IslandMap.LakePoints.Add(Position);
                    int[] LakePoints = MathUtil.MathUtil.generateFibonocciNumbers(sx + px + 12, sy + py + 13, 20, 2);

                    List <Point> P = new List <Point>();
                    for (int j = 0; j < LakePoints.GetLength(0) / 2; j++)
                    {
                        //Debug.WriteLine(new Point(Position.X + ((LakePoints[j] % lakeRange) - lakeRange / 2), Position.Y + ((LakePoints[j + 1] % lakeRange) - lakeRange / 2)));
                        Point newPoint = new Point(Position.X + ((LakePoints[j] % lakeRange) - lakeRange / 2), Position.Y + ((LakePoints[j + 1] % lakeRange) - lakeRange / 2));
                        P.Add(newPoint);
                    }
                    //add 5 points
                    P.Add(P[0]);
                    Boolean[,] Map = new Boolean[(wx + 1), (wy + 1)];
                    for (int j = 0; j < P.Count - 1; j++)
                    {
                        Map = MapUtil.createCurve(Map, P[j], P[j + 1], 2);
                    }
                    Boolean[,] shadeMap = MapUtil.basicFill(Map);
                    for (int countX = 0; countX < Map.GetLength(0); countX++)
                    {
                        for (int countY = 0; countY < Map.GetLength(1); countY++)
                        {
                            if (!IslandMap.lk[countX, countY])
                            {
                                IslandMap.lk[countX, countY] = !shadeMap[countX, countY];
                            }
                        }
                    }

                    Boolean[,] RiverMap = new Boolean[(wx + 1), (wy + 1)];
                    Point OceanPoint = MapUtil.getClosest((int)Position.X, (int)Position.Y, IslandMap.o, wx / 4);
                    Point RiverPoint = MapUtil.getClosest((int)Position.X, (int)Position.Y, IslandMap.r, wx / 4);

                    Point ClosestPoint = MathUtil.MathUtil.distance(Position, OceanPoint) < MathUtil.MathUtil.distance(Position, RiverPoint) ? OceanPoint : RiverPoint;
                    IslandMap.DeltaPoints.Add(ClosestPoint);

                    MapUtil.createCurve(RiverMap, Position, ClosestPoint, 2);
                    for (int countX = 0; countX < Map.GetLength(0); countX++)
                    {
                        for (int countY = 0; countY < Map.GetLength(1); countY++)
                        {
                            if (!IslandMap.r[countX, countY] && RiverMap[countX, countY])
                            {
                                IslandMap.r[countX, countY] = RiverMap[countX, countY];
                            }
                        }
                    }
                    CurrentLakeCount++;
                }
                attempt++;
                int tx = px;
                px += py + 1;
                px %= wx;
                py  = (tx) % wx;
            }

            for (int i = 0; i < IslandMap.r.GetLength(0); i++)
            {
                for (int j = 0; j < IslandMap.r.GetLength(1); j++)
                {
                    if (IslandMap.r[i, j])
                    {
                        IslandMap.l[i, j] = false;
                    }
                    if (IslandMap.lk[i, j])
                    {
                        IslandMap.l[i, j] = false;
                    }
                }
            }
            //Debug.WriteLine("Attempts: " + attempt);
        }