Tài liệu Professional Windows Phone 7 Game Development: Creating Games using XNA Game Studio 4 - Pdf 10


ffirs.indd ivffirs.indd iv 1/31/2011 3:36:50 PM1/31/2011 3:36:50 PM
Download from Wow! eBook <www.wowebook.com>
PROFESSIONAL
WINDOWS
®
PHONE 7 GAME DEVELOPMENT
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
CHAPTER 1 Getting to Know the Windows Phone 7 Device . . . . . . . . . . . . . . . . . . . . . .1
CHAPTER 2 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
CHAPTER 3 Orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
CHAPTER 4 Touch Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
CHAPTER 5 Give Me Your Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
CHAPTER 6 The State of Things . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
CHAPTER 7 Let the Music Play . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127
CHAPTER 8 Putting It All Together: Drive & Dodge . . . . . . . . . . . . . . . . . . . . . . . . . . . .147
CHAPTER 9 Whoa! The World Isn’t Flat After All . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
CHAPTER 10 It’s Your Turn! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
CHAPTER 11 The World Outside Your Window(s) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
CHAPTER 12 Putting It All Together: Poker Dice with Friends . . . . . . . . . . . . . . . . . . . 351
CHAPTER 13 Dude, Where’s My Car? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
CHAPTER 14 Take a Picture; It’ll Last Longer! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
CHAPTER 15 Putting It All Together: Picture Puzzle . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
CHAPTER 16 Where Do You Go from Here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .513
ffirs.indd iffirs.indd i 1/31/2011 3:36:49 PM1/31/2011 3:36:49 PM
ffirs.indd iiffirs.indd ii 1/31/2011 3:36:50 PM1/31/2011 3:36:50 PM
PROFESSIONAL
Windows
®
Phone 7 Game Development

748-6008, or online at />Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and specifi cally disclaim all warranties, including
without limitation warranties of fi tness for a particular purpose. No warranty may be created or extended by sales or pro-
motional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold
with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services.
If professional assistance is required, the services of a competent professional person should be sought. Neither the pub-
lisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to
in this work as a citation and/or a potential source of further information does not mean that the author or the publisher
endorses the information the organization or Web site may provide or recommendations it may make. Further, readers
should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was
written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available
in electronic books.
Library of Congress Control Number: 2011920609
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trade-
marks or registered trademarks of John Wiley & Sons, Inc. and/or its affi liates, in the United States and other countries,
and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley
Publishing, Inc., is not associated with any product or vendor mentioned in this book.
ffirs.indd viffirs.indd vi 1/31/2011 3:36:52 PM1/31/2011 3:36:52 PM
ABOUT THE AUTHORS
CHRIS G. WILLIAMS is a principal consultant for Magenic, delivering custom-built .NET
solutions to clients. He founded Reality Check Games as a studio for his various
XNA projects on Windows, Xbox 360, and Windows Phone 7. In addition to creat-
ing games, Williams is a Microsoft MVP in XNA/DirectX (for six years running). He
is an active contributor to the XNA Indie Games community, and founded an XNA
Developers Group in Minneapolis, MN. He speaks regularly at user groups, code camps, and profes-
sional conferences country-wide, lecturing on XNA game development, Windows Phone 7, and other
topics. He has also authored articles for the magazines CODE and Flagship. You can follow him on

COPY EDITOR
Gayle Johnson
EDITORIAL DIRECTOR
Robyn B. Siesky
EDITORIAL MANAGER
Mary Beth Wakefi eld
FREELANCER EDITORIAL MANAGER
Rosemarie Graham
ASSOCIATE DIRECTOR OF
MARKETING
David Mayhew
PRODUCTION MANAGER
Tim Tate
VICE PRESIDENT AND EXECUTIVE GROUP
PUBLISHER
Richard Swadley
VICE PRESIDENT AND EXECUTIVE PUBLISHER
Barry Pruett
ASSOCIATE PUBLISHER
Jim Minatel
PROJECT COORDINATOR, COVER
Katherine Crocker
PROOFREADER
Candace English
INDEXER
Robert Swanson
COVER DESIGNER
Michael E. Trent
COVER IMAGE
© Daniel Stein/istockphoto.com

extremely valuable technical support late at night, Björn Graf for always being there supporting me,
and Andy Dunn for keeping me motivated. So many others, too — @Ubergeekgames, @Xalterax,
@kriswd40… the list goes on, and I’m running out of room. But if you chatted me up while I was
writing this book, thanks!
To friends, family, acquaintances, and everyone else I’ve been ignoring while writing this book,
sorry, but I’m done now and I’m available again! Until I start my next project, of course.…
— George W. Clingerman
ffirs.indd xffirs.indd x 1/31/2011 3:36:53 PM1/31/2011 3:36:53 PM
CONTENTS
INTRODUCTION xxiii
CHAPTER 1: GETTING TO KNOW THE WINDOWS PHONE 7 DEVICE 1
Minimum Specifi cations 1
Chassis Design 2
Screen Resolution 3
Phone Features 3
Capacitive Touch 3
Sensors 4
Accelerometer 4
aGPS 4
Compass 4
Light Sensor 5
Proximity Sensor 5
Digital Camera 5
DirectX 9 Acceleration 6
Face Buttons 6
Back Button 6
Start Button 6
Search Button 7
QWERTY Keyboard 7
Software Features 7

