I'm trying to make a two/four player LAN game. I just want it to be where 2 or 4 players login and move around.
Here is the server code:
setvirtualresolution(1024,768)
INetID = hostnetwork("AGKserver","host",6444)
SetSpriteSize(3, 1024, 768 )
loadimage(1,"player.png")
NumPlayer = 4
gosub checkforplayers
do
sync()
gosub internet
loop
checkforplayers:
for x = 1 to 2
if x = 1
id = GetNetworkFirstClient(iNetID)
createsprite(1,1)
else
id = GetNetworkNextClient(iNetID)
loadimage(2,"player2.png")
createsprite(2,2)
endif
if id = 0 then exit
if GetNetworkClientDisconnected(iNetID, id) = 1
DeleteNetworkClient(iNetID, id)
endif
next x
return
internet:
msg = GetNetworkMessage(iNetID)
if msg > 0
for Players = 1 to 2
x#=getnetworkmessagefloat(msg)
y#=getnetworkmessagefloat(msg)
name$=getnetworkmessagestring(msg)
setspriteposition(Players,GetSpriteX (Players) + ( x# / 0.1 ),GetSpritey (Players) + ( y# / 0.1 ))
print(name$)
next id
endif
DeleteNetworkMessage(msg)
return
Here is the client code:
SetVirtualResolution (960, 640)
SetResolutionMode (1)
net = joinnetwork("AGKserver","client")
AddVirtualJoystick(1,210,380,280)
addvirtualbutton(2,580,300,150)
addvirtualbutton(3,580,500,150)
addvirtualbutton(4,780,300,150)
addvirtualbutton(5,780,500,150)
SetVirtualButtonColor( 2, 255, 5, 5 )
SetVirtualButtonColor( 3, 255, 5, 5 )
SetVirtualButtonColor( 4, 255, 5, 5 )
SetVirtualButtonColor( 5, 255, 5, 5 )
SetVirtualButtonText( 2, "PUNCH" )
SetVirtualButtonText( 3, "KICK" )
SetVirtualButtonText( 4, "JUMP" )
SetVirtualButtonText( 5, "BLOCK" )
SetOrientationAllowed (0, 0, 1, 1)
do
sync()
gosub internet
if getvirtualbuttonstate(2)=1 then x=x-1
if getvirtualbuttonstate(3)=1 then y=y+1
if getvirtualbuttonstate(4)=1 then y=y-1
joystickX# = GetVirtualJoystickX ( 1 )
joystickY# = GetVirtualJoystickY ( 1 )
loop
internet:
msg=createnetworkmessage()
addnetworkmessagefloat(msg,joystickX#)
addnetworkmessagefloat(msg,joystickY#)
addnetworkmessagestring(msg,"client")
sendnetworkmessage(net,0,msg)
deletenetworkmessage(msg)
return
rem host software
Thank you for your time.