XNA in a Day

Preview:

DESCRIPTION

Presentation deck to go along with my XNA in a Day training.

Citation preview

XNA-in-a-Day

Introduction to XNAGame Studio

Andrew ParsonsAcademic Developer Evangelist@MrAndyPuppy

GETTING STARTED

The Tools You Need

• A computer– A decent card if you want graphics

acceleration

• Windows– Windows 7 works well

• Visual Studio or Visual C#– Visual Studio 2010 Professional – available to

students through DreamSpark

• XNA Game Studio– Current version – XNA Game Studio 4.0

What is DreamSpark?o DreamSpark provides free Microsoft software to verified

students around the world for FREE!

Who is eligible for DreamSpark?o All part-time and full-time students are entitled to DreamSpark software

What software can they get from DreamSpark?o Visual Studio 2010 Professional, Expression Studio 4 Ultimate, Windows

Server, SQL Servero Free appHub account for Windows Phone 7 Marketplaceo One year free subscription to XNA Creators Clubo 90 days of free Pluralsight training

www.DreamSpark.comto register

Visual Studio

• Integrated Development Environment

• Main code window• Solution Explorer• Toolbars and menus

Creating a game

• Create new project• Basic structure of game project– Initialize– LoadContent (and UnloadContent)– Update– Draw

• GraphicsDeviceManager• SpriteBatch (we’ll revisit)

ACTUALLY CREATING A GAME…

Adding Assets

• http://bit.ly/XNADayFiles • Content – what is it• Add content to project

Preparing Assets (Background)

• Texture2D• ContentManager• Content.Load• viewPortRect

Using Assets

• Draw() method• 2D graphical assets - SpriteBatch

Now for some fun stuff

• Cannon– Loaded in the same way– Drawn in the same way– Not quite!

GameObject Class

• Sprite Texture• Position– Vector2.Zero

• Center• Rotation– Float

Cannon Take 2

• Declare• Load – and set position

• Draw – Using GameObject properties

…• Interact

INTERACTION

Interaction Part 1

• Cannon Rotation– Shorthand operator += – Thumbstick– Restricting movement

• Keyboard control too– Conditional compilation #if

• Change Draw method

Cannonballs - setup

• GameObject updates– Velocity– Alive

• Constants and Arrays• Loops– for– foreach and condition to draw

Interaction Part 2

• State – GamePad and Keyboard– Define objects– Retrieve and save state

Cannonballs - firing

• Buttons.A == ButtonState.Pressed– Previous state should be Released

(make them work for it)

• Automatic Method creation• Rotation in Radians – Cos/Sin math

functions• return to exit loop

Cannonballs - moving

• Position + Velocity• Is it still visible?– viewPortRect.Contains(Point)

Something to shoot at (1)

• Same as cannonballs – Array Declaration– Load Content– Draw– Update if alive

Something to shoot at (2)

• Different from cannonballs– Update if not alive– Set Velocity– Set Position– Set Alive

Introducing randomness

• Random• Random.NextDouble• Lerp - MathHelper function – Interpolate number within range

Contact!

• Compare cannonballs and enemies• Create virtual Rectangles• Check Intersect

Scoring - SpriteFont

• Create• Declare• Load• Draw

WHERE TO NEXT?

Particle System

• Use– 2D textures– Randomness– Rotation, velocity, position

Imagine Cup

VIDEOS!

Windows Phone 7

• Converting to Windows Phone 7 (or Xbox 360).

• Add touch support• Take it to the next level

Windows Phone 7 - Touch

• Add Reference

• Get TouchPanel state

• Check TouchLocation state

Starter Kits

• Platformer• RPG• Space Shooter• Racing

ScriptTD

• http://bit.ly/APscriptTD

More Info

• http://bit.ly/puppyblog• http://bit.ly/puppytube