Okay you have seen how you can use variables to move a point around the screen. Last time if the point reached an edge you made the point move in the opposite direction. This time when you will be moving lotsa stars. There is an empty loop near the end, in this loop you will treate the arrays StarX(s) and StarY(s) the same way that you were moving X1,Y1,X2 and Y2 last time but this time you will do it in a loop the code is commented but if you need something explained like what a loop is then you know where to ask.
The screen is 800 pixels wide and 600 pixels high. You only have to move the stars along one axis (left -> right or top->bottom) any time a star reaches the last edge it must be replotted on the opposite edge.
Here is the starfeild take your time looking at the arrays StarX(),StarY() see how similar they are to variables then have a go at moving them around and checking their new positions. The for loop and array is a powerful combination so get to know them
' OPEN A SCREEN 800 PIXELS WIDE 600 PIXELS HIGH
SCREEN 19,,2,
' DECLARE VARIABLES THAT WILL BE USED (REQUIRED BY MY VERSION OF FB NOTHING TO WORRY ABOUT)
dim as integer Stars = 255 ' Number of Stars
dim as integer ResX = 800 ' Screen Width
dim as integer ResY = 600 ' Screen Height
dim as integer size = 1 ' initial size of the sparkle for all stars
dim as integer s ' s will be used as the loop counter its initial value is undefined
' DECLARE ARRAYS THAT WILL BE USED (REQUIRED BY MY VERSION OF FB NOTHING TO WORRY ABOUT)
dim as integer StarX(Stars), StarY(Stars) ' these arrays are for X,Y co-ordinates. Both arays
' have a number of indexes equal to the value of Stars
' Start a Loop we will use its counter (s) as an index into the arrays
' counter starts at value 1 and increases by 1 with each run through the loop
' the loop terminates when the counter is greater than the value of Stars
For s = 1 to Stars
StarX(s) = ResX*rnd(1) ' random gives a fraction between 0.0 and 1.0 multiply this by screen width
StarY(s) = ResY*rnd(1) ' random gives a fraction between 0.0 and 1.0 multiply this by screen height
Next s ' <- At this point we increase the loop counter and jump to the start of the For-Next loop unless
' the counter is larger than the value of Stars (which is 255) in which case execution
' 'falls through' (exits the loop and continues execution of code below this point)
SCREENSET 1,0:' SET WORKPAGE 1, VISIBLE PAGE 0 (DONT WORRY!)
' Main Loop ...
DO
' Make stars sparkle ...
size = size + 1
If size > 3 Then
size = 1
Endif
' Draw two diagonal lines to make an effect that looks like a star sparkle
For s = 1 to Stars
Line (StarX(s)-size, StarY(s)-size)-(StarX(s)+size, StarY(s)+size)
Line (StarX(s)+size, StarY(s)-size)-(StarX(s)-size, StarY(s)+size)
Next s
'--------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------
' Make the stars scroll from left to right This part I leave to you but here is something to work with
For s = 1 to Stars
' Move each star around the screen
' Check if any star has been moved past the edge of a screen
' and if that is the case reposition the star at the other edge of the screen
Next s
'--------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------
SCREENCOPY ' UPDATE SCREEN WITH NEW IMAGE
SLEEP 40 ' WAIT FOR A SHORT TIME FOR SCREEN UPDATE TO COMPLETE THIS AVOIDS FLICKER
CLS ' CLEAR THE SCREEN SO THAT WE CAN DRAW THE NEXT IMAGE
LOOP UNTIL INKEY$<>"" ' ETERNAL LOOP UNTIL USER PUSHES ANY KEY