Chapter 3: Your First Program

 Download CD Content

What Is a Program?

In order to make any game, you are going to have to tell the computer exactly what you want it to do. For example, if your game involves firing a missile when the spacebar is pressed, you must somehow pass this information on to the computer. If you want the missile to destroy different parts of a ship depending on where the missile hits, then you will also have to let the computer know this. And even more basic, if you want a menu to pop up when the program user turns on the game, you must tell the computer to make the menu pop up.

In one sense, computers are very dumb ”they cannot figure anything out unless you tell them to. You must give them fully detailed instructions that explain what they must do, how they must do it, and when they must do it. These detailed instructions are given to a computer using a computer program, like the ones you will soon be writing. It is such a program that passes on all the necessary instructions to a computer.

If you want, you can compare a computer program to a cooking recipe. A recipe is a set of specific instructions that a cook must follow: add one egg, beat for one minute, and so on. A computer program is a set of instructions that a computer must follow.

Remember what we said a moment ago about computers being dumb, in a sense? Suppose that we were to tell you something, but we slightly mispronounced one of the words. Chances are, you would still understand what you were told. Unfortunately, computers do not function the same way when it comes to processing programs. If you misspell a crucial word in your program, or if you leave out a semicolon (;) where one is supposed to appear, or if you do anything that s only slightly wrong, then the computer will not recognize it. Everything must be exactly right (although you could program a computer to recognize common errors, but that s a subject beyond this book), so you must be very careful when you type in your code ( code is another term for your program). Being careful is the best way to avoid bugs (errors) in your program.

Maybe you are a little confused now. If you are, don t worry ”once you see some examples, you will know exactly what we are talking about.

Elementary Game Programming and Simulators Using Jamagic
Elementary Game Programming & Simulations Using Jamagic (Charles River Media Game Development)
ISBN: 1584502614
EAN: 2147483647
Year: 2002
Pages: 105
Authors: Sergio Perez © 2008-2017.
If you may any questions please contact us: