Game Development Reference
In-Depth Information
The spaceship is moved around by the values in the
Input
class, which is
handled in the
Level Update
loop.
public void Update(double elapsedTime)
{
// Get controls and apply to player character
double _x
¼
_input.Controller.LeftControlStick.X;
double _y
¼
_input.Controller.LeftControlStick.Y * - 1;
Vector controlInput
¼
new Vector(_x, _y,0);
if (Math.Abs(controlInput.Length())
<
0.0001)
{
// If the input is very small, then the player may not be using
// a controller; he might be using the keyboard.
if (_input.Keyboard.IsKeyHeld(Keys.Left))
{
controlInput.X
¼
-1;
}
if (_input.Keyboard.IsKeyHeld(Keys.Right))
{
controlInput.X
¼
1;
}
if (_input.Keyboard.IsKeyHeld(Keys.Up))
{
controlInput.Y
¼
1;
}
if (_input.Keyboard.IsKeyHeld(Keys.Down))
{
controlInput.Y
¼
-1;
}
}
_playerCharacter.Move(controlInput * elapsedTime);
}
The controls are quite simple for the gamepad. A vector is created that describes
how the control stick is pushed (The Y axis is reversed by multiplying the value
Search WWH ::
Custom Search