Try the sync command. This will give YOU control over the refresh rate, rather than leaving it on the auto refresh (which refreshes after every line or so, which is bad because loops can slow down the main one).
Here is the usage for sync:
SYNC ON : SYNC RATE 0
put code here
DO
everything you want to happen before the refresh (such as moving sprites and such)
SYNC
LOOP
So there are 3 commands used: SYNC ON, SYNC RATE, and SYNC.
The SYNC ON simply tells it to turn off auto refreshing and enable the usage of sync.
The SYNC RATE tells it a refresh rate that you want to max at. This is optional, but usually helpful. A value of 0 will tell the computer that it should refresh as fast as the computer will allow (good and bad, depends on situation). Optionally, you can put your own number in there to help control the program (such as if the program is going too fast)
The SYNC command is the command that tells the computer to actually refresh the screen. It is good to have as few of these as possible (I usually do my best to only have 1, so that everything essentially gets displayed at the same time).
Now, for your other questions:
1. You can use a FOR->NEXT loop to spawn the enemies. Using a counter variable you can make sure it only spawns them every 30 loops or whatever. To make them appear randomly, just use RND(479). 479 is chosen because while there are 480 sprites, you have to count 0 as well. Actually, you should put 479-the height of the target so that it doesn't appear offscreen. You would also need the RANDOMIZE TIMER() command. The RANDOMIZE command will reseed the random equation (since it isn't really random). A value of TIMER() will set the seed value to the system timer, which will make it very unlikely for the same event to occur (though not entirely impossible).
The code for all this would look something like this:
SYNC ON : SYNC RATE 0
RANDOMIZE TIMER()
DIM SpawnArea(479)
DO
REM to spawn creatures every 50 iterations-might be a bit off
IF counter>=50
GOSUB Spawn_Enemies
counter=0
ELSE
INC counter
ENDIF
FOR movement=1 to current_enemy
IF Sprite Exist(movement)
SPRITE movement,SPRITE X(movement)-enemy_speed,Sprite Y(movement),5
ENDIF
NEXT movement
SYNC
LOOP
END
Spawn_Enemies:
REM Spawns 10 enemies. Assumes that the image for the enemies is image 5
FOR i=1 TO 10
Y=RND(479)
IF SpawnArea(Y)=0 and SpawnArea(Y+height of target)=0
SPRITE current_enemy,639-width of target,Y,5
INC current_enemy
attempts=0
FOR fill=Y to Y+SPRITE HEIGHT(current_enemy)
SpawnArea(fill)=1
NEXT fill
ELSE
INC attempts
ENDIF
IF attempts=3
i=11
ENDIF
NEXT i
FOR clear=0 to 479
SpawnArea(clear)=0
NEXT clear
RETURN
This is a big example (not tested, but it should be all right, maybe a few typos here and there, I actually intended for it to be more pseudocode and real code, OOPS) that demonstrates both number 1 and 2. Notice, I included some code in the spawn area to make sure that two sprites wouldn't overlap when spawned. The problem with that though is that you may run into a point where you can't place another sprite and you haven't spawned 10 enemies. That is where the attempts variable comes in. If it tries 3 times and can't place it, it sets i (the for-next loop variable) to 11, so that it will exit immediately (the result: you might not get 10 enemies but they don't overlap).
For 3, do a check (perhaps within the FOR movement= 1 to current_enemy) that if it moves and it is past the edge of the screen, position it at the right side of the screen.
Hope this helps!
Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose