I have a portable control system that I can drop into a project and then tweak to add specific controls the game requires. The controls are exposed to the rest of the game through an enumerator-indexed array. The enumerator describes all the actions (controls) of the game, and the array contains the current state of each action. For example,
Code:
enum Action {
Left,
Right,
Up,
Down,
Shoot
}
State[Action.Left] = 0;
State[Action.Right] = 0;
State[Action.Up] = 0;
State[Action.Down] = 0;
State[Action.Shoot] = 0;
The
State contents would usually be 0 or 1, unless it represents something like gamepad stick's output. Beneath this sits what I call an action binding system. It's job is to connect each defined
Action to multiple control sources. For example, I could define bindings for
Action.Shoot to keyboard "Space" button, gamepad "X" button and mouse left button. That is, if I was supporting all three control methods. The
obj_control where all this stuff resides goes through the bindings array each step and combines its discoveries into the
State array. An example of a binding definition would be:
Code:
// Action: left, binding to keyboard.
var _k1 = [];
_k1[Action_Data.Action] = Action.Left;
_k1[Action_Data.Method] = Control_Method.Keyboard_Button;
_k1[Action_Data.Binding] = vk_left;
_k1[Action_Data.Description] = "ARROW LEFT";
Binding_List[Action_Binding.Keyboard_Left] = _k1;
To actually change these controls, a settings page would go through this
Binding_List and display all that have
Control_Method.Keyboard_Button in them. On top of that would sit some code that lets player to pick one from the shown list and enter a new control key, which the settings page system would then save into the array that describes the binding. In this case, replacing
vk_left with whatever user pressed.