xna-in-a-day

34
XNA-in-a-Day Introduction to XNA Game Studio

Upload: ed-donahue

Post on 22-Nov-2014

1.391 views

Category:

Technology


0 download

DESCRIPTION

Slides presented at XNA-in-a-Day events. It walks through the creation of an XNA Windows game. Download the files at http://bit.ly/XNADayFiles.

TRANSCRIPT

Page 1: XNA-in-a-Day

XNA-in-a-Day

Introduction to XNA Game Studio

Page 2: XNA-in-a-Day

Ed Donahue

Academic Developer Evangelist Mid-Atlantic Region (MD, DC, VA, WV, NC, SC) Developer & Platform Evangelism (DPE)

I love my job because… I help people build cool technology!

I love my job because… I get to share my passion for technology with students!

I love my life because… I get to travel!

I love my life because… I have random dance parties!

@creepyed creepyed.com

Page 3: XNA-in-a-Day

GETTING STARTED

Page 4: XNA-in-a-Day

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

[email protected] | creepyed.com | @creepyed

Page 5: XNA-in-a-Day
Page 6: XNA-in-a-Day

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 Server

o Free appHub account for Windows Phone 7 Marketplace

o One year free subscription to XNA Creators Club

o 90 days of free Pluralsight training

Page 7: XNA-in-a-Day

www.DreamSpark.com to register

Page 8: XNA-in-a-Day

Visual Studio

• Integrated Development Environment

• Main code window

• Solution Explorer

• Toolbars and menus

[email protected] | creepyed.com | @creepyed

Page 9: XNA-in-a-Day

Creating a game

• Create new project

• Basic structure of game project

– Initialize

– LoadContent (and UnloadContent)

– Update

– Draw

• GraphicsDeviceManager

• SpriteBatch (we’ll revisit)

[email protected] | creepyed.com | @creepyed

Page 10: XNA-in-a-Day

ACTUALLY CREATING A GAME…

Page 11: XNA-in-a-Day

Adding Assets

• http://bit.ly/XNADayFiles

• Content – what is it

• Add content to project

[email protected] | creepyed.com | @creepyed

Page 12: XNA-in-a-Day

Preparing Assets (Background)

• Texture2D

• ContentManager

• Content.Load

• viewPortRect

[email protected] | creepyed.com | @creepyed

Page 13: XNA-in-a-Day

Using Assets

• Draw() method

• 2D graphical assets - SpriteBatch

[email protected] | creepyed.com | @creepyed

Page 14: XNA-in-a-Day

Now for some fun stuff

• Cannon

– Loaded in the same way

– Drawn in the same way

– Not quite!

[email protected] | creepyed.com | @creepyed

Page 15: XNA-in-a-Day

GameObject Class

• Sprite Texture

• Position

– Vector2.Zero

• Center

• Rotation

– Float

[email protected] | creepyed.com | @creepyed

Page 16: XNA-in-a-Day

Cannon Take 2

• Declare

• Load

– and set position

• Draw

– Using GameObject properties

• Interact

[email protected] | creepyed.com | @creepyed

Page 17: XNA-in-a-Day

INTERACTION

Page 18: XNA-in-a-Day

Interaction Part 1

• Cannon Rotation – Shorthand operator +=

– Thumbstick

– Restricting movement

• Keyboard control too – Conditional compilation #if

• Change Draw method

[email protected] | creepyed.com | @creepyed

Page 19: XNA-in-a-Day

Cannonballs - setup

• GameObject updates

– Velocity

– Alive

• Constants and Arrays

• Loops

– for

– foreach and condition to draw

[email protected] | creepyed.com | @creepyed

Page 20: XNA-in-a-Day

Interaction Part 2

• State – GamePad and Keyboard

– Define objects

– Retrieve and save state

[email protected] | creepyed.com | @creepyed

Page 21: XNA-in-a-Day

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

[email protected] | creepyed.com | @creepyed

Page 22: XNA-in-a-Day

Cannonballs - moving

• Position + Velocity

• Is it still visible?

– viewPortRect.Contains(Point)

[email protected] | creepyed.com | @creepyed

Page 23: XNA-in-a-Day

Something to shoot at (1)

• Same as cannonballs

– Array Declaration

– Load Content

– Draw

– Update if alive

[email protected] | creepyed.com | @creepyed

Page 24: XNA-in-a-Day

Something to shoot at (2)

• Different from cannonballs

– Update if not alive

– Set Velocity

– Set Position

– Set Alive

[email protected] | creepyed.com | @creepyed

Page 25: XNA-in-a-Day

Introducing randomness

• Random

• Random.NextDouble

• Lerp - MathHelper function

– Interpolate number within range

[email protected] | creepyed.com | @creepyed

Page 26: XNA-in-a-Day

Contact!

• Compare cannonballs and enemies

• Create virtual Rectangles

• Check Intersect

[email protected] | creepyed.com | @creepyed

Page 27: XNA-in-a-Day

Scoring - SpriteFont

• Create

• Declare

• Load

• Draw

[email protected] | creepyed.com | @creepyed

Page 28: XNA-in-a-Day

WHERE TO NEXT?

Page 29: XNA-in-a-Day

Particle System

• Use

– 2D textures

– Randomness

– Rotation, velocity, position

[email protected] | creepyed.com | @creepyed

Page 30: XNA-in-a-Day

Imagine Cup

VIDEOS!

[email protected] | creepyed.com | @creepyed

Page 31: XNA-in-a-Day

Windows Phone 7

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

• Add touch support

• Take it to the next level

[email protected] | creepyed.com | @creepyed

Page 32: XNA-in-a-Day

Windows Phone 7 - Touch

• Add Reference

• Get TouchPanel state

• Check TouchLocation state

[email protected] | creepyed.com | @creepyed

Page 33: XNA-in-a-Day

Starter Kits

• Platformer

• RPG

• Space Shooter

• Racing

[email protected] | creepyed.com | @creepyed

Page 34: XNA-in-a-Day

ScriptTD

• Tower defense game engine

• Customizable images and audio

• scriptTD.codeplex.com

[email protected] | creepyed.com | @creepyed