@@ -37,21 +37,25 @@ public void Update()
37
37
// Check initial conditions emission
38
38
while ( ShouldEmit ( elapsed , movementComponent , particleComponent ) )
39
39
{
40
+
40
41
// Spawn new particles
41
42
_previousSpawn = DateTime . Now ;
43
+ var velocity = GetVelocity ( rng , particleComponent ) ;
42
44
var rotation = GetRotation ( rng , locationComponent , particleComponent ) ;
43
45
var location = GetLocation ( rng , locationComponent , particleComponent ) ;
44
46
var textureId = particleComponent . TextureIds [ rng . Next ( particleComponent . TextureIds . Length ) ] ;
45
47
46
48
_particles . Add ( new Particle
47
49
{
48
50
Location = location ,
51
+ Velocity = velocity ,
49
52
Lifetime = 0 ,
50
- Fade = 0 ,
53
+ Fade = particleComponent . InitialFade ,
51
54
Size = particleComponent . InitialSize ,
52
55
TextureId = textureId ,
53
56
FacingAngle = rotation ,
54
57
PaletteTextureId = particleComponent . PaletteTextureId ,
58
+ PalleteSpeed = particleComponent . PalleteSpeed ,
55
59
} ) ;
56
60
}
57
61
@@ -60,6 +64,7 @@ public void Update()
60
64
{
61
65
p . Lifetime += ( float ) elapsed ;
62
66
p . Size *= particleComponent . GrowRate ;
67
+ p . Location += p . Velocity ;
63
68
64
69
if ( p . Lifetime > particleComponent . FadeDelay )
65
70
p . Fade = ( byte ) Math . Min ( 255 , p . Fade + particleComponent . FadeRate ) ; // todo: this should be timebased
@@ -94,7 +99,7 @@ public void Draw(Rectangle viewport, IGraphics graphics)
94
99
if ( TextureFactory . TryGetTexture ( p . PaletteTextureId , out var palette ) )
95
100
{
96
101
// todo: change this to stay on the last colour?
97
- var hue = palette . Image . GetPalette ( p . HueIndex ++ , 40 ) ;
102
+ var hue = palette . Image . GetPalette ( p . HueIndex ++ , p . PalleteSpeed ) ;
98
103
rotated . ChangeHue ( hue ) ;
99
104
}
100
105
@@ -106,6 +111,13 @@ public void Draw(Rectangle viewport, IGraphics graphics)
106
111
}
107
112
}
108
113
114
+ private static Vector2 GetVelocity ( Random rng , ParticleComponent particleComponent )
115
+ {
116
+ var jitterX = rng . Next ( - particleComponent . InitialVelocity , particleComponent . InitialVelocity ) ;
117
+ var jitterY = rng . Next ( - particleComponent . InitialVelocity , particleComponent . InitialVelocity ) ;
118
+ return new Vector2 ( jitterX , jitterY ) ;
119
+ }
120
+
109
121
private static Vector2 GetLocation ( Random rng , LocationComponent locationComponent , ParticleComponent particleComponent )
110
122
{
111
123
var jitterX = rng . Next ( - particleComponent . SpawnOffset , particleComponent . SpawnOffset ) ;
0 commit comments