TE AM FL Y Programming Role Playing Games with ® DirectX This page intentionally left blank Programming Role Playing Games with ® DirectX Jim Adams © 2002 by Premier Press, Inc All rights reserved No part of this book 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 written permission from Premier Press, except for the inclusion of brief quotations in a review The Premier Press logo, top edge printing, and related trade dress are trademarks of Premier Press, Inc., and may not be used without written permission All other trademarks are the property of their respective owners Publisher: Stacy L Hiquet Marketing Manager: Heather Buzzingham Managing Editor: Sandy Doell Acquisitions Editor: Emi Smith Series Editor: André LaMothe Project Editor: Melba Hopper Editorial Assistant: Margaret Bauer Technical Reviewer: Ernest Pazera Interior Layout: Shawn Morningstar Illustrator: Susan Honeywell Cover Design: Phil Velikan Indexer: Katherine Stimson Proofreader: Jenny Davidson DirectX, DirectPlay, DirectSound, DirectMusic, DirectInput, Direct3D, DirectDraw, and Windows are registered trademarks of Microsoft MilkShape 3-D is a registered trademark of chUmbaLum sOft GoldWave is a registered trademark of GoldWave Inc trueSpace is a registered trademark of Caligari Corporation Poser is a registered trademark of Curious Labs, Inc Paint Shop Pro is a trademark of Jasc Software, Inc Important: Premier Press cannot provide software support Please contact the appropriate software manufacturer’s technical support line or Web site for assistance Premier Press and the author have attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the capitalization style used by the manufacturer Information contained in this book has been obtained by Premier Press from sources believed to be reliable However, because of the possibility of human or mechanical error by our sources, Premier Press, or others, the Publisher does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from use of such information Readers should be particularly aware of the fact that the Internet is an ever-changing entity Some facts may have changed since this book went to press ISBN: 1-931841-09-8 Library of Congress Catalog Card Number: 2001096217 Printed in the United States of America 02 03 04 05 06 RI 10 To my wife 2E: The love of my life and best friend till the end— you are my sunshine Acknowledgments P ublishing a book takes considerable work and dedication on the part of everyone involved First and foremost, I want to thank my family—my wife, 2E, for all her loving support; my mother, Pam, and my brother John for giving me moral support; the kids, Michael, John, and Jordan, for letting me play their video games and for giving me great ideas; and my sister, Jennifer, for irking me enough to show her that writing is a job worth pursuing I extend special thanks to the book’s technical editor and fellow programmer-atlarge, Ernest Pazera, for dropping my name into the mix and for ensuring that the technical material in this book is accurate I’m particularly grateful to the book’s acquisitions editor, Emi Smith, for her voice of calmness and for understanding that things sometimes become delayed Thanks also to the project editor, Melba Hopper, undoubtedly the best editor with whom I’ve had the pleasure of working I offer sincere appreciation to Chris Taylor, president of Gas Powered Games, for writing the book’s Foreword; to Wayne Peters (aka Scarecrow) for the great models in the book’s demos; and to Andrew Russell for the cool music that fits the game demos perfectly I would be remiss not to also thank Susan Honeywell for her artistic renditions of my drawings, Shawn Morningstar for the excellent interior layout of the book, Katherine Stimson for the book’s fine index, and the book’s proofreader, Jenny Davidson, for her keen eyes Finally, I want to acknowledge friends and family members who were with me along the way, if only in spirit: To my brother Jeff—I wish you could have been here to see this; to Ian McArdle—as you can see, the motivation to write this book never wore out; to the rest of my friends and family—thanks for being there! About the Author Jim Adams’ current career, and his passion for programming, began at the age of nine when using an Atari computer and a few lines of code, he discovered that he could just about anything his young mind imagined Over the years, with the help of increasingly advanced books on programming— and countless hours molding together small games—he moved from computer to computer until he finally discovered the world of IBM PCs At the same time, he was progressing through the emerging programming languages—going from BASIC, to assembly, to PASCAL, to C, and finally to C++ Thanks to Jim’s knowledge and experience in programming games and business applications, he has led a satisfying career in game-making, writing, and consulting He has written numerous articles and is coauthor of several books on consumer electronics and computer programming Jim is currently owner of The Collective Mind, a programming and consulting business You can find Jim cruising the Internet and hanging out at various gamerelated Web sites Contents at a Glance Foreword xxxvi Introduction xxxix Part One An Introduction to Role-Playing Games Chapter A World of Role-Playing Part Two Role-Playing Game Design 19 Chapter Exploring RPG Design Elements 21 Chapter Story-Writing Essentials 35 Part Three Programming Basics 61 Chapter Starting with C++ 63 Chapter Programming with Windows and Application Basics 97 Chapter Drawing with DirectX Graphics 159 Chapter Interacting with DirectInput 261 Chapter Playing Sound with DirectX Audio 293 Chapter Networking with DirectPlay 351 Chapter 10 Creating the Game Core 399 Contents at a Glance Part Four Role-Playing Game Programming 465 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18 Chapter 19 Using 2-D Graphics 467 Creating 3-D Graphics Engines 501 Mixing 2-D and 3-D Graphics Engines 561 Implementing Scripts 579 Defining and Using Objects 613 Controlling Players and Characters 653 Working with Maps and Levels 761 Creating Combat Sequences 819 Getting Online with Multiplayer Gaming 843 Part Five The Finishing Touches 907 Chapter 20 Putting Together a Full Game 909 Chapter 21 Marketing and Publishing Your Game 967 Epilogue 980 Part Six Appendixes 983 Appendix A Setting Up DirectX 8.0 and Configuring the Compiler 985 Appendix B Getting Help on the Web 995 Appendix C Recommended Reading 999 Appendix D Glossary 1003 Appendix E What’s on the CD 1017 Index 1021 ix 1048 Index with cMap class, 494 limiting number of, 490–491 rendering maps with, 495–497 Squaresoft, 15, 56 sRoutePoint structure, 676, 736 sScriptEntry structure, 588–589, 591 sScript structure, 591, 601–602 executing scripts with, 606–611 sSpell Controller class, 720 sSpellMeshList structure, 715–716 sSpell structure, 710–715, 753–754 See also master spell list (MSL) sSpellTracker structure, 716–717, 753–754 stacks processes, calling, 143 states, calling, 138–139 standard meshes See meshes StartTime parameter, 435–436 state-based programming (SBP), 138 state functions, 408 state manager object, 138–141 for The Tower, 939 state processing, 135 states, 137–141 static functions See Functions static variables, 73–74 with classes, 83–84 status ailments See characters StatusFrame function, 945 stereo sounds, 296 Steven Jackson Games, Web site, 997 storage of action templates, 587 with cTexture, 416 of sound, 296 story bible, 24, 26 story-writing, 31 See also Characters; cut-scenes; Plot points art of, 36–37 back-stories, 53 beginning of story, 38 components of story, 37 with emotions, 44, 54–55 end of story, 39 enveloping players, 56 TE AM FL Y smoke, particles for, 233 smooth scrolling technique, 486–488 mouse and, 489–490 sNode structure, 524 sociological traits of character, 41 Software, Inc., 906 Software Developers Kit (SDK), 986 debug version, 987 using, 987 Win32 SDK, 99 sorrow in stories, 55 SortNode function, 530, 531–533 sound, 33 See also DirectMusic; DirectSound basics of, 294–295 digital sounds, recording, 295–296 magic spell sounds, 712 streaming sounds, 327–329 in The Tower, 958–960 in The Tower, 935 sound bible, 24, 27 Sound Core, 328, 401, 441–453 cMusicChannel, 450–452 cSoundChannel class, 447–450 cSoundData class, 444–446 cSound object, 441–444 list of classes, 442 sparks, particles for, 233 specials, 618 specular color, 167 in lights, 219 setting, 197–198 spell controller See magic spells spell effect chance, 709 spells See magic spells sphere triggers, 766–767 adding, 778 GetTrigger function with, 782–783 spicing up story, 47 SPlayer structure See multiplayer gaming sPolygon structure, 524, 533 spotlights, 210 cautions on using, 221, 222 defined, 218 D3DX library with, 222 using, 220–222 sprites Team-Fly® Index experiencing events in, 54 flashbacks, 53 foreshadowing, 53–54 games, applying story to, 56–59 ladder, 37–40 linear/nonlinear story lines, 58–59 middle of story, 39 mood, setting, 4–6, 42–43 narrative voice in, 44 point of view, 43–44 steps to, 47–48 for The Tower, 910–912 wrapping up story, 60 streaming sounds See sound sTrigger structure, 771 strips See triangle strips Strong status, 660, 725–726 structures, 78–79 advanced structures, 95–96 WNDCLASSEX structure, 106, 107 styles (.STY), 297 style variable, 106 submitting games to publisher See publishers subplots, 45 subsets of meshes, 251 supporting characters, 40–41 Surefooted status, 660, 724 sVertex structure, 524 text windows and, 686 swords See weapons Swords & Circuitry: A Designers Guide to Computer Role-Playing Games (Hallford & Hallford), 30, 1002 synchronous messages, 360, 362 System Core, 400, 401–410 cApplication, using, 402–405 cDataPackage, managing data with, 410 cProcessManager, 408–409 cStateManager, state processing with, 405–408 processes, 408–409 system requirements, 33 T table of contents in design document, 28, 29 in proposal letter, 969 Take2 Interactive, 976 talk action, 662 talking dummy character, 684 targeting magic spells, 709 Taylor, Chris, xxxvi–xxxviii, 12 TCP/IP, 355–356 with cNetworkAdapter, 454–455 for DirectPlay, 373–374 DirectPlay with TCP/IP device, 394–395 tech bible, 24, 27 Teleport spell, 707, 709 chance of success value, 711 character controller setting, 754–755 in The Tower, 921 template hierarchy, 241–242 template referencing, 242 templates See also Mad Lib Script system for animation, 258 embedded templates, 244–245 frame templates, 242–244 MLS action templates, 583 for sound (.TPL), 297 X file templates, 241 tempo changes, DirectMusic, 347 test runs for game, 971 texture groups cVertexBuffer objects in, 530 rendering nodetrees and, 539 working with, 522 texture-mapping, 167, 202–211 with cTexture, 415–417 with Direct3D, 204 filtering, 208–209 loading textures, 204–206 particles and, 233 rendering textured objects, 210–211 setting the texture, 206–208 sky boxes, 553 standard meshes, code for, 250–251 textures, 162, 202, 203 See also cTiles class; tiles and tiling alpha values, 211 big bitmap engine, 498–500 color keys, loading textures with, 214–215 with cTexture, 415–417 D3DX library information, 178 1049 1050 Index filtering, 208–209 textures (continued) fonts and, 228 loading, 204–206 LoadTexture function, 557–558 for particles, 237 rendering textured objects, 210–211 resources, 123 restrictions on, 204 setting the texture, 206–208 for sky boxes, 554, 557 stages, 206–207 in The Tower, 945–946 text windows, 685–686 See also cWindow class setting window text, 689 for The Tower, 930, 936 third person story-writing, 43 this keyword, 88 threads, 125–128 critical sections, 128 for DirectSound events, 321–323 3-D graphics, 33, 160–162 See also Direct3D; mixing dimensions angled tile engines, 497–498 characters, 41 for characters, 667 3-D graphics engines See also MeshLvl demo; NodeTree engines; sky boxes; 3D objects; viewing frustum advanced engine, developing, 517–518 levels, meshes as, 502–504 MeshLvl demo and, 502–503 slowdowns in, 506–507 worlds, adding objects to, 541–543 3Din2D, 568–576 adding 3-D objects, 576 backdrops, 569 camera, orienting, 575 chunks, splitting backdrop into, 571–572 collision detection, 576 prerendered backdrops, 569 rendering the scene, 574–576 scene mesh for, 572–574 simplified meshes, using, 572–574 splitting backdrop images, 571–572 2D backdrops, dealing with, 570–572 Z-buffers for backdrops, 569, 570 3-D models, 34 normals with, 225 3DO, 11 3-D objects See also collision detection adding, 541–543 bounding spheres and, 542–543 3Din2D scene, adding to, 576 3DS files to X files, converting, 574 3D Studio Max, 244, 517, 569 animation data, 258 throttling messages, 362–363 tilde characters See Mad Lib Script system tile engines adding objects, 485–486 angled tile engines, 497–498 basic tile maps, drawing, 483–484 fine coordinates, using, 487–488 layers, using, 484–485 map arrays, using, 484–485 maps, drawing, 483–484 objects, adding, 485–486 smooth scrolling technique, 486–488 tiles and tiling, 468–469, 471–473 See also cMap class; cTiles class; maps; sprites; tile engines alpha values for, 473, 481 angled tiles, 469–470 big bitmap engine, 498–500 bounds checking, 489–490 colors for, 473 cTiles class, building, 474–481 DirectX, using with, 470–474 Draw function for, 471–473 free-floating tiles, limiting, 490–491 ID3DXSprite, 470–474 numbering tiles, 471 RECT structure for, 471–472 scaling tiles, 472 tile-handler class, building, 474–481 for 2Din3D, 563–567 time animations, playing, 436 in multiplayer gaming, 860 network sessions, 354 time slice, 125 Times New Roman font, 229 tips assert function for bugs, 157 Index CheckSphereIntersect function, 551 classes, forward-referencing, 79 class variables, prefix for, 81 default argument values, placing, 67 derived classes, protecting data in, 92 DirectMusic instruments, changing, 341 DirectPlay canceling information, 390 devices, assigning, 371 different network model, calling, 365 service providers, enumerating, 373 DirectSound event handlers, organizing, 319 flags, setting, 312 lost resources, 316 instruments, changing, 341 lights, color levels of, 219 multidimensional array, allocating, 77 multiplayer game synchronization, improving, 854 NodeTree engine structure, optimizing, 520 pen-and-paper game resources, scripts, action templates for, 623 shareware publishing, 978 for story-writing, 52 textures, saving time with, 204 2D tiles, using, 567 3Din2D scene mesh, 572, 573 3DS files to X files, converting, 574 tiles and tiling numbering tiles, 471 scaling tiles, 472 textures with, 471 U,V coordinates, specifying, 203 weak characters, modifying levels of damage, 656 Titanic, 55 to-hit ability of character, 618, 657, 658, 723–724 Tolkien, J R R., 55–56 topics in design document, 28–30 Total Annihilation, xxxviii The Tower, 841 assigning characters, 919 barriers in, 930, 949 BarterFrame function, 956–957 bartering, handling, 956–957 barter window state, 939 cApplication class, 931–938 constructor, 933 Init function, 934–936 private functions, 932–933 Shutdown function, 936–937 state-based processing for, 938–945 cGameScript class, 961–965 characters assigning, 919 controlling, 949–956 defining, 916–919 game components, 930 character status window state, 938–939 charge bar, displaying, 932 CheckIntersect function, 945–946 combat scripts, 923 components for, 929–931 controlling characters, 949–956 controls, defining, 925–926 derived spells, storing, 955–956 effect range of spells, 921 experience points in, 918–919 flow, laying out, 927–928 frames for, 937–938 FreeLevel function, 945–946, 947–948 GameFrame function, 939–945 GetCharacterAt function, 952 GetHeightBelow function, 945–946 global variables, 940 if then-related functions, 964 in-game state, 938 initializing, 934–936 legend for characters, 916 levels, designing, 912–915 LoadLevel function, 945–946, 947–948 magic spells creating, 919–922 derived spells, storing, 955–956 effects of, 921 experience points for, 918–919 game components, 930 list of, 921 spell controller, 956 main menu for, 925, 938 maps in, 945–948 master item list (MIL) for, 930 MenuFrame function, 945 MonstersInLevel flag, 940–942 MSL editor, using, 920 music, playing, 958–960 1051 1052 Index music system, initializing, 935 The Tower (continued) objects creating, 919–922 list of, 920 PCUpdate function, 950–954 PlaySound function, 958–960 pre-game story, writing, 910–911 Process function, 964 programming for, 928–931 purpose of, 912 Release function, 964 RenderFrame function, 943–944, 960–961 rendering scenes, 943–945, 960–961 scenes, rendering, 943–945, 960–961 sChars class, 949–956 scripts advanced scripts, viewing, 924–925 developing, 922–925 flow, laying out, 927–928 game component, 930 list of, 923–924 processing, 961–965 SetCamera function, 947 SetData function, 950 Shutdown function for, 936–937 sound, playing, 958–960 sound system, initializing, 935 spell controller, 956 state-based processing for, 938–945 state manager object, using, 939 StatusFrame function, 945 story of game, writing, 910–912 target distance of spells, 921, 922 text windows for, 936 triggers, 923, 930, 942–943, 949 updating, 937–938, 950–951 tracking with cCamera, 429 characters, 737–742 magic spells, 716–717 transformations, 167–168 See also view transformations; world transformations auto map, centering, 814 combined matrices, 427 for drawing graphics, 191–197 matrices for, 178–179 for particles, 234 for skinned meshes, 254–255 transformed coordinates, 162–164, 164 matrix math with, 179 TranslateMessage function, 113 translations, 179–180 in animation, 258 with billboards, 232–233 transparent blits, 211, 213–217 with cTiles class, 477–478 Draw function, 480 example of, 215–217 transparent colors with cTexture, 416 with cTiles class, 480 transportation objects attributes of, 619 function of, 617 Traveller, triangle fans, 165–166 vertex buffers with, 186 vertices for, 187 triangle lists, 165–166 vertex buffers with, 186 triangle strips, 165–166 vertex buffer for, 187 triangle triggers, 768 adding, 779–780 GetTrigger function with, 783–785 triggers, 766 See also cTrigger class; triangle triggers in automaps, 816 box triggers, 767 current status, checking, 785 cylinder triggers, 768 defining triggers, 770, 787 loading triggers, 773–775, 788 radius as argument, functions using, 780 saving data, 775–776 sphere triggers, 766–767 sTrigger structure, 771 touching triggers, 788 in The Tower, 923, 930, 942–943, 949 triggering a trigger, 768–769 using triggers, 787–788 zero values to, 782 Triple Play Baseball, xxxviii trueSpace, xlixli, 241, 569, 570 Index TSR, Inc., Tweet, Jonathan, 1000, 1001 2-D coordinates, 162–164 2-D graphics See also mixing dimensions; tile engines; tiles and tiling big bitmap engine in, 498–500 billboarding and, 231 2Din3D, 563–567 drawing level mesh, 566 preparation for, 566 2-D objects, 566–567 loading meshes, 565 tiles, 565 moving in 3-D world, 567–568 preparing to draw, 566 sample program, 568 tiles, drawing, 563–567 2xDmg characters, 921 Type argument with cInputDevice class, 439 for lighting, 218 with texture filters, 208–209 U UDP (User Datagram Protocol), 362 Ultima Online, 12, 13, 354, 666, 846–847 wandering NPCs in, 674 Ultima Pagan, 14 Ultima series, 10, 11, 468 underlines, setting use of, 229 Unicode, 265 with DirectPlay, 363–364 untransformed coordinates, 164 Update function with cCharacterController class, 749 with cSpellController class, 721 with world transformation matrix, 427 UpdateLatency function, 884–885 UpdatePlayers function See multiplayer gaming UpdateWindow function, 110 updating cCharacterController class, 746 game, 851 The Tower, 937–938, 950–951 uppercase letters, 263 usage restrictions, 622–623 resource management and, 702 of weapons, 618 use item action, 662 UseTiles function, 495 U,V coordinates, 202–203 rendering textured objects, 210–211 V ValidateMove function, 747 Value argument with texture filters, 208–209 value to objects, assigning, 621 Vampire: The Masquerade, 10 variables, 71–75 class variables, 81–87 const keyword with, 74–75 declaring, 71–72 global variables, 73 precedence of, 72–73 scope of, 72–73 static variables, 73–74 vector objects, 195 casting a ray and, 545 Verant Interactive, 12 vertex buffers, 186–189 attribute buffers, 529 for auto maps, 805, 808–809 for Battle project, 828 bounding sphere, computing, 542 creating, 187–188 with cSkyBox class, 557 cVertexBuffer class, 422–425 indexed vertex buffers, 529 locking, 188–189 for particles, 237 stuffing in vertex data, 189–190 text window using, 686–687 vertex shaders, 190–191 vertex streams, 190 vertices, 161 for auto maps, 805 in cNodeTree class, 522 converting from local to view coordinates, 182–183 with cVertexBuffer class, 422–425 1053 1054 Index drawing with, 184–191 vertices (continued) flexible vertex format (FVF), 184–186 normals with, 224–226 objects, constructing, 164 ordering, 166–167 shaders, 190–191 stored vertices, 186–187 streams, 190 stuffing in vertex data, 189–190 vertex buffers, 186–189 in viewing frustum, 507–508 video card lighting support, 227 viewing frustum, 507–517 See also cFrustum class; clipping planes with cCharacterController class, 749–750 clipping planes, 508–511 entire objects in frustum, checking, 511 nodes falling within, 536 normals and, 508–509 as pyramid, 507 rendering nodetrees in, 538–539 spell controller using, 718 3-D objects, adding to world, 541–543 for The Tower, 930 vertices in, 507–508 viewing matrix, 182 viewpoints, 193 See also viewing frustum for billboarding, 231–232 clearing, 198–199 collision checking and, 552 of player, 668 in 2-D games, 469 working with, 240 Z-buffers and, 237–239 view transformations, 168 and cCamera, 427–429 constructing, 193–195 local coordinates, converting from, 182–183 viewing frustum, calculating planes of, 509 virtual functions, 93–94 Virtual Key Codes, 264–265 visibility of classes, 80–81 Visual C/C++, 989–994 char Variables, default for, 992–993 debug and release versions, 993 volume control with cSoundChannel, 449 with cSound class, 444 DirectMusic, 344–347 DirectSound, 314 W Walsh, Peter, 1002 wave files (.WAV), 296 with cSoundData class, 444–446 headers, 324–325 loading, 323–327, 445 Weak status ailment, 660 damage from combat and, 725–726 modifying levels of damage, 656 weapons, 618 attack modifiers, 618 attributes of, 617, 618 form, using, 615–616 function of, 617 groups, 618 range of use of, 618 resource management for, 701–702 to-hit modifiers, 618 usage restrictions, 618, 622–623 Web sites Association of Shareware Professionals (ASP), 978 design document information, 30 Microsoft Gaming Zone Web site, 355 resource information, 996–998 White Wolf Publishing, 10 weight of objects, 615–616 White Gold Wielder (Donaldson), 39 White Wolf Publishing, 10 Web site, 997 width of maps, 495 for tiles, 479–480 of viewing frustum rectangle, 517 Williams, Kip, 1000, 1001 Win32 data types, 99–100, 101 window message procedure, 104 window procedure, 113–114 windows appearance of, 109 for application framework, 154 with cGraphics, 414 conversation windows, 685–686 Index creating, 108–110 from dialog box template, 122 Direct3D presentation method, 174–176 position of, 109 shell application for, 116–119 size of, 109 working in, 102–119 Windows 95, 98 Windows programming, 99–158 See also COM (Component Object Module); DirectX; windows class, registering, 105–108 coding conventions, 99–101 critical sections, 128 custom classes, creating, 105–106 debugging, 154 default window procedure, 114 dialog boxes, 121–122 events in, 104–105 function naming, 100–101 global queue, 104 header files, 103 joysticks with, 268 keyboards in, 264–265 message boxes, using, 119–121 message pumps/loops, 111–113 messages, 104–105 common messages, 115–116 procedure, 113–114 multithreading, 125–128 resources, 122–125 shell application, 116–119 threads, 125–128 Win32 data types, 99–100 WinMain function, 103–104 WinMain.cpp file, 149–155 WinMain function, 103–104 entire coding for, 112 expanding, 109 Win32 SDK, 99 Wizardry, 10, 11 Wizards of the Coast, Inc., Web site, 997 Wizard Works, 976 WNDCLASSEX structure, 106, 107 word use in story, 44 world objects, 65 world space, 164 world transformations, 168, 182–183 for billboards, 232 constructing, 182–183, 192–193 with cWorldPosition, 425–427 writers, studying, 55–56 writing See Story-writing www.excite.com, 997 www.GameDev.net, 996 www.gamedev.net Web site, 997 X X-coordinates, 162–164, 179–180 for barriers, 796 for joysticks, 289 lights, placement of, 218 with tile engines, 488 X files, 241–247 animation in, 255–258 cAnimation for loading meshes from, 434–436 for cAutomap class, 807–808 cMesh loading meshes from, 431 creating meshes, 244 frame templates, 242–244 with multiple meshes, loading, 249–250 parsing, 244–247 templates in, 241–242 3DS files to X files, converting, 574 2Din3D, loading meshes for, 565 versatility of, 241 Xtreme Games, LLC, 976 Web site, 996 Y Y-coordinates, 162–164, 179–180 for barriers, 796 for joystick, 289–290 lights, placement of, 218 with tile engines, 488 for triangle triggers, 768 Z Z-buffers, 237–239 with cGraphics, 414, 415 1055 1056 Index ranges for, 239 for 2Din3D drawing, 566 for 2-D tiles, 567 for 3Din2D, 569, 570 Z-coordinates, 162–164, 179–180 for barriers, 796 lights, placement of, 218 The Zen of Direct 3D Game Programming (Walsh), 1002 zf parameter, 196–197 zn parameter, 196–197 “Game programming is without a doubt the most intellectually challenging field of Computer Science in the world However, we would be fooling ourselves if we said that we are ‘serious’ people! Writing (and reading) a game programming book should be an exciting adventure for both the author and the reader.” —André LaMothe, Series Editor Premier Press www.premierpressbooks.com TE AM FL Y This page intentionally left blank Team-Fly® This page intentionally left blank Take Your Game to the XTREME! Xtreme Games LLC was founded to help small game developers around the world create and publish their games on the commercial market Xtreme Games helps younger developers break into the field of game programming by insulating them from complex legal and business issues Xtreme Games has hundreds of developers around the world, if you’re interested in becoming one of them, then visit us at www.xgames3d.com www.xgames3d.com License Agreement/Notice of Limited Warranty By opening the sealed disc container in this book, you agree to the following terms and conditions If, upon reading the following license agreement and notice of limited warranty, you cannot agree to the terms and conditions set forth, return the unused book with unopened disc to the place where you purchased it for a refund License: The enclosed software is copyrighted by the copyright holder(s) indicated on the software disc You are licensed to copy the software onto a single computer for use by a single user and to a backup disc You may not reproduce, make copies, or distribute copies or rent or lease the software in whole or in part, except with written permission of the copyright holder(s) You may transfer the enclosed disc only together with this license, and only if you destroy all other copies of the software and the transferee agrees to the terms of the license You may not decompile, reverse assemble, or reverse engineer the software Notice of Limited Warranty: The enclosed disc is warranted by Premier Press, Inc to be free of physical defects in materials and workmanship for a period of sixty (60) days from end user’s purchase of the book/disc combination During the sixty-day term of the limited warranty, Premier Press will provide a replacement disc upon the return of a defective disc Limited Liability: THE SOLE REMEDY FOR BREACH OF THIS LIMITED WARRANTY SHALL CONSIST ENTIRELY OF REPLACEMENT OF THE DEFECTIVE DISC IN NO EVENT SHALL PREMIER PRESS OR THE AUTHORS BE LIABLE FOR ANY OTHER DAMAGES, INCLUDING LOSS OR CORRUPTION OF DATA, CHANGES IN THE FUNCTIONAL CHARACTERISTICS OF THE HARDWARE OR OPERATING SYSTEM, DELETERIOUS INTERACTION WITH OTHER SOFTWARE, OR ANY OTHER SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES THAT MAY ARISE, EVEN IF PREMIER AND/OR THE AUTHORS HAVE PREVIOUSLY BEEN NOTIFIED THAT THE POSSIBILITY OF SUCH DAMAGES EXISTS Disclaimer of Warranties: PREMIER AND THE AUTHORS SPECIFICALLY DISCLAIM ANY AND ALL OTHER WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY, SUITABILITY TO A PARTICULAR TASK OR PURPOSE, OR FREEDOM FROM ERRORS SOME STATES DO NOT ALLOW FOR EXCLUSION OF IMPLIED WARRANTIES OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THESE LIMITATIONS MIGHT NOT APPLY TO YOU Other: This Agreement is governed by the laws of the State of Indiana without regard to choice of law principles The United Convention of Contracts for the International Sale of Goods is specifically disclaimed This Agreement constitutes the entire agreement between you and Premier Press regarding use of the software .. .Programming Role Playing Games with ® DirectX This page intentionally left blank Programming Role Playing Games with ® DirectX Jim Adams © 2002 by Premier... 190 190 191 192 193 195 197 198 199 199 201 xv xvi Contents Using Texture Maps 202 Using Texture-Mapping with Direct3D ... 1 59 Chapter Interacting with DirectInput 261 Chapter Playing Sound with DirectX Audio 293 Chapter Networking with DirectPlay 351 Chapter 10 Creating the Game Core 399