11 Adding a Bread Bat Session 12.1. Session Overview  We have created a cheese sprite that bounces around the display  We now need to create a bread.

Slides:



Advertisements
Similar presentations
 Functions breakdown: Functions purpose Modularity Declaring and defining a function Calling a function Parameter passing Returning a value Reusability.
Advertisements

This terms course Last term we both worked on learning 2 things –Processing –The concepts of graphics etc. This term will focus more on the basic concepts.
C Structures and Memory Allocation There is no class in C, but we may still want non- homogenous structures –So, we use the struct construct struct for.
Lesson Four: More of the Same
AU/MITM/1.6 By Mohammed A. Saleh 1. Arguments passed by reference  Until now, in all the functions we have seen, the arguments passed to the functions.
1 Chapter Three Using Methods. 2 Objectives Learn how to write methods with no arguments and no return value Learn about implementation hiding and how.
Asteroids Games and Simulations O-O Programming in Java The Walker School The Walker School – Games and Simulations
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 6 Functions.
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
Games and Simulations O-O Programming in Java The Walker School
Classes / Objects An introduction to object-oriented programming.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
AI & 2D Development COSC 315 Fall 2014 Bridget M. Blodgett.
CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.
Rob Miles Microsoft MVP University of Hull Fun Programming with Visual Studio.
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.
11 A First Game Program Session Session Overview  Begin the creation of an arcade game  Learn software design techniques that apply to any form.
Chapter 6: Modularity Using Functions. In this chapter, you will learn about: – Function and parameter declarations – Returning a single value – Returning.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
4.1 Instance Variables, Constructors, and Methods.
Chapter 8 Friends and Overloaded Operators. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Friend Function (8.1) Overloading.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
Chapter 6: Functions Starting Out with C++ Early Objects
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.
User Input and Collisions COSC 315 Fall 2014 Bridget M. Blodgett.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
11 Using the Keyboard Session Session Overview  Introduce the keyboard device  Show how keys on a keyboard can be represented by enumerated types.
CHAPTER 10 Using C# Methods to Solve Problem XNA Game Studio 4.0.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
1 Advanced Issues on Classes Part 3 Reference variables (Tapestry pp.581, Horton 176 – 178) Const-reference variables (Horton 176 – 178) object sharing:
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.
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.
11 Getting Player Input Using a Gamepad Session 3.1.
Chapter 4 Introduction to Classes, Objects, Methods and strings
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Simple Classes. ADTs A specification for a real world data item –defines types and valid ranges –defines valid operations on the data. Specification is.
Session 13 Pinball Game Construction Kit (Version 3):
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
Starting Out with C++ Early Objects ~~ 7 th Edition by Tony Gaddis, Judy Walters, Godfrey Muganda Modified for CMPS 1044 Midwestern State University 6-1.
1 Brief Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
Functions Chapter 6. Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules Function: a collection.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – August 23, 2001.
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.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
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.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
11 Adding Vibration Effects Session Session Overview  Describe how the vibration feature of the gamepad works  Show how an XNA program can control.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
Chapter 6 Functions. 6-2 Topics 6.1 Modular Programming 6.2 Defining and Calling Functions 6.3 Function Prototypes 6.4 Sending Data into a Function 6.5.
Functions Skill Area 314 Part B. Lecture Overview Functions Function Prototypes Function Definitions Local Variables Global Variables Default Parameters.
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.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
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.
TK1924 Program Design & Problem Solving Session 2011/2012
Sound and more Animations
MOM! Phineas and Ferb are … Aims:
Collision Detection Box-to-Box.
Chapter 3 Introduction to Classes, Objects Methods and Strings
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
Chapter 10 Algorithms.
Chapter 10 Algorithms.
Presentation transcript:

11 Adding a Bread Bat Session 12.1