Automatic Rotation 26
Detecting Device Orientation 29
Running in Full-Screen Mode 30
Phone Title-Safe Area 31
Accelerometer 32
AccelerometerSample 34
Summary 37
CHAPTER 4: TOUCH INPUT 39
Responding to Touch Events 39
Overview of Touch Interfaces 40
Detecting Touch Input 40
Detecting Gestures 44
Tap 47
DoubleTap 47
Hold 48
HorizontalDrag 48
VerticalDrag 48
FreeDrag 48
DragComplete 49
Flick 49
Pinch 49
PinchComplete 50
Seeing Results 50
Custom Gestures 50
Designing for Touch Games 51
ftoc.indd xiiftoc.indd xii 1/31/2011 3:37:57 PM1/31/2011 3:37:57 PM
xiii
CONTENTS
Remember Your Platform 51
Design for the Right Resolution 51

CHAPTER 7: LET THE MUSIC PLAY 127
Handling Audio 127
Playing Music with MediaPlayer 127
Do You Mind? I’m Playing Music Here 128
Background Music 129
Song Collections 131
ftoc.indd xiiiftoc.indd xiii 1/31/2011 3:37:57 PM1/31/2011 3:37:57 PM
Download from Wow! eBook <www.wowebook.com>
xiv
CONTENTS
Visualizations 132
SoundE ect 133
SoundE ectInstance 136
XACT 3.0 137
Recording Audio 138
The Microphone Class 138
Saving and Retrieving Captured Audio 143
Summary 145
CHAPTER 8: PUTTING IT ALL TOGETHER: DRIVE & DODGE 147
Creating the Game 148
Screens 149
Screen.cs 149
ScreenStateSwitchboard.cs 153
Title.cs 155
Sprite.cs 157
Background.cs 159
Content 159
Game1.cs 160
Text.cs 162
screenFont.spritefont 168

SerializableDictionary.cs 228
Screen.cs 231
MainGame.cs 231
GameOver.cs 234
Proper Care and Feeding of the Back Button 237
Screen.cs 237
Title.cs 240
MainGame.cs 240
InGameMenu.cs 241
GameOver.cs 241
Creating a Base Game Template 241
Stripping Down to the Essentials 242
Title.cs 242
ScreenStateSwitchboard.cs 243
Creating the Templates 244
Using the Templates 244
Summary 245
CHAPTER 9: WHOA! THE WORLD ISN’T FLAT AFTER ALL 247
3D Graphics 247
Creating 3D Models for Your Game 247
Getting the Bits 248
Getting Started with Blender 248
Creating Primitive Shapes 248
Changing Your Point of View 249
Combining Shapes 249
Bringing It All Together 250
Exporting Your Shapes 250
Using 3D Models in Your Game 251
Adding Models to Your Project 251
Displaying the Models Onscreen 251

PushingTileWindows 290
Good Vibrations 294
The Microsoft.Devices Namespace 294
Environment 295
VibrateController 295
Summary 297
CHAPTER 11: THE WORLD OUTSIDE YOUR WINDOWS 299
Consuming Web Services 300
Live to Serve You 300
Serve Me 305
Adding a Service Reference 305
Game1.cs 308
I Get High Scores with a Little Help from My Friends 310
HighScoreService 310
ftoc.indd xviftoc.indd xvi 1/31/2011 3:37:57 PM1/31/2011 3:37:57 PM
xvii
CONTENTS
ScoreMe 317
Anonymous Live ID 319
HighScoreClient 319
Push Notifi cations 321
HighScoreTester 325
Testing the High-Score Service 328
Got a Match? 329
MatchMaker 329
GameRequest.cs 330
Gamer.cs 330
IMatchMaker.cs 332
MatchMakerService.svc.cs 333
MatchMe 335

Adding the PokerDiceService 382
Creating the GameInformation and DiceGame Supporting Classes 383
DiceGame.cs 383
GameInformation.cs 385
Button.cs 385
Creating the Game Lobby 386
GameLobby.cs 386
Message.cs 394
Creating the GameInfo Screen 397
GameInfo.cs 397
Adding the Dice Model 404
Die.cs 405
Creating the MainGame Screen 414
MainGame.cs 414
Creating the DiceSelect Screen 417
DiceSelect.cs 417
Enhancing Your Game 423
Summary 424
CHAPTER 13: DUDE, WHERE’S MY CAR? 425
Understanding and Accessing the Location API 425
Best Practices for Using Location Services 425
Asking Permission 426
Power Consumption 426
Level of Accuracy 426
Movement Threshold 426
Using Location Services in Your Games 426
CivicAddress 427
CivicAddressResolver 427
Did You Order Pizza? 427
Resolving an Address Synchronously 428

