XNA-in-a-Day
-
Upload
ed-donahue -
Category
Technology
-
view
1.391 -
download
0
description
Transcript of XNA-in-a-Day
![Page 1: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/1.jpg)
XNA-in-a-Day
Introduction to XNA Game Studio
![Page 2: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/2.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/3.jpg)
GETTING STARTED
![Page 4: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/4.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/5.jpg)
![Page 6: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/6.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/7.jpg)
www.DreamSpark.com to register
![Page 8: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/8.jpg)
Visual Studio
• Integrated Development Environment
• Main code window
• Solution Explorer
• Toolbars and menus
[email protected] | creepyed.com | @creepyed
![Page 9: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/9.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/10.jpg)
ACTUALLY CREATING A GAME…
![Page 11: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/11.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/12.jpg)
Preparing Assets (Background)
• Texture2D
• ContentManager
• Content.Load
• viewPortRect
[email protected] | creepyed.com | @creepyed
![Page 13: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/13.jpg)
Using Assets
• Draw() method
• 2D graphical assets - SpriteBatch
[email protected] | creepyed.com | @creepyed
![Page 14: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/14.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/15.jpg)
GameObject Class
• Sprite Texture
• Position
– Vector2.Zero
• Center
• Rotation
– Float
[email protected] | creepyed.com | @creepyed
![Page 16: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/16.jpg)
Cannon Take 2
• Declare
• Load
– and set position
• Draw
– Using GameObject properties
…
• Interact
[email protected] | creepyed.com | @creepyed
![Page 17: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/17.jpg)
INTERACTION
![Page 18: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/18.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/19.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/20.jpg)
Interaction Part 2
• State – GamePad and Keyboard
– Define objects
– Retrieve and save state
[email protected] | creepyed.com | @creepyed
![Page 21: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/21.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/22.jpg)
Cannonballs - moving
• Position + Velocity
• Is it still visible?
– viewPortRect.Contains(Point)
[email protected] | creepyed.com | @creepyed
![Page 23: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/23.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/24.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/25.jpg)
Introducing randomness
• Random
• Random.NextDouble
• Lerp - MathHelper function
– Interpolate number within range
[email protected] | creepyed.com | @creepyed
![Page 26: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/26.jpg)
Contact!
• Compare cannonballs and enemies
• Create virtual Rectangles
• Check Intersect
[email protected] | creepyed.com | @creepyed
![Page 28: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/28.jpg)
WHERE TO NEXT?
![Page 29: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/29.jpg)
Particle System
• Use
– 2D textures
– Randomness
– Rotation, velocity, position
[email protected] | creepyed.com | @creepyed
![Page 31: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/31.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/32.jpg)
Windows Phone 7 - Touch
• Add Reference
• Get TouchPanel state
• Check TouchLocation state
[email protected] | creepyed.com | @creepyed
![Page 33: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/33.jpg)
Starter Kits
• Platformer
• RPG
• Space Shooter
• Racing
[email protected] | creepyed.com | @creepyed
![Page 34: XNA-in-a-Day](https://reader034.fdocuments.us/reader034/viewer/2022051609/5474629eb4af9fc30a8b5624/html5/thumbnails/34.jpg)
ScriptTD
• Tower defense game engine
• Customizable images and audio
• scriptTD.codeplex.com
[email protected] | creepyed.com | @creepyed