`set up enviroment
sync on
sync rate 40
hide mouse
gosub setup
balla#=rnd(45)+5
bluescore=0
redscore=0
do
   `set up sub routines
   gosub writing
   `if up or down is pressed move the paddles
   i$=lower$(inkey$())
   If i$="d" then bluepos#=bluepos#+.5
   if i$="a" then bluepos#=bluepos#-.5
   if i$="l" then redpos#=redpos#+.5
   if i$="j" then redpos#=redpos#-.5
   `restrict paddles
   if I$="d" and bluepos#>10
      bluepos#=bluepos#-.5
   endif
   if I$="a" and bluepos#<0
      bluepos#=bluepos#+.5
   endif
   if I$="l" and redpos#>10
      redpos#=redpos#-.5
   endif
   if I$="j" and redpos#<0
      redpos#=redpos#+.5
   endif
   `bounce the ball back from blue paddle
   if ballx#<-8.5 and ballx#>-9 and abs(bluepos#-ballz#)<2.5
      balla#=360-balla#
   endif
   `bounce the ball back from red paddle
   if ballx#>8.5 and ballx#<9 and abs(redpos#-ballz#)<2.5
      balla#=360-balla#
   endif
   `curve the ball when paddle moving
   if i$="a" and ballx#<-8.5 and ballx#>-9 then balla#=balla#-11
   if i$="d" and ballx#<-8.5 and ballx#>-9 then balla#=balla#+11
   if i$="j" and ballx#>8.5 and ballx#<9 then balla#=balla#-11
   if i$="l" and ballx#>8.5 and ballx#<9 then balla#=balla#+11
   `bounce from top and bottom walls
   if ballz#>10 or ballz#<0 then balla#=180-balla#
   ` WHAT TO DO IF BLUE WINS
   if ballx#>11
      balla#=45
      ballx#=0
      inc bluescore
   endif
   `WHAT TO DO IF RED WINS
   if ballx#<-11
      balla#=-45
      ballx#=0
      inc redscore
   endif
   if redscore>bluescore then color object 3,16711680
   if bluescore>redscore then color object 3,255
   if redscore=bluescore then color object 3,9868950
   `ball movement
   ballx#=newxvalue(ballx#,balla#,0.3)
   ballz#=newzvalue(ballz#,balla#,0.3)
   balla#=wrapvalue(balla#)
   yrotate object 3,balla#
   `position paddles and ball
   position object 1,9.5,1,redpos#
   position object 2,-9.5,1,bluepos#
   position object 3,ballx#,1,ballz#
   position object 4,0,-1,7
   position object 5,0,0,15
   sync
loop
end
setup:
`make right side paddle color it red
make object box 1,1,1,3
color object 1,16711680
`make left side padde and color it blue
make object box 2,1,1,3
color object 2,255
`make the ball color it grey
make object sphere 3,1
color object 3,9868950
`make the floor color it green
make object box 4,23,1,15
color object 4,65280
make object box 5,23,7,1
color object 5,65280
`background white
color backdrop 0
`put camera in position
position camera 0,8,-15
return
`scoretable sub routine
writing:
   `put the title in various colors
   ink 255,0
   set text size 30
   text 230,20,"3D"
   ink 16711680,0
   set text size 40
   text 270,20,"Pong"
   ink 16777215,0
   `set score table
   set cursor 20,10
   ink 255,0
   print "Blue Score: ";bluescore
   set cursor 540,10
   ink 16711680,0
   print "Red Score: ";redscore
return