'---- DEMO TLS: TEXT, LINES AND STAR FIELD ----


'---- STARTUP DEMO TLS ----

SUB INIT_DEMO_TLS

 LOCAL T

 'INIT ROUTINES
 INIT_STARS(80)
 INIT_FONT_K

 'SET BUFFER PAGE
 PAGE WRITE 1
 LINEL=0 'LEFT LINE WIDTH INTRO
 LINER=0 'RIGHT LINE WIDTH INTRO
 SN=0    'FOR RADIANS
 FL=0    'FOR FLASHING EFFECT
 ANIC=0  'ANIMATION COUNT
 DEMOC=0 'DEMO COUNT TO FINISH

 'INIT TEXT
 T=1
 TXT$(T)="            ": T=T+1
 TXT$(T)="   LET'S START WITH A SIMPLE STARFIELD WITH A MOVING ": T=T+1
 TXT$(T)="TEXT IN PERSPECTIVE, LINES, AND BACKGROUND ": T=T+1
 TXT$(T)="FLASHING SYNCHRONIZED WITH THE MUSIC... ": T=T+1
 TXT$(T)="COOL FOR AN OLD SCHOOL FASHION, ": T=T+1
 TXT$(T)="BUT BORING... LET'S TRY ANOTHER THING...": T=T+1
 TXT$(T)="                    |": T=T+1

 'RESET LINES DEPTH
 FOR T=1 TO 3
  SLINE(T)=0
 NEXT T

 'START MUSIC AND SYNC WITH TIMER
 PLAY STOP
 PLAY MODFILE "./ASSETS/econmy17.mod",22050

END SUB


'---- RUN TEXT, LINES AND STARFIELD DEMO ----

SUB RUN_DEMO_TLS

 LOCAL SEC,T

 Timer=0
 TIMENOW=Timer
 TSPD=10.7

 DO WHILE SEC<25

  DEMOC=DEMOC+1
  SEC=(Timer-TIMENOW)\1000

  'PREPROCESS SIN AND COS
  SN=SN+0.1
  CS=COS(SN): SI=SIN(SN)

  'IMAGE EFFECTS
  FL=FL-70:IF FL<0 THEN FL=0 
  SELECT CASE ANIC
   'FIRST PART - BACKGROUND FLASHES
   CASE <10: If Timer>TIMENOW+5000 then FL=255: TIMENOW=Timer-2450: ANIC=ANIC+1
  END SELECT
  IF LINER<10 THEN FL=255
  BOX 0,0,MAXX,MAXY,0,,RGB(FL,FL,FL)

  'SHOW 80 STARS
  STARFIELD(80)

  PAGE WRITE 3: BOX 0,0,MM.HRES,MM.VRES,0,0,0

  'LINES WIDTH INTRO
  IF SEC<22 THEN LINER=LINER+10 ELSE LINEL=LINEL+10
 
  IF LINEL>MAXX THEN LINEL=MAXX
  IF LINER>MAXX/2 THEN
   IF LINER>MAXX THEN LINER=MAXX
   'SHOW TEXT ONLY WHEN LINES ARE FULL WIDTH
   MOVE_KROME
  ENDIF

  'WRITE LINES BEHIND TEXT
  IF SLINE(1)=1 THEN HLINE(1,0,0,255,LINEL,LINER)
  IF SLINE(2)=1 THEN HLINE(2,0,255,0,LINEL,LINER)
  IF SLINE(3)=1 THEN HLINE(3,255,0,0,LINEL,LINER)
 
  'SCROLL TEXT (ONLY WHEN LINES ARE FULL WIDTH)
  IF LINER>MAXX/2 THEN 
   TTROW=TROW:TTCOL=TCOL
   FOR T=0 TO MAXX/54+1
    TTCOL=TTCOL+1
    IF TTCOL>LEN(TXT$(TTROW)) THEN TTCOL=1: TTROW=TTROW+1
    PRINTK(T*54-54-TSCR,MAXY/2-25+SIN(SN+TNUM+T+FL/150)*25,CHR$(PEEK(VAR TXT$(TTROW),TTCOL)),4)
   NEXT T
  ENDIF

  'WRITE LINES ABOVE TEXT
  IF SLINE(3)=0 THEN HLINE(3,255,0,0,LINEL,LINER)
  IF SLINE(2)=0 THEN HLINE(2,0,255,0,LINEL,LINER)
  IF SLINE(1)=0 THEN HLINE(1,0,0,255,LINEL,LINER)

  PAGE WRITE 1

  IMAGE WARP_H 0,120,MM.HRES-1,MM.VRES-240, 0,0,MM.VRES-1, MM.HRES-1,MM.VRES/2-40,80, 3,1
 
  FPS(25)

  '?@(0,0) SEC

  'COPY BUFFER PAGE TO MAIN
  PAGE COPY 1 TO 0,I

 LOOP

END SUB

