  #compact
  % filename "t.exe"
 'uses RTL64
  % Title "Console Demo (F1 help)"
 '% Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
 '% NoEscape

  $ filename "t.exe"
 'uses RTL64
  uses ConsoleG

  ! DescribeCraftParts()
  ! RenderCraft()

  function main()
  ===============
  sys i,p
  string s
  float  a
  cls 0,0,0
  scale 2.,1.25
  printl "Select"
  scale .5,.80
  for i=1 to 10
    PickLabel i
    PushState
      color .99,.00,.00
      print i
    PopState
    PushState
    move 4 'tab
    print chr(i+64)
    PopState
    PushState
    move 8 'tab
    print hex(i+64,2)+"h"
    PopState
    move 0,-1 'linefeed
    PushState
      if picked=i 'mouse picker
        a=1.0
      else
        a=0.2
      end if
      Color .10,.10,.70, a
      move -0.5,0.9,-0.001
      PutBoxArea 12,1
    PopState
    PickLabel 0
  next
  '
  'TAB
  '
  if lastkey=9
    if picked
      picked=0 'allow text input
    else
      picked=1 'top of menu table
    end if
    lastkey=0
    lastchar=0
  end if
  '
  'MENU SELECTION USING KEYS
  '
  if picked>=1 and picked<=10
    SelectWithKeys p,1,10
    lastchar=0 : lastkey=0 'no further action
  end if
  '
  'SHOW SELECTION
  '
  if picked>0 and picked<=10
    color .4,.1
    printl "identity: " picked
  else
    printl
  end if
  printl
  '
  'LINE INPUT
  '
  PushState
  color .20,.80,.00,.88
  Scale 2
  print "Enter: "
  color .80,.80,.00,.88
  a=input inputs
  lastchar=0
  if a
    inputs="" : cp=1
  end if
  PopState
  printl
  '
  'DISPLAY LINE AND POINT
  '
  color .00,.80,.80,1.
  thickness 3
  line 10
  PointSize 11
  point 10,0,.0001
  move 0,-1
  '
  'DISPLAY LAST INPUT
  '
  if LastInput
    printl "Last input: " LastInput
  end if
  printl
  '
  'F1 HELP
  '
  if key[0x70]
    pushstate
    move 16,16
    color .8,.5
    scale  1.5,1.0
    printl "Active Keys:"
    scale  1/1.5,1.0
    printl "Tab"
    printl "Space"
    printl "Up"
    printl "Down"
    printl "Home"
    printl "End"
   'printl "Enter"
    printl "Esc"    tab "Exit"
    printl "Ctrl-P" tab "Take snapshot"
    printl
    scale 1.5,1.0
    printl "Mouse:"
    scale 1/1.5,1.0
    printl "Click to Select"
    printl "Can also move craft"
    popstate
  end if
  '
  lastkey=0
  lastchar=0
  '
  '3D SHADING opposite of 'flat'
  '
  shading
  move 2.,-2.,0.0
  Material Gold
  go sphere
  move 0.,-2.0
  Material Red
  go cube
  '
  pushState
   move 2.00
   rotateX -70
   scale 5
   Material Silver
   print3d "Solids",1,0
  popstate
  pushstate
  move 0.,-5.
  static MoveableObject saucer
  if not saucer.id
    saucer.mode=0x101
    saucer.snap=.5
    saucer.set 100,@RenderCraft,0.,0.,-4.
  end if
  saucer.act
  popstate
  move -2,-6
  pushstate
  DescribeCraftParts
  popstate
  '
  end function


  sub DescribeCraftParts()
  ======================
    string s
    if picked>=100 and picked<200
    select picked
      case 100        : s="Main Body"
      case 101 to 109 : s="Fin"
      case 111 to 119 : s="Propulsion"
      case 120        : s="Cabin"
      case 131 to 139 : s="Port"
    end select
    color 1,1,0
    printl picked ":  " s
    end if
  end sub


  sub RenderCraft
  ===============
  int i
  '
  'CRAFT MAIN BODY
  '
  PickLabel 100
  '
  'glTranslatef t.p.x+dx,t.p.y+dy,t.p.z+dz
  'glRotatef    t.a.x,1,0,0
  'glRotatef    t.a.y,0,1,0
  'glRotatef    t.a.z,0,0,1
  glScalef      3.,.5,3.
  Material Silver
  glCallList sphere
  '
  'FINS
  '
  for i=0 to 5
  PickLabel i+101
  glpushMatrix
  glRotatef i*60.0,0,1,0
  glTranslatef -.5,.20,.0
  glScalef      .4,.89,.15
  glCallList sphere
  glPopMatrix
  next
  '
  'PROPULSION
  '
  for i=0 to 5
  PickLabel i+111
  glpushMatrix
  glRotatef i*60.0,0,1,0
  glTranslatef -.75,-.60,.00
  glScalef      .10, .30,.10
  glCallList sphere
  glPopMatrix
  next
  '
  'CABIN
  '
  PickLabel 120
  glTranslatef .00,.99,.00
  glScalef     .50,1.99,.50
  Material Alloy
  glCallList sphere
  '
  'PORTS
  '
  for i=0 to 5
  PickLabel i+131
  glpushMatrix
  glRotatef 30.0+i*60.0,0,1,0
  glTranslatef .90,.10,.00 
  glscalef .10,.40,.20
  Material BlackShiny
  glCallList sphere
  glPopMatrix
  next
  '
  end sub 'craft

  EndScript
