93 lines
2.4 KiB
C#
93 lines
2.4 KiB
C#
using Voile;
|
|
using Voile.Audio;
|
|
using Voile.Resources;
|
|
using Voile.SceneGraph;
|
|
using Voile.Utils;
|
|
using Voile.Input;
|
|
|
|
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("my_sound", "sounds/test_sound.ogg", out Sound? _testSound))
|
|
{
|
|
|
|
}
|
|
|
|
if (!ResourceManager.TryLoad("inter_regular", "fonts/Inter-Regular.ttf", out Font? _font))
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
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 (Renderer.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));
|
|
} |