Jypeli
10
The simple game programming library
Lightning.cs
Siirry tämän tiedoston dokumentaatioon.
1
using
System
.Collections.Generic;
2
3
namespace
Jypeli.Effects
4
{
5
internal
class
LightningLayer
6
{
7
public
List<LightningNode>
Nodes
8
{
9
get
{
return
nodes
; }
10
set
{
nodes
= value; }
11
}
12
13
private
List<LightningNode>
nodes
;
14
15
private
double
y
;
16
public
double
Y
{
get
{
return
y
; }
set
{
y
= value; } }
17
18
public
LightningLayer
()
19
{
20
nodes
=
new
List<LightningNode>();
21
}
22
23
public
void
Add
(
LightningNode
n)
24
{
25
nodes
.Add(n);
26
}
27
}
28
29
internal
class
LightningNode
30
{
31
private
LightningNode
parentNode
;
32
private
List<LightningNode>
childNodes
;
33
public
List<LightningNode>
ChildNodes
{
get
{
return
childNodes
; } }
34
35
private
double
splitChance
= 0;
36
public
double
SplitChance
{
get
{
return
splitChance
; } }
37
38
private
Vector
position
;
39
public
Vector
Position
{
get
{
return
position
; }
set
{
position
= value; } }
40
public
LightningNode
()
41
{
42
childNodes
=
new
List<LightningNode>();
43
}
44
45
public
LightningNode
(
Vector
position
)
46
{
47
this.position =
position
;
48
childNodes
=
new
List<LightningNode>();
49
}
50
51
public
void
AddChild
(
Vector
position
)
52
{
53
AddChild
(
new
LightningNode
(
position
));
54
}
55
56
public
void
AddChild
(
LightningNode
node)
57
{
58
node.
parentNode
=
this
;
59
this.childNodes.Add(node);
60
}
61
}
62
66
public
class
Lightning
:
ParticleSystem
67
{
68
private
LightningLayer
[]
layers
;
69
//public LightningLayer[] Layers { get { return layers; } }
70
//private List<LightningNode> nodes;
71
private
int
layerAmount
= 7;
72
73
private
int
currentLayer
;
74
75
//private double height;
76
//private double width;
77
78
private
bool
striking
=
false
;
79
private
double
strikeSpeed
= 0.0;
80
81
//private Color levelColor;
82
83
private
int
particlesPerLayer
;
84
90
public
Lightning
(
Image
particleImage,
int
maxAmountOfParticles)
91
: base(particleImage, maxAmountOfParticles)
92
{
93
InitializeLayers
();
94
particlesPerLayer
= maxAmountOfParticles /
layers
.Length;
95
}
96
98
protected
override
void
InitializeParticle
(
Particle
p,
Vector
position)
99
{
100
p.
Initialize
(position, 2.0, 0.0, 0.0,
Vector
.
Zero
,
Vector
.
Zero
, 0.4);
101
}
102
104
public
override
void
Update
(
Time
time)
105
{
106
double
t = time.
SinceLastUpdate
.TotalSeconds;
107
strikeSpeed
+= t;
108
if
(
striking
)
109
{
110
if
(
strikeSpeed
> 0.01)
111
{
112
foreach
(
LightningNode
node
in
layers
[
currentLayer
].Nodes)
113
{
114
foreach
(
LightningNode
child
in
node.
ChildNodes
)
115
{
116
Vector
v = child.
Position
- node.
Position
;
117
int
particlesPerBranch =
particlesPerLayer
/ node.
ChildNodes
.Count;
118
for
(
int
i = 0; i < particlesPerBranch; i++)
119
{
120
base.AddEffect(node.
Position
+ v*(i/(
double
)particlesPerBranch), 1);
121
}
122
}
123
//base.AddEffect(node.Position, 1);
124
}
125
currentLayer
++;
126
strikeSpeed
= 0.0;
127
if
(
currentLayer
>=
layers
.Length)
128
{
129
striking
=
false
;
130
currentLayer
= 0;
131
}
132
}
133
}
134
base.Update(time);
135
}
136
137
private
void
InitializeLayers
()
138
{
139
layers
=
new
LightningLayer
[
layerAmount
];
140
for
(
int
i = 0; i <
layers
.Length; i++)
141
{
142
layers
[i] =
new
LightningLayer
();
143
}
144
}
145
152
public
void
Strike
(
Vector
startPoint,
double
width,
double
height)
153
{
154
double
branchHeight = height /
layerAmount
;
155
InitializeLayers
();
156
LightningNode
startNode =
new
LightningNode
(startPoint);
157
layers
[0].
Add
(startNode);
158
layers
[0].
Y
= startNode.
Position
.
Y
;
159
//startNode.AddChild(startPoint);
160
161
for
(
int
i = 1; i <
layers
.Length - 1; i++)
162
{
163
for
(
int
j = 0; j <
layers
[i - 1].
Nodes
.Count; j++)
164
{
165
LightningNode
currentNode =
layers
[i - 1].
Nodes
[j];
166
layers
[i].
Y
=
layers
[i - 1].
Y
- branchHeight;
167
if
(
RandomGen
.
NextDouble
(0, 100) <
layers
[i - 1].
Nodes
[j].SplitChance)
168
{
169
Vector
pLeft =
new
Vector
(
RandomGen
.
NextDouble
(currentNode.
Position
.
X
- width / 6, currentNode.
Position
.
X
),
layers
[i].
Y
);
170
Vector
pRight =
new
Vector
(
RandomGen
.
NextDouble
(currentNode.
Position
.
X
, currentNode.
Position
.
X
+ width / 6),
layers
[i].
Y
);
171
LightningNode
nLeft =
new
LightningNode
(pLeft);
172
LightningNode
nRight =
new
LightningNode
(pRight);
173
layers
[i].
Nodes
.Add(nLeft);
174
currentNode.
AddChild
(nLeft);
175
layers
[i].
Nodes
.Add(nRight);
176
currentNode.
AddChild
(nRight);
177
178
}
179
Vector
p =
new
Vector
(
RandomGen
.
NextDouble
(startPoint.
X
- width / 4, startPoint.
X
+ width / 4),
layers
[i].
Y
);
180
LightningNode
n =
new
LightningNode
(p);
181
layers
[i].
Nodes
.Add(n);
182
currentNode.
AddChild
(n);
183
}
184
}
185
striking
=
true
;
186
}
187
}
188
}
Jypeli.Effects.Lightning
Salama
Definition:
Lightning.cs:67
Jypeli.Effects.Lightning.Strike
void Strike(Vector startPoint, double width, double height)
Luo salamaniskun lähtien annetusta pisteestä
Definition:
Lightning.cs:152
Jypeli.Effects.Lightning.layers
LightningLayer[] layers
Definition:
Lightning.cs:68
Jypeli.Effects.Lightning.striking
bool striking
Definition:
Lightning.cs:78
Jypeli.Effects.Lightning.particlesPerLayer
int particlesPerLayer
Definition:
Lightning.cs:83
Jypeli.Effects.Lightning.Update
override void Update(Time time)
Peliolion päivitys. Tätä kutsutaan, kun IsUpdated-ominaisuuden arvoksi on asetettu true ja olio on li...
Definition:
Lightning.cs:104
Jypeli.Effects.Lightning.layerAmount
int layerAmount
Definition:
Lightning.cs:71
Jypeli.Effects.Lightning.Lightning
Lightning(Image particleImage, int maxAmountOfParticles)
Salama
Definition:
Lightning.cs:90
Jypeli.Effects.Lightning.InitializeLayers
void InitializeLayers()
Definition:
Lightning.cs:137
Jypeli.Effects.Lightning.currentLayer
int currentLayer
Definition:
Lightning.cs:73
Jypeli.Effects.Lightning.InitializeParticle
override void InitializeParticle(Particle p, Vector position)
Alustaa yhden partikkelin
Definition:
Lightning.cs:98
Jypeli.Effects.Lightning.strikeSpeed
double strikeSpeed
Definition:
Lightning.cs:79
Jypeli.Effects.LightningLayer
Definition:
Lightning.cs:6
Jypeli.Effects.LightningLayer.Add
void Add(LightningNode n)
Definition:
Lightning.cs:23
Jypeli.Effects.LightningLayer.nodes
List< LightningNode > nodes
Definition:
Lightning.cs:13
Jypeli.Effects.LightningLayer.Y
double Y
Definition:
Lightning.cs:16
Jypeli.Effects.LightningLayer.Nodes
List< LightningNode > Nodes
Definition:
Lightning.cs:8
Jypeli.Effects.LightningLayer.y
double y
Definition:
Lightning.cs:15
Jypeli.Effects.LightningLayer.LightningLayer
LightningLayer()
Definition:
Lightning.cs:18
Jypeli.Effects.LightningNode
Definition:
Lightning.cs:30
Jypeli.Effects.LightningNode.position
Vector position
Definition:
Lightning.cs:38
Jypeli.Effects.LightningNode.splitChance
double splitChance
Definition:
Lightning.cs:35
Jypeli.Effects.LightningNode.AddChild
void AddChild(Vector position)
Definition:
Lightning.cs:51
Jypeli.Effects.LightningNode.childNodes
List< LightningNode > childNodes
Definition:
Lightning.cs:32
Jypeli.Effects.LightningNode.ChildNodes
List< LightningNode > ChildNodes
Definition:
Lightning.cs:33
Jypeli.Effects.LightningNode.LightningNode
LightningNode()
Definition:
Lightning.cs:40
Jypeli.Effects.LightningNode.Position
Vector Position
Definition:
Lightning.cs:39
Jypeli.Effects.LightningNode.parentNode
LightningNode parentNode
Definition:
Lightning.cs:31
Jypeli.Effects.LightningNode.SplitChance
double SplitChance
Definition:
Lightning.cs:36
Jypeli.Effects.LightningNode.AddChild
void AddChild(LightningNode node)
Definition:
Lightning.cs:56
Jypeli.Effects.LightningNode.LightningNode
LightningNode(Vector position)
Definition:
Lightning.cs:45
Jypeli.Effects.Particle
Partikkeli
Definition:
Particle.cs:9
Jypeli.Effects.Particle.Initialize
void Initialize(Vector position, double scale, double rotation, double rotationSpeed, Vector velocity, Vector acceleration, double lifetime)
Alusta partikkeli
Definition:
Particle.cs:112
Jypeli.Effects.ParticleSystem
Järjestelmä partikkelien käsittelyyn
Definition:
ParticleSystem.cs:24
Jypeli.Image
Kuva.
Definition:
Image.cs:30
Jypeli.RandomGen
Satunnaisgeneraattori. Luo satunnaisia arvoja, mm. lukuja, vektoreita sekä kulmia.
Definition:
RandomGen.cs:39
Jypeli.RandomGen.NextDouble
static double NextDouble(double min, double max)
Palauttaa satunnaisen liukuluvun parametrien
Definition:
RandomGen.cs:70
Jypeli.Effects
Definition:
ExplosionSystem.cs:4
System
Definition:
CFFauxAttributes.cs:29
Jypeli.Time
Sisältää tiedon ajasta, joka on kulunut pelin alusta ja viime päivityksestä.
Definition:
Time.cs:14
Jypeli.Time.SinceLastUpdate
TimeSpan SinceLastUpdate
Aika joka on kulunut viime päivityksestä.
Definition:
Time.cs:27
Jypeli.Vector
2D-vektori.
Definition:
Vector.cs:67
Jypeli.Vector.Y
double Y
Vektorin Y-komponentti
Definition:
Vector.cs:339
Jypeli.Vector.Zero
static readonly Vector Zero
Nollavektori.
Definition:
Vector.cs:71
Jypeli.Vector.X
double X
Vektorin X-komponentti.
Definition:
Vector.cs:334
Jypeli
Effects
Lightning.cs
Generoinut projektille Jypeli Tue Sep 14 2021 15:57:41
1.9.2