2 using System.Collections.Generic;
3 using Microsoft.Xna.Framework;
4 using Microsoft.Xna.Framework.Graphics;
8 internal class LightningLayer
10 public List<LightningNode> Nodes
13 set { nodes = value; }
16 private List<LightningNode> nodes;
19 public double Y {
get {
return y; }
set { y = value; } }
21 public LightningLayer()
23 nodes =
new List<LightningNode>();
26 public void Add(LightningNode n)
32 internal class LightningNode
34 private LightningNode parentNode;
35 private List<LightningNode> childNodes;
36 public List<LightningNode> ChildNodes {
get {
return childNodes; } }
38 private double splitChance = 0;
39 public double SplitChance {
get {
return splitChance; } }
41 private Vector position;
42 public Vector Position {
get {
return position; }
set { position = value; } }
43 public LightningNode()
45 childNodes =
new List<LightningNode>();
48 public LightningNode(Vector position)
50 this.position = position;
51 childNodes =
new List<LightningNode>();
54 public void AddChild(Vector position)
56 AddChild(
new LightningNode(position));
59 public void AddChild(LightningNode node)
61 node.parentNode =
this;
62 this.childNodes.Add(node);
69 private LightningLayer[] layers;
71 private List<LightningNode> nodes;
72 private int layerAmount = 7;
74 private int currentLayer;
76 private double height;
79 private bool striking =
false;
80 private double strikeSpeed = 0.0;
82 private Color levelColor;
84 private int particlesPerLayer;
87 : base(particleImage, maxAmountOfParticles)
90 particlesPerLayer = maxAmountOfParticles / layers.Length;
104 if (strikeSpeed > 0.01)
106 foreach (LightningNode node
in layers[currentLayer].Nodes)
108 foreach (LightningNode child
in node.ChildNodes)
110 Vector v = child.Position - node.Position;
111 int particlesPerBranch = particlesPerLayer / node.ChildNodes.Count;
112 for (
int i = 0; i < particlesPerBranch; i++)
114 base.AddEffect(node.Position + v*(i/(
double)particlesPerBranch), 1);
121 if (currentLayer >= layers.Length)
131 private void InitializeLayers()
133 layers =
new LightningLayer[layerAmount];
134 for (
int i = 0; i < layers.Length; i++)
136 layers[i] =
new LightningLayer();
142 double branchHeight = height / layerAmount;
144 LightningNode startNode =
new LightningNode(startPoint);
145 layers[0].Add(startNode);
146 layers[0].Y = startNode.Position.Y;
149 for (
int i = 1; i < layers.Length - 1; i++)
151 for (
int j = 0; j < layers[i - 1].Nodes.Count; j++)
153 LightningNode currentNode = layers[i - 1].Nodes[j];
154 layers[i].Y = layers[i - 1].Y - branchHeight;
159 LightningNode nLeft =
new LightningNode(pLeft);
160 LightningNode nRight =
new LightningNode(pRight);
161 layers[i].Nodes.Add(nLeft);
162 currentNode.AddChild(nLeft);
163 layers[i].Nodes.Add(nRight);
164 currentNode.AddChild(nRight);
168 LightningNode n =
new LightningNode(p);
169 layers[i].Nodes.Add(n);
170 currentNode.AddChild(n);
Järjestelmä partikkelien käsittelyyn
Lightning(Image particleImage, int maxAmountOfParticles)
Satunnaisgeneraattori. Luo satunnaisia arvoja, mm. lukuja, vektoreita sekä kulmia.
static double NextDouble(double min, double max)
Palauttaa satunnaisen liukuluvun parametrien
TimeSpan SinceLastUpdate
Aika joka on kulunut viime päivityksestä.
static readonly Vector Zero
Nollavektori.
Sisältää tiedon ajasta, joka on kulunut pelin alusta ja viime päivityksestä.
override void InitializeParticle(Particle p, Vector position)
Alustaa yhden partikkelin
void Strike(Vector startPoint, double width, double height)
override void Update(Time time)
Peliolion päivitys. Tätä kutsutaan, kun IsUpdated-ominaisuuden arvoksi on asetettu true ja olio on li...
void Initialize(Vector position, double scale, double rotation, double rotationSpeed, Vector velocity, Vector acceleration, double lifetime)
Alusta partikkeli