Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

Chapter 1: Game Programming Basics

This chapter introduces the basics of game programming by exploring the subject from several viewpoints and taking you on a short jaunt through the history of the game industry. Then, I will explain the relationship between Visual Basic and DirectX, and how you can use them to write your own high-performance games. Finally, the chapter explains how the Visual Basic Game Library (which is developed in later chapters) will make game programming simple and fun.

Welcome!

Welcome to the fascinating world of Visual Basic Game Programming with DirectX! Game programming is a rewarding career, an enjoyable hobby, and an entertaining pastime for many people. The primary goal of this chapter is to introduce the subject of game programming and provide you with a little insight into what this book is about. As your host, I will take you through the first chapter of the adventure that will challenge your assumptions about Visual Basic and teach you how to write exciting, high-quality games.

Visual Basic Games

Visual Basic is a truly awesome programming language that is fully capable of supporting game development. Visual Basic has proven itself as a multi-purpose language that millions of programmers worldwide use on a daily basis. What many people overlook, however, is that Visual Basic is also a capable language for writing cutting-edge games.

Visual Basic is far too often dismissed as a serious language for game programming, but this assumption comes from lack of experience and lack of in-depth knowledge of the language. In my experience, poor performance in Visual Basic programs comes primarily from poorly written code! For this reason, I have dedicated two chapters to the subject of optimization: Chapter 4, "Getting to Know the Windows API" and Chapter 5, "Optimizing Visual Basic with Objects." I want to convince you that Visual Basic is an awesome language that is great for writing games! I will prove this to you using sound arguments, as well as actual benchmarks that compare different methods of drawing figures and bitmap images.

A Glimpse at DirectX

This book is heavily involved with DirectX programming from the start. In fact, as the title suggests, DirectX will be the core of most of the code in the book. I will touch upon the subject in this chapter and the next few chapters, and you will have an opportunity to write your first DirectX program in Chapter 6, "Supercharging Visual Basic with DirectX."

Since DirectX is the backbone of this book, I will show you how to get the most out of it using Visual Basic. But first things first! Before jumping into full-blown DirectX programming, I will start at the beginning and teach you some graphics programming with Visual Basic, followed by more advanced features in the Windows API. There are a few things you need to learn before you jump into DirectX.

I will start with intrinsic Visual Basic graphics code, and then add some punch with some really awesome Windows API functions that allow you to get under the hood, so to speak. After you have learned everything you need to know to write a complete game without DirectX, I will then show you how to do the same thing with DirectX.

I like to compare it to taking a walk to the park. There is so much to see, so many sounds, faces, nature, and landmarks to enjoy. When you jump into a car and drive to the park, it is fast and comfortable, but you miss something along the way. Likewise, there is a certain amount of enjoyment to be had from manipulating pixels on the screen without any help from a library like DirectX. Besides, software evolves quickly, so it is a good idea to understand how things work behind the scenes.

Game Programming Topics

If you are reading this as a complete novice who has never written a game before, you will not have any problem with DirectX programming. This book starts at the very beginning!

Visual Basic Game Programming with DirectX is the book on game programming with Visual Basic, covering not only the basics (such as drawing sprites with Windows API functions), but also the advanced subjects (like DirectDraw and Direct3D). DirectX is used almost exclusively by professional game developers today, because it has the complete support of the hardware industry (the companies that make sound cards and video cards, for instance). DirectX is fully supported in Visual Basic. This book makes the most of it, and you should have no problem developing full-blown DirectX games in a short time

What is a Video Game?

Okay, here's a simple question: What is a computer game?

A computer game or video game is a program written in a programming language, such as C++ or Visual Basic, that allows a player to interact with and respond to events in an imaginary world. The goal of a video game is usually to compete with other players in a cooperative or adversarial competition (or to play solo), with an emphasis on setting the high score or completing the game.

Why Do We Play Video Games?

Video games are fun because they are very good at simulating another world and drawing the player into that world. Video games are excellent for developing keen hand-eye coordination and problem-solving skills through the achievement of goals with specific rewards. Often the completion of the game alone is reward enough, but many games do not have a specific solution. Rather, some games are suited for pitting two or more friends against each other, either at the same time or in turn. Other games are pointless and endless and continue playing in a never-ending loop, while continually increasing the difficulty until the player can no longer play.

Competition is not a bad thing. On the contrary, competition helps people to develop the skills they need to work with others and strive to better themselves.

Video games are fascinating works of art (yes, art!) that reflect the wild imaginings of a game designer. As such, game designers are like painters with a virtual canvas, capable of transporting someone to another world. The most exciting games are those with endless replay value, since consumers have made it clear that no amount of graphical wizardry can make up for mediocre gameplay. Once a game has achieved a minimum acceptable standard on the visual and audio level, players expect the game to entertain through a gripping story or fantastic goal. Once in a while, a rare game comes along that achieves both visual wizardry and fantastic gameplay. HALO: Combat Evolved is one such game, developed by Bungie for the Microsoft Xbox. The physics and environment are so realistic that it makes the game seem to come alive.

 

Tip

Video games are excellent for developing keen hand-eye coordination and problem-solving skills through the achievement of goals with specific rewards.

The Game Engine

Every game, from the simplest card game to the most complicated 3-D first-person shooter game, has what is called a game engine. The game engine, shown in Figure 1.1, is the core set of routines that are executed repeatedly in a main animation loop. Such routines include displaying images on the screen, playing sound effects, and handling user input.

 

Figure 1.1: Games are made up of source code that is best organized in a game library (or game engine).

Of course, this is a simplified definition, as a large percentage of games (and the engines that power them) are written completely from scratch.

The best-developed games showcase the game engine, which is of more interest than the game itself. Games such as Quake III Arena and Unreal Tournament feature an engine that is licensed to other game developers who may not have the time, willingness, or ability to develop a comparable game engine on their own. Licensing a game engine is an excellent way to allow a game designer to focus on the aspects of gameplay and story, rather than spending that valuable time developing the technology for the game. Figure 1.2 illustrates the concept of licensing the game engine from one game to another.

 

Figure 1.2: The Quake III engine powers numerous games, including Voyager Elite Force.

Another reason why a development team might license software technology rather than develop it is the amount of time involved in creating an advanced 3-D engine. Most games are developed quickly, compared to the time involved in creating the engine itself. For this reason, a development company is usually able to recoup some of the costs for development by licensing the technology to others. It is a win-win situation for many.

 

Note

The game engine is the core set of routines that are executed repeatedly in the main loop, including displaying images on the screen, playing sound effects, and handling user input.

Game Graphics

In the old days, all games used two-dimensional images called sprites. The source image for a sprite usually has a background color that is defined as the transparent color-a pixel color that is not displayed when the sprite is drawn on the screen, allowing anything in the background to show through.

Most games developed today run entirely in 3-D and feature three-dimensional objects throughout the game world, rather than simple sprites. Both PC and console games have made the transition to 3-D, although consoles seem to be a step behind PC graphics technology. This was not the case in past generations of console video games. In the past, most consoles set the standards for graphics and immersion. Now it seems that console manufacturers are building video game machines that are more like PCs, with multiplayer options.

The Microsoft Xbox console is a prime example of this manufacturing. Featuring a high-end Pentium III CPU (Central Processing Unit), a custom Nvidia GPU (Graphics Processing Unit) that is based on the GeForce 3 chip, and a 256-channel DSP (Digital Signal Processor), this console is bristling with PC technology. Xbox will forever change the console industry by combining the best of both worlds into a single $299 unit. Figure 1.3 illustrates the three primary processors in a computer system and the functions they perform in a game.

 

Figure 1.3: The CPU, GPU, and DSP chips handle most of the functionality in a game.

This book uses several techniques to display graphics on the screen. Starting with intrinsic Visual Basic graphics functions, you will be introduced to Windows API functions that display graphics objects. You will dig into DirectDraw through the DirectX 7.0 library, followed by DirectX Graphics with the DirectX 8.0 library. However, as I have mentioned before, I will show you how to write graphics code the hard way before you jump into DirectX full speed.

 

Buzzword

A sprite is a small image that may or may not be animated, with properties that define how it will move around on the screen.

Sound Effects and Music

Sound is quite often more important than the graphics in a game. It is clear that we humans interact primarily through speech and sound. It should, therefore, be no surprise that sound is a vital part of every game. A game without sound might be acceptable on a fancy cell phone or wristwatch, but on any serious game hardware, sound is a major factor.

