Visual Basic Game Programming with DirectX 1st Edition Jonathan S. Harbour download
Visual Basic Game Programming with DirectX 1st Edition Jonathan S. Harbour download
https://ebookname.com/product/visual-basic-game-programming-with-
directx-1st-edition-jonathan-s-harbour/
https://ebookname.com/product/visual-c-game-programming-for-
teens-1st-edition-jonathan-s-harbour/
https://ebookname.com/product/beginning-game-programming-4th-
edition-edition-jonathan-s-harbour/
https://ebookname.com/product/darkbasic-pro-game-programming-
second-edition-jonathan-s-harbour/
https://ebookname.com/product/home-workout-dk-publishing/
Bifurcation Stenting 1st Edition Ron Waksman
https://ebookname.com/product/bifurcation-stenting-1st-edition-
ron-waksman/
https://ebookname.com/product/tales-from-the-7-000-isles-
filipino-folk-stories-1st-edition-dianne-de-las-casas/
https://ebookname.com/product/imperial-politics-and-symbolics-in-
ancient-japan-the-tenmu-dynasty-650-800-1-edition-herman-ooms/
https://ebookname.com/product/deaf-culture-exploring-deaf-
communities-in-the-united-states-2nd-edition-irene-w-leigh/
https://ebookname.com/product/chiral-amine-synthesis-methods-
developments-and-applications-1st-edition-thomas-c-nugent/
Poverty in the Roman World 1st Edition Margaret Atkins
https://ebookname.com/product/poverty-in-the-roman-world-1st-
edition-margaret-atkins/
Microsoft Visual Basic Game Programming
with DirectX
Jonathan S. Harbour
’ 2002 by Premier Press, Inc. 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 and the author have attempted throughout this book to distinguish
proprietary trademarks from descriptive terms by following the capitalization style used by
the manufacturer.
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,
ISBN: 1-931841-25-X
01 02 03 04 05 RI 10 9 8 7 6 5 4 3 2 1
I would like to thank two buddies of mine, Raul Aguilar and Chris Henson, who were in the
thick of it early on, providing suggestions and feedback. Thanks for meeting with me once
a week just to go over the early chapters and talk about how to develop the book. Many of
your comments helped to direct the content later on. Thanks to John Striker for helpful
feedback and for play-testing the sample games.
Thanks to Edgar Ibarra for contributing the 3-D artwork used in the book and for doing all
the graphics for Stellar War. The asteroids, ships, and black holes look great!
Thanks also go out to William White and the ”Circuit Scramblersé at Vera C. O“Leary
Junior High in Twin Falls, Idaho, for reviewing chapters of the book and providing helpful
input.
I owe a debt of gratitude to Andre LaMothe for his encouragement and suggestions for
this book, and for all of his previous books that helped to set the standard for others to
follow.
About the Author
Jonathan S. Harbour is the author of Pocket PC Game Programming, also by Premier
Press. He has been writing games for 14 years, having created his first game on a Tandy
1000 in 1988. He has worked on commercial games and has developed information
systems for cellular, aerospace, pharmeceutical, education, and medical research
companies. Jonathan is currently living in Phoenix, Arizona, working as a software
consultant. In his spare time, Jonathan enjoys writing Pocket PC games, reading science
fiction, and spending time with his wife and two children.
License Agreement/Notice of Limited Warranty
By opening the sealed disc container in this book, you agree to the following terms and
conditions. If, upon reading the following license agreement and notice of limited warranty,
you cannot agree to the terms and conditions set forth, return the unused book with
unopened disc to the place where you purchased it for a refund.
License:
The enclosed software is copyrighted by the copyright holder(s) indicated on the software
disc. You are licensed to copy the software onto a single computer for use by a single
user and to a backup disc. You may not reproduce, make copies, or distribute copies or
rent or lease the software in whole or in part, except with written permission of the
copyright holder(s). You may transfer the enclosed disc only together with this license,
and only if you destroy all other copies of the software and the transferee agrees to the
terms of the license. You may not decompile, reverse assemble, or reverse engineer the
software.
Notice of Limited Warranty:
The enclosed disc is warranted by Premier Press, Inc. to be free of physical defects in
materials and workmanship for a period of sixty (60) days from end user“s purchase of the
book/disc combination. During the sixty-day term of the limited warranty, Premier Press
will provide a replacement disc upon the return of a defective disc.
THE SOLE REMEDY FOR BREACH OF THIS LIMITED WARRANTY SHALL CONSIST
ENTIRELY OF REPLACEMENT OF THE DEFECTIVE DISC. IN NO EVENT SHALL
PREMIER PRESS OR THE AUTHORS BE LIABLE FOR ANY OTHER DAMAGES,
INCLUDING LOSS OR CORRUPTION OF DATA, CHANGES IN THE FUNCTIONAL
CHARACTERISTICS OF THE HARDWARE OR OPERATING SYSTEM, DELETERIOUS
INTERACTION WITH OTHER SOFTWARE, OR ANY OTHER SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES THAT MAY ARISE, EVEN IF PREMIER AND/OR
THE AUTHORS HAVE PREVIOUSLY BEEN NOTIFIED THAT THE POSSIBILITY OF
SUCH DAMAGES EXISTS.
Disclaimer of Warranties:
PREMIER AND THE AUTHORS SPECIFICALLY DISCLAIM ANY AND ALL OTHER
WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF
MERCHANTABILITY, SUITABILITY TO A PARTICULAR TASK OR PURPOSE, OR
FREEDOM FROM ERRORS. SOME STATES DO NOT ALLOW FOR EXCLUSION OF
IMPLIED WARRANTIES OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL
DAMAGES, SO THESE LIMITATIONS MIGHT NOT APPLY TO YOU.
Other:
This Agreement is governed by the laws of the State of Indiana without regard to choice
of law principles. The United Convention of Contracts for the International Sale of Goods
is specifically disclaimed. This Agreement constitutes the entire agreement between you
and Premier Press regarding use of the software.
Foreword
In this book, Jonathan Harbour presents a comprehensive overview of game
development using Visual Basic. One very important point he covers concerns Visual
Basic versus C++. After almost 20 years of software development, one of the things I can
attest to is that it“s not the language that makes or breaks the program, but the knowledge,
Our BIG compiler machine was an IBM AT that had a whopping 10MB hard disk and a
CPU that we overclocked to get a blistering 12MHz processor speed. We used CGA
artifact mode to get 16 brilliant colors, and came up with laser blasts and explosion
sounds that could be played through
the PC speaker because there were no sound cards yet. The game was so huge when it
was completed that it shipped on not one, but two 360K floppy disks. I mention all this
because Starflight, with its primitive graphics and sound, still engenders fan mail from
people who tell us how much they loved the game and ask us where can they find a copy
that will run on their Pentium IV.
Starflight came together perhaps more ”organicallyé than you would see for games of its
magnitude that are produced today. I was in my last quarter of my Linguistics major in
San Diego when I started the project, and Greg Johnson was my roommate at the time.
He was intrigued by the project and started using an early computer graphics program on
an Atari 800 to draw the major characters of the game, just for fun. He joined the
company a couple of months after I did to help out with design work, and as his ideas
blossomed into major portions of the game, he took on the lead designer role. Bob
Gonsalves came on board to develop an interleaved disk I/O methodology that ended up
being scrapped because we changed platforms; he stayed on to develop all the
planet-side activity in the terrain vehicle and the combat sequences in space. Tim Lee
joined and brought with him a high-powered graphics idea he was working on that we
When you start programming your own games, remember that technology is only a part of
what you need. I don“t want to sound trite, but it“s true that no matter what cool special
effect you put into a game, someone will come up with something cooler. What makes a
game special, what makes it unique, is that you put part of yourself into it. So what are
you waiting for? Read this book and go write that game!
Alec Kercso
I never thought I would say this, but the time has finally come that Visual Basic is a valid
language to create high-speed 2-D and 3-D games!
Letter from the Series Editor
This book starts off showing you the basics of Visual Basic programming and how to
integrate graphics and sound using the standard VB components. Once you have that
under your belt, the book covers DirectX 7.0 and 8.0 and illustrates how to use every
single major DirectX componentó from DirectDraw, DirectSound, and DirectInput to
Direct3D. Along with the discussions are beautiful annotations and tons of demos.
Furthermore, the code in the book is some of the best I have seen; it“s clear, well
commented, and efficient. Jonathan really is a master of VB; he knows all the pitfalls of
game programming under this platform and hence guides you smoothly from topic to
topic without leaving out details or making assumptions.
After the initial coverage of DirectX, the game programming material ensues, and boy
does it! Artificial intelligence, basic physics, game theory, and more. The book even
covers multiplayer networked games with VB! That“s a first! The book concludes by
showing you how to create complete games, rounding out the theory with concrete
examples.
In conclusion, I can“t recommend this book highly enough. Even if you“re a C/C++ game
programmer, you should really read this book. It will open your eyes and might give you
Sincerely,
Andre LaMothe
Series Editor
Introduction
Welcome to Visual Basic Game Programming with DirectX. Like so many titles in the
Premier Press Game Development Series, this book tackles a subject that has never
before been covered in so much detail, providing you with tips, tricks, and techniques for
doing things that most would have disregarded. This is the first comprehensive book that
teaches you how to write complete games with Visual Basic and DirectX.
Make no mistakeó Visual Basic is an awesome language! Nearly half of the three- to
four-million programmers in the world are using Visual Basic on a daily basis. Most
programmers entered the field due to the influence of a game at one time or another. Not
everyone, of course. But of the millions of Visual Basic programmers in the world, a large
number of them do enjoy playing games, myself included.
The problem, as I see it, is that few game developers have considered Visual Basic a
serious game development language. For one reason or another, most Visual Basic
programmers themselves do not even believe that Visual Basic is suitable for game
programming. It“s a common belief that Visual Basic is just too slow to write a decent
game.
I believe the reason why Visual Basic is not taken seriously is because C++ is the
dominant language today in this field. Most of the printed books and online resources are
geared toward C++, leaving little room for other languages to get into the gaming action.
Visual Basic programmers just do not have the required information needed to get started
writing games with their favorite language.
It is my primary goal with this book to show you every trick and technique that I have
learned over the years for getting the absolute most out of Visual Basic. I will teach you
Learning by Example
I wholeheartedly believe that the best way to learn is by example. Mastery of a subject
comes from practice, practice, practice! For that reason, this book is about 50 percent
theory and 50 percent exercise. There is a lot of source code presented in this book (the
projects on the CD-ROM include over 33,000 lines of code!), but I explain every function
in detail before it is used. I usually include code snippets throughout a chapter to explain
how something works.
After all, what is more excitingó talking about a 1968 Shelby Cobra or actually driving
one?
Target Audience
This book is not a beginner“s guide to programming games with Visual Basic. Ironically,
this book started out life as an absolute beginner“s book for game programming, but
ended up being much, much more. I wanted to help newcomers who love games learn
how to write their own games, and that is the emphasis throughout the book. I don“t jump
into any subjects that are too difficult to understand.
However, that is only the beginning. The first half of the book teaches the basic
mechanics of building a double buffered sprite engine, while the second half of the book
delves into numerous subjects that are more advanced (such as positional sound effects).
Overall, I believe that I have achieved the goal of making this book accessible to alló from
beginner to experienced developer. Because there were no other books on which to base
this work, I had to approach this project as a C++ programmer. As you will see throughout
the pages found herein, there are very few lines of pure Visual Basic code. Most of the
subjects and samples are based on modern game development techniques, not on
modern Visual Basic code for building applications.
The end result is a book that any beginner can use to learn how to write games with
Visual Basic. Advanced games! Cutting-edge games! I“m not talking about Tic-Tac-Toe
and Solitaire, but rather scrolling arcade games, space shooters, 3-D arcade games, and
strategy games. But be prepared for a roller-coaster ride in later chapters, because
there“s no turning back when it comes to the more advanced subjects.
This book teaches the right way to create games from the start. You will not find
comfortable point-and-click walk-throughs in these pages. I do not provide you with
drag-and-drop ActiveX controls. If you were hoping to register an ArcadeGame.ocx
control, drop it onto a form, and then call it a game, you will be in for a disappointment.
Most of the sample games just use the standard form that comes with a new project:
Form1. Any necessary controls are added to the program at run-time. That“s right: Most of
the time, you won“t even touch the form, not even to add a PictureBox!
Hopefully, this is not too much of a disappointment. After all, if you want to create the best
games possible, why not learn how to do it right? What I do give youó rather than an
I recommend that you read this book if you meet any of the following criteria:
§ You have never written a computer game in your life, but you want to learn how
to do it.
§ You are just starting out as a programmer, you know maybe one or two
programming languages, and you want to pick up Visual Basic.
§ You are a capable Visual Basic programmer who has already written many
applications, but you want to expand your skills to include multimedia
(games, graphics, sound, input, 3-D, and so on).
§ You are an accomplished game developer who is intrigued by Visual Basic and
you want to learn more about it.
Your Expectations
Since I have no way to tell exactly what topics you would like to learn about ahead of time,
my goal is to cover as much material as possible within a finite amount of space. Every
page is important, and every topic is crucial to the subject at hand. While I can“t please
everyone, it is my hope that every person who reads this book will learn something
valuable. Even if you know almost everything that I have covered, it is my hope that you
will find something new to enhance your game development efforts. There are enough
pages in this book that you are likely to learn something new even if you have been
writing games for many years.
My Expectations
My expectations while writing this book have been simple. I want to present you with
everything you need to develop games with Visual Basicó games that rival those
developed with other languages. I have set my sights on providing a complete solution for
writing extremely high-quality, professional games with Visual Basic. When you are
finished with this book, I expect you will need no other reference on the subject (until such
time as the technologies presented herein become obsolete, which is inevitable in the
game and computer industries).
My only expectation is that you keep an open mind, filled with creativity, and that you are
willing to learn. There is no black box or black art to game programming. It all just
amounts to a lot of hard work, self-learning, and good information. The cutting edge
System Requirements
Most of the source code in this book will run on a mid-range computer, with the exception
of some of the Direct3D code. Low-end PCs have had some problems running the
sample games, such as Warbirds 1944 (a vertical-scrolling arcade game) and Pong 3D (a
game that runs entirely in 3-D). DirectX 8.0 requires that you have a 3-D accelerator card
to make use of most of the features provided by Direct3D, even when working on 2-D
games (using Direct3D sprites).
In general you will want the most powerful computer system you can get your hands on
for game development. But the code in this book is pretty forgiving of computer hardware
and will run on most systems without any trouble. However, just to be thorough, here are
my recommendations for the minimum system requirements:
§ Pentium II 500MHz
§ 128MB memory
§ 6GB hard drive
§ 16MB 3-D accelerator card (which supports DX8)
§ 19é monitor
Book Summary
This book is divided into five parts, as described in the following paragraphs.
Part I: Introducing Visual Basic and DirectX. Part I will teach you how to get started
programming Visual Basic, with an introduction to the language, an in-depth study of the
variable types, and how to get the most performance out of the language. I have included
benchmarks with several sample programs to demonstrate how one method is superior to
another, along with comparable Windows API routines that provide even more speed.
This Part is wrapped up with an introduction to DirectX, with two sample programs
showing how to harness DirectX in the Visual Basic environment.
Part II: The Nuts and Bolts of Game Development. Part II is where the most important
subjects are covered for programming games with Visual Basic. This Part begins with
Summary
Part Overview
Welcome to Part I of Visual Basic Game Programming with DirectX. Part I includes six
chapters that introduce you to Visual Basic and DirectX programming. It begins with an
overview of the basic capabilities of Visual Basic for game programming, and then
proceeds to explain how to get up to speed in a short amount of time with the use of
sample code and illustrations.
In this part, you will learn some of the advanced features available by tapping into the
core functionality of the Windows API, as well as how to optimize Visual Basic to get the
most performance out of the languageó an essential requirement for game programming.
Part I includes an introduction to DirectX, explaining each of the DirectX components and
how they can be used by Visual Basic to create more advanced games, and includes a
sample DirectX program.
By the time you are finished with Part I, you will have a solid understanding of the Visual
Basic language, how to optimize Visual Basic for speed, how to tap into advanced
Windows API functions, and how to initialize DirectX to gain full-screen exclusive access
using DirectDraw.
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 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
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.
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.
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.
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.
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.
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.
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 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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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!
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.
Language: German
CARL EHRENSTEIN
LEIPZIG
KURT WOLFF VERLAG
1916
Sechster Band der Bücherei
» D e r j ü n g s t e Ta g « .
Zweite Auflage
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com