Difference between revisions of "Game Programming Class3"

esse quam videri
Jump to: navigation, search
(in class)
Line 9: Line 9:
 
[[Image:XBoxGamePadWithLabels.png]]
 
[[Image:XBoxGamePadWithLabels.png]]
  
XNA has builtin support for up to 4 game controllers. The default controller is a x-box controller.
+
XNA has built in support for up to 4 game controllers. The default controller is a x-box controller.
 
X-Box Controller The Controller is accessed through the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad.aspx GamePad] Object and the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate_members.aspx GamePadState] Structure reference types
 
X-Box Controller The Controller is accessed through the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad.aspx GamePad] Object and the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate_members.aspx GamePadState] Structure reference types
 
<csharp>
 
<csharp>
Line 15: Line 15:
 
         GamePadState gamePad1State = GamePad.GetState(PlayerIndex.One);  
 
         GamePadState gamePad1State = GamePad.GetState(PlayerIndex.One);  
 
          
 
          
 
+
/*Since the Keyboard structure is Windows only we need to use some preprocessor
Since the Keyboard structure is Windows only we need to use some preprocessor directives to only compile the KeyBoard state code if the target is not XBOX360 (I should also add zune if this is one of our build targets)
+
directives to only compile the KeyBoard state code if the target is not XBOX360 (I
 
+
should also add zune if this is one of our build targets)
 +
*/
 
         #if !XBOX360
 
         #if !XBOX360
 
             #region KeyBoard
 
             #region KeyBoard

Revision as of 03:24, 9 February 2009

Class 3 Input Handling

Input

input from Game Controller and Keyboard

GamePad XBoxGamePadWithLabels.png

XNA has built in support for up to 4 game controllers. The default controller is a x-box controller. X-Box Controller The Controller is accessed through the GamePad Object and the GamePadState Structure reference types <csharp>

        //Get and instance of the gamePadState Structure
        GamePadState gamePad1State = GamePad.GetState(PlayerIndex.One); 
        

/*Since the Keyboard structure is Windows only we need to use some preprocessor directives to only compile the KeyBoard state code if the target is not XBOX360 (I should also add zune if this is one of our build targets)

  • /
        #if !XBOX360
           #region KeyBoard
           KeyboardState keyboardState = Keyboard.GetState();
        #endif
        

</csharp>

Angle Measured in Radians

using atan2 to get the angle from the direction vector

Vibration

<csharp>

       GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f);  //left low freq motor right high freq motor
       

</csharp>

Classes and Generics

Shooting with pacman

in class

PacMan Project with input

Extract Input class and create a new project

Homework

  • Create an XNA project that uses the Keyboard for input.
  • Read Chapter 3 in XNA 3.0