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.More Timers
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.
- start counting at 0 at the beginning of the programHere are commands to make this happen - you must put them in the correct place in your 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.
Sprite plane;== Practice ==
....
....
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();
}