Although hebegan his programming career at age 15 as a database programmer in Visual Basic, he never lost his passion for game development.. 297 Chapter 10 Designing Your Game Library: M
Trang 1TE AM
Team-Fly®
Trang 2Game Programming
All in One
Bruno Miguel Teixeira de Sousa
Trang 3© 2002 by Premier Press 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.
Premier Press, Inc is a registered trademark of Premier Press, Inc.
Publisher:Stacy L Hiquet
Marketing Manager: Heather Buzzingham
Managing Editor:Sandy Doell
Acquisitions Editor:Mitzi Foster
Series Editor: André LaMothe
Project Editor:Heather Talbot
Technical Reviewer:André LaMothe
Copy Editor: Jenny Davidson
Interior Layout:Marian Hartsough
Cover Design:Mike Tanamachi
CD-ROM Producer:Keith Davenport
Indexer: Kelly Talbot
Proofreaders:Anne Owen, Fran Blauw, Linda Seifert
Microsoft, DirectX, DirectSound, and DirectInput are registered trademarks of Microsoft
Corporation.
Jasc and Paint Shop Pro are trademarks or registered trademarks of Jasc Software, Inc.
All other trademarks are the property of their respective owners.
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 marks from descriptive terms by following the capitalization style used by the manufacturer.
trade-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-chang- ing entity Some facts may have changed since this book went to press.
ISBN: 1-931841-23-3
Library of Congress Catalog Card Number: 2001096486
Printed in the United States of America
02 03 04 05 06 RI 10 9 8 7 6 5 4 3 2 1
Trang 4De todas as coisas que quero,
és a única coisa que eu preciso.
Para ti, Ana.
Trang 5Now is the time I should go up to the stage, get the Oscar, and recite a length script of all the people that helped make this book However, thethank you would probably be as big as this book, so to prevent from forgetting any-one, I would like to thank everyone that directly or indirectly made this book possi-ble
book-On the technical side, I would like to thank the people at Premier Press for giving
me the opportunity to write this book I would also like to thank my editors, EmiSmith, Mitzi Foster, Heather Talbot, and Jenny Davidson for all their patience andall they had to put up with (Yes, the usual delays and the incessant questions.)Please remember that what you are reading is not a book that I wrote myself, butone that comprises the work of many talented people who are usually forgotten
I would also like to thank André LaMothe for reviewing the book
On the personal side, I would like to thank my mom and dad for their support andlove during my life, and of course, for paying those enormous Internet bills when Iwas still learning game programming
I would also like to thank all of my friends and relatives for their support not onlywith the book, but also with my life I would like to send a special thanks to Dianafor always being there for me whenever I needed her
Last, and probably most important, I would like to thank Ana for her love, support,patience, and just about everything I love you from the bottom of my heart
Trang 6About the Author
B RUNO M IGUEL T EIXEIRA DE S OUSAbegan programming at age 11 Although hebegan his programming career at age 15 as a database programmer in Visual Basic,
he never lost his passion for game development Two years later, he began a time career performing general game programming for a UK-based company Hehas been using C++ for more than 4 years and remains an avid game hobbyist
full-R ONALD P ENTONwrote Chapter 17 Ron started programming on his Tandy 1000TLway back in 1989, when he became interested in making games, rather than justplaying them Ever since then, he has been on a never-ending quest to learn moreabout computers and become more efficient at programming them He startedschool at the Rochester Institute of Technology in 1998, and is currently finishinghis bachelor’s degree in computer science at The University of Buffalo
Trang 7Contents at a Glance
Introduction xxxvi
Part One C++ Programming 1
Chapter 1 Introduction to C++ Programming 3
Chapter 2 Variables and Operators 25
Chapter 3 Functions and Program Flow 51
Chapter 4 Multiple Files and the Preprocessor 95
Chapter 5 Arrays, Pointers, and Strings 107
Chapter 6 Classes 153
Chapter 7 Developing Monster 197
Chapter 8 Streams 245
Chapter 9 Basic Software Architecture 279
Part Two Windows Programming 297
Chapter 10 Designing Your Game Library: Mirus 299
Chapter 11 Beginning Windows Programming 317
Chapter 12 Introduction to DirectX 357
Chapter 13 DirectX Graphics 369
Chapter 14 DirectInput 521
Trang 8Part Three
Hardcore Game Programming 595
Chapter 16 Introduction to Game Design 597
Chapter 17 Data Structures and Algorithms 609
Chapter 18 The Mathematical Side of Games 661
Chapter 19 Introduction to Artificial Intelligence 697
Chapter 20 Introduction to Physics Modeling 723
Chapter 21 Building Breaking Through 791
Chapter 22 Publishing Your Game 851
Part Four Appendixes 863
Appendix A What’s on the CD-ROM 865
Appendix B Debugging Using Microsoft Visual C++ 870
Appendix C Binary, Hexadecimal, and Decimal System 874
Appendix D A C Primer 877
Appendix E Answers to the Exercises 885
Appendix F C++ Keywords 893
Appendix G Useful Tables 895
Appendix H More Resources 902
Index 907
ix
Contents at a Glance
Trang 9Letter from the Series Editor xxxiv
Introduction xxxvi
Part One C++ Programming 1
Chapter 1 Introduction to C++ Programming 3
Why Use C++? 4
Setting Up Visual C++ 5
Creating a Workspace 5
Creating Projects 6
Creating and Adding Files 8
Your First Program: “Hello all you happy people” 9
Structure of a C++ Program 12
Program Design Language 12
Program Source and Compiling 14
Objects and Linking 14
Executable 15
Commenting 16
Catching Errors 17
Warnings 20
Summary 21
Questions and Answers 21
Exercises 23
Team-Fly®
Trang 10Chapter 2
Variables and Operators 25
Variables and Memory 26
What Type of Variables Are There? 27
Using Variables in Your Programs 30
Declaring a Variable 30
Using Variables 31
Initializing Variables 32
Variable Modifiers 33
Const 33
Register 35
Variable Naming 36
Redefining Types 36
What Is an Operator? 37
Assignment Operator 37
Mathematical Operators 37
Unary Operators 38
Binary Operators 39
Compound Assignment Operators 41
Bitwise Shift Operators 41
Relational Operators 42
Conditional Operator 43
Logical Operators 44
Operator Precedence 45
Summary 47
Questions and Answers 48
Exercises 48
xi
Contents
Trang 11Chapter 3
Functions and Program Flow 51
Functions:What Are They and What Are They Used For? 52
Creating and Using Functions 54
Declaring the Prototype 55
Return Type 55
Name 55
Parameters 56
Function Body 56
Default Parameters 58
Variable Scope 60
Locals 61
Global 61
Static 62
Recursion 64
Things to Remember When Using Functions 66
Program Flow 66
Code Blocks and Statements 66
if, else if, else Statements 67
if 67
else 70
while, do while, and for Loops 70
while 70
do while 72
for 73
Breaking and Continuing 75
break 75
continue 76
Switching to switch 77
Randomizing 80
First Game: “Craps” 83
Objective 83
Rules 84
xii Contents
Trang 12Design 84
Implementation 85
Summary 92
Questions and Answers 93
Exercises 93
Chapter 4 Multiple Files and the Preprocessor 95
Differences between Source and Header Files 96
Handling Multiple Files 97
What Is the Preprocessor? 99
Avoiding Multiple Includes 101
Using #pragma 101
Using #ifdef, #define, and #endif 102
Macros 104
Other Preprocessor Directives 104
Summary 106
Exercises 106
Chapter 5 Arrays, Pointers, and Strings 107
What Is an Array? 108
Declaring and Using an Array 109
Declaration 109
Using 109
Initializing an Array 112
Multi-Dimensional Arrays 112
Pointers to What? 116
Pointers and Variables 117
Declaring and Initializing 117
Using Pointers 117
xiii
Contents
Trang 13Pointers and Arrays 119
Relation of Pointers to Arrays 119
Passing Arrays to Functions 120
Declaring and Allocating Memory to a Pointer 122
Allocating the Memory 123
Freeing the Memory 123
Pointer Operators 126
Manipulating Memory 129
memcpy 129
memset 130
Strings 131
Strings and Arrays 131
Using Strings 132
Strings and Arrays 132
String Allocation at Compilation 132
Input and Output 132
String Operations 133
strcpy 133
strncpy 134
strlen 135
strcat 136
strncat 138
strcmp 138
strncmp 140
strchr 140
strstr 142
atoi 143
atof 145
atol 145
sprintf 145
strftime 147
Summary 150
Questions and Answers 151
Exercises 151
xiv Contents
Trang 14Chapter 6
Classes 153
What Is a Class? 154
New Types 155
Building Classes 155
Design 155
Definition 156
Implementation 157
Using Classes 158
Private, Protected, and Public Members 158
private 159
public 159
protected 159
What Kind of Access Is Right? 160
Constructors and the Destructor 161
Default Constructor 161
General Constructors 162
Copy Constructor and References 162
Destructor 163
Operator Overloading 164
Putting It All Together—The String Class 166
Basics of Inheritance and Polymorphism 172
Inheritance 172
Deriving from a Class 173
Virtual Methods 174
Polymorphism 178
Casting 180
Enumerations 182
Unions 183
Static Members 185
Useful Techniques Using Classes 186
A Singleton Class 186
An Object Factory 190
xv
Contents
Trang 15Summary 195
Questions and Answers 195
Exercises 196
Chapter 7 Developing Monster 197
ConLib 198
Design 199
Implementation 202
Building Monster 215
Objective 215
Rules 215
Design 216
Game Description 216
Thinking in Classes 216
Implementation 221
Summary 244
Chapter 8 Streams 245
What Is a Stream? 246
Binary and Text Streams 246
Input and Output 247
istream 247
get 248
getline 249
ignore 250
Extraction Operator (>>) 251
ostream 251
put 251
flush 252
Insertion Operator (<<) 252
xvi Contents
Trang 16File Streams 253
Opening and Closing Streams 253
open 254
close 255
is_open 256
Text 259
Binary 264
write 264
read 267
seekg 268
seekp 269
tellg 269
tellp 269
Modifying Monster to Save and Load Games 270
Summary 277
Questions and Answers 278
Exercises 278
Chapter 9 Basic Software Architecture 279
The Importance of Software Design 280
Design Approaches 281
Top Down 281
Bottom Up 282
Top Down Versus Bottom Up 282
Some Basic Techniques 283
Example 1: Assignment Instead of Equality Operator 283
Example 2: Statements Versus Blocks 284
Example 3: Macros Versus Inline Functions 284
Example 4: Private Versus Public, the First Case 285
Example 5: Private Versus Public, the Second Case 287
xvii
Contents
Trang 17Modules and Multiple Files 288
Creating Modules with C++ 288
Why Make Something a Module? 288
Naming Conventions 289
Function Naming 289
Variable Names 290
Identification 290
Where Common Sense Beats Design 292
The Design Used in This Book 292
Summary 293
Questions and Answers 294
Exercises 295
Part Two Windows Programming 297
Chapter 10 Designing Your Game Library: Mirus 299
General Description 300
Mirus Components 301
Helper Component 301
Window Component 302
Graphics Component 302
mrScreen 303
mrRGBAImage 303
mrSurface 304
mrTexture 304
mrTemplateSet 304
mrAnimation 305
mrABO 305
Trang 18Sound Component 306
mrSoundPlayer 306
mrCDPlayer 306
Input Component 307
mrKeyboard 307
mrMouse 307
mrJoystick 308
Building the Help Component 308
Declaring the Types 308
mrTimer 309
How to Create the Error File 315
How to Use Mirus 316
Summary 316
Questions and Answers 316
Chapter 11 Beginning Windows Programming 317
History of Windows 318
Introduction to Windows Programming 319
Windows 319
Multitasking 321
Windows Has Its Own API 322
Message Queues 322
Visual C++ and Windows Applications 322
Building the Windows Application 323
WinMain Versus Main 326
Creating the Window 328
The Window Class 328
Creating the Window 332
The Message Loop 334
The Message Handler 335
xix
Contents
Trang 19Creating a Real-Time Message Loop 336
Making a Reusable Window Class 342
Using the Mirus Window Framework 350
Some Common Window Functions 351
SetPosition 351
GetPosition 352
SetSize 354
GetSize 354
Show 355
Summary 355
Questions and Answers 355
Exercises 356
Chapter 12 Introduction to DirectX 357
What Is DirectX? 358
Brief History of DirectX 359
Why Use DirectX? 360
DirectX Components 361
How Does DirectX Work? 362
Hardware Abstraction Layer 362
The Component Object Model 363
Virtual Tables 365
COM and DirectX 365
How to Use DirectX with Visual C++ 366
Summary 367
Questions and Answers 367
Exercises 368
xx Contents
Team-Fly®
Trang 20Chapter 13
DirectX Graphics 369
Interfaces You Will Be Using 370
Using Direct3D:The Basics 372
Surfaces, Buffers, and Swap Chains 387
Surfaces 387
Buffers 388
Swap Chains 388
Rendering Surfaces 389
Vertices, Polygons, and Textures 397
Vertices and Polygons 397
Textures 398
Texture Coordinates 399
From the Third Dimension to the Second 401
Rendering in 2D 401
Windows Bitmaps 411
Bitmap Structure 411
Loading a Bitmap 413
Full Screen and Other Bit Modes 414
Color Theory and Color Keying 416
Color Theory 416
Color Keying 419
Targa Files 420
Structure of a Targa File 420
Loading a Targa File 421
Animation and Template Sets 422
Animation 422
Template Sets 423
Collision Detection 424
Bounding Volumes 424
Bounding Circles 425
Bounding Rectangles 426
xxi
Contents
Trang 212D Image Manipulation 428
Translation 428
Scaling 429
Rotation 430
2D Primitives Revealed 433
Lines 433
Rectangles and Other Polygons 437
Circles 438
Developing Mirus 438
mrScreen 439
mrRGBAImage 458
mrSurface 472
mrTexture 480
mrTemplateSet 488
mrAnimation 493
mrABO 501
Summary 519
Questions and Answers 519
Exercises 520
Chapter 14 DirectInput 521
Introduction to DirectInput 522
Unbuffered Data 523
Buffered Data 523
mrInputManager 524
mrKeyboard 527
mrMouse 541
mrJoystick 554
Summary 565
Questions and Answers 566
Exercises 566
xxii Contents
Trang 22Chapter 15
DirectSound 567
Sound Theory 568 DirectSound Basics 569 mrSoundPlayer 571 mrSound 575 Media Control Interface 586 mrCDPlayer 587 Summary 593 Questions and Answers 593 Exercises 594
Part Three
Hardcore Game Programming 595
Chapter 16
Introduction to Game Design 597
What Is Game Design? 598 The Dreadful Design Document 599 Why the “It’s in My Head” Technique Isn’t Good 600 The Two Types of Designs 600
Mini Design 601Complete Design 601
A Fill In Design Document Template 602
General Overview 602Target System and Requirements 602Story 602Theme: Graphics and Sound 603Menus 603Playing a Game 603Characters and NPCs Description 603
xxiii
Contents
Trang 23Artificial Intelligence Overview 603Conclusion 603
A Sample Game Design: Space Invaders 604
General Overview 604Target System and Requirements 604Story 605Theme: Graphics and Sound 605Menus 605Start New Game 605Continue Previously Saved Game 605See Table of High Scores 605Options 606Exit 606Playing a Game 606Characters and NPCs Description 606Normal Ships 607Bonus Ships 607Artificial Intelligence Overview 607Conclusion 607
Summary 607 Questions and Answers 608 Exercises 608
xxiv Contents
Trang 24Deleting a Node from a List 620Doubly Linked Lists 621Modifying the Algorithms for Doubly Linked Lists 622Circular Lists 622Advantages of Lists 623Disadvantages of Lists 623
Trees 624 General Trees 625
Constructing a General Tree 629Traversing a General Tree 630General Tree Destructor 632Uses of General Trees 632
Binary Search Trees 633
A Primer on Binary Trees 633What Is a Binary Search Tree? 634Searching a Binary Search Tree 635Inserting into a Binary Search Tree 637Removing a Value from a Binary Search Tree 638Efficiency Considerations 646Uses of Binary Search Trees 647
Sorting Data 648 Bubble Sort 648
Swap Counter Optimization 649Declining Inner Iterations 650Combining the Optimizations 650
The Quick Sort 651
Another Optimization 653Source Listing 653Comparisons of the Sorts 655
Compression 656 RLE Compression 657
RLE Compression Code 658
xxv
Contents
Trang 25Summary 659 Questions and Answers 659 Exercises 660
Matrices 678
Addition and Subtraction 681Scalar and Multiplication and Division 682Special Matrices 684Transpose 685Matrix Concatenation 686Vector Transformation 688
Probability 688
Sets 689Union 689Intersection 690
xxvi Contents
Trang 26Functions 691
Integration and Differentiation 692Differentiation 693
Summary 694 Questions and Answers 694 Exercises 695
Deterministic Algorithms 707
Random Motion 707Tracking 709Patterns 710
Finite State Machines 713 Fuzzy Logic 715
Fuzzy Logic Basics 715Fuzzy Matrices 717
A Simple Method for Memory 719 Artificial Intelligence and Games 720 Summary 720 Questions and Answers 721 Exercises 721
xxvii
Contents
Trang 27Chapter 20
Introduction to
Physics Modeling 723
Introduction to Physics 724 Building a Physics Engine 725
Why Make a Physics Engine? 725Designing the Engine 725mrEntity 726
Basic Physics Concepts 728
Mass 728Time 729Position 729Velocity 731Linear Velocity 731Angular Velocity 732Acceleration 732Linear Acceleration 733Angular Acceleration 733Center of Mass 734
Forces 735
Linear Force 736Torque 739The Resulted Force 740
Gravitational Interaction 741
Law of Universal Gravitation 742Gravity on Earth and Other Planets 743Simulating Projectiles 745
Friction 748
Friction Concept 748Decomposing Friction 749The Normal Force 749
Trang 28Static Friction 751Kinetic Friction 752Friction on a Sloped Surface 752The Computer Method 753
Handling Collisions 755
Maintaining the Momentum 755Conservation of Momentum 755The Impulse Method 756
Simulating 761
Getting the Step 763
Particle Systems 770
Particle Systems 101 770Designing a Particle System 770Particle Systems’ Data Structures 770Making It Work 775Particle Demo 784
Summary 788 Questions and Answers 788 Exercises 789
Chapter 21
Building Breaking Through 791
Designing Breaking Through 792
General Overview 792Target System and Requirements 792Story 793Rules 793Theme: Graphics 794Menus 795Playing a Game 796
xxix
Contents
Trang 29Code Design 798btBlock 798btPaddle 798btBall 798btGame 799BreakThroughWindow 799
Building Breaking Through 799
btBlock 800btPaddle 804btBall 809btGame 817BreakThroughWindow 848
Conclusion 850
Chapter 22 Publishing Your Game 851
Is Your Game Worth Publishing? 852 Whose Door to Knock On 853 Learn to Knock Correctly 854 Contracts 854
Non-disclosure Agreement 855The Actual Publishing Contract 856
Milestones 856
Bug Report 856Release Day 857
No Publisher, Now What? 857 Interviews 857
Niels Bauer: Niels Bauer Software Design 857André LaMothe: Xtreme Games LLC 859
Summary 861 References 861 Conclusion 862
xxx Contents
Team-Fly®
Trang 30Jasc Paint Shop Pro 7 867Syntrillium Cool Edit 2000 868Caligari TrueSpace 5 868
Games 868
Gemdrop 868Smiley 869Smugglers 2 869
Modifying Variables During Runtime 872 Watching Variables 873
Appendix C
Binary, Hexadecimal,
and Decimal System 874
Binary 875 Hexadecimal 875 Decimal 876
xxxi
Contents
Trang 31Appendix D
A C Primer 877
Standard Input and Output 878 File Input and Output 879 Structures: Say Bye-Bye to Classes 882 Dynamic Memory 882
Appendix E
Answers to the Exercises 885
Chapter 1 886 Chapter 2 886 Chapter 3 887 Chapter 4 887 Chapter 5 887 Chapter 6 888 Chapter 7 888 Chapter 8 888 Chapter 9 888 Chapter 10 889 Chapter 11 889 Chapter 12 889 Chapter 13 889 Chapter 14 889 Chapter 15 890 Chapter 16 890 Chapter 17 890 Chapter 18 891 Chapter 19 891 Chapter 20 891
Trang 32Appendix H
More Resources 902
Game Development and Programming 903News, Reviews, and Download Sites 904Engines 904Independent Game Developers 904Industry 905Computer Humor 905Books 906
Index 907
xxxiii
Contents
Trang 33xxxiv Letter from the Series Editor
Letter from the
Series Editor
Game programming has become serious business! With the introduction
of the Microsoft Xbox, Sony PlayStation II, Nintendo GameCube, andNintendo Game Boy Advance, we see that there is no slowing down of the gaming market in sight Moreover, programming games on the PC and on consoles is becoming more and more a unified approach The
Xbox is nothing more than a really, really, really, REALLY, fast PC!
Hence, as a newbie game programmer interested in learning either PC
or console game programming, a good place to start is the PC and move
on from there Game Programming All in One is an ambitious lead into
game programming
As the series editor, what I wanted was a book that started from groundzero and taught C++, Algorithms, Data Structures, Game Programming,and DirectX, culminating in something simple like an arcade or actiongame — that’s the theme of this book Granted it’s literally impossible tocover all those topics in fewer than 3,000–5,000 pages in complete fashion,
but we think that Game Programming All in One has definitely come close to
being an all-in-one guide that a complete beginner can pick up to learngame programming
So if you’re a beginner interested in becoming a game programmer, oryou just want to know what it’s about but don’t want to spend hundreds ofdollars on books covering all the specific game programming topics thenthis is a great book for you to start with Although having programmingexperience is a big plus, this book assumes you have none and teaches C++along with Windows programming before getting into the game program-ming material Once there, you’re not going to learn 3D graphics and how
to make Quake or HALO, but you will learn about the fundamental
processes and techniques to create a solid 2D game; from there it’s up toyou if you want to keep on learning and move to ISOmetric 3D games,
Multiplayer Games, or full 3D Games — the choice is yours, but with Game
Programming All in One you will have a solid foundation to start from.
Trang 34Letter from the Series Editor
Additionally, the coding habits you will learn in this book are excellent
The author Bruno Sousa is one of the best coders I have seen; his code is
clean, functional, and very object-oriented, thus you will begin learning
good habits from day 1 rather than bad ones which can kill you when
creating games that easily near the 1 million line mark these days
So without further ado, get your compiler set up, open this book wide,
and take your time reading and exploring for I really do envy the journey
that you’re about to go on Learning game programming was probably
one of the most interesting and exciting times of my life, and I can only
expect you will have just as much fun or more — since when I learned I
was getting excited with 4 colors and 8 × 8 bitmaps!!!
Sincerely,
André LaMothe
Series Editor
CEO@xgames3d.com
Trang 35Istill remember my first trip to the arcades I was four years old, and my fathertook me to a local fair where I played a racing game I instantly fell in love withgames I wanted to play them; I wanted to design them
At the age of eight I started programming my old ZX Spectrum with 64KB of ory and an old tape player, and I had fun like I never had before
mem-It wasn’t until the age of 13 that I seriously started programming games Readinganything I could get my hands on about programming, I managed to do some VGA (if you are young, you probably don’t know what VGA is) games in Pascal andevolved from there
When I first logged on to the Internet, in 1995, if I’m not mistaken, I found awhole new world Among other things, it housed a collection of sites about gameprogramming with enough information to last a lifetime I was amazed
Today, I do remote programming from Portugal (when will someone put some bucks
on the table and start a game company here?) and work on tools for programmers.I’ve also decided to go to college to pursue a Mathematics and Computer Sciencedegree at the Universidade do Minho here in Portugal I hope I can finish it.This book is a collection of my own experiments during these last years I hope itwill help you get started as a game programmer But don’t finish this book and stopthere; there are loads of other good books and sites you should read to continueyour career This book is just the tip of the iceberg
I’ve created an Internet site for this book where I include errata, updated source
code, and more information regarding this book You can visit it at http://gpaione kyuumu.com.
Also, don’t hesitate to e-mail me (bsousa@kyuumu.com) if you have any questions
about the book, the source code on the CD, or just general questions about gamedevelopment Of course, if you just finished your game and want someone to play
it, don’t forget to send me an e-mail so I can try it
Also, if you want a live chat, you can probably find me in GameDev’s IRC channel
(http://www.gamedev.net/) Just ask for Akura.
Trang 36What You Are Going to Learn
This is an ambitious book; it covers all the elements to get you started in ing your own games, including:
develop-■ The basics of C++ programming
■ C++ techniques and practices
■ Windows programming
■ The DirectX 8.0 API
■ Game programming techniques
And a little more
How This Book Is Organized
This book is divided into four parts Each relies on the preceding part to explainthe concepts If you already know C++ programming, you can just skim through thefirst part and move to Parts 2 and 3, but if you are a beginner, I suggest you readthis book linearly, from start to finish
Part 1 covers C++ programming You will learn the basics and the most importantaspects of C++ programming, such as text input and output, file manipulation, andpointers You will also develop two simple text games
Part 2 explains Windows programming and DirectX It covers the basics to get yourWindows application running and covers in detail the three main components ofDirectX: DirectXGraphics, DirectSound, and DirectInput In this part, you will
build Mirus, the game library you will be using in this book
In Part 3, you will see many game programming related fields, such as ics, physics, and artificial intelligence You finish this part by building a breakouttype of game
mathemat-Part 4 contains the appendixes, where you can find information about using the
CD-ROM, the debugging application, the chapter exercises’ answers, and some erences you may want to check while you read the book
ref-Don’t forget to check out the CD; it contains loads of cool tools and all the sourcecode included in the book (which should save you a lot of time) You will need yourown copy of Microsoft Visual C++ to compile the source code from the CD-ROM
xxxvii
Introduction
Trang 37This page intentionally left blank
Trang 38PART ONE
C++
Programming
Trang 391 Introduction to C++ Programming
2 Variables and Operators
3 Functions and Program Flow
4 Multiple Files and the Preprocessor
5 Arrays, Pointers, and Strings
Trang 40CHAPTER 1
Introduction
to C++ Programming