- Page 4:
This page intentionally left blank
- Page 8:
© 2004 by Thomson Course Technolog
- Page 12:
AcknowledgmentsAbook of this size i
- Page 16:
Contents at a GlanceIntroduction .
- Page 20:
ContentsIntroduction . . . . . . .
- Page 24:
xiiContentsChapter 4 Writing Your F
- Page 28:
xivContentsStory . . . . . . . . .
- Page 32:
xviContentsChapter 10 Programming T
- Page 36:
xviiiContentsSummary . . . . . . .
- Page 40:
xxContentsChapter 18 Introduction t
- Page 44:
xxiiContentsChapter 5 . . . . . . .
- Page 48:
This page intentionally left blank
- Page 52:
xxviIntroductionCross-Platform Game
- Page 56:
xxviiiIntroductionsource code. When
- Page 60:
xxxIntroduction■■■Part II: 2D
- Page 64:
Welcome to Part I of Game Programmi
- Page 68:
4Chapter 1 ■Demystifying Game Dev
- Page 72:
6Chapter 1 ■Demystifying Game Dev
- Page 76:
8Chapter 1 ■Demystifying Game Dev
- Page 80:
10Chapter 1 ■Demystifying Game De
- Page 84:
12Chapter 1 ■Demystifying Game De
- Page 88:
14Chapter 1 ■Demystifying Game De
- Page 92:
16Chapter 1 ■Demystifying Game De
- Page 96:
18Chapter 1 ■Demystifying Game De
- Page 100:
20Chapter 1 ■Demystifying Game De
- Page 104:
22Chapter 1 ■Demystifying Game De
- Page 108:
24Chapter 1 ■Demystifying Game De
- Page 112:
26Chapter 1 ■Demystifying Game De
- Page 116:
28Chapter 1 ■Demystifying Game De
- Page 120:
30Chapter 1 ■Demystifying Game De
- Page 124:
32Chapter 1 ■Demystifying Game De
- Page 128:
34Chapter 2 ■Getting Started with
- Page 132: 36Chapter 2 ■Getting Started with
- Page 136: 38Chapter 2 ■Getting Started with
- Page 140: 40Chapter 2 ■Getting Started with
- Page 144: 42Chapter 2 ■Getting Started with
- Page 148: 44Chapter 2 ■Getting Started with
- Page 152: 46Chapter 2 ■Getting Started with
- Page 156: 48Chapter 2 ■Getting Started with
- Page 160: 50Chapter 2 ■Getting Started with
- Page 164: 52Chapter 2 ■Getting Started with
- Page 168: 54Chapter 2 ■Getting Started with
- Page 172: 56Chapter 2 ■Getting Started with
- Page 176: 58Chapter 2 ■Getting Started with
- Page 180: 60Chapter 2 ■Getting Started with
- Page 186: Gaining More Experience with Allegr
- Page 190: Gaining More Experience with Allegr
- Page 194: Gaining More Experience with Allegr
- Page 198: Chapter Quiz 695. What is the name
- Page 202: chapter 3Basic 2D GraphicsProgrammi
- Page 206: Introduction 73Figure 3.2 A typical
- Page 210: Graphics Fundamentals 75smallest un
- Page 214: Graphics Fundamentals 77The next tw
- Page 218: Graphics Fundamentals 79The last fu
- Page 222: Graphics Fundamentals 81char *filen
- Page 226: Drawing Graphics Primitives 83Figur
- Page 230: Drawing Graphics Primitives 85Figur
- Page 234:
Drawing Graphics Primitives 87color
- Page 238:
Drawing Graphics Primitives 89Figur
- Page 242:
Drawing Graphics Primitives 91x2 =
- Page 246:
Drawing Graphics Primitives 93Figur
- Page 250:
Drawing Graphics Primitives 95green
- Page 254:
Drawing Graphics Primitives 97Figur
- Page 258:
Drawing Graphics Primitives 99#incl
- Page 262:
Drawing Graphics Primitives 101//wa
- Page 266:
Drawing Graphics Primitives 103Draw
- Page 270:
Drawing Graphics Primitives 105//mo
- Page 274:
Drawing Graphics Primitives 107Figu
- Page 278:
Drawing Graphics Primitives 109//dr
- Page 282:
Drawing Graphics Primitives 111}//d
- Page 286:
Printing Text on the Screen 113This
- Page 290:
Summary 115#include int main(){//in
- Page 294:
Chapter Quiz 1176. What function is
- Page 298:
chapter 4Writing Your FirstAllegro
- Page 302:
Tank War 121Figure 4.2 The tanks ar
- Page 306:
Tank War 123If that color is anythi
- Page 310:
Tank War 125}}//print the bullet’
- Page 314:
Tank War 127for your favorite compi
- Page 318:
Tank War 129///////////////////////
- Page 322:
Tank War 131}break;case 2:tanks[num
- Page 326:
Tank War 133//draw bulletx = bullet
- Page 330:
Tank War 135break;}}//check pixels
- Page 334:
Tank War 137///////////////////////
- Page 338:
Tank War 139}//player 2tanks[1].x =
- Page 342:
Tank War 141//update the bulletsupd
- Page 346:
Chapter Quiz 1437. What function in
- Page 350:
chapter 5Programming theKeyboard, M
- Page 354:
Handling Keyboard Input 147When you
- Page 358:
Handling Keyboard Input 149Figure 5
- Page 362:
Handling Keyboard Input 151//displa
- Page 366:
Handling Keyboard Input 153This int
- Page 370:
Handling Mouse Input 155int k, x, y
- Page 374:
Handling Mouse Input 157Detecting M
- Page 378:
Handling Mouse Input 159Figure 5.5
- Page 382:
Handling Mouse Input 161int destroy
- Page 386:
Handling Mouse Input 163}//show mou
- Page 390:
Handling Mouse Input 165Setting the
- Page 394:
Handling Mouse Input 167Limiting Mo
- Page 398:
Handling Mouse Input 169{int n, col
- Page 402:
Handling Joystick Input 171extern i
- Page 406:
Handling Joystick Input 173type of
- Page 410:
Handling Joystick Input 175The fina
- Page 414:
Handling Joystick Input 177}//displ
- Page 418:
Handling Joystick Input 179#include
- Page 422:
Handling Joystick Input 181//store
- Page 426:
Chapter Quiz 183Chapter QuizYou can
- Page 430:
PART II2D Game Theory, Design,and P
- Page 434:
chapter 6Introduction toGame Design
- Page 438:
Game Design Basics 189Feasibility i
- Page 442:
Game Design Basics 191One of my fav
- Page 446:
Game Design Basics 193Galactic Conq
- Page 450:
Game Development Phases 195Space Si
- Page 454:
Game Development Phases 197However,
- Page 458:
Post-Production 199Official Release
- Page 462:
Post-Production 201Unreal was devel
- Page 466:
Future-Proof Design 203But now you
- Page 470:
The Dreaded Design Document 205idea
- Page 474:
A Sample Design Document Template 2
- Page 478:
A Sample Game Design: Space Invader
- Page 482:
A Sample Game Design: Space Invader
- Page 486:
Chapter Quiz 2132. What types of ga
- Page 490:
chapter 7Basic BitmapHandling and B
- Page 494:
Dealing with Bitmaps 217The blit fu
- Page 498:
Dealing with Bitmaps 219GFX_VTABLE
- Page 502:
Dealing with Bitmaps 221and by movi
- Page 506:
Dealing with Bitmaps 223will return
- Page 510:
Dealing with Bitmaps 225I think 24-
- Page 514:
Blitting Functions 227Saving a Scre
- Page 518:
Enhancing Tank War—From Graphics
- Page 522:
Enhancing Tank War—From Graphics
- Page 526:
Enhancing Tank War—From Graphics
- Page 530:
Chapter Quiz 2352. What is a DHD?A.
- Page 534:
chapter 8Basic Sprite Programming:D
- Page 538:
Basic Sprite Handling 239The most i
- Page 542:
Basic Sprite Handling 241Figure 8.2
- Page 546:
Basic Sprite Handling 243#include #
- Page 550:
Basic Sprite Handling 245Figure 8.6
- Page 554:
Basic Sprite Handling 247Table 8.1
- Page 558:
Basic Sprite Handling 249Figure 8.9
- Page 562:
Basic Sprite Handling 251set_gfx_mo
- Page 566:
Basic Sprite Handling 253keys to ad
- Page 570:
Basic Sprite Handling 255}}if (pivo
- Page 574:
Basic Sprite Handling 257Figure 8.1
- Page 578:
Enhancing Tank War259sprite around
- Page 582:
Enhancing Tank War 261New TanksNow
- Page 586:
Enhancing Tank War 263//define some
- Page 590:
Enhancing Tank War 265{}int x = tan
- Page 594:
Enhancing Tank War 267}explode_bmp
- Page 598:
Enhancing Tank War 269}bullet_bmp =
- Page 602:
Enhancing Tank War 271/////////////
- Page 606:
Enhancing Tank War 273void setuptan
- Page 610:
Enhancing Tank War 275allegro_init(
- Page 614:
Chapter Quiz 2775. Which function d
- Page 618:
chapter 9Advanced SpriteProgramming
- Page 622:
Animated Sprites 281Figure 9.2 The
- Page 626:
Animated Sprites 283}rest(10);retur
- Page 630:
Animated Sprites 285Now that we hav
- Page 634:
Animated Sprites 287Figure 9.4 The
- Page 638:
Animated Sprites 289//simple screen
- Page 642:
Animated Sprites 291ball->x, ball->
- Page 646:
Animated Sprites 293The SpriteGrabb
- Page 650:
Animated Sprites 295}//update frame
- Page 654:
Animated Sprites 297//initialize th
- Page 658:
Animated Sprites 299}sprites[n]->yd
- Page 662:
Animated Sprites 301updatesprite(sp
- Page 666:
Animated Sprites 303}}if (—spr->c
- Page 670:
Animated Sprites 305}destroy_bitmap
- Page 674:
Run-Length Encoded Sprites 307Creat
- Page 678:
Run-Length Encoded Sprites 309The a
- Page 682:
Run-Length Encoded Sprites 311}spr-
- Page 686:
Compiled Sprites 313dragon->animdir
- Page 690:
Compiled Sprites 315The bitmap in t
- Page 694:
Collision Detection 317There is one
- Page 698:
The CollisionTest Program 319I have
- Page 702:
The CollisionTest Program 321int in
- Page 706:
The CollisionTest Program 323void m
- Page 710:
Enhancing Tank War 325you’ll foll
- Page 714:
Enhancing Tank War 327}void eraseta
- Page 718:
Enhancing Tank War 329}explode_bmp
- Page 722:
fire bullet in direction tank is fa
- Page 726:
Enhancing Tank War 333void turnrigh
- Page 730:
Enhancing Tank War 335//load bullet
- Page 734:
Chapter Quiz 337important points we
- Page 738:
chapter 10ProgrammingTile-Based Bac
- Page 742:
A Limited View of the World 341scro
- Page 746:
A Limited View of the World 343note
- Page 750:
Introduction to Tile-Based Backgrou
- Page 754:
Introduction to Tile-Based Backgrou
- Page 758:
Introduction to Tile-Based Backgrou
- Page 762:
Introduction to Tile-Based Backgrou
- Page 766:
Introduction to Tile-Based Backgrou
- Page 770:
Enhancing Tank War 355{}for (tilex=
- Page 774:
Enhancing Tank War 357Figure 10.11
- Page 778:
Enhancing Tank War 359Figure 10.15
- Page 782:
Enhancing Tank War 361{//new elemen
- Page 786:
Enhancing Tank War 363{}explode_bmp
- Page 790:
Enhancing Tank War 365}}//draw expl
- Page 794:
Enhancing Tank War 367/////////////
- Page 798:
Enhancing Tank War 369#include “t
- Page 802:
Enhancing Tank War 371{}tank_bmp[0]
- Page 806:
Enhancing Tank War 373}}blit(grabfr
- Page 810:
Enhancing Tank War 375int map[MAPW*
- Page 814:
Enhancing Tank War377//draw scrolli
- Page 818:
Chapter Quiz 3792. What does a scro
- Page 822:
chapter 11Timers, InterruptHandlers
- Page 826:
Timers 383The rest1 callback functi
- Page 830:
Timers 385void updatesprite(SPRITE
- Page 834:
Timers 387sprites[0]->x = 500;sprit
- Page 838:
Timers 389sprites[3]->animdir = 1;/
- Page 842:
Timers 391//update the spritesfor (
- Page 846:
Interrupt Handlers 393Not all opera
- Page 850:
Using Timed Game Loops 395//update
- Page 854:
Multi-Threading 397framerate = tick
- Page 858:
Multi-Threading 399Math-intensive p
- Page 862:
Multi-Threading 401Creating a New T
- Page 866:
Multi-Threading 403You must destroy
- Page 870:
Multi-Threading 405Figure 11.5 Addi
- Page 874:
Multi-Threading 407}}spr->framecoun
- Page 878:
Multi-Threading 409}}balls[n]->fram
- Page 882:
Multi-Threading 411//erase sprite 1
- Page 886:
Enhancing Tank War 413//unlock the
- Page 890:
Enhancing Tank War 415Figure 11.8 T
- Page 894:
Enhancing Tank War 417draw_sprite(b
- Page 898:
Enhancing Tank War 419}{scrolly[num
- Page 902:
Enhancing Tank War 421//load second
- Page 906:
Enhancing Tank War 423}}}else{explo
- Page 910:
Enhancing Tank War 425textprintf(bu
- Page 914:
Chapter Quiz 4271. Why is it import
- Page 918:
chapter 12Creating a GameWorld: Edi
- Page 922:
Creating the Game World 431Figure 1
- Page 926:
Creating the Game World 433Figure 1
- Page 930:
Creating the Game World435I’ll sh
- Page 934:
Loading and Drawing Mappy Level Fil
- Page 938:
Loading and Drawing Mappy Level Fil
- Page 942:
Loading and Drawing Mappy Level Fil
- Page 946:
Loading and Drawing Mappy Level Fil
- Page 950:
Enhancing Tank War 445yoffset-=4;if
- Page 954:
Enhancing Tank War 447Figure 12.14
- Page 958:
Enhancing Tank War 449if (scroll ==
- Page 962:
Enhancing Tank War 451{}scrollx[num
- Page 966:
Chapter Quiz 453Only one more chang
- Page 970:
chapter 13Vertical ScrollingArcade
- Page 974:
Building a Vertical Scroller Engine
- Page 978:
Building a Vertical Scroller Engine
- Page 982:
Building a Vertical Scroller Engine
- Page 986:
Building a Vertical Scroller Engine
- Page 990:
Writing a Vertical Scrolling Shoote
- Page 994:
Writing a Vertical Scrolling Shoote
- Page 998:
Writing a Vertical Scrolling Shoote
- Page 1002:
Writing a Vertical Scrolling Shoote
- Page 1006:
Writing a Vertical Scrolling Shoote
- Page 1010:
Writing a Vertical Scrolling Shoote
- Page 1014:
Writing a Vertical Scrolling Shoote
- Page 1018:
Writing a Vertical Scrolling Shoote
- Page 1022:
Writing a Vertical Scrolling Shoote
- Page 1026:
Writing a Vertical Scrolling Shoote
- Page 1030:
Writing a Vertical Scrolling Shoote
- Page 1034:
Chapter Quiz 487SummaryVertical scr
- Page 1038:
chapter 14Horizontal ScrollingPlatf
- Page 1042:
Creating Horizontal Platform Levels
- Page 1046:
Creating Horizontal Platform Levels
- Page 1050:
Creating Horizontal Platform Levels
- Page 1054:
Creating Horizontal Platform Levels
- Page 1058:
Developing a Scrolling Platform Gam
- Page 1062:
Developing a Scrolling Platform Gam
- Page 1066:
Developing a Scrolling Platform Gam
- Page 1070:
Developing a Scrolling Platform Gam
- Page 1074:
Chapter Quiz 507Chapter QuizYou can
- Page 1078:
PART IIITaking it to theNext LevelC
- Page 1082:
chapter 15Mastering the AudibleReal
- Page 1086:
The PlayWave Program 513//initializ
- Page 1090:
Sound Initialization Routines 515wh
- Page 1094:
Standard Sample Playback Routines 5
- Page 1098:
Low-Level Sample Playback Routines
- Page 1102:
Low-Level Sample Playback Routines
- Page 1106:
The SampleMixer Program 523Figure 1
- Page 1110:
Enhancing Tank War525destroy_sample
- Page 1114:
Enhancing Tank War 527if (install_s
- Page 1118:
Enhancing Tank War 529Now scroll do
- Page 1122:
Enhancing Tank War 531}}//player 2
- Page 1126:
Enhancing Tank War 533{key_count[nu
- Page 1130:
Enhancing Tank War 535}return;//set
- Page 1134:
Chapter Quiz 537SummaryThis chapter
- Page 1138:
chapter 16Using Datafiles toStore G
- Page 1142:
Creating Allegro Datafiles 541If yo
- Page 1146:
Creating Allegro Datafiles 543dat -
- Page 1150:
Testing Allegro Datafiles 545noteIf
- Page 1154:
Testing Allegro Datafiles 547//init
- Page 1158:
Chapter Quiz 5497. What is the data
- Page 1162:
chapter 17Playing FLIC MoviesFLI is
- Page 1166:
Playing FLI Animation Files 553Figu
- Page 1170:
Loading FLIs into Memory 555Opening
- Page 1174:
Loading FLIs into Memory 557Figure
- Page 1178:
Loading FLIs into Memory 559Figure
- Page 1182:
Chapter Quiz 561SummaryThis chapter
- Page 1186:
chapter 18Introduction toArtificial
- Page 1190:
The Fields of Artificial Intelligen
- Page 1194:
The Fields of Artificial Intelligen
- Page 1198:
The Fields of Artificial Intelligen
- Page 1202:
Deterministic Algorithms 571Random
- Page 1206:
Deterministic Algorithms573kDistanc
- Page 1210:
Finite State Machines 575GuardPatte
- Page 1214:
Fuzzy Logic 577}// State 4if (Dista
- Page 1218:
Fuzzy Logic 579You can also see tha
- Page 1222:
Summary 581You can use this method
- Page 1226:
Chapter Quiz 5836. Which type of in
- Page 1230:
chapter 19The MathematicalSide of G
- Page 1234:
Trigonometry 587Equation 19.1Equati
- Page 1238:
Trigonometry 589What is the differe
- Page 1242:
Vectors591Figure 19.4 A 2D vectorco
- Page 1246:
Vectors 593Equation 19.16noteIn Fig
- Page 1250:
Vectors 595a length of 1.0, you mus
- Page 1254:
Vectors 597Equation 19.23Equation 1
- Page 1258:
Matrices599Equation 19.28Equation 1
- Page 1262:
Matrices 601Equation 19.34Matrix Co
- Page 1266:
Probability 603ProbabilityProbabili
- Page 1270:
Functions 605Figure 19.10 Intersect
- Page 1274:
Functions 607How do you know the in
- Page 1278:
Chapter Quiz 6095. Which C function
- Page 1282:
chapter 20Publishing Your GameYou h
- Page 1286:
Whose Door to Knock On 613If you ha
- Page 1290:
Milestones 615is to run the contrac
- Page 1294:
Interviews 617Q: What was it like h
- Page 1298:
Interviews 619A: I’ve been told t
- Page 1302:
Interviews 621California and took a
- Page 1306:
Interviews 623very easy to learn an
- Page 1310:
Summary 625Q: From a developer’s
- Page 1314:
Chapter Quiz 6274. What is an impor
- Page 1318:
EpilogueItend to say this each time
- Page 1322:
PART IVAppendixesAppendix AChapter
- Page 1326:
Appendix AChapter QuizAnswersChapte
- Page 1330:
Chapter 4 635Chapter 31. What is th
- Page 1334:
Chapter 6 6376. Which function is u
- Page 1338:
Chapter 9 639Chapter 81. What is th
- Page 1342:
Chapter 11 6415. Which process uses
- Page 1346:
Chapter 14 643Chapter 131. In which
- Page 1350:
Chapter 16 6455. What function woul
- Page 1354:
Chapter 18 647Chapter 181. Which of
- Page 1358:
Chapter 20 6493. What is the second
- Page 1362:
Appendix BUseful TablesThis appendi
- Page 1366:
ASCII Table 653ASCII TableThis is a
- Page 1370:
Char Value Char Value Char ValueASC
- Page 1374:
Appendix CNumbering Systems:Binary
- Page 1378:
Hexadecimal 659Using this table you
- Page 1382:
Hexidecimal 661Table C.4 Hexadecima
- Page 1386:
Appendix DRecommended Booksand Web
- Page 1390:
Recommended Books 665Samu Games: ht
- Page 1394:
Recommended Books 667C++ Programmin
- Page 1398:
Recommended Books 669Programming Ro
- Page 1402:
Appendix EConfiguring Allegrofor Mi
- Page 1406:
Microsoft Visual C++ 673Figure E.2
- Page 1410:
Dev-C++ 675dx80_mgw.zip to C:\Dev-C
- Page 1414:
Dev-C++ 677If you choose to create
- Page 1418:
KDevelop for Linux 679That’s all
- Page 1422:
KDevelop for Linux 681Figure E.10 S
- Page 1426:
Final Comments 683Returning to the
- Page 1430:
Appendix FCompiling theAllegro Sour
- Page 1434:
Borland C++/C++Builder 687That is f
- Page 1438:
KDevelop for LinuxI’m going to ha
- Page 1442:
Appendix GUsing the CD-ROMThe CD th
- Page 1446:
INDEXNumbers1942, 4552D games marke
- Page 1450:
Index 695book, thisartwork, 353goal
- Page 1454:
Index 697DDR graphics, 73-74debuggi
- Page 1458:
Index 699game designbackups, 189-19
- Page 1462:
Index 701Tank War, 229-334transpare
- Page 1466:
Index 703keyboard_needs_poll functi
- Page 1470:
Index 705non-disclosure agreements
- Page 1474:
Index 707random motion deterministi
- Page 1478:
Index 709hyperspace program, 165-16
- Page 1482:
Index 711tankscreating, 120-122movi
- Page 1486:
GNU GENERAL PUBLIC LICENSEVersion 2
- Page 1490:
These requirements apply to the mod
- Page 1494:
8. If the distribution and/or use o
- Page 1498:
License Agreement/Notice of Limited