xna-in-a-day
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
XNA-in-a-Day
Introduction to XNA Game Studio
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
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
[email protected] | creepyed.com | @creepyed
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
www.DreamSpark.com to register
Visual Studio
• Integrated Development Environment
• Main code window
• Solution Explorer
• Toolbars and menus
[email protected] | creepyed.com | @creepyed
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
ACTUALLY CREATING A GAME…
Adding Assets
• http://bit.ly/XNADayFiles
• Content – what is it
• Add content to project
[email protected] | creepyed.com | @creepyed
Preparing Assets (Background)
• Texture2D
• ContentManager
• Content.Load
• viewPortRect
[email protected] | creepyed.com | @creepyed
Using Assets
• Draw() method
• 2D graphical assets - SpriteBatch
[email protected] | creepyed.com | @creepyed
Now for some fun stuff
• Cannon
– Loaded in the same way
– Drawn in the same way
– Not quite!
[email protected] | creepyed.com | @creepyed
GameObject Class
• Sprite Texture
• Position
– Vector2.Zero
• Center
• Rotation
– Float
[email protected] | creepyed.com | @creepyed
Cannon Take 2
• Declare
• Load
– and set position
• Draw
– Using GameObject properties
…
• Interact
[email protected] | creepyed.com | @creepyed
INTERACTION
Interaction Part 1
• Cannon Rotation – Shorthand operator +=
– Thumbstick
– Restricting movement
• Keyboard control too – Conditional compilation #if
• Change Draw method
[email protected] | creepyed.com | @creepyed
Cannonballs - setup
• GameObject updates
– Velocity
– Alive
• Constants and Arrays
• Loops
– for
– foreach and condition to draw
[email protected] | creepyed.com | @creepyed
Interaction Part 2
• State – GamePad and Keyboard
– Define objects
– Retrieve and save state
[email protected] | creepyed.com | @creepyed
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
Cannonballs - moving
• Position + Velocity
• Is it still visible?
– viewPortRect.Contains(Point)
[email protected] | creepyed.com | @creepyed
Something to shoot at (1)
• Same as cannonballs
– Array Declaration
– Load Content
– Draw
– Update if alive
[email protected] | creepyed.com | @creepyed
Something to shoot at (2)
• Different from cannonballs
– Update if not alive
– Set Velocity
– Set Position
– Set Alive
[email protected] | creepyed.com | @creepyed
Introducing randomness
• Random
• Random.NextDouble
• Lerp - MathHelper function
– Interpolate number within range
[email protected] | creepyed.com | @creepyed
Contact!
• Compare cannonballs and enemies
• Create virtual Rectangles
• Check Intersect
[email protected] | creepyed.com | @creepyed
WHERE TO NEXT?
Particle System
• Use
– 2D textures
– Randomness
– Rotation, velocity, position
[email protected] | creepyed.com | @creepyed
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
Windows Phone 7 - Touch
• Add Reference
• Get TouchPanel state
• Check TouchLocation state
[email protected] | creepyed.com | @creepyed
Starter Kits
• Platformer
• RPG
• Space Shooter
• Racing
[email protected] | creepyed.com | @creepyed
ScriptTD
• Tower defense game engine
• Customizable images and audio
• scriptTD.codeplex.com
[email protected] | creepyed.com | @creepyed