' ---- DEMO START ----


' -- DEMO X 3D INITIALIZATION --

SUB INIT_DEMO_3D_X

 'LOAD POLYGONAL "X"
 LOADPLY("X-MINI.PLY",0,-1,0,-1)
 PLY_ADJUST_COLOR(0,40)
 PLY_RGB(0,10,0.5,0.5)

 'LOAD "DEMO" WORD
 PAGE WRITE 2
 LOAD PNG "./ASSETS/DEMO.PNG"

 'SET BUFFER PAGE
 PAGE WRITE 1

 PLAY MODFILE "./ASSETS/drozerix_-_neon_techno.mod",22050

END SUB


' -- RUN DEMO 3D X --

SUB RUN_DEMO_3D_X

 LOCAL X,Y,XX,XW,I,T,DIST,WR,COR,CLX

 MAXX=MM.HRES: MAXY=MM.VRES

 'RESET VARIABLES 
 TIMENOW=0: PAUSETIMER=0: DIST=0: XX=0: Timer=0
 X=0: Y=0: XW=0: CLX=0

 'RUN UNTIL 15.6 SECONDS
 DO WHILE SEC<15.6

  'CLEAR BUFFER PAGE
  BOX 0,0,MAXX,MAXY,0,,RGB(0,0,0)

  'COLOR VARIATION
  COR=COS(RAD(I*2))*60+60

  'MOVE POLYGONAL "X" AFTER 3.1 SECONDS
  IF SEC>3.1 THEN
   XX=XX+16: IF XX>180 THEN XX=180
   DIST=DIST+0.2: IF DIST>2 THEN DIST=2

   'RENDER POLYGONAL "X"
   PLY_MOVE(0,MM.HRES/2+XX,MM.VRES/2-64,DIST)
   PLY_ROT(0,I+X+90,Y-90,0)
   X=COS(RAD(I))*90:Y=SIN(RAD(I))*90
  ENDIF
  I=I+8

  'GET POLYGONAL X ON BACKGROUND
  IF XX>120 THEN
   PAGE WRITE 2
   BLIT MAXX/2+XX-70,MAXY/2-164,MAXX/2+XX-70,MAXY/2-164,140,200,1,0
   PAGE WRITE 1
  ENDIF

  'MOVE "DEMO" WORD
  XW=XW+5: IF XW>180 THEN XW=180

  'RESTORE "DEMO" WORD
  IF XW<180 THEN
   I=0
   FOR T=0 TO 126 STEP (180-XW)/5
    I=I+1
    BLIT 0,T,40,70+I+126/2-(126/2)/((180-XW)/5),369,1,2,4
   NEXT T
  ELSE
   BLIT 0,0,40,70-(180-XW),369,126,2,4
  ENDIF

  'CHANGE FPS TO 10 WHEN APPEARS POLYGONAL "X"
  IF SEC>3.1 THEN FPS(20) ELSE FPS(20)
  SEC=Timer/1000

  'REFLEXIVE WATER
  ROT=ROT+16  
  FOR T=MAXY/2+INT(COR/10) TO MAXY+INT(COR/10) STEP 2
   WR=(T-MAXY/2+COR)/2: IF WR>215 THEN WR=215
   LINE 0,T,MAXX,T,1,RGB(WR,WR,255)
   BLIT 0,MAXY/2-(T-240)+37,COS(RAD(ROT*2+T*2))*8,T+1-INT(COR/10)*2,MAXX,1,1,4
  NEXT T

  'DRAW FAKE 3D FLOOR
  'FLOOR_3D(ROT/4,0,MAXY/2+COR/10,0,0,255,255,255)

  'RESTORE POLYGONAL X TO FOREGROUND
  IF XX>120 THEN BLIT MAXX/2+XX-70,MAXY/2-164,MAXX/2+XX-70,MAXY/2-164,140,200,2,4

  'BORDER FIX
  BOX 0,0,MAXX,MAXY,1,RGB(0,0,0)

  'CLOSE SCREEN AFTER 14.6 SECONDS
  IF SEC>14 THEN
   FOR T=0 TO MAXX STEP 10
    BOX T,0,CLX,MAXY,0,,RGB(0,0,0)
   NEXT T
   CLX=CLX+1
  ENDIF

  'COPY TO MAIN PAGE
  PAGE COPY 1 TO 0,B

 LOOP

END SUB

