Timer Variables

VARIABLES are numbers that CONTROL what happens in a computer program.
There are some basic VARIABLES already built-in to the system:

frameCount

This starts at 0 when the program starts. 
Every time that DRAW executes (20 times per second),
the frameCount increases by 1.  So this is a timer
that is constantly counting.

Sprite.x , Sprite.y

Every Sprite (picture object) has a variable .X that tells its horizontal position.
It also has a .Y variable that tells its vertical position.
These can be used find out the position of the player,
and then start (spawn) a new object at the same position, like a bullet.
More Timers

We can create another variable to use as an extra TIMER.
For example, we can make a plane appear every 10 seconds like this:
- start counting at 0 at the beginning of the program
- when the TIMER reaches 200, we make the plane appear (.show).
- make the plane fly across the screen and then disappear (.hide)
  At the same time, reset the TIMER back to 0.
- Now the plane will appear again after another 10 seconds.


Here are commands to make this happen - you must put them in the correct place in your program.

Sprite plane;
  ....
  ....
int  TIMER = 0; 
  ....
  ....
plane = new Sprite("Plane.png");
plane.place(10,10);
plane.hide();
  ....
  ....
TIMER++ ;     // count by adding 1
 
if(TIMER > 200)
{
     plane.show();
     plane.place(10,10);   // back to starting position
     plane.setSpeed(15,0);
     plane.setSides(2);
     TIMER = 0;           // reset TIMER back to 0
}
  ....
  ....
if(plane.x >= 700)       // near right edge of window
{
     plane.hide();
}

== Practice ==

(1)  Add an airplane to your program, that travels from left to right
      and appears/disappears every 10 seconds.
      Place the commands above in the RIGHT PLACE in your program.
      You also need to copy the plane picture into your DATA folder.

(2)  Add another object that appears/disappears every 5 seconds.
       Make it travel from the right side of the screen to the left side.

(3)  Check whether the right-moving plane HITS the left-moving object.
       If then collide, make them both disappear.

(4)  Make another timer that HIDES one of the enemies after 10 seconds.

(5)  Make a new timer that counts to 15 seconds.
       Whenever this timer gets to 15 seconds, move the player
        back to the center of the screen and start counting at 0 again,
        then reset the player after another 15 seconds.

(6)  Make another timer for some other purpose.