How Your First Phrogram Program Works
- How Programs Are Structured
- Method Main ( )
- Using Sprites to Display Graphics for Games
- Coordinate System
How Programs Are Structured
In Section 1, you typed in and ran your first program—way to go! From now on, our job with this short cut is to explain it all to you so that you understand how and why your program works the way it does, and how you can start creating your own programs. Of course, by the end of this short cut, you will have created a complete game of your own, not just the simple example shown in Figure 2.1.
Figure 2.1 Your first Phrogram program
Let's note a few key things about how the instructions (or code) are presented in Phrogram. First, Phrogram doesn't actually use the line numbers to "run" your program. The line numbers shown at the left end of each instruction are shown there for your own reference as you work within the program. Computer programs are normally processed one instruction at a time, starting at the top and moving downward. We will discuss later how there are important exceptions to this principle in Phrogram (just as there are in other languages).
Another important point to note is that you must place each instruction on a separate line in your program. For instance, the following program contains the same instructions as the one you typed, but this one will not work, because each instruction is not on its own line:
Program HelloUFO Method Main() Define myUFO As Sprite myUFO.Load( "ufo.gif" ) myUFO.MoveTo( 50, 50 ) myUFO.Show() End Method End Program
All programming languages have rules such as these that make it possible for the computer to understand your instructions. Person-to-person communication has lots of rules, too; it's just that we are so used to them that we follow them without even thinking about them. For example, we don't say "Goodbye" at the beginning of a telephone call; instead, we say "Hello"!
Just as with our telephone calls, there are specific cues that Phrogram recognizes for the start and end of a program. Thus, all programs must begin with a line such as Program HelloUFO, as shown in line 1, and they all must end with End Program, as shown in line 12. That first line—Program HelloUFO—indicates that the name of this program is HelloUFO. You can name a program anything you want, but it's a good idea to name it something that describes what the program does.