Arcade Shooter
InputState.h
1 
2 /* ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
3  ██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
4  █████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
5  ██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
6  ██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
7  ╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
8  /vvvvvvvvvvvvvvvvvvv \=========================================,
9  `^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
10  Katana Engine \/ © 2012 - Shuriken Studios LLC */
11 
12 #pragma once
13 
14 namespace KatanaEngine
15 {
16 
18  class InputState
19  {
20  friend class Game;
21 
22  public:
23 
25  static const uint8_t MAX_NUM_GAMEPADSTATES = 4;
26 
27  InputState();
28  virtual ~InputState() { }
29 
33  bool IsKeyDown(Key key) const;
34 
38  bool IsKeyUp(Key key) const;
39 
43  bool IsNewKeyPress(Key key) const;
44 
48  bool IsNewKeyRelease(Key key) const;
49 
50 
53  Point GetMousePosition() const { return Point(m_currentMouseState.x, m_currentMouseState.y); }
54 
58  bool IsMouseButtonDown(MouseButton button) const { return (m_currentMouseState.buttons & (int)button); }
59 
63  bool IsMouseButtonUp(MouseButton button) const { return !IsMouseButtonDown(button); }
64 
68  bool WasMouseButtonDown(MouseButton button) const { return (m_previousMouseState.buttons & (int)button); }
69 
73  bool WasMouseButtonUp(MouseButton button) const { return !WasMouseButtonDown(button); }
74 
78  bool IsNewMouseButtonPress(MouseButton button) const { return (IsMouseButtonDown(button) && WasMouseButtonUp(button)); }
79 
83  bool IsNewMouseButtonRelease(MouseButton button) const { return (WasMouseButtonDown(button) && IsMouseButtonUp(button)); }
84 
85 
93  bool IsButtonUp(Button button, int8_t &indexOut, int8_t controllingIndex = -1) const;
94 
102  bool IsButtonDown(Button button, int8_t &indexOut, int8_t controllingIndex = -1) const;
103 
111  bool IsNewButtonPress(Button button, int8_t &indexOut, int8_t controllingIndex = -1) const;
112 
120  bool IsNewButtonRelease(Button button, int8_t &indexOut, int8_t controllingIndex = -1) const;
121 
125  GamePadState GetGamePadState(const int8_t gamePadIndex) const;
126 
127 
128  private:
129 
130  ALLEGRO_KEYBOARD_STATE m_currentKeyboardState;
131  ALLEGRO_KEYBOARD_STATE m_previousKeyboardState;
132 
133  ALLEGRO_MOUSE_STATE m_currentMouseState;
134  ALLEGRO_MOUSE_STATE m_previousMouseState;
135 
136  GamePadState m_currentGamePadStates[MAX_NUM_GAMEPADSTATES];
137  GamePadState m_previousGamePadStates[MAX_NUM_GAMEPADSTATES];
138 
139  std::map<ALLEGRO_JOYSTICK *, int> m_map;
140 
141  void Update();
142 
143  int8_t GetGamePadIndex(ALLEGRO_JOYSTICK *pId);
144 
145  void InitializeGamePads();
146 
147  void UpdateConfigurationEvent();
148  void UpdateAxisEvent(ALLEGRO_EVENT alEvent);
149  void UpdateButtonEvent(ALLEGRO_EVENT alEvent, ButtonState state);
150 
151  };
152 }
bool IsMouseButtonUp(MouseButton button) const
Determines if a mouse button is currently not being pressed down.
Definition: InputState.h:63
bool IsNewMouseButtonRelease(MouseButton button) const
Determines if a mouse button was just released this frame.
Definition: InputState.h:83
ButtonState
Defines the possible states of a Button.
Definition: GamePadState.h:23
bool IsKeyUp(Key key) const
Determines if a keyboard key is currently not being pressed down.
Definition: InputState.cpp:150
bool WasMouseButtonDown(MouseButton button) const
Determines if a mouse button was being pressed down during the previous frame.
Definition: InputState.h:68
Key
Defines the keys on a keyboard.
Definition: KeyState.h:18
Handles the state of multiple player input devices.
Definition: InputState.h:18
static const uint8_t MAX_NUM_GAMEPADSTATES
The maximum number of Xbox controllers that the system can manage.
Definition: InputState.h:25
bool IsNewButtonPress(Button button, int8_t &indexOut, int8_t controllingIndex=-1) const
Determines if a the button on an Xbox controller was just pressed this frame.
Definition: InputState.cpp:203
bool IsNewKeyRelease(Key key) const
Determines if a keyboard key was just released this frame.
Definition: InputState.cpp:160
bool IsNewButtonRelease(Button button, int8_t &indexOut, int8_t controllingIndex=-1) const
Determines if a the button on an Xbox controller just released this frame.
Definition: InputState.cpp:223
bool IsButtonUp(Button button, int8_t &indexOut, int8_t controllingIndex=-1) const
Determines if a the button on an Xbox controller is up.
Definition: InputState.cpp:165
bool IsKeyDown(Key key) const
Determines if a keyboard key is currently being pressed down.
Definition: InputState.cpp:145
bool IsMouseButtonDown(MouseButton button) const
Determines if a mouse button is currently being pressed down.
Definition: InputState.h:58
Base class for all games. Provides graphics initialization, game loop, and rendering code...
Definition: Game.h:18
bool IsNewMouseButtonPress(MouseButton button) const
Determines if a mouse button was just pressed this frame.
Definition: InputState.h:78
MouseButton
Defines the buttons for a mouse.
Definition: MouseState.h:18
GamePadState GetGamePadState(const int8_t gamePadIndex) const
Get the current state of an Xbox controller.
Definition: InputState.cpp:243
bool IsButtonDown(Button button, int8_t &indexOut, int8_t controllingIndex=-1) const
Determines if a the button on an Xbox controller is down.
Definition: InputState.cpp:184
bool IsNewKeyPress(Key key) const
Determines if a keyboard key was just pressed this frame.
Definition: InputState.cpp:155
Represents specific information about the state of an Xbox Controller, including the current state of...
Definition: GamePadState.h:125
Defines a point in 2D space.
Definition: Point.h:19
Button
Defines the buttons for an Xbox Controller.
Definition: GamePadState.h:36
bool WasMouseButtonUp(MouseButton button) const
Determines if a mouse button was not being pressed down during the previous frame.
Definition: InputState.h:73
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition: Animation.cpp:14
Point GetMousePosition() const
Gets the current screen position of the mouse cursor.
Definition: InputState.h:53