The development of a good sound effects library will be helpful when you select the sound effects for a new game. However, equally important is the source code that will play the sound files.

Getting Input

User input is always needed, no matter what type of game you are writing. After all, a game without user input is nothing more than a technology demo!

Visual Basic is capable of handling just about any type of input device that you can plug into your PC, including the newer USB (Universal Serial Bus) force-feedback joysticks and driving wheels. These topics will be explored in depth with coverage of DirectInput, the component of DirectX that handles input devices.

 

Buzzword

USB is a new type of high-speed communications port that is gradually replacing aging interfaces like serial ports, parallel ports, and joystick ports. IEEE 1394, or FireWire, is another high-speed port that is competing with USB and is capable of higher data transmission rates.

Artificial Intelligence

Computer-controlled players are needed for most types of games, and are absolutely essential for single-player games. Some multiplayer games, such as FPS (First-Person Shooter) games, do not always have computer-controlled players, and thus do not need AI (Artificial Intelligence) code. But the vast majority of games do-especially strategy games-so it is important to learn the tricks and techniques for simulating intelligence and challenging the player with competitive computer players. Some games use self-running mini programs called bots for the computer players. These bots are often programmable plug-ins for the game, which allows fans to develop their own AI players. Chapter 21, "Stellar War: Multiplayer Space Combat Game," includes a bot program that you can modify and run on the Stellar War server while playing the game.

Supporting Multiple Players

Nearly every game written today has multiplayer features that allow two or more players to compete or work cooperatively in the game. Most games also allow you to run your own game server on your PC and invite your friends to join your game over the Net. Since this is such a basic aspect of games today, it is important that you learn how to write multiplayer code and support networking in your own games. There is still a strong market for single-player games (such as the phenomenal game, Civilization III), but that market is dwindling as players flock to massively-multiplayer games like Operation Flashpoint.

One sub-genre is called MMORPG, which is short for "massively-multiplayer online role-playing game." These types of games were once only theoretical, until Ultima Online, EverQuest, and other large-scale games built an industry for themselves. These games usually require a monthly fee for access, because the developers are constantly improving and expanding the game and adding new worlds for the players to explore.

The online network created for Blizzard's games is called Battle.net, and is one of the most successful online game services in the industry-while remaining free for anyone who buys one of the supported games. Battle.net was created for the original Diablo and has been expanded to support all of Blizzard's games since, including StarCraft, Diablo II, and WarCraft III.

Rewriting Your Favorite Game

Since technology is such a large focus of game development today, with numerous game libraries and game engines available, it can be a bit overwhelming for someone who is trying to get his foot in the door. You probably have a favorite game and would like to recreate it with your own embellishments. That is exactly how I got started writing games! I was an avid fan of sci-fi games like space shoot-em-ups and space exploration games (before Master of Orion re-defined the genre), and I wanted to create my own Star Trek game that incorporated all of the best features of the best games.

Perfecting an Already-Perfect Game

Two of my all-time favorite games are Starflight and Star Control. These two games fascinated me more than any other. I loved the open-ended nature of Starflight, and I also loved the intense gaming action of Star Control. The sequels to these games were even better! Starflight II and Star Control II were filled with plenty of creativity and replay value. Today, the galactic conquest genre has dominated sci-fi games, due to modern gaming advancements like multiplayer Internet support and the popularity of RTS (Real-Time Strategy) games. Now there are massive games like Master of Orion II and Imperium Galactica II that have yet to be bested in the genre. But those two originals were more like adventure games, rather than galactic conquest games, with a personal element that drew players into the game.

Building Your Ultimate Game

Whatever your interest, it is a good idea to have a major game idea in the back of your mind as you read through this book. If you already have a favorite type of game that you would like to write, that's great! If you are starting out without a prototype game of your own design, you should try to come up with one soon. Having a game idea in your mind as you read this book will make the subjects and source code covered look like bright spots in your mind's eye, as you learn how to implement each part of your game. Numerous sample games in later chapters will give you the examples you need to write your own game.

None of that will be of much use unless you have a side project, a hobby of sorts, a vision of that game you have always dreamed of writing. The important thing will not be whether the game lives up to your stratospheric expectations; the only thing that matters is that you finish writing the game.