Session Overview  We have created a cheese sprite that bounces around the display  We now need to create a bread bat sprite that the player will control and can be used to hit the cheese  In this session, we find out the best way to manage multiple sprites in a game, how a player can control the position of a sprite, and how to detect and respond to collisions between the two objects  At the end, we will have the first game play element of “Bread and Cheese”  We have created a cheese sprite that bounces around the display  We now need to create a bread bat sprite that the player will control and can be used to hit the cheese  In this session, we find out the best way to manage multiple sprites in a game, how a player can control the position of a sprite, and how to detect and respond to collisions between the two objects  At the end, we will have the first game play element of “Bread and Cheese” Chapter 12.1: Adding a Bread Bat2

Cheese Sprite Information  This is all the information that is required to represent the cheese on the screen  It includes the texture, size, and speed information for the sprite  This is all the information that is required to represent the cheese on the screen  It includes the texture, size, and speed information for the sprite Chapter 12.1: Adding a Bread Bat3 Texture2D cheeseTexture; Rectangle cheeseRectangle; float cheeseWidthFactor = 0.05f; float cheeseX; float cheeseXSpeed; float cheeseY; float cheeseYSpeed; float cheeseTicksToCrossScreen = 200.0f; Texture2D cheeseTexture; Rectangle cheeseRectangle; float cheeseWidthFactor = 0.05f; float cheeseX; float cheeseXSpeed; float cheeseY; float cheeseYSpeed; float cheeseTicksToCrossScreen = 200.0f;

Creating a Bread Sprite  To create a bread sprite we could declare a set of variables with information about the bread  Each variable matches the purpose of the corresponding cheese variable  To create a bread sprite we could declare a set of variables with information about the bread  Each variable matches the purpose of the corresponding cheese variable Chapter 12.1: Adding a Bread Bat4 Texture2D breadTexture; Rectangle breadRectangle; float breadWidthFactor = 0.05f; float breadX; float breadXSpeed; float breadY; float breadYSpeed; float breadTicksToCrossScreen = 200.0f; Texture2D breadTexture; Rectangle breadRectangle; float breadWidthFactor = 0.05f; float breadX; float breadXSpeed; float breadY; float breadYSpeed; float breadTicksToCrossScreen = 200.0f;

Variables and Design  From a design point of view, it is not sensible to just declare a whole set of extra variables  Although from a technical point of view it would work, from a programming point of view a large number of variables with similar names is not a good play  Instead of using a convention that the word at the start of the variable name sets out which sprite it is part of, it would be nice if we had a way of grouping sprite information together  C# provides a mechanism called a structure to collect together related elements  From a design point of view, it is not sensible to just declare a whole set of extra variables  Although from a technical point of view it would work, from a programming point of view a large number of variables with similar names is not a good play  Instead of using a convention that the word at the start of the variable name sets out which sprite it is part of, it would be nice if we had a way of grouping sprite information together  C# provides a mechanism called a structure to collect together related elements Chapter 12.1: Adding a Bread Bat5

The C# Struct  A struct is a C# construction that brings together methods and data  Structures are very good for holding “lumps of data”  The XNA Framework and C# system library use structures a lot  A DateTime value is a struct type  A Color value is a struct type  We are going to create a structure to hold a sprite  A struct is a C# construction that brings together methods and data  Structures are very good for holding “lumps of data”  The XNA Framework and C# system library use structures a lot  A DateTime value is a struct type  A Color value is a struct type  We are going to create a structure to hold a sprite Chapter 12.1: Adding a Bread Bat6

Cheese Sprite Information  The GameSpriteStruct type is one we have invented to hold all the data fields that this type needs Chapter 12.1: Adding a Bread Bat7 struct GameSpriteStruct { public Texture2D SpriteTexture; public Rectangle SpriteRectangle; public float X; public float Y; public float XSpeed; public float YSpeed; public float WidthFactor; public float TicksToCrossScreen; }

