`   'Aargh - not another Pong Clone!' by Ric.
 
if check display mode(1024,768,32)=1 then set display mode 1024,768,32
hide mouse
sync on
sync rate 50
autocam off
hide light 0
color backdrop rgb(0,0,0)
set ambient light 80
make light 1
position light 1,100,100,20
set light range 1,100000
color light 1,rgb(255,220,180)
 
fog on
fog color 0
fog distance 1000
 
`create green texture
for x=0 to 100
   for y=0 to 100
      ink rgb(0,x+y,0),0
      dot x,y
   next y
next x
get image 103,0,0,100,100
 
cls
 
`create purple texture
for x=0 to 100
   for y=0 to 100
      ink rgb(x+y,0,x+y),0
      dot x,y
   next y
next x
get image 102,0,0,100,100
 
cls
 
`create blue texture
for x=0 to 100
   for y=0 to 100
      ink rgb(0,0,x+y),0
      dot x,y
   next y
next x
get image 101,0,0,100,100
 
`create star texture
for x=0 to 100
for y=0 to 100
d=rnd(20)
ink rgb(100+rnd(100),100+rnd(100),rnd(100)+100),0
if d=1 then dot x,y
next y
next x
get image 1,0,0,100,100
 
`create tile texture
cls
ink rgb(0,0,255),0
box 0,0,10,10
box 10,10,20,20
get image 2,0,0,20,20
 
set text font "sf automaton_mod"
set text size 25
 
`create starsphere
make object sphere 1000,-1000,50,50
texture object 1000,1
scale object texture 1000,5,5
xrotate object 1000,-90
 
`player paddle
make object sphere 1,20,20,20
scale object 1,100,400,100
ghost object on 1
texture object 1,102
set object emissive 1,rgb(200,200,200)
set object specular 1,rgb(250,250,250)
set object specular power 1,10
set object fog 1,0
set object collision on 1
set object collision to boxes 1
 
 
`reflection of player paddle
clone object 302,1 `top
scale object 302,100,400,100
fade object 302,90
clone object 303,1 `bottom
scale object 303,100,400,100
fade object 303,90
 
`computer paddle
make object sphere 2,20,20,20
scale object 2,100,400,100
ghost object on 2
texture object 2,103
set object emissive 2,rgb(200,200,200)
set object specular 2,rgb(250,250,250)
set object specular power 2,10
set object fog 2,0
set object collision on 2
set object collision to boxes 2
 
`reflection of computer paddle
clone object 304,2 `top
scale object 304,100,400,100
fade object 304,90
clone object 305,2 `bottom
scale object 305,100,400,100
fade object 305,90
 
`ball
make object sphere 3,20,40,40
texture object 3,101
set object specular 3,rgb(200,200,200)
set object specular power 3,15
set object emissive 3,rgb(150,150,100)
set object ambient 3,0
set object collision on 3
set object fog 3,0
 
`reflection of ball
clone object 300,3 `top reflection
fade object 300,50
clone object 301,3 `bottom reflection
fade object 301,50
 
`bottom wall
make object plain 4,500,800
xrotate object 4,90
set object collision on 4
texture object 4,2
scale object texture 4,5,5
set object transparency 4,1
 
`top wall
make object plain 5,500,800
xrotate object 5,90
set object collision on 5
texture object 5,2
scale object texture 5,5,5
set object transparency 5,1
 
`back wall
make object plain 6,500,100
texture object 6,101
scale object texture 6,2,10
set object texture 6,2,0
set object transparency 6,1
set object fog 6,0
ghost object on 6
 
`position walls
position object 4,0,-150,100
position object 5,0,150,100
position object 6,0,0,300
 
`restart point for new game (the goto command is not dead yet!)
newgame:
 
for object=300 to 305
hide object object
next object
 
`zoom in
paddlex#=0
position object 1,-paddlex#,0,0
position object 2,paddlex#,0,0
position object 3,0,0,0
 
 
zrotate camera 0
camz#=-2000.0
position camera 0,0,0,camz#
while camz#<-500.0
inc camz#,5
position camera 0,0,camz#
sync
endwhile
position camera 0,0,0,-500
 
`set paddle positions
 
while paddlex#<180
inc paddlex#
position object 1,-paddlex#,0,0
position object 2,paddlex#,0,0
sync
endwhile
 
 
 
do
text screen width()/2-100,200,"Gravity on? (y/n)"
if inkey$()="y" then gravity=1:exit
if inkey$()="n" then gravity=0:exit
sync
loop
 