The games in this book come from my own imagination, which is largely influenced by factors in my life, such as the books I read and the movies I watch. The sample games were inspired by my experience as a gamer, so I'm pretty sure that these games are fun. However, you might disagree, since everyone has different opinions and assumptions. For this reason, having your own game project in mind will be very helpful.

 

Note

Starflight III is in the works, with support from the authors of the original game. Take a look at http://www.starflight3.net for more information.

Making Your Game Ideas into Reality

You must apply the technology in this book to make your ideas a reality. The technology alone-such as the game library developed in this book-is not sufficient to create a game. Anyone, even RPG II and Cobol database programmers, can write a game. (I should know, since I have worked on large corporate databases.)

The difference between a run-of-the-mill card game and a new genre buster is an ephemeral quality which comes from the magical part of your mind that is capable of leaping beyond facts and working intuitively. Grasp that part of your inner being and you will build something masterful.

What Makes a Game Tick?

You might be wondering, what exactly makes a game tick? What is inside a game that makes it run, display the graphics, play the sounds, and interact with the player? It is difficult to answer those questions without a basic understanding of game architecture.

While you may or may not understand these steps at this point, I would like to show you how a game runs. Here are the basic steps that are processed during the run of a typical game:

1. Display the title screen.

2. Load the sprites and sounds.

3. Create a double buffer.

4. Display a static or rendered background image.

5. Save the image under each sprite.

6. Erase all sprites from the double buffer.

7. Check for user input and update the player's position.

8. Process enemy positions using A.I.

9. Move each sprite to the new location.

10. Check for collisions between the sprites.

11. Increment the animation frame for each sprite.

12. Draw all sprites to the double buffer.

13. Quickly transfer the double buffer to the screen.

14. Loop back to Step 5.

15. Delete all game objects and free memory.

16. End the game.

Although the details of each step are not displayed, this is a pretty good list of activities that occur while a game is running. Since I don't want to get into the habit of listing pseudo-code (which I have always felt was redundant), I will just explain what each step does.

Steps 1 through 4 are handled when the game first starts running. They initialize the game by loading all of the graphics, sounds, and setup of the game screen.

Steps 5 through 14 make up the game loop and are executed repeatedly while the game is running. These steps must run in order to display each frame in the game. Therefore, when you hear that some games run at 60 FPS (Frames Per Second), you must realize that a lot of work is being done during each frame. Too often, gamers will compare two or more games based solely on the frame rate. This is unfortunate, because some games do a lot more behind the scenes than others! Some games have far more intelligent computer players, while other games might run at twice the frame rate but have poor computer players.

Steps 15 and 16 are executed at the end of the game.

There are many more steps in an actual game, but this simplified list should give you a good idea how a game runs internally. The goal of a game library is to make these steps as simple as possible by handling the complicated details behind the scenes.

Video Games Versus Computer Games

The IBM PC was never meant to be a game machine, so I'm sure no one would disagree with the irony that today, most computer games run on descendants of the original IBM PC. In comparison to computer technology today, the original IBM PC and its clones were ridiculously primitive. It was only through sheer ingenious wizardry (with a dash of highly-optimized assembly language) that games were ever created for the PC at all.

While my friends were blasting aliens (with multi-channel digital sound and loads of color) on their Atari ST and Amiga 500 computers, I was pecking away at my PC, trying to make sense of the four colors available with my CGA video card and finding new ways to squeak something out of the PC speaker. So it is a wonder that the PC made it at all! Look at computers today-they are mind-boggling in complexity and power. It is absolutely amazing to think that a modern PC with a GeForce 3 card can crank out graphics in real-time that rival the digital artistry of feature films like Jurassic Park and The Phantom Menace.

How It All Started

The current generation of gamers, those who got into it in more recent times and have computers that come standard with 3-D graphics acceleration and 3-D positional sound, do not appreciate the old days with the same nostalgia that older gamers feel for games such as Starflight, Battlehawks 1942, Star Control, Archon, King's Quest, Power Monger, and Lode Runner. It is easy to take computer hardware for granted today, when it is so powerful and inexpensive!

