Rob Miles. How does an XNA game program work? Programs tell computers what to do A program is...

22
Rob Miles

Transcript of Rob Miles. How does an XNA game program work? Programs tell computers what to do A program is...

Page 1: 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.

Rob Miles

Page 2: 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.

How does an XNA game program work?

Page 3: 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.

• Programs tell computers what to do• A program is written in a programming

language– C# is a programming language

• XNA is a framework that provides program resources for writing games

• Programs describe Data and the Actions that are performed on it

Page 4: 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.

Computer Games and Programs• A Computer Game is a program

that plays a game with us• All computer game programs

work in the same way– Load all the pictures, sounds and

models• Update the game world• Draw the game world• Repeat as fast as possible

• This is true whether the game is GTA IV, Pac Man or The Sims

Page 5: 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.

The Anatomy of Program

• A program contains two things• A description of the Data it

works with– Like a list of ingredients for a

recipe for a cake• A description of the actions

that the program should perform on the data– Like the steps to perform to

make the cake

Data

Actions

Page 6: 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.

The Anatomy of an XNA Game

• In an XNA program the data describes the “game world”

• The actions describe how to update and draw the world– Update moves items around,

detects collisions etc– Draw produces a view of the

world for the player to see

Game Data

Update action

Draw action

Other actions...

Page 7: 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.

Computer Games and XNA

• The Update and Draw behaviours in an XNA game are expressed as methods

• When you make a new game XNA creates a template game file with empty Draw and Update methods for you to fill in

Page 8: 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.

• Here is an empty XNA game with no graphics

• This is the starting point for every game

• It just draws a blue screen

Empty Game

Page 9: 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.

Performing Actions in Programs• A C# statement is a single step

in a program– Like an action in a recipe : “Turn

on oven”– Each statement is separated

from the next by a semi-colon• A C# method is a number of

statements in a block which have been given a name– Like an entire set of steps: “Boil

the kettle”

Page 10: 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.

The XNA Draw method

• A method is a block of C# with a particular name• The DrawDraw method draws the game display• Above is the method you get with a new game• The most important part has been shaded

protected override void Draw(GameTime gameTime){ graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: Add your drawing code here

base.Draw(gameTime);}

protected override void Draw(GameTime gameTime){ graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: Add your drawing code here

base.Draw(gameTime);}

Page 11: 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.

How Clear Works

graphics.GraphicsDevice.Clear(Color.CornflowerBlue);graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

The graphics device manager

The graphics device itself

The Clear method

The Colour value to use, in this caseit is a kind of blue

Page 12: 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.

Making Sense of a Method Call

backBedroom.SatelliteTV.SwitchChannel(Channel.BBC);backBedroom.SatelliteTV.SwitchChannel(Channel.BBC);

Something that holds items

The item we want to use

The instruction we want obeyed

Information for the instruction

Page 13: 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.

A Different Colour

graphics.GraphicsDevice.Clear(Color.Red);graphics.GraphicsDevice.Clear(Color.Red);

The graphics device manager

The graphics device itself

The Clear method

The Color value to use, in this caseit is red

Page 14: 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.

• We can modify the call of Clear in the Draw method

• It is told the colour to clear the screen

• We can change that colour

Yellow Screen

Page 15: 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.

• A program contains data and actions• Two of the actions in an XNA game program are

the ones that Update the game and Draw the screen

• An “empty” XNA game contains a Draw method that draws a blue screen using a Clear method

• We can change the colour of the screen by changing the information sent into the Clear method

Page 16: 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.

• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear

the screen• There is a colour called Teal

Page 17: 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.

• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear

the screen• There is a colour called Teal

Page 18: 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.

• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear

the screen• There is a colour called Teal

Page 19: 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.

• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear

the screen• There is a colour called Teal

Page 20: 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.

• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear

the screen• There is a colour called Teal

Page 21: 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.

• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear

the screen• There is a colour called Teal

Page 22: 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.

• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear

the screen• There is a colour called Teal