88 lines
2.3 KiB
C#
88 lines
2.3 KiB
C#
using Voile;
|
|
using Voile.Rendering;
|
|
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();
|
|
|
|
_audioBackend = new FmodAudioBackend();
|
|
_audioBackend.Initialize();
|
|
}
|
|
|
|
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 = _audioBackend!,
|
|
InputHandler = Input,
|
|
ResourceManager = ResourceManager
|
|
});
|
|
|
|
_uiLayer = new UiLayer();
|
|
_worldLayer = new EntityLayer();
|
|
|
|
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)
|
|
{
|
|
_scene.Update();
|
|
_scene.BeginDraw();
|
|
_scene.EndDraw();
|
|
}
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
ShutdownDefault();
|
|
_audioBackend!.Dispose();
|
|
}
|
|
|
|
private Sound? _testSound;
|
|
private Font? _font;
|
|
private FmodAudioBackend? _audioBackend;
|
|
private Scene? _scene;
|
|
|
|
private UiLayer? _uiLayer;
|
|
private EntityLayer? _worldLayer;
|
|
private Logger _logger = new(nameof(TestGame));
|
|
} |