Source Code Control
Total Page:16
File Type:pdf, Size:1020Kb
Y L F M A E T Team-Fly® Strategy Game Programming with DirectX 9.0 Todd Barron Wordware Publishing, Inc. Library of Congress Cataloging-in-Publication Data Barron, Todd. Strategy game programming with DirectX 9.0 / by Todd Barron. p. cm. ISBN 1-55622-922-4 (pbk.) 1. Computer games--Programming. 2. DirectX. I. Title. QA76.76.C672B369 2003 794.8'15268--dc21 2003012699 CIP © 2003, Wordware Publishing, Inc. All Rights Reserved 2320 Los Rios Boulevard Plano, Texas 75074 No part of this book may be reproduced in any form or by any means without permission in writing from Wordware Publishing, Inc. Printed in the United States of America ISBN 1-55622-922-4 10987654321 0306 DirectX is a registered trademark of Microsoft Corporation in the United States and/or other countries. All screen shots and game titles used in this book remain the property of their respective publishers. Screen images and concept art from Warcraft® III: Reign of Chaos™ and StarCraft® courtesy of Blizzard Entertainment®. All brand names and product names mentioned in this book are trademarks or service marks of their respective companies. Any omission or misuse (of any kind) of service marks or trademarks should not be regarded as intent to infringe on the property of others. The publisher recognizes and respects all marks used by companies, manufacturers, and developers as a means to distinguish their products. This book is sold as is, without warranty of any kind, either express or implied, respecting the contents of this book and any disks or programs that may accompany it, including but not limited to implied warranties for the book’s quality, performance, merchantability, or fitness for any particular purpose. Neither Wordware Publishing, Inc. nor its dealers or distributors shall be liable to the purchaser or any other person or entity with respect to any liability, loss, or damage caused or alleged to have been caused directly or indirectly by this book. All inquiries for volume purchases of this book should be addressed to Wordware Publishing, Inc., at the above address. Telephone inquiries may be made by calling: (972) 423-0090 Dedication For my best friend and the love of my life, my wife, Jennie. In memory of Robert L. Brown Sr. and Ralph M. Davis Jr. Contents Part I The Beginning Chapter 1 Learning from the Past ...................3 The Early RTS Games .....................3 Intellivision’s Utopia .....................3 The Game Field .....................4 Wrap-up.........................8 Bullfrog’s Populous .....................8 The Hook ........................8 Terrain Building......................8 The First Popular RTS Games ..................9 Westwood’s Command & Conquer .............9 The Story ........................10 The Interface ......................11 Technology .......................14 Game Balance .....................17 Warcraft: Orcs & Humans .................17 Blizzard’s StarCraft.....................17 The Future of RTS Games ...................19 Massively Multiplayer RTS Games..............19 Smart Computers .....................19 The Early Strategy Games...................20 Warlords .........................20 Empire ..........................20 Command H.Q. ......................21 The Seven Cities of Gold ..................22 X-COM: UFO Defense ...................22 Recap ............................23 Chapter 2 Getting Started with Windows ..............25 Windows Program Architecture ................25 Event-driven Processing ..................25 Events..........................26 Program Structure .....................26 The Event Queue ....................26 The WinMain() Function .................27 The Message Handler ..................28 Writing Your First Windows Program..............28 iv Contents Setting Up Visual C++ 6.0.................28 How to Create the Project ................29 The Workspace .....................31 Adding Source Files to the Project ............33 Getting Down and Dirty with the Code ...........35 The Include and Function Prototypes ...........36 Inside the WinMain() Function ..............37 The Message Processing Function ............51 Compiling and Executing the Code .............52 Recap ............................53 Chapter 3 Game Mechanics......................55 The Story ...........................55 The Story Theme ......................55 The Story Elements .....................56 The Story Plot ......................56 The Story Purpose ....................56 Setting Objectives.......................57 Case Study — Empire Earth ................57 Description .......................58 Early Goals .......................58 Milestone Goals.....................59 Finishing Goals .....................61 Combat Units ........................62 Unit Cost .........................62 Unit Speed.........................63 Calculating Unit Speed .................63 Unit Armor ........................63 Calculating Defensive Value ...............63 Hit Points ........................64 Unit Firepower .......................65 Rate of Fire .......................65 Damage Type ......................65 Special Damage ....................66 Weapon Velocity ....................66 RTS Resource Management ..................66 Pick Your Poison ......................67 Defining Resources.....................67 Gathering Resources ....................67 Resource Balance .....................69 Unbalanced Example ..................70 Balanced Example ...................70 Gathering Rate .....................70 RTS Technology Trees .....................71 Different Types of Technology................72 Infrastructure Technology ................72 v Contents Weapon Technology...................72 Upgrade Technology ..................73 The Cost of Technology ..................73 The Campaign Game ....................74 The Mission Editor .....................75 Mission Goals .......................75 Multiplayer Gaming .....................76 Recap ............................76 Chapter 4 Planning Your Game Project ...............77 The Envisioning Phase ....................78 Envisioning Outline ....................79 The Requirements Phase ...................80 The Technical Documentation Phase..............80 The Development Phase ...................82 Source Code Control....................82 Label Management ....................83 Bug Tracking........................85 Tracking ........................85 Source Tracking .....................85 Quality Metrics .....................86 Unit Testing ........................86 The Testing Phase.......................87 The Production Phase .....................88 Distribution ..........................88 Shareware .........................88 Auction Sites ........................89 Publisher .........................90 Recap ............................90 Part II Building Blocks Chapter 5 Tile-based Graphics ....................93 Tile Engine Basics.......................93 What Is a Tile?.......................93 Why Use Tiles? ......................95 Use Tiles to Conserve Memory..............95 Use Tiles for Graphics Reuse...............96 Use Tiles for Dynamic Content..............97 How Do You Create Tiles? .................98 Choose the Tile Dimensions ...............98 Identify Tiles Needed ..................99 vi Contents How Do You Display Tiles? ................100 Two-dimensional Grid Display .............100 Isometric Tile Display..................104 3D Tile Display ....................106 Multi-Layering Tiles .....................107 How to Add Detail Tiles ..................107 How to Add Transition Tiles ................109 How to Add Road Tiles ..................113 How to Add 3D Tree Tiles .................115 How to Add Animated Tiles ................117 Tile Editing and Storage ...................118 2D Array Storage .....................118 Multi-layer Tile Array Storage ...............120 Implementing a Tile Class ................122 The Tile Class Header .................122 The Tile Class Implementation .............124 Tile Class Example Implementation ...........127 Tile Properties ........................128 Obstruction Property ...................129 Elevation Property ....................129 Brightness Property ....................130 Offsets Property .....................130 Tile Rendering........................131 2D Tile Rendering ....................132 D3DFrame_2DTiles Project Architecture.........132 The Main.h Header File ................133 The Main.cpp Program File...............136 2D Isometric Tile Rendering ................141 D3DFrame_Isometric2DTiles Project Architecture ....141 The Main.h Header File ................142 The Main.cpp Program File...............142 2D Isometric Tile Rendering with Sprites ..........145 D3DFrame_Isometric2DSpriteTiles Project Architecture . 146 The Main.h Header File ................146 The Main.cpp Program File...............146 Why Use Sprites? ...................147 3D Tile Rendering ....................147 D3DFrame_3DTiles Project Architecture.........148 The Main.h Header File ................148 The Main.cpp Program File...............150 Recap............................154 vii Contents Chapter 6 Interface Design and Development ...........155 Defining Interface Needs ..................155 Mouse Zones and Graphics ................156 Detailing the Interface Outline ..............157 Interface Outline Relationships .............158 Interface Sounds ....................160 Interface State .....................162 Storyboarding the Interface ................166