For example, the original IBM PC came with 64k of RAM and one 360k floppy drive. The next version, the IBM PC/XT, had the option for a 5MB Winchester hard drive for several hundred dollars. Now, let's put this into perspective. The Intel Pentium III processor has a built-in instruction cache of 256k that keeps the processor from waiting for data to be loaded from memory (which is much slower than the processor). This cache is made up of more transistors than the entire 8086 processor at the core of the original IBM PC.

In the early days, before the Adlib or Sound Blaster cards, the IBM PC had only a simple internal speaker for making sounds. Early PC games had dreadful sound support, to put it mildly. Gamers were lucky to find a game with even rudimentary sound effects, and most commercial games (which were presumably cutting-edge) were even lacking.

In 1988, Access Software released an amazing game called Mean Streets. This futuristic action/adventure game featured standard VGA graphics (common in all PC games at the time). But what really made Mean Streets shine was the full-blown digital music and sound that permeated the game! Right from the start, the musical score for Mean Streets gave the player a taste of what to expect throughout the game. Each character in the game featured a real voice actor and limited video-capture sequences.

Access Software followed suit with Crime Wave and several follow-up games in the series. A few years after the release of Mean Streets and Crime Wave, sound cards like the Sound Blaster and Pro Audio Spectrum appeared on the market, and high-quality sound was finally possible on the PC.

Home Consoles

Home video game machines, also called consoles, have been around since the original Atari 2600. In the early 1980s, a Japanese coin-operated arcade game manufacturer called Nintendo came out with the Nintendo Entertainment System (NES) for homes. Nintendo had been building arcade machines (like Donkey Kong) for years. Nintendo's new console helped to invigorate the struggling video game industry at the time.

Arcade games and video games have led the pace in graphics and gameplay for many years. However, in recent years, PCs have actually surpassed arcade and video game machines. The line dividing computer games and video games is not as distinct as it was in the past. Now, games are ported from arcade to console, from PC to console, and vice versa. Development tools are also becoming more standardized as industry leaders strive for content. Software is more important than hardware, and the video game industry has finally figured out that gamers just want to play fun games, regardless of the platform. Dynamic, creative, and exciting new games that cross the barriers of game genres are the ones that sell.

 

Note

The Nvidia GeForce 3 chip, which accelerates 3-D games and features advanced transform and lighting (T&L) instructions, has over 40 million transistors, exceeding even the Pentium 4 processor in complexity.

Sega should also be credited for many advances in video game design, with three excellent home consoles: the Genesis, Saturn, and Dreamcast. These consoles greatly helped to keep the industry competitive with giants like Nintendo and Sony. Even in the midst of highly advanced consoles like the PlayStation 2, Microsoft Xbox, and Nintendo GameCube, the Sega Dreamcast is still very popular and an affordable alternative to comparable games. Sega might be out of the hardware business, but it is hardly out of the games business!

Gaming Hardware

There should be little difference in the hardware requirements for playing games and developing them. Game developers are often solely responsible for the massive hardware upgrades that take place with the release of awesome new games that push existing PCs into obsolescence. However, the games covered in this book will run on a modest PC without all of the latest and greatest hardware.

You can get away with much less, but here are the hardware specifications of the PC that I used while writing the sample programs in upcoming chapters. This is a baseline for the frame rates mentioned in the book:

* Mobile Pentium-850 Processor

* 512MB PC100 RAM

* 30GB 5400 RPM Hard Drive

* 32MB ATI Mobility M4 Graphics Chip

Notebooks: The New Gaming Rigs

Game development has now entered a new era in which notebook computers (also called laptops) are capable of running games that once required top-of-the-line desktop gaming machines.

Notebook computers once lagged behind desktop computers by several years, which is a lifetime in computing terms. However, miniaturization technology has developed some remarkable new devices at a scale that is simply staggering. The computer industry's continual price war has resulted in incredibly powerful desktop and notebook computers at the price range once reserved for the low-end budget market.

 

Note

Thanks to the marketing wizards at Intel, we now have about a dozen versions of the Pentium brand to keep track of. There are three different versions of the Pentium III alone! To make things easier from this point on, I am going to use the word Pentium to refer to the Pentium III, Celeron, and Pentium 4 processors. Similarly, I will use the word Athlon to refer to the various AMD Athlon and Duron processors.

