Add ParticleSystem, fix incorrect Argb conversion in Color, remove byte casting in LerpColor, update TestGame to demostrate particle system.
This commit is contained in:
@@ -4,6 +4,8 @@ using Voile.Resources;
|
||||
using Voile.SceneGraph;
|
||||
using Voile.Utils;
|
||||
using Voile.Input;
|
||||
using Voile.Systems;
|
||||
using System.Numerics;
|
||||
|
||||
public class TestGame : Game
|
||||
{
|
||||
@@ -12,9 +14,7 @@ public class TestGame : Game
|
||||
public override void Initialize()
|
||||
{
|
||||
InitializeDefault();
|
||||
|
||||
_audioSystem = new FmodAudioSystem();
|
||||
_audioSystem.Start();
|
||||
_particleSystem = new ParticleSystem();
|
||||
}
|
||||
|
||||
protected override void LoadResources()
|
||||
@@ -32,62 +32,50 @@ public class TestGame : Game
|
||||
|
||||
protected override void Ready()
|
||||
{
|
||||
_scene = new Scene(new SceneSettings()
|
||||
_particleSystem!.CreateEmitter(Renderer.WindowSize / 2, new ParticleEmitterSettings()
|
||||
{
|
||||
Renderer = Renderer,
|
||||
AudioBackend = _audioSystem!,
|
||||
InputHandler = Input,
|
||||
ResourceManager = ResourceManager
|
||||
ColorBegin = Color.Green,
|
||||
ColorEnd = Color.Red,
|
||||
EmitRadius = 128,
|
||||
MaxParticles = 256
|
||||
});
|
||||
|
||||
_uiLayer = new UiLayer();
|
||||
_worldLayer = new EntityLayer();
|
||||
|
||||
_testSoundInstance = _audioSystem!.CreateInstance(_testSound!);
|
||||
|
||||
Input.AddInputMapping("play", new InputAction[] { new KeyInputAction(KeyboardKey.Spacebar) });
|
||||
Input.AddInputMapping("sprint", new InputAction[] { new KeyInputAction(KeyboardKey.LeftShift) });
|
||||
Input.AddInputMapping("toggle_fullscreen", new InputAction[] { new KeyInputAction(KeyboardKey.F11) });
|
||||
|
||||
_scene!.AddLayer("World", _worldLayer!);
|
||||
|
||||
_worldLayer!.AddEntity(new World());
|
||||
_worldLayer.AddEntity(new TestPlayer());
|
||||
|
||||
_scene.AddLayer("UI", _uiLayer!);
|
||||
_scene.Start();
|
||||
}
|
||||
|
||||
protected override void Run()
|
||||
{
|
||||
while (Renderer.ShouldRun)
|
||||
{
|
||||
if (Input.IsActionPressed("play"))
|
||||
{
|
||||
_testSoundInstance!.PitchVariation(0.9f, 1.1f)
|
||||
.VolumeVariation(0.98f, 1.02f);
|
||||
_particleSystem!.Update(Renderer.FrameTime);
|
||||
|
||||
_testSoundInstance!.Play();
|
||||
Renderer.BeginFrame();
|
||||
Renderer.ClearBackground(Color.Black);
|
||||
foreach (var emitter in _particleSystem!.Emitters)
|
||||
{
|
||||
DrawEmitter(emitter);
|
||||
}
|
||||
_scene.Update();
|
||||
_scene.BeginDraw();
|
||||
_scene.EndDraw();
|
||||
|
||||
Renderer.EndFrame();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
ShutdownDefault();
|
||||
_audioSystem!.Dispose();
|
||||
}
|
||||
|
||||
private Sound? _testSound;
|
||||
private SoundInstance? _testSoundInstance;
|
||||
private Font? _font;
|
||||
private FmodAudioSystem? _audioSystem;
|
||||
private Scene? _scene;
|
||||
private void DrawEmitter(ParticleEmitter emitter)
|
||||
{
|
||||
for (int i = 0; i < emitter.Particles.Length; i++)
|
||||
{
|
||||
var particle = emitter.Particles[i];
|
||||
|
||||
private UiLayer? _uiLayer;
|
||||
private EntityLayer? _worldLayer;
|
||||
var color = new Color(particle.ColorArgb);
|
||||
|
||||
Renderer.SetTransform(emitter.OriginPosition + particle.Position, Vector2.Zero);
|
||||
Renderer.DrawCircle(16f * particle.Scale, color);
|
||||
}
|
||||
}
|
||||
|
||||
private ParticleSystem? _particleSystem;
|
||||
private Logger _logger = new(nameof(TestGame));
|
||||
}
|
||||
Reference in New Issue
Block a user