11 Adding Vibration Effects Session 3.2.2. Session Overview  Describe how the vibration feature of the gamepad works  Show how an XNA program can control.

Slides:



Advertisements
Similar presentations
11 Reaction Timer Game Session 8.1. Session Overview  Find out how an XNA program can measure the passage of time and trigger events at certain points.
Advertisements

COMPUTER PROGRAMMING 2 Chapter 7 Sound. Objectives Find out how to prepare sounds for inclusion in Microsoft XNA projects. Incorporate sounds into XNA.
Microsoft ® Office Word 2007 Training Bullets, Numbers, and Lists ICT Staff Development presents:
Computer Science – Game DesignUC Santa Cruz CMPS 20: Game Design Experience Input.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
1 9/26/08CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
Input from Controller and Keyboard in XNA Game Studio Express Game Design Experience Professor Jim Whitehead February 12, 2008 Creative Commons Attribution.
Input from Controller and Keyboard in XNA Game Studio Express Game Design Experience Professor Jim Whitehead January 21, 2009 Creative Commons Attribution.
CS 1 with Robots IDLE and Myro Institute for Personal Robots in Education (IPRE)‏
1 9/28/07CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
Ch 111 Chapter 11 Advanced Batch Files. Ch 112 Overview This chapter focuses on batch file commands that allow you to:  write sophisticated batch files.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
CHAPTER 1 XNA Game Studio 4.0. Your First Project A computer game is not just a program—it is also lots of other bits and pieces that make playing the.
In.  This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are.
GIRLS Robotic Camp. Let’s Begin Meet and Greet – Camp leaders introduce themselves – Students introduce themselves.
11 Finding Winners Using Arrays Session 8.2. Session Overview  Find out how the C# language makes it easy to create an array that contains multiple values.
COMPUTER PROGRAMMING 2 Timers. Game Idea: Mob Reaction Timer Use a timer variable to keep track of time and a variable for each player to measure the.
Getting Started. XNA Game Studio 4.0 To download XNA Game Studio 4.0 itself, go to XNA Game.
Developing the Game User Interface (UI) Lesson 5.
1 Useful Tools for Making Video Games Part V An overview of.
11 Adding Sounds Session 7.1. Session Overview  Find out how to capture and manipulate sound on a Windows PC  Show how sound is managed as an item of.
11 Using the Keyboard Session Session Overview  Introduce the keyboard device  Show how keys on a keyboard can be represented by enumerated types.
Rob Miles. Creating a Working MoodLight We know that colours in XNA are stored as values which represent the amount of red, blue, green and transparency.
CHAPTER 10 Using C# Methods to Solve Problem XNA Game Studio 4.0.
CS PC/CONSOLE GAME PROGRAMMING/DEVELOPMENT CHAPTER 2: DRAWING, DATA AND CONTROLS.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
11 Working with Images Session Session Overview  Find out more about image manipulation and scaling when drawing using XNA  Start to implement.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
How to link the robot and the computer (Bluetooth) How to turn on and off How to connect the adaptor Fluke card connection Sec Getting Started How.
XNA Game Studio 4.0 Keyboard and Mouse Controls + more on Animated Sprites.
11 Making a Sprite Session 4.2. Session Overview  Describe the principle of a game sprite, and see how to create a sprite in an XNA game  Learn more.
Rob Miles. How does an XNA game program work? Programs tell computers what to do A program is written in a programming language – C# is a programming.
11 Getting Player Input Using a Gamepad Session 3.1.
Aaron Yuen 1 Outline 9.1Storyboarding & Charting Method for Game Design 9.2Game State in Game Development 9.3Game State Management 9.4GUI Assets for Gameplay.
Lesson Two: Everything You Need to Know
CHAPTER 3 Getting Player Input XNA Game Studio 4.0.
CHAPTER 6 Multiplayer XNA Game Studio 4.0. Objectives Discover how to detect and use individual button-press events in a game. Learn how to create and.
4 out of 5 Professors Surveyed Recommend This Session TLC Day, Fall 2012 Mary Trant ELS, NH.
Computer Game Design ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects.
CHAPTER 2 The Game Loop - Variables, Types, Classes and Objects in XNA XNA Game Studio 4.0.
11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.
11 Debugging Programs Session Session Overview  Create and test a method to calculate percentages  Discover how to use Microsoft Visual Studio.
11 Computers, C#, XNA, and You Session 1.1. Session Overview  Find out what computers are all about ...and what makes a great programmer  Discover.
11 Adding a Bread Bat Session Session Overview  We have created a cheese sprite that bounces around the display  We now need to create a bread.
11 Using the Keyboard in XNA Session 9.1. Session Overview  Discover more detail on how the XNA keyboard is implemented  Find out how to use arrays.
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
Rob Miles. Using data in an XNA game program An XNA game program Draw and Update methods that are called to run the game Colours are held in XNA as four.
Improving the Crab Mrs. C. Furman August 19, 2010.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
XNA Sound Effects. float volume, pitch, pan; SoundEffect boing1; SoundEffect boing2; boing1 = Content.Load ("boing1"); boing2 = Content.Load ("boing2");
Rob Miles. Creating a Broken MoodLight An XNA game contains game data which is used by the Draw and Update methods – Update updates the game data – Draw.
Learning Javascript From Mr Saem
Computer Science Up Down Controls, Decisions and Random Numbers.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
PROGRAMMING FTC ROBOTS WITH ANDROID STUDIO EAGLE ROBOTICS TEAM 7373 JORDAN MOSS AND BRIAN BAARS.
Introduction To Robot Sensors
Scratch for Interactivity
What you asked me to teach…
Creating a Multi-Player Game
Introduction To Robot Sensors
Programming – Touch Sensors
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Iteration: Beyond the Basic PERFORM
if-else Structures Principles of Engineering
ICT Gaming Lesson 3.
Lesson 18 – how to add a new button for pivot right
Presentation transcript:

11 Adding Vibration Effects Session 3.2.2

Session Overview  Describe how the vibration feature of the gamepad works  Show how an XNA program can control gamepad vibration  Add vibration to the Color Nerve game  Look at how we can change the behavior of a game by modifications to the code  Describe how the vibration feature of the gamepad works  Show how an XNA program can control gamepad vibration  Add vibration to the Color Nerve game  Look at how we can change the behavior of a game by modifications to the code Chapter 3.2.2: Adding Vibration Effects2

The Xbox Gamepad Vibration  The gamepad contains two motors which turn weighted flywheels  The wheels turn at different speeds to vibrate the pad  Games can control the power going into the motors to get different levels of vibration  The gamepad contains two motors which turn weighted flywheels  The wheels turn at different speeds to vibrate the pad  Games can control the power going into the motors to get different levels of vibration Chapter 3.2.2: Adding Vibration Effects3

Vibration Speeds  The motor on the left provides low-frequency rumble  The motor on the right provides higher-frequency vibration  XNA allows you to control the power going to either of these motors from a C# program  The motor on the left provides low-frequency rumble  The motor on the right provides higher-frequency vibration  XNA allows you to control the power going to either of these motors from a C# program Chapter 3.2.2: Adding Vibration Effects4

Controlling Gamepad Vibration from XNA  We have used the GamePad class before  It provides the getState method that we used to read the gamepad state  It also provides a method called setVibration which is used to control the vibration of a gamepad  The method is given three parameters  A parameter is a way of feeding information into a method  We have used the GamePad class before  It provides the getState method that we used to read the gamepad state  It also provides a method called setVibration which is used to control the vibration of a gamepad  The method is given three parameters  A parameter is a way of feeding information into a method Chapter 3.2.2: Adding Vibration Effects5 GamePad.SetVibration ( PlayerIndex.One, 1, 0 ) ;

