create bitmap 1,10,50
set current bitmap 1
cls rgb(255,255,255)
get image 1,0,0,bitmap width(1),bitmap height(1),1
delete bitmap 1
create bitmap 1,20,20
circle bitmap width(1)/2-1, bitmap height(1)/2-1,bitmap width(1)/2-1
get image 2,0,0,bitmap width(1),bitmap height(1),1
delete bitmap 1
set current bitmap 0
 
Global Dim Ball(3) as float,P1,P2
Global X1,X2,Y1,Y2,Dim C(3,5)
Global ng as float
 
Ball(0)=screen width()/2 : Ball(1)=screen height()/2 : Ball(2)=1 : Ball(3)=1
sprite 1,0,screen height()/2,1
sprite 2,0,screen height()/2,1
sprite 3,Ball(0),Ball(1),2
sync on : sync rate 60
 
randomize timer()
 
for b=0 to 3
 for v=0 to 2
 C(b,v)=rnd(255)
 C(b,v+3)=1+rnd(1)*(-2)
 next v
next b
 
ng=3
do
 if ng<1 then X1=1 : X2=screen width()-1 : Y1=1 : Y2=screen height()-1
 cls rgb(255,255,255)
 box 1,1,screen width()-1,screen height()-1,_Color(0),_Color(1),_Color(2),_Color(3)
 line 50,0,50,screen height()
 line screen width()-50,0,screen width()-50,screen height()
 _Score()
 if ng>1
  if ng=3 then X1=screen width()/2-rnd(30)-20 : Y1=screen height()/2-rnd(30)-20 : X2=screen width()/2+rnd(30)+20 : Y2=screen height()/2+rnd(30)+20 : Ball(2)=1 : Ball(3)=1
  line X1,Y1,X1,Y2 : `<
  line X1,Y1,X2,Y1 : `^
  line X2,Y2,X2,Y1 : `>
  line X2,Y2,X1,Y2 : `v
  dec ng,0.016
  center text screen width()/2, screen height()/2,_Round_Number(ng)
 endif
 sprite 1,45,_Move(1),1
 sprite 2,screen width()-55,_Move(2),1
 sprite 3,_Ball(0)-10,_Ball(1)-10,2
 if escapekey() then end
 sync
loop
 
Function _Move(n)
 
 key=17 : i=14
 Y=0
 if n=2 then key=72 : i=4
 
 if keystate(key)=1 then Y=-4
 if keystate(key+i)=1 then Y=4
 
 if sprite y(n)+Y>-1 and sprite y(n)+Y+50<screen height()+3
  Y=Y+sprite y(n)
 else
  Y=sprite y(n)
 endif
 
endfunction Y
 
Function _Ball(n)
 
 if (Ball(0)+10)>X2 or (Ball(0)-10)<X1 then Ball(2)=Ball(2)*(-1)
 if (Ball(1)+10)>Y2 or (Ball(1)-10)<Y1  then Ball(3)=Ball(3)*(-1)
 
 if sprite hit(3,1)=1 and n=0
  Ball(2)=Ball(2)*(-1)
  Ball(0)=Ball(0)+Ball(2)+1
  if Ball(2)>0
   Ball(2)=Ball(2)+0.1
  else
   Ball(2)=Ball(2)-0.1
  endif
 endif
 if sprite hit(3,2)=1 and n=0
  Ball(2)=Ball(2)*(-1)
  Ball(0)=Ball(0)+Ball(2)-1
  if Ball(2)>0
   Ball(2)=Ball(2)+0.1
  else
   Ball(2)=Ball(2)-0.1
  endif
 endif
 if Ball(2)>5 then Ball(2)=5
 if Ball(2)<-5 then Ball(2)=-5
 
 Ball(0)=Ball(0)+Ball(2)
 Ball(1)=Ball(1)+Ball(3)
 
 C=Ball(0)
 if n=1 then C=Ball(1)
endfunction C
 
Function _Score()
 
 if Ball(0)<50 then inc P2 : Ball(0)=screen width()/2 : Ball(1)=screen height()/2 : Ball(2)=1 : ng=3
 if Ball(0)>screen width()-50 then inc P1 : Ball(0)=screen width()/2 : Ball(1)=screen height()/2: Ball(2)=-1 : ng=3
 
 center text screen width()/2,0,"Player 1:" + str$(P1) + "  " + "Player 2:" + str$(P2)
 center text screen width()/2,screen height()-20,"Player 1-> W and S  Player 2-> Num8 and Num5"
endfunction
 
Function _Round_Number(n as float )
 
 txt$=str$(n)
 i=1
 while mid$(txt$,i)<>"."
  inc i
 endwhile
 i=i+2
 txt$=left$(txt$,i)
 
endfunction txt$
 
Function _Color(n)
 Color as dword
 
 if rnd(1000)<5 then C(n,3)=C(n,3)*(-1)
 if rnd(1000)<5 then C(n,4)=C(n,4)*(-1)
 if rnd(1000)<5 then C(n,5)=C(n,5)*(-1)
 
 C(n,0)=C(n,0)+C(n,3)
 C(n,1)=C(n,1)+C(n,4)
 C(n,2)=C(n,2)+C(n,5)
 
 red=C(n,0)
 green=C(n,1)
 blue=C(n,2)
 
 if red>254 or red<1 then C(n,3)=C(n,3)*(-1)
 if green>254 or green<1 then C(n,4)=C(n,4)*(-1)
 if blue>254 or blue<1 then C(n,5)=C(n,5)*(-1)
 
 Color=rgb(red,green,blue)
 
endfunction Color