- Using Sprites for Game Graphics
- Variables Let You Control Your Game Over Time
- Loops Tell Phrogram to Do Something Over and Over Again
Variables Let You Control Your Game Over Time
Now we want our UFO to "land" by moving down to the bottom of the screen. To do this, we define and use a variable, which is one of the most important concepts for a beginning programmer to learn.
As the name suggests, they are called variables because they define a value that can change (or vary!) over time. Changing over time is in fact what makes variables powerful and useful, as we will see in this example. Variables should be defined with a name that makes sense given how they will be used. In this case, our variable will be used to change the y-axis location of our UFO, in order to make the UFO move down the screen, so let's call it ufoY. Here is the line of code that defines our variable:
Define ufoY As Integer
Define is a keyword you have seen before, but this time, instead of using it to define a sprite, you are using it to let Phrogram know that ufoY is an integer. As you may recall from your math class, an integer is any whole number (one that does not have a fraction or decimal). We have not yet told Phrogram which whole number value to use for ufoY, but because we defined it as Integer, Phrogram knows that its value will be a whole number when we give it one.
An Integer variable, as a fundamental building block of programming in Phrogram, is simpler than a sprite, which we know is a system class. A variable defined as a sprite—in our case, myUFO—can be manipulated with commands such as MoveTo() and Show(). But an integer is simply a number that you can use for just about any purpose for which whole numbers are useful. In our example, we will use the integer value of ufoY to move the myUFO sprite down the screen.