DOC PREVIEW
UCSC CMPS 20 - Input from Controller and Keyboard in XNA Game Studio Express

This preview shows page 1-2-19-20 out of 20 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Input from Controller and Keyboard in XNA Game Studio ExpressAnnouncementsUpcoming AssignmentsGame InputDigital vs Analog ControlsInput Type OverviewXbox 360 Controller InputGamePad ClassC# StructsGamePadState StructGamePadButtons Struct (Buttons)GameDPad Struct (DPad)GamePadThumbsticks Struct (Thumbsticks)Joystick Dead ZoneGamePadTriggers Struct (Triggers)Controller VibrationKeyboard InputMouse InputWrapper ClassReadingInput from Controller and Keyboard in XNA Game Studio ExpressGame Design ExperienceProfessor Jim WhiteheadJanuary 21, 2009Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0Announcements• Homework #1 due today► Submit printout of source code and play session in class► Also need to electronically submit ZIP file of project source code► See instructions online► www.soe.ucsc.edu/classes/cmps020/Winter09/• You are expected to be in a project team by now► Please see me after class if you are not• Craig Reynolds talk► Crowds and Emergent Teamwork► Friday, 11am► Engineering 2, room 180 (Plaza level, “Simularium”)► You are welcome to attendUpcoming Assignments• Monday: Game Concept Document► A compelling document that sells your game concept► Title page• Title of game, name of group, name of team members, sample artwork► Overview page• Table at top: game genre, platform (PC/XBox), team size• Key points section– Bulleted list of important elements of gameplay– Goal of game, what makes game unique, main characters, main fictional elements– Sample artwork image to give feel of the game► Biographies• True, pocket biographies of each team member (1-2 paragraphs each) stressing experience that makes you a strong game designer► 1-3 pages giving a textual description of the game• Fictional background, brief description of characters, goal of player in game, how does player interact with the game, brief description of levels, game audience, other important elements as needed.► 1-2 pages of sample conceptual artwork• Hand-drawn sketches are fine• See template and evaluation criteria on course websiteGame Input• XNA Framework supports three input sources► Xbox 360 controller• Wired controller under Windows• Wireless or wired for Xbox 360• Up to 4 at a time► Keyboard• Good default for Windows games• Xbox 360 also supports USB keyboards► Mouse• Windows only (no Xbox 360 support)• Poll for input► Every clock tick, check the state of your input devices► Generally works OK for 1/60th second ticksDigital vs Analog Controls• Input devices have two types of controls• Digital► Reports only two states: on or off► Keyboard: keys► Controller A, B, X, Y, Back, Start, D-Pad• Analog► Report a range of values► XBox 360 controller: -1.0f to 1.0f► Mouse: mouse cursor values (in pixels)Input Type OverviewInput DeviceDigital ButtonsAnalog ControlsVibration Win? Xbox? NumberXbox 360 Controller14 4 Yes Yes (wired or wireless with adapter)Yes (wireless or wired)4Keyboard >100 0 No Yes Yes 1Mouse 5 3 No Yes No 1Xbox 360 Controller Input• Every clock tick► Get state of controller• Call GetState() on GamePad class• Pass in PlayerIndex– PlayerIndex.One, PlayerIndex.Two, …– Corresponds to lit region in “ring of light”• Returns a GamePadState structure► Check if controller is connected• IsConnected boolean in GamePadState► Check GamePadState for current state of digital and analog inputs► Recall that update() is called every clock tick• Get input in update(), or a method called from itGamePad Class• A static class► Do not need to create an instance to use► All methods are static• GetState► Retrieve current state of all inputs on one controller• SetVibration► Use to make controller vibrate• GetCapabilities► Determine which input types are supported. ► Can check for voice support, and whether controller is connected.public static class GamePad { public static GamePadCapabilities GetCapabilities(PlayerIndex playerIndex); public static GamePadState GetState(PlayerIndex playerIndex); public static GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode); public static bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor); }C# Structs• A struct in C# is a lightweight alternative to a class• Similar to class► Can have constructors, properties, methods, fields, operators, nested types, indexers• Different from class► Struct does not support inheritance, or destructors► Is a value type (classes are reference types)• Rule of thumb:► Use structs for types that are small, simple, similar in behavior to built-in typesGamePadState Struct• Properties for reading state of the GamePad► Digital Input: Buttons, DPad► Analog Input: ThumbSticks, Triggers► Check connection state: IsConneced► PacketNumber• Number increases when gamepad state changes• Use to check if player has changed gamepad state since last tickpublic struct GamePadState { public static bool operator !=(GamePadState left, GamePadState right); public static bool operator ==(GamePadState left, GamePadState right); public GamePadButtons Buttons { get; } public GamePadDPad DPad { get; } public bool IsConnected { get; } public int PacketNumber { get; } public GamePadThumbSticks ThumbSticks { get; } public GamePadTriggers Triggers { get; } }GamePadButtons Struct (Buttons)• Properties for retrieving current button state► A, B, X, Y► Start, Back► LeftStick, RightStick• When you press straight down on each joystick, is a button press► LeftShoulder, RightShoulder• Possible values are given by ButtonState enumeration► Released – button is up► Pressed – button is downGamePadState m_pad; // create GamePadState struct m_pad = GamePad.GetState(PlayerIndex.One); // retrieve current controller state if (m_pad.Buttons.A == ButtonState.Pressed) // do something if A button pressed| if (m_pad.Buttons.LeftStick == ButtonState.Pressed) // do something if left stick button pressed if (m_pad.Buttons.Start == ButtonState.Pressed) // do something if start button pressedGameDPad Struct (DPad)• Properties for retrieving current DPad button state► Up, Down, Left, Right• Possible values are given by ButtonState enumeration► Released – button is up► Pressed – button is downGamePadState m_pad; // create GamePadState struct m_pad =


View Full Document

UCSC CMPS 20 - Input from Controller and Keyboard in XNA Game Studio Express

Documents in this Course
Load more
Download Input from Controller and Keyboard in XNA Game Studio Express
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Input from Controller and Keyboard in XNA Game Studio Express and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Input from Controller and Keyboard in XNA Game Studio Express 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?