Building XNA 2.0 GamesA Practical Guide for Independent Game Development ■ ■ ■ James Silva and John Sedlak... Building XNA 2.0 Games: A Practical Guide for Independent Game DevelopmentCo
Trang 2Building XNA 2.0 Games
A Practical Guide for Independent Game Development
■ ■ ■
James Silva and John Sedlak
Trang 3Building XNA 2.0 Games: A Practical Guide for Independent Game Development
Copyright © 2008 by James Silva and John Sedlak
All rights reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-4302-0979-9
ISBN-13 (electronic): 978-1-4302-0980-5
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
Lead Editor: Ewan Buckingham
Technical Reviewer: Fabio Claudio Ferracchiati
Editorial Board: Clay Andres, Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Kevin Goff, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Project Manager: Beth Christmas
Copy Editor: Marilyn Smith
Associate Production Director: Kari Brooks-Copony
Production Editor: Ellie Fountain
Compositors: Susan Glinert and Octal Publishing, Inc.
Proofreader: Nancy Sixsmith
Indexer: Carol Burbo
Artist: Kinetic Publishing Services, LLC
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013 Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com,
or visit http://www.springeronline.com
For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705 Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit
http://www.apress.com
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use eBook versions and licenses are also available for most titles For more information, reference our Special Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales.
The information in this book is distributed on an “as is” basis, without warranty Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly
by the information contained in this work
The source code for this book is available to readers at http://www.apress.com
Trang 4This book is dedicated to my mom and dad,
who were always supportive of my game development obsession.
—James Silva
Trang 5Contents at a Glance
About the Authors xiii
About the Technical Reviewer xv
Acknowledgments xvii
Introduction xix
■ CHAPTER 1 A NET Snapshot 1
■ CHAPTER 2 A Crash Course in XNA 19
■ CHAPTER 3 Planning Your Game 41
■ CHAPTER 4 The Map Editor 51
■ CHAPTER 5 The Character Editor 93
■ CHAPTER 6 Bringing It to the Game 127
■ CHAPTER 7 Particle Mayhem 171
■ CHAPTER 8 XACT Audio, Rumble, and More 221
■ CHAPTER 9 Scripting, AI, and Depth (and Death) 249
■ CHAPTER 10 Menus, a HUD, and Deployment 291
■ CHAPTER 11 Postprocessing Effects 333
■ CHAPTER 12 Networking 361
■ APPENDIX A Designing the Wraith 399
■ APPENDIX B Storage 413
■ INDEX 421
Trang 6■I N D E X
creating AI class for, 402
creating characters for the game, 399–411
designing with, 399–411
getting previous state and location of,
408–410
graphics, 400
initialization script for, 401
wraith characters
definition script, sounds added to, 402
process of creating, 399–400
wrench triggers
adding new to appropriate frames of
animation, 210
defining, 209–210
in character editor, 210
putting to use for smashing zombies,
209–216
Write() function
creating in character editor, 122–124
making in Map class, 88
using device and container to get a path,
415
WriteToNet() function, 385–386
■ X
XACT See also Cross-Platform Audio
Creation Tool (XACT)
setting up game audio in, 229–231
XACT Audio, Rumble, and More, 221–248
XACT Auditioning Utility, for auditioning
sound files, 231–232
XACT project
creating new, 229
creating new wave bank file in, 229–231
Xbox 360
deploying ZombieSmashers game on, 328
deployment, 291
storage container object, 413
Xbox 360 project
creating, 328
debugging, 331
XNA, a crash course in, 19–39 XNA Framework, eliminating classic networking hassles with, 361 XNA Framework Remote Performance Monitor for Xbox 360, 331 XNA Game Studio, connecting the Xbox 360
to, 329–330 XNA Game Studio 2.0 installing, 19 networking with, 361–362 working with pixel shaders in, 333 XNA Game Studio Connect
downloading and launching, 329–330 XNAPong
adding a background image, 33–35 adding rumble to, 35–36
adding the game logic, 27–32 ball logic for, 31–32
building, 20–39 class-level (Game1.cs) variables, 28 coding audio for, 38–39
creating file for graphics in, 24 loading textures, 23
paddles and gamepad logic, 28–31 task list for game logic, 27
■ Y
you-are-dead screen, for ZombieSmashers game, 325
■ Z
zap cue object, playing from XNAPong, 38 zdx filename extension, 59
zombie attack, adding animation for, 251 zombie bloodsplosions, adding triggers for, 250–251
Zombie class, extending AI base class with, 265
zombie head splatter, 267 zombie hit trigger, adding in CharacterEditor, 250–251
Trang 7442 ■I N D E X
Zombie Smashers XNA game, keeping
separate functions organized, 136
ZombieSmashersXna project See also
ZombieSmashers game adding CharacterEditor to, 93–94
building the game, 127–153
cleaning up odds and ends, 168–169
combat concept art, 46
creating, 51–53
hero concept art, 46
maps concept art, 47
naming, 49
rough game plan for, 49–50
super simple scripting, 153–167
tool planning for, 47–48
zombie.zmx file, adding to ZombieSmashers
game, 199–204 zombies
adding animations to, 250–251
adding to ZombieSmashers game,
199–204 bringing into ZombieSmashers game,
202–204
in CharacterEditor, 199–201
making killable, 249–267
putting wrench to use for smashing,
209–216 shooting, 204
smashing, 204–216
ZombieSmashers game
adding a background image to, 150–153
adding the HUD and menu to, 320–321
bringing it all together, 285–289
bringing triggers into, 191–196
bringing zombies into, 202–204
class-level objects, 147
creating, 128
drawing one character for, 149
fields used in, 147–148 implementing the action in, 210–216 in-game scoring, 327
initializing, 148 loading game content, 148 making enemies killable, 249–267 manually changing namespaces in, 128 parting word from author, 397–398 plugging everything into, 394–395 reorganizing the code, 322–326 setting character’s facing, scale, state and starting animation in, 135–136 setting things in motion, 147–149 super simple scripting, 153–167 updating, 320–326
updating frameTime calculating and sound, 324–325
updating scroll and handling input, 148–149
ZombieSmashers project adding MapEditor project to, 52–53 creating, 51–53
ZombieSmashersXna project adding audio to, 229–239 adding music to, 236–239 bringing audio functionality into, 233 sounds used for, 222–223
ZombieSmashersXNA.Particles namespace creating BloodDust class in, 255–256 Zombie-Smashing game
choosing 2D or 3D for, 45 concept image for protagonist, 46 initial design, 46–47
maps, 47 planning, 45–50 tool planning for, 47–48