96 lines
2.5 KiB
C#
96 lines
2.5 KiB
C#
using Voile;
|
|
using Voile.Resources;
|
|
using Voile.Utils;
|
|
using Voile.Input;
|
|
using Voile.Systems.Particles;
|
|
using System.Numerics;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
public class TestGame : Game
|
|
{
|
|
public override string ResourceRoot => "Resources/";
|
|
|
|
public override void Initialize()
|
|
{
|
|
InitializeDefault();
|
|
|
|
_particleSystem = new ParticleSystem();
|
|
|
|
ResourceManager.AddResourceLoaderAssociation(new ParticleEmitterSettingsResourceLoader());
|
|
|
|
Input.AddInputMapping("reload", new InputAction[] { new KeyInputAction(KeyboardKey.R) });
|
|
}
|
|
|
|
protected override void LoadResources()
|
|
{
|
|
// if (!ResourceManager.TryLoad("my_sound", "sounds/test_sound.ogg", out Sound? _testSound))
|
|
// {
|
|
|
|
// }
|
|
|
|
// if (!ResourceManager.TryLoad("inter_regular", "fonts/Inter-Regular.ttf", out Font? _font))
|
|
// {
|
|
|
|
// }
|
|
|
|
if (!ResourceManager.TryLoad("test_emitter.toml", out _emitterSettings))
|
|
{
|
|
throw new Exception("Failed to load emitter settings!");
|
|
}
|
|
}
|
|
|
|
protected override void Ready()
|
|
{
|
|
_emitterId = _particleSystem.CreateEmitter(Renderer.WindowSize / 2, _emitterSettings);
|
|
}
|
|
|
|
protected override void Run()
|
|
{
|
|
while (Renderer.ShouldRun)
|
|
{
|
|
if (Input.IsActionPressed("reload"))
|
|
{
|
|
ResourceManager.Reload();
|
|
_particleSystem!.RestartEmitter(_emitterId);
|
|
}
|
|
|
|
_particleSystem!.Update(Renderer.FrameTime);
|
|
|
|
Renderer.BeginFrame();
|
|
Renderer.ClearBackground(Color.Black);
|
|
foreach (var emitter in _particleSystem!.Emitters)
|
|
{
|
|
DrawEmitter(emitter);
|
|
}
|
|
|
|
Renderer.EndFrame();
|
|
}
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
ShutdownDefault();
|
|
}
|
|
|
|
private void DrawEmitter(ParticleEmitter emitter)
|
|
{
|
|
Renderer.BeginBlended(Voile.Rendering.BlendMode.BlendAlpha);
|
|
|
|
for (int i = 0; i < emitter.Particles.Length; i++)
|
|
{
|
|
var particle = emitter.Particles[i];
|
|
|
|
var color = new Color(particle.ColorArgb);
|
|
|
|
Renderer.SetTransform(emitter.OriginPosition + particle.Position, Vector2.Zero);
|
|
Renderer.DrawCircle(16f * particle.Scale, color);
|
|
}
|
|
|
|
Renderer.EndBlended();
|
|
}
|
|
|
|
[NotNull] private ParticleSystem _particleSystem;
|
|
private int _emitterId;
|
|
private ResourceRef<ParticleEmitterSettingsResource> _emitterSettings;
|
|
private Logger _logger = new(nameof(TestGame));
|
|
} |