|
| 1 | +using Microsoft.Xna.Framework; |
| 2 | +using Microsoft.Xna.Framework.Graphics; |
| 3 | +using Microsoft.Xna.Framework.Input; |
| 4 | +using myStartkit.Core.Inputs; |
| 5 | + |
| 6 | +namespace AutoPong; |
| 7 | + |
| 8 | +public class Game1 : Game |
| 9 | +{ |
| 10 | + private GraphicsDeviceManager _graphics; |
| 11 | + private SpriteBatch _spriteBatch; |
| 12 | + private readonly InputState inputState = new InputState(); |
| 13 | + private SpriteFont hudFont; |
| 14 | + private int playerIndex = (int)PlayerIndex.One; |
| 15 | + private Color textDrawColour = Color.White; |
| 16 | + private int textStartPosition = 20; |
| 17 | + private int positionSpacing = 40; |
| 18 | + |
| 19 | + public Game1() |
| 20 | + { |
| 21 | + _graphics = new GraphicsDeviceManager(this); |
| 22 | + Content.RootDirectory = "Content"; |
| 23 | + IsMouseVisible = true; |
| 24 | + _graphics.IsFullScreen = true; |
| 25 | + _graphics.PreferredBackBufferWidth = 2560; |
| 26 | + _graphics.PreferredBackBufferHeight = 1440; |
| 27 | + } |
| 28 | + |
| 29 | + protected override void Initialize() |
| 30 | + { |
| 31 | + // TODO: Add your initialization logic here |
| 32 | + |
| 33 | + base.Initialize(); |
| 34 | + } |
| 35 | + |
| 36 | + protected override void LoadContent() |
| 37 | + { |
| 38 | + _spriteBatch = new SpriteBatch(GraphicsDevice); |
| 39 | + |
| 40 | + // TODO: use this.Content to load your game content here |
| 41 | + hudFont = Content.Load<SpriteFont>("Fonts/Hud"); |
| 42 | + } |
| 43 | + |
| 44 | + protected override void Update(GameTime gameTime) |
| 45 | + { |
| 46 | + inputState.Update(gameTime, GraphicsDevice.Viewport); |
| 47 | + |
| 48 | + base.Update(gameTime); |
| 49 | + } |
| 50 | + |
| 51 | + protected override void Draw(GameTime gameTime) |
| 52 | + { |
| 53 | + GraphicsDevice.Clear(Color.CornflowerBlue); |
| 54 | + |
| 55 | + string state = inputState.CurrentGamePadStates[playerIndex].IsConnected ? "Connected" : "Disconnected"; |
| 56 | + |
| 57 | + string connectedValue = $"GamePad: {state}"; |
| 58 | + string AbuttonValue = $"A Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.A)}"; |
| 59 | + string BbuttonValue = $"B Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.B)}"; |
| 60 | + string XbuttonValue = $"X Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.X)}"; |
| 61 | + string YbuttonValue = $"Y Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.Y)}"; |
| 62 | + |
| 63 | + string StartbuttonValue = $"Start Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.Start)}"; |
| 64 | + string BackbuttonValue = $"Back Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.Back)}"; |
| 65 | + string BigbuttonValue = $"Big Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.BigButton)}"; |
| 66 | + |
| 67 | + string DPadLbuttonValue = $"DPadL Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.DPadLeft)}"; |
| 68 | + string DPadRbuttonValue = $"DPadR Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.DPadRight)}"; |
| 69 | + string DPadUbuttonValue = $"DPadU Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.DPadUp)}"; |
| 70 | + string DPadDbuttonValue = $"DPadD Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.DPadDown)}"; |
| 71 | + |
| 72 | + string RBumperbuttonValue = $"RBumper Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.RightShoulder)}"; |
| 73 | + string RThumbstickbuttonValue = $"RThumbstick Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.RightThumbstickDown)}"; |
| 74 | + string RThumbstickStateValue = $"RThumbstick State: {inputState.CurrentGamePadStates[playerIndex].ThumbSticks.Right}"; |
| 75 | + string RTriggerValue = $"RTrigger Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.RightTrigger)}"; |
| 76 | + string RTriggerStateValue = $"RTrigger State: {inputState.CurrentGamePadStates[playerIndex].Triggers.Right}"; |
| 77 | + |
| 78 | + string LBumperbuttonValue = $"LBumper Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.LeftShoulder)}"; |
| 79 | + string LThumbstickbuttonValue = $"LThumbstick Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.LeftThumbstickDown)}"; |
| 80 | + string LThumbstickStateValue = $"LThumbstick State: {inputState.CurrentGamePadStates[playerIndex].ThumbSticks.Left}"; |
| 81 | + string LTriggerValue = $"LTrigger Button: {inputState.CurrentGamePadStates[playerIndex].IsButtonDown(Buttons.LeftTrigger)}"; |
| 82 | + string LTriggerStateValue = $"LTrigger State: {inputState.CurrentGamePadStates[playerIndex].Triggers.Left}"; |
| 83 | + _spriteBatch.Begin(); |
| 84 | + // TODO: Add your drawing code here |
| 85 | + _spriteBatch.DrawString(hudFont, connectedValue, new Vector2(20, textStartPosition), textDrawColour); |
| 86 | + DrawInputValue(AbuttonValue, 1); |
| 87 | + DrawInputValue(BbuttonValue, 2); |
| 88 | + DrawInputValue(XbuttonValue, 3); |
| 89 | + DrawInputValue(YbuttonValue, 4); |
| 90 | + |
| 91 | + DrawInputValue(StartbuttonValue, 5); |
| 92 | + DrawInputValue(BackbuttonValue, 6); |
| 93 | + DrawInputValue(BigbuttonValue, 7); |
| 94 | + |
| 95 | + DrawInputValue(DPadLbuttonValue, 8); |
| 96 | + DrawInputValue(DPadRbuttonValue, 9); |
| 97 | + DrawInputValue(DPadUbuttonValue, 10); |
| 98 | + DrawInputValue(DPadDbuttonValue, 11); |
| 99 | + |
| 100 | + DrawInputValue(LBumperbuttonValue, 12); |
| 101 | + DrawInputValue(LThumbstickbuttonValue, 13); |
| 102 | + DrawInputValue(LThumbstickStateValue, 14); |
| 103 | + DrawInputValue(LTriggerValue, 15); |
| 104 | + DrawInputValue(LTriggerStateValue, 16); |
| 105 | + |
| 106 | + DrawInputValue(RBumperbuttonValue, 17); |
| 107 | + DrawInputValue(RThumbstickbuttonValue, 18); |
| 108 | + DrawInputValue(RThumbstickStateValue, 19); |
| 109 | + DrawInputValue(RTriggerValue, 20); |
| 110 | + DrawInputValue(RTriggerStateValue, 21); |
| 111 | + |
| 112 | + _spriteBatch.End(); |
| 113 | + |
| 114 | + base.Draw(gameTime); |
| 115 | + } |
| 116 | + |
| 117 | + private void DrawInputValue(string AbuttonValue, int index) |
| 118 | + { |
| 119 | + _spriteBatch.DrawString(hudFont, AbuttonValue, new Vector2(20, GetTextPositionForIndex(index)), textDrawColour); |
| 120 | + } |
| 121 | + |
| 122 | + private int GetTextPositionForIndex(int index) |
| 123 | + { |
| 124 | + return textStartPosition + positionSpacing * index; |
| 125 | + } |
| 126 | +} |
0 commit comments