Selecting the Gamepad to Be Controlled  This parameter value identifies the gamepad to be controlled  We used it to tell getState which gamepad to read  You can try to control gamepads that aren’t there, but the method call won’t do anything  This parameter value identifies the gamepad to be controlled  We used it to tell getState which gamepad to read  You can try to control gamepads that aren’t there, but the method call won’t do anything Chapter 3.2.2: Adding Vibration Effects6 GamePad.SetVibration ( PlayerIndex.One, 1, 0 ) ;

Setting the Vibration Levels  This parameter value gives the amount of vibration the left (low frequency) motor should produce  It is given as a floating point value between 0 and 1  If we give the value 1 it will produce maximum vibration  If we give the value 0 the vibration is turned off  This parameter value gives the amount of vibration the left (low frequency) motor should produce  It is given as a floating point value between 0 and 1  If we give the value 1 it will produce maximum vibration  If we give the value 0 the vibration is turned off Chapter 3.2.2: Adding Vibration Effects7 GamePad.SetVibration ( PlayerIndex.One, 1, 0 ) ;

Setting the Vibration Levels  This parameter value gives the amount of vibration the right (high frequency) motor should produce  It is given as a floating point value between 0 and 1  It works in the same way as the left-hand value, but the vibration effect is different  Once you have set a vibration level the pad will continue to vibrate until you tell it something different  This parameter value gives the amount of vibration the right (high frequency) motor should produce  It is given as a floating point value between 0 and 1  It works in the same way as the left-hand value, but the vibration effect is different  Once you have set a vibration level the pad will continue to vibrate until you tell it something different Chapter 3.2.2: Adding Vibration Effects8 GamePad.SetVibration ( PlayerIndex.One, 1, 0 ) ;

Vibration Demonstration Chapter 3.2.2: Adding Vibration Effects9 protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); GamePadState pad1 = GamePad.GetState(PlayerIndex.One); if (pad1.Buttons.X == ButtonState.Pressed) GamePad.SetVibration(PlayerIndex.One, 1, 0); base.Update(gameTime); } protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); GamePadState pad1 = GamePad.GetState(PlayerIndex.One); if (pad1.Buttons.X == ButtonState.Pressed) GamePad.SetVibration(PlayerIndex.One, 1, 0); base.Update(gameTime); }

1. Vibration Demonstration Chapter 3.2.2: Adding Vibration Effects10  This program implements the vibration behavior that we have just seen  However, it does have a problem…  This program implements the vibration behavior that we have just seen  However, it does have a problem…

Making the Vibration Stop  The game program must tell the gamepad to stop vibrating when the button is not pressed  The easiest way to achieve this is to add an else part to the conditional statement  This version of the code will only make the gamepad vibrate when the Blue button is pressed  The game program must tell the gamepad to stop vibrating when the button is not pressed  The easiest way to achieve this is to add an else part to the conditional statement  This version of the code will only make the gamepad vibrate when the Blue button is pressed Chapter 3.2.2: Adding Vibration Effects11 if (pad1.Buttons.X == ButtonState.Pressed) GamePad.SetVibration(PlayerIndex.One, 1, 0); else GamePad.SetVibration(PlayerIndex.One, 0, 0); if (pad1.Buttons.X == ButtonState.Pressed) GamePad.SetVibration(PlayerIndex.One, 1, 0); else GamePad.SetVibration(PlayerIndex.One, 0, 0);

Adding Vibration to Color Nerve  The Color Nerve program could make the gamepad vibrate when the intensity values get close to wrapping round  The condition must compare two values and trigger when one is greater than the other  We can use the “greater than” operator to do this  The Color Nerve program could make the gamepad vibrate when the intensity values get close to wrapping round  The condition must compare two values and trigger when one is greater than the other  We can use the “greater than” operator to do this Chapter 3.2.2: Adding Vibration Effects12 if (redIntensity > 220) GamePad.SetVibration(PlayerIndex.One, 1, 0); else GamePad.SetVibration(PlayerIndex.One, 0, 0); if (redIntensity > 220) GamePad.SetVibration(PlayerIndex.One, 1, 0); else GamePad.SetVibration(PlayerIndex.One, 0, 0);

