loading

Logout succeed

Logout succeed. See you again!

ebook img

Beginning XNA 2.0 Game Programming: From Novice to Professional PDF

pages457 Pages
release year2008
file size10.408 MB
languageEnglish

Preview Beginning XNA 2.0 Game Programming: From Novice to Professional

cyan yelloW maGenTa Black panTone 123 c Books for professionals By professionals® The eXperT’s Voice® in Game proGramminG Companion eBook Available Beginning XNA 2.0 Game Programming: Beginning From Novice to Professional X Beginning Dear Reader, N Alexandre Lobão, Creating games usually involves many challenges, from learning a lot of math author of to understanding details about how to gather data from game input devices. A Beginning .NET Game You need to figure out how to draw a 2-D or 3-D scene, how to include sound Programming in C# in your game, how to connect to other players’ machines in multiplayer games, XNA 2.0 Game Beginning .NET Game 2 and more. Before XNA, when creating games for both the Windows and Xbox 360 Programming in VB .NET platforms, the challenges were doubled. It’s not surprising that game programmers . .NET Game Programming with DirectX 9.0 are some of the most versatile and hardworking developers around—but also, 0 we must confess, the ones with the coolest jobs! Due to the complexity involved in creating a game, starting out in this area G has always been problematic. Where do you begin? Programming In this book, we guide you in your first steps into this fascinating area, by a including a mix of overview chapters—where you get in touch with common m terms in the game programming area and learn some basic concepts with practical examples—and complete game programming chapters, so you can apply the e knowledge you’ve gathered to real games, to prepare you to create your own Bruno Evangelista designs. Even better, we do this using XNA, the groundbreaking new cross-platform P game development framework from Microsoft, which makes it simple to create r your own games and run them both in Windows and Xbox 360, with few or no o From Novice to Professional modifications! The XNA technology has been created in a way that minimizes the complexity of code needed for accessing game devices, rendering scenes, g connecting machines, and playing sounds, so you can focus on what really r matters: your game logic. a You already have what it takes to start creating successful games: passion! José Antonio Leal de Farias And with this book, we provide you with the necessary knowledge to define m your next steps. Enjoy! Guiding your first steps in creating Companion eBook Alexandre Lobão, Bruno Evangelista, and José Antonio Leal de Farias m Xbox 360 and Windows games! i THE APRESS ROADMAP n Beginning XNA 2.0 XNA 2.0 Game g See last page for details Game Programming Programming Recipes on $10 eBook version Creating Mobile Games Beginning C# 2008 Building XNA 2.0 Games E v da en Alexandre Lobão, Bruno Evangelista, SOURCE CODE ONLINE ISBN-13: 978-1-59059-924-2 g F L www.apress.com ISBN-10: 1-59059-924-1 aeo 53999 rialistbã and José Antonio Leal de Farias sao US $39.99 ,, Foreword by Amintas Lopes Neto, Shelve in Games Programming Academic Relations Manager—Microsoft Brazil User level: 9 781590 599242 Beginner–Intermediate this print for content only—size & color not accurate spine = 0.865" 456 page count 9241FM.qxd 4/1/08 10:32 AM Page i Beginning XNA 2.0 Game Programming From Novice to Professional Alexandre Lobão, Bruno Evangelista, and José Antonio Leal de Farias 9241FM.qxd 4/1/08 10:32 AM Page ii BeginningXNA2.0GameProgramming:FromNovicetoProfessional Copyright©2008byAlexandreLobão,BrunoEvangelista,JoséAntonioLealdeFarias Allrightsreserved.Nopartofthisworkmaybereproducedortransmittedinanyformorbyanymeans, electronicormechanical,includingphotocopying,recording,orbyanyinformationstorageorretrieval system,withoutthepriorwrittenpermissionofthecopyrightownerandthepublisher. ISBN-13(pbk):978-1-59059-924-2 ISBN-10(pbk):1-59059-924-1 ISBN-13(electronic):978-1-4302-0512-8 ISBN-10(electronic):1-4302-0512-1 PrintedandboundintheUnitedStatesofAmerica987654321 Trademarkednamesmayappearinthisbook.Ratherthanuseatrademarksymbolwitheveryoccurrence ofatrademarkedname,weusethenamesonlyinaneditorialfashionandtothebenefitofthetrademark owner,withnointentionofinfringementofthetrademark. LeadEditor:EwanBuckingham TechnicalReviewer:FabioClaudioFerracchiati EditorialBoard:ClayAndres,SteveAnglin,EwanBuckingham,TonyCampbell,GaryCornell, JonathanGennick,MatthewMoodie,JosephOttinger,JeffreyPepper,FrankPohlmann, BenRenow-Clarke,DominicShakeshaft,MattWade,TomWelsh SeniorProjectManager:KylieJohnston CopyEditor:SusannahDavidsonPfalzer AssociateProductionDirector:KariBrooks-Copony SeniorProductionEditor:LauraCheu Compositor:DinaQuan Proofreader:AprilEddy Indexer:BeckyHornyak Artist:AprilMilne CoverDesigner:KurtKrames ManufacturingDirector:TomDebolski DistributedtothebooktradeworldwidebySpringer-VerlagNewYork,Inc.,233SpringStreet,6thFloor, NewYork,NY10013.Phone1-800-SPRINGER,fax201-348-4505,[email protected],or visithttp://www.springeronline.com. Forinformationontranslations,pleasecontactApressdirectlyat2855TelegraphAvenue,Suite600, Berkeley,CA94705.Phone510-549-5930,fax510-549-5939,[email protected],orvisit http://www.apress.com. ApressandfriendsofEDbooksmaybepurchasedinbulkforacademic,corporate,orpromotionaluse. eBookversionsandlicensesarealsoavailableformosttitles.Formoreinformation,referenceourSpecial BulkSales–eBookLicensingwebpageathttp://www.apress.com/info/bulksales. Theinformationinthisbookisdistributedonan“asis”basis,withoutwarranty.Althougheveryprecau- tionhasbeentakeninthepreparationofthiswork,neithertheauthor(s)norApressshallhaveany liabilitytoanypersonorentitywithrespecttoanylossordamagecausedorallegedtobecauseddirectly orindirectlybytheinformationcontainedinthiswork. Thesourcecodeforthisbookisavailabletoreadersathttp://www.apress.com. 9241FM.qxd 4/1/08 10:32 AM Page iii Contents at a Glance Foreword........................................................................xiii AbouttheAuthors.................................................................xv AbouttheTechnicalReviewer......................................................xvii Acknowledgments................................................................xix Introduction......................................................................xxi nCHAPTER 1 GamePlanningandProgrammingBasics........................1 nCHAPTER 2 2-DGraphics,Audio, andInputBasics..........................17 nCHAPTER 3 Creating YourFirst2-DGame..................................43 nCHAPTER 4 ImprovingYourFirst2-DGame.................................69 nCHAPTER 5 BasicsofGameNetworking ..................................129 nCHAPTER 6 RockRainLive!...............................................161 nCHAPTER 7 3-DGameProgrammingBasics...............................197 nCHAPTER 8 RenderingPipeline, Shaders,andEffects......................227 nCHAPTER 9 Lights,Camera,Transformations!.............................245 nCHAPTER 10 GeneratingaTerrain..........................................265 nCHAPTER 11 SkeletalAnimation ...........................................299 nCHAPTER 12 CreatingaThird-PersonShooterGame........................339 nCHAPTER 13 ClosingWords................................................407 nINDEX .......................................................................411 iii 9241FM.qxd 4/1/08 10:32 AM Page iv 9241FM.qxd 4/1/08 10:32 AM Page v Contents Foreword........................................................................xiii AbouttheAuthors.................................................................xv AbouttheTechnicalReviewer......................................................xvii Acknowledgments................................................................xix Introduction......................................................................xxi nCHAPTER 1 Game Planning and Programming Basics..................1 PlanningtheGame ...............................................1 EnhancingYourPlanforaGreatGame..............................4 XNAGameProgrammingConcepts.................................6 GeneralGameStructure......................................8 GameInitialization ..........................................9 GameFinalization ..........................................12 GameLoop ................................................13 Summary.......................................................15 nCHAPTER 2 2-D Graphics, Audio, and Input Basics....................17 2-DGraphics ...................................................17 CommonlyUsedGamingTerms ..............................17 2-DandScreenCoordinateSystems .........................18 DrawingaSpriteUsingXNA..................................20 MovingtheSpriteontheScreen..............................26 CodingforCollisionDetection................................28 GameInput.....................................................32 UsingtheXbox360Gamepad................................32 UsingtheKeyboard.........................................34 UsingtheMouse ...........................................34 v 9241FM.qxd 4/1/08 10:32 AM Page vi vi nCONTENTS GameAudio ....................................................34 CreatingAudioContentwithXACT............................35 UsingAudioinGames.......................................38 Summary.......................................................40 nCHAPTER 3 Creating Your First 2-D Game..............................43 DesigninganXNAGame .........................................43 DesignfortheFirstGame:RockRain .........................43 Let’sGettoIt ...................................................45 DrawingtheBackground ....................................46 CreatingthePlayer’sGameComponent........................47 CreatingtheMeteors........................................55 CreatingtheGameLogic ....................................58 AddingSounds.............................................60 AddingaScoreboard........................................63 Shake,Baby!...............................................64 ModifyingandDeployingtotheXbox360......................66 Summary.......................................................67 nCHAPTER 4 Improving Your First 2-D Game............................69 PlanningRockRain’sNewVersion.................................69 CreatingtheGameScreens.......................................69 CreatingtheHelpScreen....................................74 CreatingtheOpeningScreen.................................79 MorefortheOpeningScreen.................................86 CreatingtheActionScene ...................................91 CreatingtheScoreboard....................................102 CreatingtheEnergySource.................................105 CreatingthePlayer’sGameComponent.......................108 BringingEverythingTogether ...............................114 NavigatingBetweentheScenes..................................122 Summary .....................................................128 9241FM.qxd 4/1/08 10:32 AM Page vii nCONTENTS vii nCHAPTER 5 Basics of Game Networking ..............................129 IntroducingMultiplayerGames...................................129 ChoosingtheNetworkTopology.............................129 Turn-Basedvs.Real-TimeGames ...........................133 SomeTechnicalTips.......................................134 IntroducingXNANetworking.....................................138 StartingtheGamerServicesComponent......................139 DefiningtheNetworkHelperClass ...........................142 SigninginaGamer ........................................143 CreatingaSession ........................................144 FindingandJoiningaSessionSynchronously.................149 FindingandJoiningaSessionAsynchronously................152 StartingtheGame.........................................154 HandlingMessages........................................155 AFinalTouch .............................................158 Summary......................................................160 nCHAPTER 6 Rock Rain Live! ............................................161 PlanningRockRainLive.........................................161 AddingtheSupportforNetworkGames ...........................163 ChangingtheOpeningScreen....................................163 CreatingtheNetworkGameScene ...............................166 ControllingtheInputtotheScene............................172 TheNetworkHelperClass...................................175 CreatingtheGameSessions.....................................178 Let’sTalk .....................................................182 SynchronizingthePlayers.......................................188 Summary......................................................196 nCHAPTER 7 3-D Game Programming Basics...........................197 3-DCoordinateSystemsandProjections..........................197 VerticesandPrimitives..........................................199 Vectors,Matrices,and3-DTransformations .......................203 Lights,Camera...Effects! ......................................207 9241FM.qxd 4/1/08 10:32 AM Page viii viii nCONTENTS Drawingthe3-DAxisinXNA.....................................209 CodingtheVerticesandtheVertexBuffer.....................210 CodingaBasicEffectandRenderingthe3-DScene ...........215 CodingtheMainProgramCalls..............................217 ModelsandMeshes ............................................220 Summary......................................................224 nCHAPTER 8 Rendering Pipeline, Shaders, and Effects................227 RenderingPipeline .............................................227 RenderingPipeline:FixedorProgrammable ..................228 XNARenderingPipeline ....................................228 Shaders.......................................................229 VertexShader.............................................229 Rasterization..............................................229 PixelShader ..............................................230 HighLevelShadingLanguage....................................230 DataTypes ...............................................230 UniformandVaryingInputs.................................232 Semantics................................................232 Functions.................................................234 IntrinsicFunctions.........................................234 CreatingaSimpleShader...................................235 Effects ...................................................236 UsingEffectswithXNA..........................................237 HelperEffects.............................................239 Materials.................................................239 ShaderAuthoringTools .........................................242 Summary......................................................243 nCHAPTER 9 Lights, Camera, Transformations!........................245 Cameras ......................................................245 BaseCameraClass.........................................245 Third-PersonCamera ......................................251

See more

The list of books you might like