  #compact
  % filename "t.exe"
 'uses RTL32
  % Title    "PONG BASE 2"
  % Animated
  % ScaleUp
  % PlaceCentral
 '% AnchorCentral
  uses ConsoleG

  indexbase 0

  'sys sseed=GetTickCount


  sub main()
  ==========
  '
  'static float ay
  'static sys   pki,count
  glClearColor 0,0.20,0,0
  if not pick
    thickness 3
    if opening
      static float byl=10
      static float bxl=15
      static float byd=11
      static float bxd=16
    endif
    '
    flat

    color .99,0,0

    glbegin GL_LINES
    glvertex3f -bxd,-byd,0
    glvertex3f bxd,-byd,0
    '
    glvertex3f -bxd,byd,0
    glvertex3f bxd,byd,0
    '
    glvertex3f -bxd,-byd,0
    glvertex3f -bxd,byd,0
    '
    glvertex3f bxd,-byd,0
    glvertex3f bxd,byd,0
    '
    glend
    '
    shading

    color .90,.90,0
    static float blx,bly
    static float vlx,vly
    static int tal,ntal
    if opening
      vlx=0.2
      vly=0.1
    endif
    '
    pushstate
    move blx,bly
    go sphere 'radius 0.5
    popstate

    blx+=vlx
    bly+=vly
    '
    'LIMIT AND BOUNCE
    '
    if blx > bxl
      vlx = -vlx
      ntal++
    elseif blx<-bxl
      vlx = -vlx
    endif
    '
    if bly>byl
      vly = -vly
    elseif bly < -byl
      vly = -vly
    endif
    '
    'PONG BAT AND SCORE
    '
    if opening
      static float btu=2.0
      static float btx=bxl-2.0
      static float bty=0.0
    endif
    'pong impact
    if blx>=btx-1.0
      if vlx<0.0
        'bouncing behind bat
      elseif bly>bty+btu+0.5
        'above bat
      elseif bly<bty-btu-0.5
        'below bat
      else
        tal++
        vlx = -vlx
      endif
    endif


    'SCORE
    flat
    pushstate
    move -bxd,byd+1.0
    scale 2
    print str(tal)" / "+str(ntal)
    popstate
    '
    '
    'pong bat render
    pushstate
    glbegin GL_QUADS
    glvertex3f btx-0.25,bty-btu,0
    glvertex3f btx+0.25,bty-btu,0
    glvertex3f btx+0.25,bty+btu,0
    glvertex3f btx-0.25,bty+btu,0
    glend
    popstate
    '
  end if
  '
  'KEYBOARD CONTROL
  if GetAsyncKeyState VK_UP
    if byd>bty+btu 'limit
      bty+=0.1
    endif
  endif
  if GetAsyncKeyState VK_DOWN
    if  -byd < bty-btu
      bty-=0.1
    endif
  endif
  '
  end sub

  EndScript
