Friday, October 22, 2010

Input System: Part 5 Thumbsticks

This tutorial will go over creating two basic functions to use in our input class that will use the thumbsticks. These two functions will be identical in concept to the triggers but will involve a little more work to get the same result. Thumbsticks are very important to most games so having an easy function will probably save a lot of trouble. Before I start I would like to first say that the thumbsticks use a normal Cartesian coordinate system where the center is the origin, that is you haven't moved the thumbstick at all. To the right is the positive X, left is negative X, up is positive Y and down is negative Y. This is slightly different from the screen coordinate system where down is positive Y and up is negative Y so that is just a heads up. 

So we want to create two functions one that will return the value of a thumbstick ( left or right ) and another that will return a bool for if we passed the threshold in any direction ( left, right, up or down ). So were going to start by creating two enums one for the thumbstick and another for each direction. The thumbsticks enum is the same as the trigger enum so we could combine to one enum, but I doubt having two enums with the same values will make any performance issue and the clarity we get is really nice.

Sunday, October 10, 2010

Input System: Part 4 Triggers

This part of the tutorial will cover using the triggers on the game pads. The triggers give a value between 0 and 1 indicating how far the trigger is pressed, 0 being not pressed and 1 being fully pressed. There are two common ways we use triggers, using them as a button like shooting a gun and using them as a trigger were you use the value between 0 and 1 to correspond to an action such as a gas pedal of a car. The first step were going to do is to distinguish between our left and right triggers by creating an enum. For simplicity reasons I created this enum inside the Input file directly above the input class.

Next I created a const variable to distinguish the threshold to pass in order for the trigger to act as a button. You can change this value or even remove it entirely and have it as a parameter in your function, but I found that I always just used one number in all cases so it made the most sense to declare a constant.

Next were going to create the two functions were going to use for our triggers. Trigger will just return the value of that trigger and Trigger Threshold will return if we just passed the threshold or not.

Saturday, October 9, 2010

Input System: Part 3 Keys and Buttons

Due to the extremely easy nature of this part of the tutorial there will not be much in terms of explanations. This part is going to cover key presses, button presses, key down and button down methods that we will add into our input class. First were going to make our prototypes, all these methods return bool so we can easily use them with an if state. Note the red underline is because they don't return anything which is required for non-void functions. Also click on the pictures if you can't read them.

Simply enough return if the key is down for the key down method. And in the key pressed return if our previous states key is up and our current state key is down.

Friday, October 8, 2010

Input System: Part 2 Input Basics

So for the first part of the input class were creating the basic aspects of the input system. The input system will handle controls for the game pads and keyboard we will not be needing the mouse since the mouse does not work on the xbox and well I never really use it. Keyboard controls are good for simple debug commands such as pressing F for full screen or pushing a button to go back to the main menu without having to use a game pad button. Now were going to start with two functions, one that will initialize our variables since static classes can not have a constructor and another one to update our game pad and keyboard states so they will be named Initialize and Update. The class itself will just be called Input and will be a static class therefore our functions must be static as well. Here is what our class looks like so far except that your namespace will probably be different.