Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Global host = CreateGNetHost()
- Global msgobj:TGNetObject
- Global remoteobj:TGNetObject
- Global clientid
- Global objlist:TList
- Graphics 800,600
- in$=""
- While Not (KeyHit (KEY_ENTER))
- If AppTerminate () End
- Delay 10
- If KeyHit (KEY_BACKSPACE) in=Left (in,Len (in)-1)
- ch=GetChar ()
- If (ch>47 And ch<58) Or ch=46 in$=in$+Chr(ch)
- DrawText ("Serverin ip:"+in,1,1)
- Flip
- Cls
- Wend
- address$=in
- DrawText ("Yhdistetaan",1,1)
- Flip
- cerror=connecthost(address$,21231)
- Cls
- ox=0
- oy=0
- While Not (KeyHit(KEY_ESCAPE) Or AppTerminate ())
- Delay 10
- If cerror=0
- DrawText ("Ei yhteytta",1,1)
- Else
- DrawText ("Yhteys",1,1)
- GNetSync host
- DrawText ("id "+clientid,1,20)
- If KeyDown (KEY_LEFT)
- DrawText ("moving",1,40)
- SetGNetInt (msgobj,2,-1)
- EndIf
- If KeyDown (KEY_RIGHT)
- DrawText ("moving",1,40)
- SetGNetInt (msgobj,2,1)
- EndIf
- If KeyDown (KEY_DOWN)
- DrawText ("moving",1,40)
- SetGNetInt (msgobj,3,1)
- EndIf
- If KeyDown (KEY_UP)
- DrawText ("moving",1,40)
- SetGNetInt (msgobj,3,-1)
- EndIf
- objlist = GNetObjects (host, GNET_MODIFIED)
- For remoteobj = EachIn objlist
- ox=GetGNetInt (remoteobj,2)
- oy=GetGNetInt (remoteobj,3)
- Next
- DrawText (ox,1,60)
- DrawText (oy,1,80)
- EndIf
- Flip
- Cls
- Wend
- CloseGNetHost(host)
- End
- Function connecthost (ip$,port)
- connect = GNetConnect (host,ip,port,5000)
- If Not connect Return 0
- msgobj=CreateGNetObject (host)
- SeedRnd MilliSecs()
- clientid=Rand (1,320000)
- objlist:TList= New TList
- SetGNetInt (msgobj,0,1)
- SetGNetInt (msgobj,1,clientid)
- Return connect
- EndFunction
Add Comment
Please, Sign In to add comment