Game Development Reference
In-Depth Information
// KeyState enum (JustPressed, JustReleased, etc.)
from earlier in this
chapter
...
// GetKeyState from earlier in this chapter
...
// BindInfo is used for the "value" in the map
struct
BindInfo
int
keyCode
KeyState
stateType
end
class
InputManager
// Stores all the bindings
Map
keyBindings
;
// Stores only the active bindings
Map
activeBindings
;
// Helper function to add a binding to keyBind-
ings
function
AddBinding(
string
name
,
int
code
,
KeyState
type
)
keyBindings
.Add(
name
,
BindInfo
(
code
,
type
))
end
// Initializes all bindings
function
InitializeBindings()
// These could be parsed from a file.
// Call AddBinding on each binding.
// For example, this would be a binding
"Fire" mapped to
// enter's keyCode and a KeyState of
JustReleased:
// AddBinding("Fire", K_ENTER, JustReleased)
...
end