Quite honestly, a modest sum will not only buy the absolute latest and greatest computer today, it will buy all of the accessories too! What is even more startling is that the same amount may be used to buy a notebook computer of comparable power. Even year-old computing technology was once considered grossly obsolete by high-end users (most notably, gamers). But today, the low-end budget PCs are capable of running some of the most advanced games. This state of affairs should keep game programmers employed for at least the next few years.

Instant LAN Party

LANs (Local Area Networks) were once only found in large businesses. As the technology improved and prices dropped, small- to medium-sized businesses were able to network their office computers together, as were savvy hobbyists at home. Today, a significant number of households have two or more computers with a high-speed Internet connection, and a home network just makes sense. The ability to share drive space, Internet connectivity, and printers is appealing to most people, and especially to gamers.

LAN parties are now common forms of entertainment around the world, as friends get together (usually at a site with a high-speed Internet line and a network router), toting their massive tower cases jammed full of every conceivable type of drive and accessory and gigantic 19" or 21" monitors (the only way to play, in the opinion of many). Now picture a newcomer with a lightweight notebook computer, featuring most of the same high-end features and accessories, in a leather case strapped to his shoulder, and you get an idea about how far the computer industry has come in recent years.

Wireless LAN Cards

Wireless networking is now a viable technology and may soon change the way networks are planned and configured. While past home and office networks required endless streams of CAT-5 cable, modern networks built with wireless network cards and hubs are definitely the wave of the future. There's nothing quite as much fun as playing games and browsing the Web with a laptop, while sitting on the back porch or on the living room couch-without a network cable. Leading technologies include the original 802.11, the faster 802.11b, HomeRF, and OpenAir. Proxim has an excellent wireless system that supports both HomeRF and OpenAir at a reasonable price, and they even have a new CompactFlash card available for portable devices like Pocket PCs.

This bodes well for gamers and makes the concept of the instant LAN party even more of a reality. In the near future, most systems will likely be wireless, including notebook and handheld computers. The only problem with wireless technology is a lack of security. Just about anyone can tap into a wireless network unimpeded. As with any new technology, this will have to be addressed in time, by adding more robust encryption to the myriad of signals traveling through the air.

3-D Acceleration to Go

Most new games today require 3-D acceleration in order to run, due to the intense graphics featured in these games. 3-D acceleration has only been available since about 1996, with the advent of the 3Dfx Voodoo card. However, 3-D acceleration is now available for the first time on notebook computers featuring the ATI Mobility and Nvidia GeForce2Go chips. These high-end graphics processors are capable of supporting nearly all of the latest games that normally would run only on high-end desktop systems.

The Impact of DirectX

DirectX is a significant development in the PC gaming world, and has been a successful library on consoles like the Dreamcast and Xbox as well (get it, "X" box?). The standardization that comes with DirectX has done much to further the computer game and video card industries.

When a company develops a new game that supports the latest version of DirectX, they are guaranteed that nearly every Windows PC will be able to run the game. Similarly, when a graphics card company invents a new graphics chip with new features, it is also guaranteed sales by providing DirectX drivers with the new graphics chip.

DirectX has helped the software and hardware sides of gaming come to terms, whereas in the past hardware and software have always been somewhat at odds. Today, with the latest version of DirectX, both hardware and software seem to be more consistent, with neither far ahead of the other. Years ago it was common for an awesome new game to compel gamers to upgrade their computers. Today, game developers are lucky if they are able to push the latest PC hardware to its limits. How things have changed!

Visual Basic Is a Cool Language!

The premise behind the use of Visual Basic for game development is the language's versatility. Visual Basic is capable of handling large database programs as well as advanced 3-D games. Not many programming languages can claim such a feat. Often, a language will be well-suited for a particular task. But now it is possible to use Visual Basic to do many things that once might have been spread across two or more languages. Many Web servers that once used Perl or C++ scripts now use VBScript, and many ASP (Active Server Pages) Web sites also use VBScript, because it is so easy to use and supports many different types of databases for Web development.

Power, Flexibility, Saturation, and Speed

Put simply, Visual Basic has the power to handle the most challenging computing tasks, including advanced 3-D games. It has the flexibility to handle a multitude of different tasks. Visual Basic now compiles native executable program files that run under Windows without an interpreter (as in previous versions, such as 4.0). Finally, Visual Basic is used by millions of programmers on a daily basis, which means that the language has saturated business and home users alike.

Visual Basic and DirectX in the Same Sentence?

It might seem odd for a C or C++ programmer to consider using Visual Basic to create DirectX games. After all, DirectX is a COM (Component Object Model) library that was built with C++, and would be best utilized with the native language of Windows.

However, starting with DirectX 7.0, Microsoft has provided a type library for writing DirectX programs with Visual Basic. This type library contains the link between the DirectX library and Visual Basic that allows you to take full advantage of every feature in DirectX without limitation. Yes, you can even write Direct3D programs in Visual Basic, with performance close to what can be done in C or C++. For an example, check out the game in Chapter 22, "Pong 3D: Modern Arcade Game."

The Visual Basic Game Library

The goal of this book is to teach game programming with Visual Basic and DirectX first and foremost, and the best way to do that (in my opinion) is through practice. Therefore, you will write numerous sample programs throughout the course of this book. In the process, I will show you how to build an advanced game library that uses all the features and functionality of the Windows API and DirectX.

The Visual Basic Game Library, which is assembled in Chapter 13, "Building the DirectX Game Library," will start off with all of the code you need to write games with Visual Basic (in other words, without DirectX). I'll show you how to enhance the library with Windows API functions that will drastically increase the speed of graphics functions that are essential for writing high-speed games. Later, I will show you how to add DirectX support to the library. In the end, you will have a full-featured game library suitable for building any type of game, from the simplest card game to the most advanced real-time strategy game. It will be a simple matter to add the necessary game library files to your project or simply reference the compiled game library as a DLL.

Promotions

At this early stage, you might consider yourself a white-belt Newbie Gamer. I assume that you know how to play games (that is, your brain is sufficiently developed to make the connection between your eyes and your hands), but that is about all that I will assume. As you learn and demonstrate skill in increasingly advanced subjects, you will be promoted!

The ranks look like this:

1. Newbie Gamer

2. Apprentice Hacker

3. Skilled Programmer

4. Veteran Coder

5. Master Developer

6. Adept Game Designer

Each new level in the ranking is an order of magnitude higher than the one before, in relation to the amount of information you will learn. If you are already an experienced programmer, you might progress through the ranks quickly, but later ranks will be extremely challenging and you must demonstrate your prowess with the subjects to advance. The final rank of Adept Game Designer requires a great deal of study and skill that can only be honed by developing complete games. To quote Master Yoda, "My own counsel will I keep on when you are ready!"

Basically, you will have to write lines of code as easily as you breathe air, and be able to call up algorithms and function libraries from memory. You must be able to control every aspect of game creation so that it is second nature to you. You will no longer work with mere functions and structures, but with whole libraries of code that do your bidding. You must build your own game engine and learn how to master it.

Remember at the end of The Matrix, when Neo began to see the real world? That is how you must see games and code to reach the final rank of Adept Game Designer, by pondering a higher plane of gaming design that transcends mere source code. Most of our peers are Skilled Programmers. A smaller number are Veteran Coders, while a select few are Master Developers. Needless to say, Adept Game Designers are rare, at the top of their genre. Study the material herein, practice by writing code, leave no idea unexplored, and one day you might find yourself sharing stories with John Carmack, Sid Meier, and Peter Molyneux.

Summary

The most important factor in game development is this: Be creative! Visual Basic is a fun language to use for writing games, and it handles all of the complexities of Windows programming for you. So use this opportunity to focus on creativity and gameplay! Go the extra mile and put the extra bells and whistles into a game. Put all of your energy into it.

This chapter has presented the subject of game development with Visual Basic and DirectX as an achievable concept-something that you can easily do with a little bit of know-how. If you find yourself intimidated by new games that come out full of awesome features, then all you need is a little experience creating games of your own. This book will teach you how to do that! Visual Basic and DirectX work well together, and you are going to have a lot of fun learning how to write games in later chapters.

This is only the beginning and I haven't even scratched the surface of what is possible. In Chapter 2, "Getting Started with Visual Basic," I'll give you a formal introduction to Visual Basic, explain all the features of the language, and show you the various versions available. So put on your seatbelt and get ready, because it's full speed ahead.