|
| 1 | +using Silk.NET.Input; |
| 2 | +using SimulationFramework; |
| 3 | +using SimulationFramework.Drawing; |
| 4 | +using SimulationFramework.Input; |
| 5 | +using System.Numerics; |
| 6 | + |
| 7 | +Start<Program>(); |
| 8 | + |
| 9 | +partial class Program : Simulation |
| 10 | +{ |
| 11 | + Color backgroundColor = Color.FromHSV(0, 0, .05f); |
| 12 | + Color foregroundColor = Color.FromHSV(0, 0, .75f); |
| 13 | + |
| 14 | + public override void OnInitialize() |
| 15 | + { |
| 16 | + } |
| 17 | + |
| 18 | + public override void OnRender(ICanvas canvas) |
| 19 | + { |
| 20 | + canvas.Clear(backgroundColor); |
| 21 | + canvas.Translate(canvas.Width / 2f, canvas.Height / 2f); |
| 22 | + |
| 23 | + canvas.PushState(); |
| 24 | + canvas.Translate(100, 0); |
| 25 | + DrawJoystick(canvas, Gamepad.RightJoystick, Gamepad.IsButtonDown(GamepadButton.RightStick)); |
| 26 | + canvas.PopState(); |
| 27 | + |
| 28 | + canvas.PushState(); |
| 29 | + canvas.Translate(-100, 0); |
| 30 | + DrawJoystick(canvas, Gamepad.LeftJoystick, Gamepad.IsButtonDown(GamepadButton.LeftStick)); |
| 31 | + canvas.PopState(); |
| 32 | + |
| 33 | + canvas.PushState(); |
| 34 | + canvas.Translate(100, -200); |
| 35 | + DrawTrigger(canvas, Gamepad.RightTrigger); |
| 36 | + DrawButton(canvas, new(0, 30), Gamepad.IsButtonDown(GamepadButton.RightBumper)); |
| 37 | + canvas.PopState(); |
| 38 | + |
| 39 | + canvas.PushState(); |
| 40 | + canvas.Translate(-100, -200); |
| 41 | + DrawTrigger(canvas, Gamepad.LeftTrigger); |
| 42 | + DrawButton(canvas, new(0, 30), Gamepad.IsButtonDown(GamepadButton.LeftBumper)); |
| 43 | + canvas.PopState(); |
| 44 | + |
| 45 | + canvas.PushState(); |
| 46 | + canvas.Translate(300, 0); |
| 47 | + DrawButton(canvas, new(0, 40), Gamepad.IsButtonDown(GamepadButton.A)); |
| 48 | + DrawButton(canvas, new(40, 0), Gamepad.IsButtonDown(GamepadButton.B)); |
| 49 | + DrawButton(canvas, new(-40, 0), Gamepad.IsButtonDown(GamepadButton.X)); |
| 50 | + DrawButton(canvas, new(0, -40), Gamepad.IsButtonDown(GamepadButton.Y)); |
| 51 | + canvas.PopState(); |
| 52 | + |
| 53 | + canvas.PushState(); |
| 54 | + canvas.Translate(-300, 0); |
| 55 | + DrawButton(canvas, new(0, 40), Gamepad.IsButtonDown(GamepadButton.Down)); |
| 56 | + DrawButton(canvas, new(40, 0), Gamepad.IsButtonDown(GamepadButton.Right)); |
| 57 | + DrawButton(canvas, new(-40, 0), Gamepad.IsButtonDown(GamepadButton.Left)); |
| 58 | + DrawButton(canvas, new(0, -40), Gamepad.IsButtonDown(GamepadButton.Up)); |
| 59 | + canvas.PopState(); |
| 60 | + |
| 61 | + canvas.PushState(); |
| 62 | + canvas.Translate(0, 200); |
| 63 | + DrawButton(canvas, new(60, 0), Gamepad.IsButtonDown(GamepadButton.Back)); |
| 64 | + DrawButton(canvas, new(0, 0), Gamepad.IsButtonDown(GamepadButton.Home)); |
| 65 | + DrawButton(canvas, new(-60, 0), Gamepad.IsButtonDown(GamepadButton.Start)); |
| 66 | + canvas.PopState(); |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + private void DrawJoystick(ICanvas canvas, Vector2 joystickPosition, bool down) |
| 71 | + { |
| 72 | + canvas.Fill(foregroundColor); |
| 73 | + canvas.DrawCircle(0, 0, 75); |
| 74 | + |
| 75 | + canvas.Fill(Color.Red); |
| 76 | + canvas.DrawLine(Vector2.Zero, joystickPosition * 75); |
| 77 | + |
| 78 | + if (down) |
| 79 | + { |
| 80 | + canvas.DrawCircle(0, 0, 70); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + private void DrawTrigger(ICanvas canvas, float position) |
| 85 | + { |
| 86 | + canvas.Fill(foregroundColor); |
| 87 | + canvas.DrawRect(0, 0, 20, 100, Alignment.BottomCenter); |
| 88 | + canvas.Fill(Color.Red); |
| 89 | + canvas.DrawRect(0, 0, 20, 100 * position, Alignment.BottomCenter); |
| 90 | + } |
| 91 | + |
| 92 | + private void DrawButton(ICanvas canvas, Vector2 offset, bool down) |
| 93 | + { |
| 94 | + canvas.PushState(); |
| 95 | + canvas.Translate(offset); |
| 96 | + canvas.Fill(foregroundColor); |
| 97 | + canvas.DrawCircle(0, 0, 20); |
| 98 | + if (down) |
| 99 | + { |
| 100 | + canvas.Fill(Color.Red); |
| 101 | + canvas.DrawCircle(0, 0, 16); |
| 102 | + } |
| 103 | + canvas.PopState(); |
| 104 | + } |
| 105 | +} |
0 commit comments