The player UpdateControls function will be added to the start of the player Update and will manage user inputs via the keyboard and mouse:
Inside UpdateControls we get the current window and detect if any of the W,A,S,D keys are currently pressed. We will track forward and backward movements in the variable called move and left and right movements in the variable called strafe. KeyDown() will return a Boolean value of true or false, but in C++ these values are essentially the integers 1 (true) and 0 (false). So if you look at the code for move pressing the ‘W’ key would translate to move = 1 – 0 which results in 1.
Window* window = Window::GetCurrent();
//Get inputs from the controller class
move = window->KeyDown(Key::W) - window->KeyDown(Key::S);
strafe = window->KeyDown(Key::D) - window->KeyDown(Key::A);
Now that we have values for move and strafe we need to normalize them so that moving while strafing doesn’t move the character faster than normal. Then after normalizing we scale the movement to the correct movespeed: