set_displaymode()
create_graphics()
Global ball_y
Global ball_x
Global ai_y
Global p1_score
Global p2_score
Global speed#
Global dir$
Global y_speed#
Global bg01_x#
Global bg02_x#
y_speed# = 2
dir$ = "right"
ball_x = screen width()/2 : ball_y = screen height()/2
p1_score = 0 : p2_score = 0
speed# = 2
 
do
 
   cls
   scroll_bg()
   p1_score(p1_score)
   p2_score(p2_score)
   p1_control()
   ai_control()
   ball_movement()
   ball_collision()
   ball_score()
   sync rate 70
 
loop
 
function scroll_bg()
 
   sprite 4,bg01_x#,0,200
   sprite 5,bg01_x#+screen width(),0,200
   sprite 6,bg02_x#,0,201
   sprite 7,bg02_x#+screen width(),0,201
   dec bg01_x#,0.5+(speed#*0.5) : dec bg02_x#,1+(speed#*0.5)
   if bg01_x# < -screen width() Then bg01_x# = 0
   if bg02_x# < -screen width() Then bg02_x# = 0
 
 
endfunction
 
function ball_score()
 
   if ball_x > screen width()
      inc p1_score,1+speed#
      ball_x = screen width()/2
      ball_y = screen height()/2
      y_speed# = 2
      speed# = 2
   endif
   if ball_x < 0
      inc p2_score,1+speed#
      ball_x = screen width()/2
      ball_y = screen height()/2
      speed# = 2
      y_speed# = 2
   endif
 
endfunction
 
function ball_movement()
 
   inc ball_y,y_speed#
   if dir$="right" Then inc ball_x,speed#
   if dir$="left" Then dec ball_x,speed#
   sprite 1,ball_x,ball_y,500
 
endfunction
 
function ball_collision()
 
   if ball_y > screen height()
      y_speed# = -y_speed#
   endif
   if ball_y < 0
      y_speed# = -y_speed#
   endif
   if SPRITE COLLISION(1,2)
      dir$ = "right"
      inc speed#,0.5
      y_speed# = speed#*rnd(1)+1
   endif
   if SPRITE COLLISION(1,3)
      dir$ = "left"
      inc speed#,0.5
      y_speed# = speed#*rnd(1)+1
   endif
 
endfunction
 
function ai_control()
 
   bally = mousey()
   if ai_y < ball_y+40 And ball_x > screen height()/2 then inc ai_y,10+speed#
   if ai_y > ball_y-40 And ball_x > screen height()/2 then dec ai_y,10+speed#
   sprite 3,screen width()-50,ai_y,501
 
endfunction
function p1_control()
 
   sprite 2,30,mouseY(),501
 
endfunction
 
function set_displaymode()
 
   set display mode 1024,768,32
   Sync Rate 70
   Hide Mouse
 
 
endfunction
 
function p1_score(p1_score)
 
      if p1_score = 0 Then paste image 1,200,40,1
      if p1_score < 10 and p1_score > 0
         paste image p1_score+1,200,40
      endif
      if p1_score >=10 and p1_score < 100
         paste image (p1_score/10)+1,200,40,1
         paste image (p1_score MOD 10)+1,240,40,1
      endif
      if p1_score >= 100 and p1_score < 1000
         paste image (p1_score/100)+1,200,40,1
         paste image ((p1_score MOD 100)/10)+1,240,40,1
         paste image ((p1_score MOD 100) MOD 10)+1,280,40,1
      endif
 
endfunction
 
function p2_score(p2_score)
 
      if p2_score = 0 Then paste image 1,650,40,1
      if p2_score < 10 and p2_score > 0
         paste image p2_score+1,650,40
      endif
      if p2_score >=10 and p2_score < 100
         paste image (p2_score/10)+1,650,40,1
         paste image (p2_score MOD 10)+1,690,40,1
      endif
      if p2_score >= 100 and p2_score < 1000
         paste image (p2_score/100)+1,650,40,1
         paste image ((p2_score MOD 100)/10)+1,690,40,1
         paste image ((p2_score MOD 100) MOD 10)+1,730,40,1
      endif
 
endfunction
 
 
function create_graphics()
 
   Set Text Font "Arial Bold"
   ink rgb(255,255,0),1
   Set Cursor (screen width()/2)-25,(screen height()/2)-50 : Print "LOADING"
   box (screen width()/2)-150,(screen height()/2)-25,(screen width()/2)+150,(screen height()/2+25)
   ink rgb(0,0,0),1
   box (screen width()/2)-148,(screen height()/2)-23,(screen width()/2)+149,(screen height()/2+23)
   ink rgb(255,255,0),1
   box (screen width()/2)-146,(screen height()/2)-21,(screen width()/2)-100,(screen height()/2+21)
   sync
   REM Make Background
   cls : ink rgb(255,255,255),1
   for i = 0 to 500
      dot rnd(screen width()),rnd(screen height())
   next i
   get image 200,0,0,screen width(),screen height()
   cls
   for i = 0 to 100
      circle rnd(screen width()),rnd(screen height()),1
   next i
   get image 201,0,0,screen width(),screen height()
   cls
   REM Make The Ball
   _centerX = 200 : _centerY = 200
   ballradius# = 10
for i = 0 to 360
   angle# = i
  ballx#=ballradius#*cos(angle#)+_centerX
  bally#=ballradius#*sin(angle#)+_centerY
  ink rgb(255,255,255),1
  line _centerX,_centerY, ballx#,bally#
next i
   r# = 50 : g# = 50 : b# = 50
   for a = 188 to 212
      for b = 188 to 212
         ink rgb(r#,g#,b#),1
         red = RGBR(point(b,a))
         if red = 255 Then dot b,a,RGB(r#,g#,b#)
      next b
      inc g#,10 : inc r#,10 : inc b#,10
   next a
   ballradius# = 8
   for i = 0 to 360
      angle# = i
     ballx#=ballradius#*cos(angle#)+_centerX
     bally#=ballradius#*sin(angle#)+_centerY
     ink rgb(255,255,255),1
     line _centerX,_centerY, ballx#,bally#
   next i
   r# = 50 : g# = 0 : b# = 0
   for a = 188 to 212
      for b = 188 to 212
         ink rgb(r#,g#,b#),1
         red = RGBR(point(b,a))
         if red = 255 Then dot b,a,RGB(r#,g#,b#)
      next b
      inc r#,10
   next a
   get image 500,188,188,212,221,1
   cls : sync
   ink rgb(255,255,0),1
   Set Cursor (screen width()/2)-25,(screen height()/2)-50 : Print "LOADING"
   box (screen width()/2)-150,(screen height()/2)-25,(screen width()/2)+150,(screen height()/2+25)
   ink rgb(0,0,0),1
   box (screen width()/2)-148,(screen height()/2)-23,(screen width()/2)+149,(screen height()/2+23)
   ink rgb(255,255,0),1
   box (screen width()/2)-146,(screen height()/2)-21,(screen width()/2)-50,(screen height()/2+21)
   sync
 
   Set Text Size 75
   global r# : Global g#
   r# = 255 : g# = 0
      cls
      Set Cursor 10,100 : Print "0  1  2  3  4  5  6  7  8  9" ` 160 to 114 X 693
   ink rgb(r#,g#,0),1
   for y = 114 to 160
      for x = 0 to 700
         ink rgb(r#,g#,0),1
         `set cursor 10,400 : Print RGBR(point(mousex(),mousey()))
         `circle mousex(),mousey(),5
         red = RGBR(point(x,y))
         `g = RGBG(point(mousex(),mousey()))
         `b = RGBB(point(mousex(),mousey()))
         if red = 255 Then dot x,y,RGB(r#,g#,0)
      next x
      inc g#,4
   next y
   get image 999,10,114,700,160
   paste image 999,10,114
   Get Image 1,2,114,52,160
   Get Image 2,75,114,125,160
   Get Image 3,146,114,196,160
   Get Image 4,217,114,267,160
   Get Image 5,289,114,339,160
   Get Image 6,363,114,413,160
   Get Image 7,434,114,484,160
   Get Image 8,506,114,556,160
   Get Image 9,578,114,628,160
   Get Image 10,650,114,700,160
   cls : sync
   ink rgb(255,255,0),1
   set text size 12
   Set Cursor (screen width()/2)-25,(screen height()/2)-50 : Print "LOADING"
   box (screen width()/2)-150,(screen height()/2)-25,(screen width()/2)+150,(screen height()/2+25)
   ink rgb(0,0,0),1
   box (screen width()/2)-148,(screen height()/2)-23,(screen width()/2)+149,(screen height()/2+23)
   ink rgb(255,255,0),1
   box (screen width()/2)-146,(screen height()/2)-21,(screen width()/2)+50,(screen height()/2+21)
   sync
  ` do
  `    p1_score(11)
  ` loop
 
   REM MAKE THE PADDLE
   r# = 27 : g# = 22 : b# = 77
   ink rgb(r#,g#,b#),1
   for i = 0 to 99
      line 10,10+i,35,10+i
      if i < 25
         inc r#,9.1 : inc g#,8.4 : inc b#,6.9
      endif
      if i > 25
         dec r#,9.5*0.33 : dec g#,8.8*0.33 : dec b#,7.00*0.33
      endif
      ink rgb(r#,g#,b#),1
   next i
      REM INNER PADDLE
   r# = 27 : g# = 22 : b# = 77
   ink rgb(r#,g#,b#),1
   for i = 0 to 20
      line 12+i,12,12+i,108
   if i < 15
      inc r#,15.2 : inc g#,15.53 : inc b#,11.86
   endif
   if i > 15
      dec r#,45.6 : dec g#,46.6 : dec b#,36.6
   endif
      ink rgb(r#,g#,b#),1
   next i
   get image 501,10,10,35,110
 
   cls : sync
   ink rgb(255,255,0),1
   set text size 12
   Set Cursor (screen width()/2)-25,(screen height()/2)-50 : Print "LOADING"
   box (screen width()/2)-150,(screen height()/2)-25,(screen width()/2)+150,(screen height()/2+25)
   ink rgb(0,0,0),1
   box (screen width()/2)-148,(screen height()/2)-23,(screen width()/2)+149,(screen height()/2+23)
   ink rgb(255,255,0),1
   box (screen width()/2)-146,(screen height()/2)-21,(screen width()/2)+146,(screen height()/2+21)
   sync
   wait 2000 : cls
 
endfunction
 
Function free_image()
 
   repeat
      inc n
   until image exist(n) = 0
 
endfunction n
 
Function free_sprite()
 
   repeat
      inc n
   until sprite exist(n) = 0
 
endfunction n