Here are some ideas for how the enemies (squares) should be added:
To do this, we need to back to the main program, into the main loop (the Repeat getKey(15)
). Change prgmASQUARES
into this:
All the changes should come right before the first sub(DA)
.
You probably understand this too. If a random two-byte integer is less than 4096 (that's a probability of 4096/65536, or 1/16), stick a square in the middle of the screen and give it a random X- and Y-speed. Then quit when the user presses CLEAR.
Before we compile, there's one thing that's missing. Something that every enemy/bullet system needs to have—movement. So change prgmASQUARES
again:
All the new additions are right after the ones you just added. The point here is that it has to be before the first sub(DA)
. Otherwise, you'd be changing the squares' position after they get drawn but before they get erased, so they'd end up being "erased" from a different location.
Well? Compile and run!
It works! Amazing, eh? You can let it run for as long as you want, and even though it slows down quite a bit with a lot of enemies on the screen, they all move on their own!
The only problem now is that they keep wrapping around the screen. Usually that's not what you want to happen, since if an enemy or bullet goes off the screen, it should stay off the screen. We'll take care of that in the next section.