|
1 |
| -using Microsoft.Xna.Framework.Input; |
2 |
| -using MonoGameLibrary; |
3 |
| -using MonoGameLibrary.Input; |
4 |
| - |
5 |
| -namespace DungeonSlime; |
6 |
| - |
7 |
| -/// <summary> |
8 |
| -/// Provides a game-specific input abstraction that maps physical inputs |
9 |
| -/// to game actions, bridging our input system with game-specific functionality. |
10 |
| -/// </summary> |
11 |
| -public class GameController |
12 |
| -{ |
13 |
| - private KeyboardInfo _keyboard; |
14 |
| - private GamePadInfo _gamePad; |
15 |
| - |
16 |
| - /// <summary> |
17 |
| - /// Creates a new GameController that handles input for the game. |
18 |
| - /// </summary> |
19 |
| - public GameController() |
20 |
| - { |
21 |
| - _keyboard = Core.Input.Keyboard; |
22 |
| - _gamePad = Core.Input.GamePads[0]; |
23 |
| - } |
24 |
| - |
25 |
| - /// <summary> |
26 |
| - /// Returns true if the player has triggered the "move up" action. |
27 |
| - /// </summary> |
28 |
| - public bool MoveUp() |
29 |
| - { |
30 |
| - return _keyboard.WasKeyJustPressed(Keys.Up) || |
31 |
| - _keyboard.WasKeyJustPressed(Keys.W) || |
32 |
| - _gamePad.WasButtonJustPressed(Buttons.DPadUp) || |
33 |
| - _gamePad.WasButtonJustPressed(Buttons.LeftThumbstickUp); |
34 |
| - } |
35 |
| - |
36 |
| - /// <summary> |
37 |
| - /// Returns true if the player has triggered the "move down" action. |
38 |
| - /// </summary> |
39 |
| - public bool MoveDown() |
40 |
| - { |
41 |
| - return _keyboard.WasKeyJustPressed(Keys.Down) || |
42 |
| - _keyboard.WasKeyJustPressed(Keys.S) || |
43 |
| - _gamePad.WasButtonJustPressed(Buttons.DPadDown) || |
44 |
| - _gamePad.WasButtonJustPressed(Buttons.LeftThumbstickDown); |
45 |
| - } |
46 |
| - |
47 |
| - /// <summary> |
48 |
| - /// Returns true if the player has triggered the "move left" action. |
49 |
| - /// </summary> |
50 |
| - public bool MoveLeft() |
51 |
| - { |
52 |
| - return _keyboard.WasKeyJustPressed(Keys.Left) || |
53 |
| - _keyboard.WasKeyJustPressed(Keys.A) || |
54 |
| - _gamePad.WasButtonJustPressed(Buttons.DPadLeft) || |
55 |
| - _gamePad.WasButtonJustPressed(Buttons.LeftThumbstickLeft); |
56 |
| - } |
57 |
| - |
58 |
| - /// <summary> |
59 |
| - /// Returns true if the player has triggered the "move right" action. |
60 |
| - /// </summary> |
61 |
| - public bool MoveRight() |
62 |
| - { |
63 |
| - return _keyboard.WasKeyJustPressed(Keys.Right) || |
64 |
| - _keyboard.WasKeyJustPressed(Keys.D) || |
65 |
| - _gamePad.WasButtonJustPressed(Buttons.DPadRight) || |
66 |
| - _gamePad.WasButtonJustPressed(Buttons.LeftThumbstickRight); |
67 |
| - } |
68 |
| - |
69 |
| - /// <summary> |
70 |
| - /// Returns true if the player has triggered the "pause" action. |
71 |
| - /// </summary> |
72 |
| - public bool Pause() |
73 |
| - { |
74 |
| - return _keyboard.WasKeyJustPressed(Keys.Escape) || |
75 |
| - _gamePad.WasButtonJustPressed(Buttons.Start); |
76 |
| - } |
77 |
| - |
78 |
| - /// <summary> |
79 |
| - /// Returns true if the player has triggered the "action" button, |
80 |
| - /// typically used for menu confirmation. |
81 |
| - /// </summary> |
82 |
| - public bool Action() |
83 |
| - { |
84 |
| - return _keyboard.WasKeyJustPressed(Keys.Enter) || |
85 |
| - _gamePad.WasButtonJustPressed(Buttons.A); |
86 |
| - } |
87 |
| -} |
| 1 | +using Microsoft.Xna.Framework.Input; |
| 2 | +using MonoGameLibrary; |
| 3 | +using MonoGameLibrary.Input; |
| 4 | + |
| 5 | +namespace DungeonSlime; |
| 6 | + |
| 7 | +/// <summary> |
| 8 | +/// Provides a game-specific input abstraction that maps physical inputs |
| 9 | +/// to game actions, bridging our input system with game-specific functionality. |
| 10 | +/// </summary> |
| 11 | +public class GameController |
| 12 | +{ |
| 13 | + private KeyboardInfo _keyboard; |
| 14 | + private GamePadInfo _gamePad; |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// Creates a new GameController that handles input for the game. |
| 18 | + /// </summary> |
| 19 | + public GameController() |
| 20 | + { |
| 21 | + _keyboard = Core.Input.Keyboard; |
| 22 | + _gamePad = Core.Input.GamePads[0]; |
| 23 | + } |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Returns true if the player has triggered the "move up" action. |
| 27 | + /// </summary> |
| 28 | + public bool MoveUp() |
| 29 | + { |
| 30 | + return _keyboard.WasKeyJustPressed(Keys.Up) || |
| 31 | + _keyboard.WasKeyJustPressed(Keys.W) || |
| 32 | + _gamePad.WasButtonJustPressed(Buttons.DPadUp) || |
| 33 | + _gamePad.WasButtonJustPressed(Buttons.LeftThumbstickUp); |
| 34 | + } |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Returns true if the player has triggered the "move down" action. |
| 38 | + /// </summary> |
| 39 | + public bool MoveDown() |
| 40 | + { |
| 41 | + return _keyboard.WasKeyJustPressed(Keys.Down) || |
| 42 | + _keyboard.WasKeyJustPressed(Keys.S) || |
| 43 | + _gamePad.WasButtonJustPressed(Buttons.DPadDown) || |
| 44 | + _gamePad.WasButtonJustPressed(Buttons.LeftThumbstickDown); |
| 45 | + } |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Returns true if the player has triggered the "move left" action. |
| 49 | + /// </summary> |
| 50 | + public bool MoveLeft() |
| 51 | + { |
| 52 | + return _keyboard.WasKeyJustPressed(Keys.Left) || |
| 53 | + _keyboard.WasKeyJustPressed(Keys.A) || |
| 54 | + _gamePad.WasButtonJustPressed(Buttons.DPadLeft) || |
| 55 | + _gamePad.WasButtonJustPressed(Buttons.LeftThumbstickLeft); |
| 56 | + } |
| 57 | + |
| 58 | + /// <summary> |
| 59 | + /// Returns true if the player has triggered the "move right" action. |
| 60 | + /// </summary> |
| 61 | + public bool MoveRight() |
| 62 | + { |
| 63 | + return _keyboard.WasKeyJustPressed(Keys.Right) || |
| 64 | + _keyboard.WasKeyJustPressed(Keys.D) || |
| 65 | + _gamePad.WasButtonJustPressed(Buttons.DPadRight) || |
| 66 | + _gamePad.WasButtonJustPressed(Buttons.LeftThumbstickRight); |
| 67 | + } |
| 68 | + |
| 69 | + /// <summary> |
| 70 | + /// Returns true if the player has triggered the "pause" action. |
| 71 | + /// </summary> |
| 72 | + public bool Pause() |
| 73 | + { |
| 74 | + return _keyboard.WasKeyJustPressed(Keys.Escape) || |
| 75 | + _gamePad.WasButtonJustPressed(Buttons.Start); |
| 76 | + } |
| 77 | + |
| 78 | + /// <summary> |
| 79 | + /// Returns true if the player has triggered the "action" button, |
| 80 | + /// typically used for menu confirmation. |
| 81 | + /// </summary> |
| 82 | + public bool Action() |
| 83 | + { |
| 84 | + return _keyboard.WasKeyJustPressed(Keys.Enter) || |
| 85 | + _gamePad.WasButtonJustPressed(Buttons.A); |
| 86 | + } |
| 87 | +} |
0 commit comments