Add new methods to input handler, add RectangleShape2d, modify test game.
This commit is contained in:
@@ -4,6 +4,7 @@ using DaggerFramework;
|
||||
using DaggerFramework.Rendering;
|
||||
using DaggerFramework.Audio;
|
||||
using DaggerFramework.Resources;
|
||||
using DaggerFramework.SceneGraph;
|
||||
|
||||
|
||||
public class TestGame : Game
|
||||
@@ -20,56 +21,17 @@ public class TestGame : Game
|
||||
{
|
||||
Title = "Test Game",
|
||||
Size = new Vector2(1280, 720)
|
||||
}, RendererSettings.Default);
|
||||
_renderer.SetTargetFps(60);
|
||||
}, new RendererSettings()
|
||||
{
|
||||
UseVSync = false
|
||||
});
|
||||
|
||||
_audioBackend.Initialize();
|
||||
}
|
||||
|
||||
protected override void LoadResources()
|
||||
{
|
||||
if (_resourceManager.TryLoad<Sound>("my_sound", "sounds/test_sound.ogg"))
|
||||
{
|
||||
_resourceManager.TryGetResource<Sound>("my_sound", out _testSound);
|
||||
}
|
||||
_scene = new Scene(_renderer, _inputHandler, _audioBackend, _resourceManager);
|
||||
|
||||
if (_resourceManager.TryLoad<Font>("inter_regular", "fonts/Inter-Regular.ttf"))
|
||||
{
|
||||
_resourceManager.TryGetResource<Font>("inter_regular", out _font);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Ready()
|
||||
{
|
||||
// _audioBackend.AddBusEffect<AudioEffectReverb>(new AudioEffectReverb());
|
||||
_inputHandler.AddInputMapping("play", new InputAction[] { new KeyInputAction(KeyboardKey.Spacebar) });
|
||||
_fontHandle = _renderer.LoadFont(_font);
|
||||
}
|
||||
|
||||
protected override void Run()
|
||||
{
|
||||
while (_renderer.ShouldRun)
|
||||
{
|
||||
_renderer.BeginFrame();
|
||||
_renderer.ClearBackground(Color.Black);
|
||||
|
||||
if (_inputHandler.IsActionJustPressed("play"))
|
||||
{
|
||||
var instance = _audioBackend.CreateInstance(_testSound)
|
||||
.PitchVariation(min: 0.9f, max: 1.2f)
|
||||
.VolumeVariation(min: 0.90f, max: 1.0f);
|
||||
instance.Play();
|
||||
}
|
||||
|
||||
_audioBackend.Update();
|
||||
|
||||
_renderer.SetTransform(new Vector2(640, 480));
|
||||
_renderer.DrawCircle(16f, Color.Chocolate);
|
||||
|
||||
_renderer.DrawText(_fontHandle, "Hello World!", 24, Color.White);
|
||||
|
||||
_renderer.EndFrame();
|
||||
}
|
||||
_uiLayer = new UiLayer();
|
||||
_worldLayer = new EntityLayer();
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
@@ -78,6 +40,60 @@ public class TestGame : Game
|
||||
_audioBackend.Shutdown();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Ready()
|
||||
{
|
||||
_inputHandler.AddInputMapping("play", new InputAction[] { new KeyInputAction(KeyboardKey.Spacebar) });
|
||||
_inputHandler.AddInputMapping("sprint", new InputAction[] { new KeyInputAction(KeyboardKey.LeftShift) });
|
||||
|
||||
_fontHandle = _renderer.LoadFont(_font);
|
||||
|
||||
_scene.AddLayer("World", _worldLayer);
|
||||
_scene.AddLayer("UI", _uiLayer);
|
||||
_worldLayer.AddEntity(new TestPlayer());
|
||||
|
||||
_scene.Start();
|
||||
}
|
||||
|
||||
protected override void Run()
|
||||
{
|
||||
while (!_scene.ShouldStop())
|
||||
{
|
||||
// _renderer.BeginFrame();
|
||||
// _renderer.ClearBackground(Color.Black);
|
||||
|
||||
// if (_inputHandler.IsActionJustPressed("play"))
|
||||
// {
|
||||
// var instance = _audioBackend.CreateInstance(_testSound)
|
||||
// .PitchVariation(min: 0.9f, max: 1.2f)
|
||||
// .VolumeVariation(min: 0.90f, max: 1.0f);
|
||||
// instance.Play();
|
||||
// }
|
||||
|
||||
// _audioBackend.Update();
|
||||
|
||||
// _renderer.SetTransform(new Vector2(32, 32));
|
||||
// _renderer.DrawCircle(16f, Color.Chocolate);
|
||||
|
||||
// _renderer.DrawText(_fontHandle, $"{(int)(1 / _renderer.GetFrameTime())} FPS", 20, Color.White);
|
||||
|
||||
// _renderer.EndFrame();
|
||||
_scene.Update();
|
||||
}
|
||||
}
|
||||
|
||||
private Renderer _renderer;
|
||||
private ResourceManager _resourceManager = new();
|
||||
private Sound? _testSound;
|
||||
@@ -85,4 +101,8 @@ public class TestGame : Game
|
||||
private int _fontHandle;
|
||||
private FmodAudioBackend _audioBackend;
|
||||
private InputHandler _inputHandler;
|
||||
private Scene _scene;
|
||||
|
||||
private UiLayer _uiLayer;
|
||||
private EntityLayer _worldLayer;
|
||||
}
|
||||
Reference in New Issue
Block a user