'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
'+                  Ping by Gareth Bailey                +
'+                    October   2001                     +
'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +


open window 640,512
start()

sub setup()
score=0
score2=0
padspd=5
x=320
y=220
dirx=-5
diry=ran(6)+1
by =185
by2=by
txt$="WElcome to Ping, have fun playing....goto http://pub51.ezboard.com/byabasicprogramming :o)"
txtend=-30-(len(txt$)*10)
tx=640
ty=500
end sub

sub main()
repeat
clear window
draw()
conread()
col()
db()
until (peek("port1")=4096)
start()
end sub

sub conread()
con = peek("port1")
if (and(con, 16) <> 0)  by =by -padspd
if (and(con, 64) <> 0)  by =by +padspd
con2 = peek("port2")
if (and(con2, 16) <> 0) by2=by2-padspd
if (and(con2, 64) <> 0) by2=by2+padspd
end sub

sub col()
x=x-dirx:y=y-diry
if x<20 then
score2=score2+1 
xtoplay()
fi
if x>620 then
score=score+1 
xtoplay()
fi
if y<20 or y>410 diry=0-diry
if y>by  and y<by+70  and x<40 and x>30   dirx=0-dirx
if y>by2 and y<by2+70 and x<610 and x>600 dirx=0-dirx
if by  > 350 by=350
if by  < 20  by=20
if by2 > 350 by2=350
if by2 < 20  by2=20
end sub

sub db()
setdispbuf draw
draw = 1 - draw
setdrawbuf 1 - draw
end sub

sub draw()
setrgb 1,0,75,0
fill rectangle 20,20 to 630,420
setrgb 1,250,250,250
line 325,20 to 325,420
fill rectangle 30,by   to 40,by+70 
fill rectangle 620,by2 to 610,by2+70 
fill rectangle x,y to x+10,y+10
text 100,450,"player(1): "+str$(score ),"lc"
text 540,450,"player(2): "+str$(score2),"rc"
text 320,475,"Press  to restart","cc"
setrgb 1,0,150,0
triangle 285,475 to 290,465 to 295,475
scrolltxt()
end sub 

sub xtoplay()
text 320,220,"PRESS 'X' TO CONTINUE","cc"
x=320:y=220
diry=ran(6)+1
repeat:until (peek("port1")=16384)
end sub

sub start()
setup()
draw()
clear fill rectangle 190,100 to 460,340
setrgb 1,150,150,150
rectangle 210,130 to 440,170
text 320,150," P I N G","Cc"
text 320,220," | G E T   R E A D Y |","cc"
text 320,235," |   T O  P L A Y    |","cc"
text 320,320," PRESS 'X' TO START GAME","CC"
repeat
until (peek("port1")=16384)
main()
end sub

sub scrolltxt()
setrgb 1,250,250,250 
text tx,ty,txt$ :tx=tx-2
if tx<txtend tx=640
end sub