text screen width()/2-70,240,"GET READY!"
sync
wait 600
 
for object=300 to 305
show object object
next object
 
`set initial variables
level=1
pscore=0
cscore=0
pv#=10 `player paddle velocity
bvx#=10 `ball velocity
if gravity=1
cv#=3.5 `computer paddle velocity
g#=0.5
else
cv#=2
g#=0
endif
 
`restart point for new serve or new level
restart:
randomize timer()
wait 800
py#=-10+rnd(20) `player's initial y position
cy#=-10+rnd(20)           `computer's initial y position
bx#=0           `ball x
by#=0           `ball y
bvy#=1.5+rnd(10)/10          `ball direction (in degrees:- horizontal=0)
bvx#=abs(bvx#)
`main loop
 
do
 
text 0,0,str$(screen fps())
 
`player input
remstart
if upkey()>0 and object collision (1,5)=0
   py#=py#+pv#
endif
 
if downkey()>0 and object collision (1,4)=0
   py#=py#-pv#
endif
remend
 
 
py#=py#-mousemovey()
if py#>110 then py#=110
if py#<-110 then py#=-110
 
`move player paddle
position object 1,-180,py#,100
position object 302,-180,-py#-300,100
position object 303,-180,-py#+300,100
`position object 401,-180,py#,100
 
`ball motion
bvy#=bvy#+g#
bx#=bx#+bvx#
by#=by#-bvy#
 
`collision with court
if by#>140
by#=by#-10
bvy#=bvy#*-1
endif
 
if by#<-140
by#=by#+10
bvy#=bvy#*-1
endif
 
`collision with player paddle
if object collision (3,0)=1
  bvx#=bvx#*-1 `reverse velocity
  bx#=-150 `prevent embedding
`measure offset between player paddle and ball and adjust direction
    po#=by#-py#
    bvy#=bvy#-po#*0.15
endif
 
`and same for computer paddle.....
if object collision (3,0)=2
  bvx#=bvx#*-1
  bx#=150
    co#=by#-cy#
    bvy#=bvy#-co#*0.15
endif
 
if bvy#>15.0 then bvy#=15.0
if bvy#<-15.0 then bvy#=-15.0
 
`new ball position
position object 3,bx#,by#,100
position object 300,bx#,-by#+300,100
position object 301,bx#,-by#-300,100
 
`computer paddle A.I.
 
`return to middle
if bvx#<0
  if cy#>2 then a#=-cv#
  if cy#<2 then a#=cv#
  if cy#<=2 and cy#>=-2 then a#=0
  cy#=cy#+a#
endif
 
`move towards ball
if bvx#>0
  if by#>cy# then a#=cv#
  if by#<cy# then a#=-cv#
  cy#=cy#+a#
endif
 
position object 2,180,cy#,100
position object 304,180,-cy#+300,100
position object 305,180,-cy#-300,100
 
`win or lose
if object position x(3) < -250
   cscore=cscore+1
   vb#=vb#*-1
   goto restart
endif
 
if object position x(3) > 250
  pscore = pscore +1
  goto restart
endif
 
`print score
text screen width()/2-20,screen height()/2-12,str$(pscore)+" : "+str$(cscore)
 
`goto next level, increase difficulty and reset scores
if pscore>2
   bv#=bv#+1
   pv#=pv#+0.3
   cv#=cv#+0.5
   level=level+1
   pscore=0
   cscore=0
   goto restart
endif
 
`display level
text screen width()/2-40,screen height()/2-100,"Level "+str$(level)
 
 
`game over text
if cscore>2
set text font "impact"
ink rgb(0,200,0),0
text screen width()/2-50,screen height()/2+200,"Game Over"
text screen width()/2-80,screen height()/2+250,"You reached level "+str$(level)
text screen width()/2-100,screen height()/2+280,"Press any key to restart"
sync
wait key
set text font "sf automaton_mod"
ink rgb(0,0,255),0
goto newgame
endif
 
if inkey$()="q" then goto restart
 
if level>3
  `scroll textures
  scroll object texture 1000,0,-0.014
  scroll object texture 4,0,0.08
  scroll object texture 5,0,0.08
 
  if clockwise=1 then roll camera right 0.1
  if camera angle z()>30 then clockwise=0:turn camera left 0.1
  if clockwise=0 then roll camera left 0.1
  if camera angle z()<-30 then clockwise=1:turn camera right 0.1
 
else
 
 `scroll textures
  scroll object texture 1000,0,-0.004
  scroll object texture 4,0,0.004
  scroll object texture 5,0,0.004
 
endif
 
sync
loop