Title.cs 457
Enhancing the ScreenStateSwitchboard 460
ScreenStateSwitchboard.cs 460
Creating the NewPuzzle Screen 463
NewPuzzle.cs 463
The Pieces of the Puzzle 468
PuzzlePiece.cs 468
StencilPiece.cs 470
Puzzle.cs 471
How It Works 478
Managing State Objects 479
StateObject.cs 479
Creating the SelectPuzzle Screen 480
SelectPuzzleScreen.cs 481
Creating the Playable Game Screen 485
MainGame.cs 485
Making the InGameMenu Screen 488
InGameMenu.cs 488
Creating the PuzzleComplete Screen 491
Message.cs 492
Enhancing Your Game 494
Summary 495
ftoc.indd xixftoc.indd xix 1/31/2011 3:37:58 PM1/31/2011 3:37:58 PM
xx
CONTENTS
CHAPTER 16: WHERE DO YOU GO FROM HERE? 497
Trial Mode 497
Understanding Trial Mode 498
Detecting Trial Mode 498
ShowMarketplace() 498

of-semester time of reckoning approached, I’d redeem myself with a term project somehow powered
by DirectX even though the course never called for it. “Exploding spacecraft, gushing blood, and
not a PowerPoint slide in sight!? My only regret is there is no grade higher than A!” is what I liked
to imagine my professors saying. But those were the risks I took to do my Favorite Thing on Earth.
Now I’m immensely spoiled. I get to stay up late, wake up late, and make games when I’m not sleep-
ing. I can’t imagine a more satisfying way to spend my time than to sit around creating little uni-
verses, breathing life into them, setting them in motion, and then creating little heroes, armed to the
teeth, to obliterate the rest of my creation.
Making games is awesome. Making Xbox 360 games has always been awesome, because the console
has a killer GPU and you can play Xbox 360 games on a couch with a controller. With XNA 4.0,
we’ve just turned the corner on Mobile Awesome in the form of Windows Phone, where we can bring
our existing frameworks, tools, and C#/XNA knowledge into the world of multitouch input and
gyroscopes.
Over the past couple of years, hardware and software have propelled indie gaming into a uniquely
great area. While AAA games now require massive development teams to produce immensely
detailed graphics that don’t impress anyone anymore, small-scale indie games that rely far more on
creative presentation than on nanosecond-effi cient algorithms end up leaving more of an impression
on gamers.
Tools such as XNA Game Studio give developers an environment for rapid development, whereas
hardware such as Xbox 360 gives coders a silly amount of performance-related breathing room.
Not to encourage sloppy coding, but if it takes me 10 minutes to implement an algorithm that’s
25 percent slower than a far more complex algorithm that could keep me up all night with funny
bugs, where I’m getting 60 frames per second with cycles to spare either way, I won’t lose any sleep
(see what I did there?) over implementing the slower, yet readable, algorithm.
flast.indd xxiflast.indd xxi 1/31/2011 3:37:10 PM1/31/2011 3:37:10 PM
xxii
PREFACE
Of course, Windows Phone isn’t quite the same hardware juggernaut as the Xbox 360. Sure, it
demolishes the Pentium II I got started with, but compared to today’s hardware, it presents some
performance challenges. And even if you do get away with abusing the GPU while maintaining a

This book covers the features of the Windows Phone 7 devices and how to use them in your games.
In the course of 16 chapters, you’ll make three games, learn a bunch of cool stuff, and hopefully
have some fun along the way.
WHO THIS BOOK IS FOR
The target audience for this book is anyone who wants to learn about programming games for
Windows Phone 7 using C# and XNA Game Studio 4.0.
It’s also for people who think most tech books are dense and dull. We’ve tried to keep this book
light and interesting, with a conversational tone, while still teaching you something useful.
Wherever relevant, we include anecdotes and comments that provide context or that lead to addi-
tional information that isn’t critical to the main fl ow of the book.
Maybe you are one of the following:

An iPhone or Android game developer who wants to port your games to Windows Phone 7

An experienced Windows developer who is getting into game development for the fi rst time

A developer who is cranking out Xbox Live Indie Games titles and who wants to know
what’s new in XNA Game Studio 4.0 as it relates to Windows Phone 7
No matter what your story, you can fi nd a way to connect with and learn from this book.
Because no book can be all things to all people, some assumptions had to be made. This book will
be most useful to people who meet some or all of the following criteria:

You have some experience coding in C# or VB.NET. Even though VB.NET is not used in the
book, there’s no reason why a .NET developer (of either fl avor) can’t keep up.

You have at least some familiarity or experience working with XNA (which implies C#
experience).

You want to make games for Windows Phone 7.
flast.indd xxiiiflast.indd xxiii 1/31/2011 3:37:11 PM1/31/2011 3:37:11 PM


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status