The Greater Than Operator  The Greater Than operator can be placed between two numeric values  It returns true if the number on the left is greater than the number on the right  In all other situations (including equals) it returns false  The Greater Than operator can be placed between two numeric values  It returns true if the number on the left is greater than the number on the right  In all other situations (including equals) it returns false Chapter 3.2.2: Adding Vibration Effects13 if (redIntensity > 220) GamePad.SetVibration(PlayerIndex.One, 1, 0); else GamePad.SetVibration(PlayerIndex.One, 0, 0); if (redIntensity > 220) GamePad.SetVibration(PlayerIndex.One, 1, 0); else GamePad.SetVibration(PlayerIndex.One, 0, 0);

Combining Tests  If we want the vibration to start when any of the color intensities exceeds 220 we have to test all of them  We can combine the results using logical OR, so that the vibration starts if any of them exceeds the limit  If we want the vibration to start when any of the color intensities exceeds 220 we have to test all of them  We can combine the results using logical OR, so that the vibration starts if any of them exceeds the limit Chapter 3.2.2: Adding Vibration Effects14 if (redIntensity > 220 || greenIntensity > 220 || blueIntensity > 220) GamePad.SetVibration(PlayerIndex.One, 1, 0); else GamePad.SetVibration(PlayerIndex.One, 0, 0); if (redIntensity > 220 || greenIntensity > 220 || blueIntensity > 220) GamePad.SetVibration(PlayerIndex.One, 1, 0); else GamePad.SetVibration(PlayerIndex.One, 0, 0);

Using Blocks to Improve Code Appearance  Creating blocks can make your code clearer  In this case it separates the code from the conditions  Creating blocks can make your code clearer  In this case it separates the code from the conditions Chapter 3.2.2: Adding Vibration Effects15 if (redIntensity > 220 || greenIntensity > 220 || blueIntensity > 220) { GamePad.SetVibration(PlayerIndex.One, 1, 0); } else { GamePad.SetVibration(PlayerIndex.One, 0, 0); } if (redIntensity > 220 || greenIntensity > 220 || blueIntensity > 220) { GamePad.SetVibration(PlayerIndex.One, 1, 0); } else { GamePad.SetVibration(PlayerIndex.One, 0, 0); }

2. Color Nerve with Vibration Chapter 3.2.2: Adding Vibration Effects16  This version of the game provides vibration feedback when any of the color intensity values exceeds 220

Summary  The Xbox gamepad has two vibration motors for different frequency vibration of the gamepad  The GamePad class which is part of XNA provides a method called setVibration which controls the intensity of the vibration the motors produce  Once a gamepad has been told to vibrate it will vibrate at that level until given another vibration command or the exit method is called to end an XNA game  The Xbox gamepad has two vibration motors for different frequency vibration of the gamepad  The GamePad class which is part of XNA provides a method called setVibration which controls the intensity of the vibration the motors produce  Once a gamepad has been told to vibrate it will vibrate at that level until given another vibration command or the exit method is called to end an XNA game Chapter 3.2.2: Adding Vibration Effects17

True/False Revision Quiz  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game.  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game. Chapter 3.2.2: Adding Vibration Effects18

True/False Revision Quiz  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game.  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game. Chapter 3.2.2: Adding Vibration Effects19

True/False Revision Quiz  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game.  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game. Chapter 3.2.2: Adding Vibration Effects20

True/False Revision Quiz  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game.  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game. Chapter 3.2.2: Adding Vibration Effects21

True/False Revision Quiz  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game.  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game. Chapter 3.2.2: Adding Vibration Effects22

True/False Revision Quiz  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game.  The Xbox 360 console contains vibration motors.  An XNA program can make the keyboard vibrate.  An XNA program can only control the vibration of one gamepad.  The amount of gamepad vibration is set using a value in the range 0 to 1.  The gamepad stops vibrating when it loses contact with the game. Chapter 3.2.2: Adding Vibration Effects23