Creating GameSpriteStruct variables  We have added a new type to the ones available to the program  Once we have declared the structure GameSpriteStruct,we can now create variables of this type  Each variable that we declare contains all the fields of the struct that we declared  We have added a new type to the ones available to the program  Once we have declared the structure GameSpriteStruct,we can now create variables of this type  Each variable that we declare contains all the fields of the struct that we declared Chapter 12.1: Adding a Bread Bat8 GameSpriteStruct cheese; GameSpriteStruct bread;

Accessing Structure Fields  A program can access fields in a structure by giving the variable name followed by the name of the required field  The statements above set the texture fields for the bread and the cheese  This works because these fields have been made public in the GameSpriteStruct declaration  A program can access fields in a structure by giving the variable name followed by the name of the required field  The statements above set the texture fields for the bread and the cheese  This works because these fields have been made public in the GameSpriteStruct declaration Chapter 12.1: Adding a Bread Bat9 cheese.SpriteTexture = Content.Load ("Images/Cheese"); bread.SpriteTexture = Content.Load ("Images/Bread"); cheese.SpriteTexture = Content.Load ("Images/Cheese"); bread.SpriteTexture = Content.Load ("Images/Bread");

Public Access Modifiers in GameSpriteStruct  The fields in GameSpriteStruct are all public  This makes them useable in code outside it  The fields in GameSpriteStruct are all public  This makes them useable in code outside it Chapter 12.1: Adding a Bread Bat10 struct GameSpriteStruct { public Texture2D SpriteTexture; public Rectangle SpriteRectangle; public float X; public float Y; public float XSpeed; public float YSpeed; public float WidthFactor; public float TicksToCrossScreen; }

Public and Private Fields  Fields that should not be used by code outside a structure can be made private  They will be accessed by calls to public methods  Fields that should not be used by code outside a structure can be made private  They will be accessed by calls to public methods Chapter 12.1: Adding a Bread Bat11 struct BankAccount { private float bankBalance; public void PayInFunds ( float amount) { } public void WithDrawFunds (float amount) { } } struct BankAccount { private float bankBalance; public void PayInFunds ( float amount) { } public void WithDrawFunds (float amount) { } }

Scaling the Bread and Cheese  We can now add statements to the ScaleSprites method to set up the bread as well as the cheese  The bread is made larger than the cheese and is able to move slightly faster  The relative speed of the bread and the cheese is something we might want to return to later  We can now add statements to the ScaleSprites method to set up the bread as well as the cheese  The bread is made larger than the cheese and is able to move slightly faster  The relative speed of the bread and the cheese is something we might want to return to later Chapter 12.1: Adding a Bread Bat12 bread.WidthFactor = 0.15f; bread.TicksToCrossScreen = 120.0f; // rest of calculations here bread.WidthFactor = 0.15f; bread.TicksToCrossScreen = 120.0f; // rest of calculations here

1. Bread and Cheese Chapter 12.1: Adding a Bread Bat13  This shows the bread and the cheese together on the screen  At the moment only the cheese moves, however  This shows the bread and the cheese together on the screen  At the moment only the cheese moves, however

Controlling the Bread Bat with a Thumbstick  We are going to use the left thumbstick to control the movement of the bread around the screen  The thumbstick provides float values in the range -1 to 1 for the X and Y directions  The values are obtained from a GamepadState variable  We are going to use the left thumbstick to control the movement of the bread around the screen  The thumbstick provides float values in the range -1 to 1 for the X and Y directions  The values are obtained from a GamepadState variable Chapter 12.1: Adding a Bread Bat14

