Game Programming Class3

esse quam videri
Revision as of 03:55, 16 February 2013 by Jeff (talk | contribs)
Jump to: navigation, search

Class 3 Input Handling

Inclass Keyboard input demo

KeyboardState keyboardState = Keyboard.GetState();

Explore Limitations of Built in Keyboard state.

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 an 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


IntroSimpleSpriteUpdateRotateWindows Project

SpriteJump Project

Vibration

<csharp>

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

</csharp>

in class

Extract sprite from pacman class and build new project

http://www.xnawiki.com/index.php?title=Basic_Sprite_Class

Sprite class

IntroPacManComponent.zip

Project that refactors the pacman class into two classes

Sprite.cs DrawableSprite.cs

Then the pacman class can inherit from one of these two classes.

PacMan.cs

Due to the desire to limit the number of spritebatches, I've created two classes. The sprite class cannot draw itself without being associated with and external spritebatch. The DrawableSprite has it's own spritebatch which makes it easier to use but less efficient.

Classes and Generics

Shooting with pacman

List<Type> Safer than Arraylist and easier to manage than Array

Homework

Moving Game 2 Interesting movement

Update your moving assigment to make the movement more interesting. Use more than 1 input method ie Keyboard, xbox controller, mouse etc.

Extra Credit

  • Sprite Class
Build a class that is reusable that can draw a single texture on the screen. Be sure to encapsulate all the properties and method that you need to draw the sprite.
  • Create an XNA project that uses the Keyboard for input.
  • Has at least 3 different moving sprite with a common code base.
  • the sprites should inherit from the same class. Game components are a plus. don't worry about collision yet

Repo URL https://iam.colum.edu:8443/svn/XNASP13/trunk