Beispiel #1
0
 void AddLowerGrowth(Node[,] grid, Texture2D tex)
 {
     for (int i = BottomNodes.Count - 1; i > -1; i--)
     {
         Node bottom = BottomNodes[i];
         if (!bottom.Solid)
         {
             BottomNodes.RemoveAt(i);
             continue;
         }
         if (bottom.Position.y > 0)
         {
             Node lower = grid[bottom.Position.x, bottom.Position.y - 1];
             if (lower.Solid)
             {
                 BottomNodes.RemoveAt(i);
                 continue;
             }
         }
         int growth = GetLowerGrowthSize(bottom, grid, 1);
         AddLowerGrowth(bottom, grid, growth, tex);
     }
 }
Beispiel #2
0
 Node[,] SetGrid(Node[,] oldGrid, NoiseData[] noiseData)
 {
     //Profiler.BeginSample("SetGrid");
     for (int x = 0; x < width; x++)
     {
         bool lastSolid = true;
         for (int y = 0; y < height; y++)
         {
             Vector2Int pos   = new Vector2Int(x, y);
             bool       added = false;
             for (int i = Layers - 1; i > -1; i--)
             {
                 if (y < noiseData[i].Data[x])
                 {
                     if (noiseData[i].Solid)
                     {
                         oldGrid[x, y] = new Node(true, pos);
                         if (y == 0)
                         {
                             lastSolid = true;
                         }
                         else if (!lastSolid)
                         {
                             BottomNodes.Add(oldGrid[x, y]);
                         }
                         lastSolid = true;
                         added     = true;
                         break;
                     }
                     else
                     {
                         oldGrid[x, y] = new Node(false, pos);
                         if (y == 0)
                         {
                             lastSolid = false;
                         }
                         else if (lastSolid && y - 1 >= 0)
                         {
                             Node top = oldGrid[x, y - 1];
                             if (top && top.Solid)
                             {
                                 TopNodes.Add(top);
                             }
                         }
                         lastSolid = false;
                         added     = true;
                         break;
                     }
                 }
             }
             if (oldGrid[x, y] == null && !added)
             {
                 oldGrid[x, y] = new Node(false, pos);
                 if (lastSolid && y - 1 >= 0)
                 {
                     Node top = oldGrid[x, y - 1];
                     if (top && top.Solid)
                     {
                         TopNodes.Add(top);
                     }
                 }
                 lastSolid = false;
                 added     = true;
             }
         }
     }
     // Profiler.EndSample();
     return(oldGrid);
 }
        private void GenerateMeshNodes(int LElements, int HElements)
        {
            Nodes.Clear();
            LeftNodes.Clear();
            RightNodes.Clear();

            int    indexCur = 0;
            double xCur     = 0;
            double yCur     = _shape.H / 2;

            if (HElements % 2 == 1)
            {
                HElements++;
            }

            int HNodes = HElements + 1;
            int LNodes = LElements + 1;

            double xStep = _shape.L / Convert.ToDouble(LElements);
            double yStep = _shape.H / Convert.ToDouble(HElements);

            int HNodesdiv2 = HNodes / 2;

            for (int i = 0; i < HNodesdiv2; i++)
            {
                if (i == 0)
                {
                    TopNodes.Clear();
                }
                for (int j = 0; j < LNodes; j++)
                {
                    Node node = new Node();
                    node.Index = indexCur;
                    node.X     = xCur;
                    node.Y     = yCur;
                    Nodes.Add(node);
                    if (j == 0)
                    {
                        LeftNodes.Add(node);
                    }
                    if (j == (LNodes - 1))
                    {
                        RightNodes.Add(node);
                    }

                    indexCur++;
                    xCur += xStep;
                    if (i == 0)
                    {
                        TopNodes.Add(node);
                    }
                }
                yCur -= yStep;
                xCur  = 0;
            }

            xCur = 0;
            yCur = 0;
            MiddleNodes.Clear();
            for (int j = 0; j < LNodes; j++)
            {
                Node node = new Node();
                node.Index = indexCur;
                node.X     = xCur;
                node.Y     = yCur;
                Nodes.Add(node);
                MiddleNodes.Add(node);
                if (j == 0)
                {
                    LeftNodes.Add(node);
                }
                if (j == (LNodes - 1))
                {
                    RightNodes.Add(node);
                }
                indexCur++;
                xCur += xStep;
            }

            xCur  = 0;
            yCur -= yStep;
            for (int i = 0; i < HNodesdiv2; i++)
            {
                if (i == (HNodesdiv2 - 1))
                {
                    BottomNodes.Clear();
                }
                for (int j = 0; j < LNodes; j++)
                {
                    Node node = new Node();
                    node.Index = indexCur;
                    node.X     = xCur;
                    node.Y     = yCur;
                    Nodes.Add(node);
                    if (j == 0)
                    {
                        LeftNodes.Add(node);
                    }
                    if (j == (LNodes - 1))
                    {
                        RightNodes.Add(node);
                    }

                    if (i == (HNodesdiv2 - 1))
                    {
                        BottomNodes.Add(node);
                    }
                    indexCur++;
                    xCur += xStep;
                }
                yCur -= yStep;
                xCur  = 0;
            }
        }