Moving the Bread Bat  The bread speed is multiplied by the position of the thumbstick  The further the thumbstick is moved, the faster the bread will move  The bread speed is multiplied by the position of the thumbstick  The further the thumbstick is moved, the faster the bread will move Chapter 12.1: Adding a Bread Bat15 GamePadState gamePad1 = GamePad.GetState(PlayerIndex.One); bread.X = bread.X + (bread.XSpeed * pad1.ThumbSticks.Left.X); bread.Y = bread.Y – (bread.YSpeed * gamePad1.ThumbSticks.Left.Y); bread.SpriteRectangle.X = (int)bread.X; bread.SpriteRectangle.Y = (int)bread.Y; GamePadState gamePad1 = GamePad.GetState(PlayerIndex.One); bread.X = bread.X + (bread.XSpeed * pad1.ThumbSticks.Left.X); bread.Y = bread.Y – (bread.YSpeed * gamePad1.ThumbSticks.Left.Y); bread.SpriteRectangle.X = (int)bread.X; bread.SpriteRectangle.Y = (int)bread.Y;

2. Moving the Bread Chapter 12.1: Adding a Bread Bat16  With this version of the game we can move the bread around  The level of control is very good, for such simple code  With this version of the game we can move the bread around  The level of control is very good, for such simple code

Improving the Program Design with Methods  At the moment, the program works OK, but some of the code still looks a bit messy  The scaleSprites method is a bit of a mess in that it contains a lot of statements that set different parts of the sprites  It would be easy to miss out one of the settings and find that a sprite did not behave correctly  A way to improve this would be to write a method that is given a set of parameters to set up a sprite  At the moment, the program works OK, but some of the code still looks a bit messy  The scaleSprites method is a bit of a mess in that it contains a lot of statements that set different parts of the sprites  It would be easy to miss out one of the settings and find that a sprite did not behave correctly  A way to improve this would be to write a method that is given a set of parameters to set up a sprite Chapter 12.1: Adding a Bread Bat17

