Beispiel #1
0
        public void Strike(Vector startPoint, double width, double height)
        {
            double branchHeight = height / layerAmount;

            InitializeLayers();
            LightningNode startNode = new LightningNode(startPoint);

            layers[0].Add(startNode);
            layers[0].Y = startNode.Position.Y;
            //startNode.AddChild(startPoint);

            for (int i = 1; i < layers.Length - 1; i++)
            {
                for (int j = 0; j < layers[i - 1].Nodes.Count; j++)
                {
                    LightningNode currentNode = layers[i - 1].Nodes[j];
                    layers[i].Y = layers[i - 1].Y - branchHeight;
                    if (RandomGen.NextDouble(0, 100) < layers[i - 1].Nodes[j].SplitChance)
                    {
                        Vector        pLeft  = new Vector(RandomGen.NextDouble(currentNode.Position.X - width / 6, currentNode.Position.X), layers[i].Y);
                        Vector        pRight = new Vector(RandomGen.NextDouble(currentNode.Position.X, currentNode.Position.X + width / 6), layers[i].Y);
                        LightningNode nLeft  = new LightningNode(pLeft);
                        LightningNode nRight = new LightningNode(pRight);
                        layers[i].Nodes.Add(nLeft);
                        currentNode.AddChild(nLeft);
                        layers[i].Nodes.Add(nRight);
                        currentNode.AddChild(nRight);
                    }
                    Vector        p = new Vector(RandomGen.NextDouble(startPoint.X - width / 4, startPoint.X + width / 4), layers[i].Y);
                    LightningNode n = new LightningNode(p);
                    layers[i].Nodes.Add(n);
                    currentNode.AddChild(n);
                }
            }
            striking = true;
        }
Beispiel #2
0
 public void AddChild(LightningNode node)
 {
     node.parentNode = this;
     this.childNodes.Add(node);
 }
Beispiel #3
0
 public void Add(LightningNode n)
 {
     nodes.Add(n);
 }