I have made a small two player ping pong game for the purpose of trying out the multiplayer commands. the host sends a memblock to the client with Paddle & Ball position and client sends a memblock back with its Paddle position.
the code works except that the clients buffer starts filling up rapidly. it checks every loop if the ball or paddle has moved and if so it sends a memblock. if I only send a memblock when the paddle moves ignoring the ball movement then the buffer stays at one. Why?
This is over a lan network.
Set Display mode 800,600,16
cls
color backdrop 0
backdrop on
sync on
sync rate 0
load image "Ball1.bmp",1
load image "Padle.bmp",2
load image "wall1.bmp",3
hide mouse
make memblock 1,16
make memblock 2,16
sprite 1,400,300,1
sprite 2,784,300,2
sprite 3,0,300,2
sprite 4,0,0,3
sprite 5,0,594,3
y=300
write memblock word 2,0,300
bx#=400
by#=300
player=default net game( "Ping Pong","Player",2,2)
xd#=.5
yd#=0
do
gosub DoNet:
ink=scancode()
gosub GetMove:
gosub bounce:
gosub Draw:
if ink=1 then exit
sync
loop
show mouse
end
GetMove:
y=y+mousemovey()*2
if y546 then y=546
if yyo then u=1:yo=y
y1=MEMBLOCK dWORD(2, 0)
if player=2
y1=memblock dword(2,0)
bx#=memblock dword(2,4)
by#=memblock dword(2,8)
write memblock dword 1,0,y
else
bx#=bx#+xd#
by#=by#+yd#
if bx#bxo# then u=1:bxo#=bx#
if by#byo# then u=1:byo#=by#
write memblock dword 1,0,y
write memblock dword 1,4,bx#
write memblock dword 1,8,by#
endif
return
Draw:
if player=1
sprite 2,784,y,2
sprite 3,0,y1,2
else
sprite 2,784,y1,2
sprite 3,0,y,2
endif
sprite 1,bx#,by#,1
text 400,100,str$(net buffer size())
return
DoNet:
if u=1 then send net message memblock 0,1:u=0
get net message
if net message exists() then net message memblock 2
return
Bounce:
sh=sprite hit(1,0)
select sh
case 2
if lhsh then xd#=xd#*-1:lh=sh
endcase
case 3
if lhsh then xd#=xd#*-1:lh=sh
endcase
case 4
if lhsh then yd#=yd#*-1:lh=sh
endcase
case 5
if lhsh then yd#=yd#*-1:lh=sh
endcase
endselect
return