Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
InputState.h
Go to the documentation of this file.
1
2/*
3 ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
4 ██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
5 █████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
6 ██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
7 ██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
8 ╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
9 /vvvvvvvvvvvvvvvvvvv \=========================================,
10 `^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
11 Katana Engine \/ © 2012 - Shuriken Studios LLC
12 http://www.shurikenstudios.com
13*/
14
15#pragma once
16
17namespace KatanaEngine
18{
19
22 {
23 friend class Game;
24
25 public:
26
28 static const uint8_t MAX_NUM_GAMEPADSTATES = 4;
29
30 InputState();
31 virtual ~InputState() { }
32
36 bool IsKeyDown(Key key) const;
37
41 bool IsKeyUp(Key key) const;
42
46 bool IsNewKeyPress(Key key) const;
47
51 bool IsNewKeyRelease(Key key) const;
52
53
56 Point GetMousePosition() const { return Point(m_currentMouseState.x, m_currentMouseState.y); }
57
61 bool IsMouseButtonDown(MouseButton button) const { return (m_currentMouseState.buttons & (int)button); }
62
66 bool IsMouseButtonUp(MouseButton button) const { return !IsMouseButtonDown(button); }
67
71 bool WasMouseButtonDown(MouseButton button) const { return (m_previousMouseState.buttons & (int)button); }
72
76 bool WasMouseButtonUp(MouseButton button) const { return !WasMouseButtonDown(button); }
77
81 bool IsNewMouseButtonPress(MouseButton button) const { return (IsMouseButtonDown(button) && WasMouseButtonUp(button)); }
82
86 bool IsNewMouseButtonRelease(MouseButton button) const { return (WasMouseButtonDown(button) && IsMouseButtonUp(button)); }
87
88
96 bool IsButtonUp(Button button, int8_t &indexOut, int8_t controllingIndex = -1) const;
97
105 bool IsButtonDown(Button button, int8_t &indexOut, int8_t controllingIndex = -1) const;
106
114 bool IsNewButtonPress(Button button, int8_t &indexOut, int8_t controllingIndex = -1) const;
115
123 bool IsNewButtonRelease(Button button, int8_t &indexOut, int8_t controllingIndex = -1) const;
124
128 GamePadState GetGamePadState(const int8_t gamePadIndex) const;
129
130
131 private:
132
133 ALLEGRO_KEYBOARD_STATE m_currentKeyboardState;
134 ALLEGRO_KEYBOARD_STATE m_previousKeyboardState;
135
136 ALLEGRO_MOUSE_STATE m_currentMouseState;
137 ALLEGRO_MOUSE_STATE m_previousMouseState;
138
139 GamePadState m_currentGamePadStates[MAX_NUM_GAMEPADSTATES];
140 GamePadState m_previousGamePadStates[MAX_NUM_GAMEPADSTATES];
141
142 std::map<ALLEGRO_JOYSTICK *, int> m_map;
143
144 void Update();
145
146 int8_t GetGamePadIndex(ALLEGRO_JOYSTICK *pId);
147
148 void InitializeGamePads();
149
150 void UpdateConfigurationEvent();
151 void UpdateAxisEvent(ALLEGRO_EVENT alEvent);
152 void UpdateButtonEvent(ALLEGRO_EVENT alEvent, ButtonState state);
153
154 };
155}
Base class for all games. Provides graphics initialization, game loop, and rendering code....
Definition Game.h:22
Handles the state of multiple player input devices.
Definition InputState.h:22
bool WasMouseButtonDown(MouseButton button) const
Determines if a mouse button was being pressed down during the previous frame.
Definition InputState.h:71
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.
bool IsNewMouseButtonPress(MouseButton button) const
Determines if a mouse button was just pressed this frame.
Definition InputState.h:81
static const uint8_t MAX_NUM_GAMEPADSTATES
The maximum number of Xbox controllers that the system can manage.
Definition InputState.h:28
bool IsMouseButtonUp(MouseButton button) const
Determines if a mouse button is currently not being pressed down.
Definition InputState.h:66
bool IsKeyDown(Key key) const
Determines if a keyboard key is currently being pressed down.
bool IsButtonUp(Button button, int8_t &indexOut, int8_t controllingIndex=-1) const
Determines if a the button on an Xbox controller is up.
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.
bool IsNewMouseButtonRelease(MouseButton button) const
Determines if a mouse button was just released this frame.
Definition InputState.h:86
GamePadState GetGamePadState(const int8_t gamePadIndex) const
Get the current state of an Xbox controller.
bool IsKeyUp(Key key) const
Determines if a keyboard key is currently not being pressed down.
bool IsNewKeyPress(Key key) const
Determines if a keyboard key was just pressed this frame.
bool WasMouseButtonUp(MouseButton button) const
Determines if a mouse button was not being pressed down during the previous frame.
Definition InputState.h:76
bool IsButtonDown(Button button, int8_t &indexOut, int8_t controllingIndex=-1) const
Determines if a the button on an Xbox controller is down.
bool IsMouseButtonDown(MouseButton button) const
Determines if a mouse button is currently being pressed down.
Definition InputState.h:61
bool IsNewKeyRelease(Key key) const
Determines if a keyboard key was just released this frame.
Point GetMousePosition() const
Gets the current screen position of the mouse cursor.
Definition InputState.h:56
Defines a point in 2D space.
Definition Point.h:23
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition Animation.cpp:18
MouseButton
Defines the buttons for a mouse.
Definition MouseState.h:22
Button
Defines the buttons for an Xbox Controller.
ButtonState
Defines the possible states of a Button.
Key
Defines the keys on a keyboard.
Definition KeyState.h:22
Represents specific information about the state of an Xbox Controller, including the current state of...