97 lines
2.6 KiB
C#
97 lines
2.6 KiB
C#
using Voile;
|
|
using Voile.Audio;
|
|
using Voile.Resources;
|
|
using Voile.SceneGraph;
|
|
using Voile.Utils;
|
|
|
|
public class TestGame : Game
|
|
{
|
|
public override string ResourceRoot => "Resources/";
|
|
|
|
public override void Initialize()
|
|
{
|
|
InitializeDefault();
|
|
|
|
_audioSystem = new FmodAudioSystem();
|
|
_audioSystem.Start();
|
|
}
|
|
|
|
protected override void LoadResources()
|
|
{
|
|
if (ResourceManager.TryLoad<Sound>("my_sound", "sounds/test_sound.ogg"))
|
|
{
|
|
ResourceManager.TryGetResource("my_sound", out _testSound);
|
|
}
|
|
|
|
if (ResourceManager.TryLoad<Font>("inter_regular", "fonts/Inter-Regular.ttf"))
|
|
{
|
|
ResourceManager.TryGetResource("inter_regular", out _font);
|
|
|
|
if (_font is not null)
|
|
{
|
|
_font.Size = 20;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void Ready()
|
|
{
|
|
_scene = new Scene(new SceneSettings()
|
|
{
|
|
Renderer = Renderer,
|
|
AudioBackend = _audioSystem!,
|
|
InputHandler = Input,
|
|
ResourceManager = ResourceManager
|
|
});
|
|
|
|
_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 (_scene!.ShouldRun)
|
|
{
|
|
if (Input.IsActionPressed("play"))
|
|
{
|
|
_testSoundInstance!.PitchVariation(0.9f, 1.1f)
|
|
.VolumeVariation(0.98f, 1.02f);
|
|
|
|
_testSoundInstance!.Play();
|
|
}
|
|
_scene.Update();
|
|
_scene.BeginDraw();
|
|
_scene.EndDraw();
|
|
}
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
ShutdownDefault();
|
|
_audioSystem!.Dispose();
|
|
}
|
|
|
|
private Sound? _testSound;
|
|
private SoundInstance? _testSoundInstance;
|
|
private Font? _font;
|
|
private FmodAudioSystem? _audioSystem;
|
|
private Scene? _scene;
|
|
|
|
private UiLayer? _uiLayer;
|
|
private EntityLayer? _worldLayer;
|
|
private Logger _logger = new(nameof(TestGame));
|
|
} |