'=========================================================================== ' Subject: COMPLEX STAR/CREDIT SCROLLER Date: 05-24-97 (15:20) ' Author: Daniel Davies Code: QB, QBasic, PDS ' Origin: ia53@rapid.co.uk Packet: GRAPHICS.ABC '=========================================================================== '======================================================================= ' Star/Credit Scroller by Daniel Davies 1996 ' Simple use of page flipping to create a complex animation including ' use of vertically scrolling text, bouncing balls, horizontaly ' scrolling multi-layered star field '======================================================================= '== INITIALISE EVERYTHING FOR THE STAR FIELD =========================== 'set to screen mode 7 so that we can use page swaping SCREEN 7, 0, 1, 0 ' Write to Page 1 (Hidden) 'set size of arrays DIM SHARED Stars1%(200): DIM SHARED Stars2%(200) DIM SHARED Stars3%(200) DIM SHARED FlineX1%(1 TO 8): DIM SHARED FlineY1%(1 TO 8) DIM SHARED FlineX2%(1 TO 8): DIM SHARED FlineY2%(1 TO 8) DIM SHARED MSG$ 'set initial position of stars FOR X% = 1 TO 200 RANDOMIZE TIMER Stars1%(X%) = INT(RND * 320) + 1 RANDOMIZE TIMER Stars2%(X%) = INT(RND * 320) + 1 RANDOMIZE TIMER Stars3%(X%) = INT(RND * 320) + 1 NEXT X% 'set initial positions and speed of the shapes RANDOMIZE TIMER Xco1% = INT(RND * 320): Yco1% = 10 + INT(RND * 180) Xspeed1% = -1 Yspeed1% = 1 Xco2% = INT(RND * 320): Yco2% = 100 + (INT(RND * 90) - 45) Xspeed2% = -3 Yspeed2% = -3 Xco3% = INT(RND * 320): Yco3% = 10 + INT(RND * 180) Xspeed3% = 2 Yspeed3% = 2 'set the position of the line and it's speed RANDOMIZE TIMER FlineX1%(1) = INT(RND * 320): FlineY1%(1) = INT(RND * 200) FlineX2%(1) = INT(RND * 320): FlineY2%(1) = INT(RND * 200) xmod1% = -2: ymod1% = 2 xmod2% = 3: ymod2% = -3 FOR X% = 2 TO 8 FlineX1%(X%) = FlineX1%(1): FlineY1%(X%) = FlineY1%(1) FlineX2%(X%) = FlineX2%(1): FlineY2%(X%) = FlineY2%(1) NEXT X% 'set info about the scrolltext y% = 19 message% = 1 '======================================================================== DO CLS 'clear page ready for the pic FOR X% = 1 TO 200 ' move and draw the stars Stars1%(X%) = Stars1%(X%) - 5 ' move the nearest layer Stars2%(X%) = Stars2%(X%) - 3 ' move the middle layer Stars3%(X%) = Stars3%(X%) - 1 ' move the back layer ' the next section maeans that when ' a star goes outside of the screen ' it is given a new position. IF Stars1%(X%) <= 0 THEN RANDOMIZE TIMER Stars1%(X%) = INT((350 - 320 + 1) * RND + 320) END IF IF Stars2%(X%) <= 0 THEN RANDOMIZE TIMER Stars2%(X%) = INT((350 - 320 + 1) * RND + 320) END IF IF Stars3%(X%) <= 0 THEN RANDOMIZE TIMER Stars3%(X%) = INT((350 - 320 + 1) * RND + 320) END IF PSET (Stars3%(X%), X%), 8 ' draw the back layer PSET (Stars2%(X%), X%), 7 ' draw the middle layer PSET (Stars1%(X%), X%), 15 ' draw the nearest layer NEXT X% ' The next section changes the ' message on screen IF TIMER - start# >= .125 THEN y% = y% - 1 IF y% = 6 THEN y% = 19: message% = message% + 1 IF message% = 26 THEN message% = 1 IF message% = 1 THEN MSG$ = "Horizontally scrolling Star field" IF message% = 2 THEN MSG$ = "By Daniel Davies" IF message% = 3 THEN MSG$ = "This program uses page flipping to get" IF message% = 4 THEN MSG$ = "reasonably smooth animation using" IF message% = 5 THEN MSG$ = "simple commands in Q-Basic it should be" IF message% = 6 THEN MSG$ = "easy to understand, but if you want or" IF message% = 7 THEN MSG$ = "need any help understanding it just ask" IF message% = 8 THEN MSG$ = "and I'll be pleased to help." IF message% = 9 THEN MSG$ = "if you find any of the code useful you" IF message% = 10 THEN MSG$ = "can use it in any programs but please" IF message% = 11 THEN MSG$ = "give me some credit" IF message% = 12 THEN MSG$ = "anyway, some of the technical info" IF message% = 13 THEN MSG$ = "it uses mode 7 which is the ega 320*200" IF message% = 14 THEN MSG$ = "16 colour mode which has 8 pages" IF message% = 15 THEN MSG$ = "this demo only uses 2 different pages" IF message% = 16 THEN MSG$ = "the demo has 11 different layers of" IF message% = 17 THEN MSG$ = "animation" IF message% = 18 THEN MSG$ = "enjoy this demo" IF message% = 19 THEN MSG$ = "Sorry the text's a bit crud but It's" IF message% = 20 THEN MSG$ = "1 am, so what can you expect?" IF message% = 21 THEN MSG$ = "Cee U l8r!" start# = TIMER END IF COLOR 11 ' the next line writes the message ' to the screen LOCATE y%, 20 - (LEN((MSG$)) / 2) + .5: PRINT MSG$ ' the next section draws the circle ' that bounces below the borders and ' undeneath the other two circles Yco1% = Yco1% + Yspeed1% Xco1% = Xco1% + Xspeed1% IF Yco1% > 189 THEN Yspeed1% = -1 IF Yco1% < 11 THEN Yspeed1% = 1 IF Xco1% < 11 THEN Xspeed1% = 1 IF Xco1% > 309 THEN Xspeed1% = -1 CIRCLE (Xco1%, Yco1%), 10, 10 PAINT (Xco1%, Yco1%), 14, 10 ' the next section draws the circle ' that goes underneath the border ' and inbetween the other two circles. Yco2% = Yco2% + Yspeed2% Xco2% = Xco2% + Xspeed2% IF Yco2% > 140 THEN Yspeed2% = -3 IF Yco2% < 61 THEN Yspeed2% = 3 IF Xco2% < 11 THEN Xspeed2% = 3 IF Xco2% > 309 THEN Xspeed2% = -3 CIRCLE (Xco2%, Yco2%), 10, 1 PAINT (Xco2%, Yco2%), 9, 1 ' the next section draws the border ' lines for the star field LINE (0, 45)-(320, 50), 8, B LINE (0, 46)-(320, 49), 7, B LINE (0, 47)-(320, 48), 15, B LINE (0, 156)-(320, 151), 8, B LINE (0, 155)-(320, 152), 7, B LINE (0, 154)-(320, 153), 15, B ' The Next section draws the circle ' that goes over the other two ' circles. Yco3% = Yco3% + Yspeed3% Xco3% = Xco3% + Xspeed3% IF Yco3% > 189 THEN Yspeed3% = -2 IF Yco3% < 11 THEN Yspeed3% = 2 IF Xco3% < 11 THEN Xspeed3% = 2 IF Xco3% > 309 THEN Xspeed3% = -2 CIRCLE (Xco3%, Yco3%), 10, 3 PAINT (Xco3%, Yco3%), 1, 3 ' check that neither end of the ' bouncing line leaves the screen IF FlineX1%(1) > 319 THEN xmod1% = -2 IF FlineX1%(1) < 0 THEN xmod1% = 2 IF FlineY1%(1) > 199 THEN ymod1% = -2 IF FlineY1%(1) < 0 THEN ymod1% = 2 IF FlineX2%(1) > 319 THEN xmod2% = -3 IF FlineX2%(1) < 0 THEN xmod2% = 3 IF FlineY2%(1) > 199 THEN ymod2% = -3 IF FlineY2%(1) < 0 THEN ymod2% = 3 ' move line. FlineX1%(1) = FlineX1%(1) + xmod1%: FlineY1%(1) = FlineY1%(1) + ymod1% FlineX2%(1) = FlineX2%(1) + xmod2%: FlineY2%(1) = FlineY2%(1) + ymod2% ' age the position of the lines FOR X% = 8 TO 2 STEP -1 FlineX1%(X%) = FlineX1%(X% - 1): FlineY1%(X%) = FlineY1%(X% - 1) FlineX2%(X%) = FlineX2%(X% - 1): FlineY2%(X%) = FlineY2%(X% - 1) NEXT X% ' Draw the lines FOR X% = 4 TO 8 STEP 2 LINE (FlineX1%(X%), FlineY1%(X%))-(FlineX2%(X%), FlineY2%(X%)), 2 NEXT X% LINE (FlineX1%(1), FlineY1%(1))-(FlineX2%(1), FlineY2%(1)), 10 PCOPY 1, 0 ' Copy Page 1 (Hidden) to Page 0 LOOP WHILE INKEY$ = ""