Finalize ParticleSystem, add angular velocity, multiple emitters, GetBool for IDataReader, use Lerp in LerpColor.
This commit is contained in:
20
TestGame/Resources/fire_effect.toml
Normal file
20
TestGame/Resources/fire_effect.toml
Normal file
@@ -0,0 +1,20 @@
|
||||
# Fire effect example
|
||||
[ParticleEmitterSettings]
|
||||
|
||||
Local = true
|
||||
MaxParticles = 128
|
||||
EmitRadius = 8
|
||||
Explosiveness = 0
|
||||
LifeTime = 1.0
|
||||
Direction = [0.0, -1.0]
|
||||
LinearVelocity = 200
|
||||
LinearVelocityDamping = 0.0
|
||||
AngularVelocity = 230
|
||||
AngularVelocityDamping = 0.0
|
||||
AngularVelocityRandom = 1.0
|
||||
Gravity = [0.0, 0.0]
|
||||
LinearVelocityRandom = 0.5
|
||||
ScaleBegin = 0.1
|
||||
ScaleEnd = 5.0
|
||||
ColorBegin = [255, 162, 0]
|
||||
ColorEnd = [64, 64, 64, 0]
|
||||
@@ -1,14 +0,0 @@
|
||||
[ParticleEmitterSettings]
|
||||
|
||||
MaxParticles = 1024
|
||||
EmitRadius = 128
|
||||
Explosiveness = 1.0
|
||||
LifeTime = 2.0
|
||||
Direction = [0.0, -1.0]
|
||||
LinearVelocity = 200
|
||||
Gravity = [0.0, 0.0]
|
||||
LinearVelocityRandom = 0.5
|
||||
ScaleBegin = 1.0
|
||||
ScaleEnd = 5.0
|
||||
ColorBegin = [255, 0, 0, 0]
|
||||
ColorEnd = [0, 255, 0, 255]
|
||||
@@ -26,11 +26,6 @@ public class TestGame : Game
|
||||
|
||||
protected override void LoadResources()
|
||||
{
|
||||
// if (!ResourceManager.TryLoad("my_sound", "sounds/test_sound.ogg", out Sound? _testSound))
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
if (!ResourceManager.TryLoad("fonts/Inter-Regular.ttf", out _font))
|
||||
{
|
||||
|
||||
@@ -38,7 +33,7 @@ public class TestGame : Game
|
||||
|
||||
ResourceManager.TryLoad("icon.png", out _icon);
|
||||
|
||||
if (!ResourceManager.TryLoad("test_emitter.toml", out _emitterSettings))
|
||||
if (!ResourceManager.TryLoad("fire_effect.toml", out _fireEffect))
|
||||
{
|
||||
throw new Exception("Failed to load emitter settings!");
|
||||
}
|
||||
@@ -46,7 +41,7 @@ public class TestGame : Game
|
||||
|
||||
protected override void Ready()
|
||||
{
|
||||
_emitterId = _particleSystem.CreateEmitter(Renderer.WindowSize / 2, _emitterSettings);
|
||||
_emitterId = _particleSystem.CreateEmitter(Renderer.WindowSize / 2, _fireEffect);
|
||||
}
|
||||
|
||||
protected override void Run()
|
||||
@@ -59,6 +54,16 @@ public class TestGame : Game
|
||||
_particleSystem!.RestartEmitter(_emitterId);
|
||||
}
|
||||
|
||||
if (Input.KeyboardKeyJustPressed(KeyboardKey.One))
|
||||
{
|
||||
_particleSystem.CreateEmitter(Input.GetMousePosition(), _fireEffect);
|
||||
}
|
||||
|
||||
if (Input.IsMouseButtonDown(MouseButton.Left))
|
||||
{
|
||||
_particleSystem.SetEmitterPosition(_emitterId, Input.GetMousePosition());
|
||||
}
|
||||
|
||||
_particleSimStopwatch = Stopwatch.StartNew();
|
||||
_particleSystem!.Update(Renderer.FrameTime);
|
||||
_particleSimStopwatch.Stop();
|
||||
@@ -97,15 +102,15 @@ public class TestGame : Game
|
||||
Renderer.BeginBlended(Voile.Rendering.BlendMode.BlendAlpha);
|
||||
|
||||
var maxParticles = emitter.Settings.MaxParticles;
|
||||
var particleSize = new Vector2(16.0f, 16.0f);
|
||||
var pivot = particleSize / 2;
|
||||
|
||||
for (int i = maxParticles - 1; i > 0; i--)
|
||||
for (int i = maxParticles - 1; i >= 0; i--)
|
||||
{
|
||||
var particle = emitter.GetParticle(i);
|
||||
|
||||
var color = new Color(particle.ColorArgb);
|
||||
|
||||
Renderer.SetTransform(emitter.OriginPosition + particle.Position, Vector2.Zero);
|
||||
Renderer.DrawRectangle(Vector2.One * 16.0f * particle.Scale, color);
|
||||
Renderer.SetTransform(particle.Position, pivot, particle.Rotation);
|
||||
Renderer.DrawRectangle(particleSize * particle.Scale, particle.Color);
|
||||
}
|
||||
|
||||
Renderer.EndBlended();
|
||||
@@ -116,7 +121,7 @@ public class TestGame : Game
|
||||
private Stopwatch _particleSimStopwatch, _renderStopwatch;
|
||||
private long _lastRenderTime;
|
||||
private int _emitterId;
|
||||
private ResourceRef<ParticleEmitterSettingsResource> _emitterSettings;
|
||||
private ResourceRef<ParticleEmitterSettingsResource> _fireEffect;
|
||||
private ResourceRef<Font> _font;
|
||||
private ResourceRef<Texture2d> _icon;
|
||||
private Logger _logger = new(nameof(TestGame));
|
||||
|
||||
Reference in New Issue
Block a user