The setupSprite Method Header  The parameters to the method give the initial sprite settings  The setup values are calculated and used to set the sprite up  The parameters to the method give the initial sprite settings  The setup values are calculated and used to set the sprite up Chapter 12.1: Adding a Bread Bat18 void setupSprite( GameSpriteStruct sprite, float widthFactor, float ticksToCrossScreen, float initialX, float initialY) { // sets the values of the sprite in here } void setupSprite( GameSpriteStruct sprite, float widthFactor, float ticksToCrossScreen, float initialX, float initialY) { // sets the values of the sprite in here }

The setupSprite Method Body Chapter 12.1: Adding a Bread Bat19 { sprite.WidthFactor = widthFactor; sprite.TicksToCrossScreen = ticksToCrossScreen; sprite.SpriteRectangle.Width = (int)((displayWidth * widthFactor) + 0.5f); float aspectRatio = (float)sprite.SpriteTexture.Width / sprite.SpriteTexture.Height; sprite.SpriteRectangle.Height = (int)((sprite.SpriteRectangle.Width / aspectRatio) + 0.5f); sprite.X = initialX; sprite.Y = initialY; sprite.XSpeed = displayWidth / ticksToCrossScreen; sprite.YSpeed = sprite.Xspeed; } { sprite.WidthFactor = widthFactor; sprite.TicksToCrossScreen = ticksToCrossScreen; sprite.SpriteRectangle.Width = (int)((displayWidth * widthFactor) + 0.5f); float aspectRatio = (float)sprite.SpriteTexture.Width / sprite.SpriteTexture.Height; sprite.SpriteRectangle.Height = (int)((sprite.SpriteRectangle.Width / aspectRatio) + 0.5f); sprite.X = initialX; sprite.Y = initialY; sprite.XSpeed = displayWidth / ticksToCrossScreen; sprite.YSpeed = sprite.Xspeed; }

Calling setupSprite  The setupSprite method is called twice, to set up the cheese and the bread  The values are the ones that have used before  The setupSprite method is called twice, to set up the cheese and the bread  The values are the ones that have used before Chapter 12.1: Adding a Bread Bat20 void setupSprites() { setupSprite(cheese, 0.05f, 200.0f, minDisplayX, minDisplayY); setupSprite(bread, 0.15f, 120.0f, displayWidth / 2, displayHeight / 2); } void setupSprites() { setupSprite(cheese, 0.05f, 200.0f, minDisplayX, minDisplayY); setupSprite(bread, 0.15f, 120.0f, displayWidth / 2, displayHeight / 2); }

A Clearer Call of setupSprite  This call works in exactly the same way  However, I have added some comments to make it clear what each parameter does  I find this format much clearer  This call works in exactly the same way  However, I have added some comments to make it clear what each parameter does  I find this format much clearer Chapter 12.1: Adding a Bread Bat21 setupSprite( cheese, // sprite to set up 0.05f, // width factor (a 20th) 200.0f, // ticks to cross the screen minDisplayX, // starting X position minDisplayY); // starting Y position setupSprite( cheese, // sprite to set up 0.05f, // width factor (a 20th) 200.0f, // ticks to cross the screen minDisplayX, // starting X position minDisplayY); // starting Y position

3. Using Methods to Break Programs Chapter 12.1: Adding a Bread Bat22  The code is now much clearer and well designed  Unfortunately it doesn’t work  We need to find out why  The code is now much clearer and well designed  Unfortunately it doesn’t work  We need to find out why

The Broken Method Call  There is nothing wrong with the method  There is nothing wrong with the values we are using to call it  Unfortunately, the problem is that we are not using parameters correctly  There is nothing wrong with the method  There is nothing wrong with the values we are using to call it  Unfortunately, the problem is that we are not using parameters correctly Chapter 12.1: Adding a Bread Bat23 setupSprite( cheese, // sprite to set up 0.05f, // width factor (a 20th) 200.0f, // ticks to cross the screen minDisplayX, // starting X position minDisplayY); // starting Y position setupSprite( cheese, // sprite to set up 0.05f, // width factor (a 20th) 200.0f, // ticks to cross the screen minDisplayX, // starting X position minDisplayY); // starting Y position

Passing Parameters by Value  These are the parameters that are passed into the setupSprite method  They are all passed by value  This is what is causing our problem  These are the parameters that are passed into the setupSprite method  They are all passed by value  This is what is causing our problem Chapter 12.1: Adding a Bread Bat24 void setupSprite( GameSpriteStruct sprite, float widthFactor, float ticksToCrossScreen, float initialX, float initialY) { // sets the values of the sprite in here } void setupSprite( GameSpriteStruct sprite, float widthFactor, float ticksToCrossScreen, float initialX, float initialY) { // sets the values of the sprite in here }

Passing Parameters by Value  When a parameter is passed by value this tells C# to send a copy of the value into the method that is called  The method then works on the copy  This means that setupSprite will work on a copy of the GameSpriteStruct it was given, not the original  So it will not change the fields in the cheese variable, it will change fields in the copy, which means the cheese variable will not be set up  When a parameter is passed by value this tells C# to send a copy of the value into the method that is called  The method then works on the copy  This means that setupSprite will work on a copy of the GameSpriteStruct it was given, not the original  So it will not change the fields in the cheese variable, it will change fields in the copy, which means the cheese variable will not be set up Chapter 12.1: Adding a Bread Bat25

Passing Parameters by Reference  We can tell the compiler we want to pass the sprite as a reference by using the keyword ref  Now the method is given a reference to the parameter variable, not a copy of it  We can tell the compiler we want to pass the sprite as a reference by using the keyword ref  Now the method is given a reference to the parameter variable, not a copy of it Chapter 12.1: Adding a Bread Bat26 void setupSprite( ref GameSpriteStruct sprite, float widthFactor, float ticksToCrossScreen, float initialX, float initialY) { // sets the values of the sprite in here } void setupSprite( ref GameSpriteStruct sprite, float widthFactor, float ticksToCrossScreen, float initialX, float initialY) { // sets the values of the sprite in here }

Supplying a Reference in the Call  If you tell C# a parameter is being passed by reference you have to give a reference in the call too  This is done by putting the ref keyword in front of the variable in the method call  You can pass other types by reference too  If you tell C# a parameter is being passed by reference you have to give a reference in the call too  This is done by putting the ref keyword in front of the variable in the method call  You can pass other types by reference too Chapter 12.1: Adding a Bread Bat27 setupSprite( ref cheese, // reference to the sprite to set up 0.05f, // width factor (a 20th) 200.0f, // ticks to cross the screen minDisplayX, // starting X position minDisplayY); // starting Y position setupSprite( ref cheese, // reference to the sprite to set up 0.05f, // width factor (a 20th) 200.0f, // ticks to cross the screen minDisplayX, // starting X position minDisplayY); // starting Y position

4. Mending Methods Chapter 12.1: Adding a Bread Bat28  Passing references into the methods means that they are set up correctly, and the game will now work

Making the Bread Hit the Cheese  When the bat hits the cheese it should “bounce” back up the screen  We can make the cheese bounce, just by reversing the direction of the Y speed, as we do when the cheese hits the top or bottom  But we have to know when the two sprites collide  The program must detect when the player hits the cheese with the bread  When the bat hits the cheese it should “bounce” back up the screen  We can make the cheese bounce, just by reversing the direction of the Y speed, as we do when the cheese hits the top or bottom  But we have to know when the two sprites collide  The program must detect when the player hits the cheese with the bread Chapter 12.1: Adding a Bread Bat29

Collisions and Rectangles  A simple collision detection can be implemented by detecting when the bread and cheese rectangles intersect  The Rectangle type provides a very easy way to do this  A simple collision detection can be implemented by detecting when the bread and cheese rectangles intersect  The Rectangle type provides a very easy way to do this Chapter 12.1: Adding a Bread Bat30

Using the Intersects Method  A Rectangle value provides an Intersects method  This is given another Rectangle to test against  The method returns true if the two rectangles intersect  We can use this to bounce the cheese off the bread  A Rectangle value provides an Intersects method  This is given another Rectangle to test against  The method returns true if the two rectangles intersect  We can use this to bounce the cheese off the bread Chapter 12.1: Adding a Bread Bat31 if (cheese.SpriteRectangle.Intersects(bread.SpriteRectangle)) { cheese.YSpeed = cheese.YSpeed * -1; }

5. Bouncing Cheese Chapter 12.1: Adding a Bread Bat32  Adding just that one condition to the Update method turns the program into a game of sorts

Summary  A C# struct is a way to bring together related fields  Members of a struct can be private (only usable by methods in the struct ) or public (useable by all)  Variables of struct type are managed by value  Parameters are usually passed by value  If a method is to change the value of a parameter the parameter must be passed by reference  The Rectangle class has an Intersects method that can be used to detect when game objects collide  A C# struct is a way to bring together related fields  Members of a struct can be private (only usable by methods in the struct ) or public (useable by all)  Variables of struct type are managed by value  Parameters are usually passed by value  If a method is to change the value of a parameter the parameter must be passed by reference  The Rectangle class has an Intersects method that can be used to detect when game objects collide Chapter 12.1: Adding a Bread Bat33

True/False Revision Quiz  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100.  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100. Chapter 12.1: Adding a Bread Bat34

True/False Revision Quiz  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100.  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100. Chapter 12.1: Adding a Bread Bat35

True/False Revision Quiz  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100.  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100. Chapter 12.1: Adding a Bread Bat36

True/False Revision Quiz  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100.  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100. Chapter 12.1: Adding a Bread Bat37

True/False Revision Quiz  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100.  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100. Chapter 12.1: Adding a Bread Bat38

True/False Revision Quiz  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100.  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100. Chapter 12.1: Adding a Bread Bat39

True/False Revision Quiz  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100.  A C# struct can contain methods and data fields.  A C# struct is managed by value.  Private fields in a struct cannot be changed.  Parameters are usually passed into methods by value.  If a method is to change the value of a parameter, the method must be passed by reference.  The gamepad thumbsticks return a value between 0 and 100. Chapter 12.1: Adding a Bread Bat40