TEAMFLY 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
10 9 8 7 6 5 4 3 2 1
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
The Early RTS Games
Chapter 1 Learning from the Past .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
The First Popular RTS Games .
.
Intellivision’s Utopia .
The Game Field .
Wrap-up .
.
Bullfrog’s Populous .
.
.
The Hook .
.
Terrain Building.
.
.
.
.
.
.
.
.
.
.
.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
.
.
.
.
.
.
The Future of RTS Games .
.
The Story .
.
.
The Interface .
Technology .
.
.
Game Balance .
.
.
.
.
Warcraft: Orcs & Humans .
.
Blizzard’s StarCraft.
.
Westwood’s Command & Conquer
.
.
.
.
.
.
.
.
.
.
.
.
. .
.
.
.
.
.
.
.
.
.
Massively Multiplayer RTS Games.
Smart Computers .
.
.
.
.
.
.
.
.
.
.
.
.
Warlords
.
Empire .
.
.
Command H.Q. .
The Seven Cities of Gold .
.
X-COM: UFO Defense .
.
.
.
The Early Strategy Games.
.
.
.
Recap .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Chapter 2 Getting Started with Windows .
.
Events.
.
Program Structure .
Event-driven Processing .
.
.
.
.
. .
.
.
.
.
.
.
.
.
.
.
.
.
Writing Your First Windows Program.
.
Windows Program Architecture .
.
.
.
.
.
.
.
.
.
.
.
The Event Queue .
.
The WinMain() Function .
The Message Handler .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
iv
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Setting Up Visual C++ 6.0.
.
.
.
How to Create the Project .
The Workspace .
.
.
Adding Source Files to the Project
.
.
.
.
Getting Down and Dirty with the Code .
The Include and Function Prototypes .
Inside the WinMain() Function .
.
.
.
The Message Processing Function .
.
.
.
.
Compiling and Executing the Code .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Recap .
Contents
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.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
.
.
.
.
.
.
.
.
.
.
The Story .
Chapter 3 Game Mechanics.
.
.
.
The Story Theme .
.
The Story Elements .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Unit Armor
Setting Objectives.
Combat Units
Unit Cost
.
Unit Speed.
.
Description .
Early Goals .
.
Milestone Goals.
Finishing Goals .
.
.
.
.
.
.
.
.
.
.
Calculating Unit Speed .
.
.
.
.
.
The Story Plot .
.
The Story Purpose .
.
.
.
.
.
.
.
.
Case Study — Empire Earth .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Calculating Defensive Value .
.
Hit Points .
.
.
.
.
.
.
.
.
.
.
.
. .
.
.
.
.
.
.
.
.
. .
.
.
.
.
.
.
Different Types of Technology .
.
.
Infrastructure Technology .
.
.
.
.
.
.
RTS Resource Management .
.
.
.
.
Unbalanced Example .
.
Balanced Example .
.
.
Gathering Rate .
RTS Technology Trees .
.
.
.
.
.
.
.
Unit Firepower .
.
.
Rate of Fire .
Damage Type .
.
Special Damage .
Weapon Velocity .
.
Pick Your Poison .
.
Defining Resources.
.
Gathering Resources .
Resource Balance .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Contents
Weapon Technology .
.
Upgrade Technology .
The Cost of Technology .
.
.
.
.
.
The Campaign Game .
.
.
.
.
The Mission Editor .
Mission Goals .
.
Multiplayer Gaming .
.
Recap .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. .
Chapter 4 Planning Your Game Project .
.
.
.
The Envisioning Phase .
Envisioning Outline .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. .
The Requirements Phase .
.
The Technical Documentation Phase.
.
The Development Phase .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. .
.
Source Code Control.
.
Label Management
.
.
Bug Tracking.
Tracking .
.
.
.
Source Tracking .
.
Quality Metrics .
.
.
.
.
The Testing Phase .
.
The Production Phase .
.
.
.
Distribution .
.
.
.
.
.
.
.
.
.
.
Shareware .
.
Auction Sites .
Publisher
.
.
.
Unit Testing .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Recap .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Part II
Building Blocks
Chapter 5 Tile-based Graphics .
.
.
.
.
Tile Engine Basics.
What Is a Tile? .
.
Why Use Tiles? .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Use Tiles to Conserve Memory .
Use Tiles for Graphics Reuse.
.
Use Tiles for Dynamic Content .
.
.
.
.
Choose the Tile Dimensions .
Identify Tiles Needed .
.
.
.
How Do You Create Tiles? .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. 72
. 73
. 73
. 74
. 75
. 75
. 76
. 76
. 77
. 78
. 79
. 80
. 80
. 82
. 82
. 83
. 85
. 85
. 85
. 86
. 86
. 87
. 88
. 88
. 88
. 89
. 90
. 90
. 93
. 93
. 93
. 95
. 95
. 96
. 97
. 98
. 98
. 99
vi
Contents
Multi-Layering Tiles .
Tile Properties .
.
.
Tile Rendering.
.
.
Tile Editing and Storage .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
How Do You Display Tiles? .
.
.
.
Two-dimensional Grid Display .
.
.
.
Isometric Tile Display.
.
.
.
.
.
.
3D Tile Display .
. .
.
.
.
.
.
.
.
.
.
How to Add Detail Tiles .
.
.
.
.
How to Add Transition Tiles .
.
.
.
.
.
.
How to Add Road Tiles .
.
.
.
.
.
How to Add 3D Tree Tiles .
.
.
.
.
.
How to Add Animated Tiles .
.
.
.
.
.
.
.
.
.
.
.
2D Array Storage .
.
.
.
.
Multi-layer Tile Array Storage .
.
.
.
Implementing a Tile Class
.
.
.
The Tile Class Header .
. .
The Tile Class Implementation .
.
Tile Class Example Implementation .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
D3DFrame_2DTiles Project Architecture.
.
The Main.h Header File .
.
.
The Main.cpp Program File.
.
.
.
Obstruction Property .
Elevation Property .
.
.
Brightness Property .
.
.
Offsets Property .
.
.
.
2D Tile Rendering .
.
2D Isometric Tile Rendering .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
D3DFrame_Isometric2DTiles Project Architecture .
.
The Main.h Header File .
.
.
The Main.cpp Program File.
.
. 100
. 100
. 104
. 106
. 107
. 107
. 109
. 113
. 115
. 117
. 118
. 118
. 120
. 122
. 122
. 124
. 127
. 128
. 129
. 129
. 130
. 130
. 131
. 132
. 132
. 133
. 136
. 141
. 141
. 142
. 142
. 145
D3DFrame_Isometric2DSpriteTiles Project Architecture . 146
.
. 146
The Main.h Header File .
.
. 146
.
The Main.cpp Program File.
. 147
.
Why Use Sprites? .
.
. .
.
. 147
. 148
. 148
. 150
. 154
.
.
.
.
D3DFrame_3DTiles Project Architecture.
.
The Main.h Header File .
.
.
The Main.cpp Program File.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2D Isometric Tile Rendering with Sprites .
3D Tile Rendering .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Recap .
.
.
vii