GNet Beispiel

Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Neue Antwort erstellen

regaa

Betreff: GNet Beispiel

BeitragMi, Jun 29, 2005 22:39
Antworten mit Zitat
Benutzer-Profile anzeigen
Server:

Code: [AUSKLAPPEN]

' gnetserver

AppTitle="GNet Server Example"
Graphics 640,480,0,80

Host=CreateGNetHost()


If Host
   Print "Einen Server erstellt"
Else
   Print "Konnte Server nicht erstellen"
EndIf

player1:TGNetObject=CreateGNetObject(Host)

Local player_x:Int=0
Local player_y:Int=0

Const GNET_PLAYER_X=0
Const GNET_PLAYER_Y=1




erfolg=GNetListen(Host,12345)

If erfolg
   Print "Server horcht nun auf den Port 12345"
Else
   Print "Konnte Socket nicht binden"
EndIf

While Not KeyDown(KEY_ESCAPE)
   Cls
   GNetSync(Host)
   
   If (GNetAccept(Host))
      Print "Ein Client will sich verbinden"
      
      
   End If
   
   player_x=MouseX()
   player_y=MouseY()
   
   SetGNetFloat player1,GNET_PLAYER_X,player_x
   SetGNetFloat player1,GNET_PLAYER_Y,player_y

   For Local obj:TGNetObject=EachIn GNetObjects( host,GNET_ALL )
      If obj=player1
         DrawText "Me",player_x,player_y
      Else
         DrawText "Him",GetGNetFloat(obj,GNET_PLAYER_X),GetGNetFloat(obj,GNET_PLAYER_Y)
      EndIf
   Next
   
   Flip
   FlushMem()
Wend


CloseGNetHost(Host)
Print "Server runtergefahren"


Client:
Code: [AUSKLAPPEN]

' gnetclient

AppTitle="GNet Client Example"
Graphics 640,480,0,80

Host=CreateGNetHost()

player2:TGNetObject=CreateGNetObject(Host)

Local player_x:Int=0
Local player_y:Int=0

Const GNET_PLAYER_X=0
Const GNET_PLAYER_Y=1



Client=GNetConnect(Host,"127.0.0.1",12345)

While Not KeyDown(KEY_ESCAPE)
   Cls
   GNetSync(Host)

   player_x=MouseX()
   player_y=MouseY()

   SetGNetFloat player2,GNET_PLAYER_X,player_x
   SetGNetFloat player2,GNET_PLAYER_Y,player_y

   For Local obj:TGNetObject=EachIn GNetObjects( host,GNET_ALL )
      If obj=player2
         DrawText "Me",player_x,player_y
      Else
         DrawText "Him",GetGNetFloat(obj,GNET_PLAYER_X),GetGNetFloat(obj,GNET_PLAYER_Y)
      EndIf
   Next
   
   Flip
   FlushMem()
Wend


Hoffentlich klärt es paar Fragen. Ich poste das deswegen weil ich es mir grade selber beibringen musste, wegen der OH die ich grade um die GNet- Befehle erweitere Smile .
UltraMixer Professional 3 - Download
QB,HTML,CSS,JS,PHP,SQL,>>B2D,B3D,BP,BlitzMax,C,C++,Java,C#,VB6 , C#, VB.Net
  • Zuletzt bearbeitet von regaa am Mi, Jun 29, 2005 23:11, insgesamt einmal bearbeitet

Suco-X

Betreff: ....

BeitragMi, Jun 29, 2005 23:07
Antworten mit Zitat
Benutzer-Profile anzeigen
Na endlich mal etwas mehr Gnet Stoff, ich danke dir.
Mfg Suco
Intel Core 2 Quad Q8300, 4× 2500 MHz, 4096 MB DDR2-Ram, GeForce 9600GT 512 MB

regaa

BeitragMi, Jun 29, 2005 23:46
Antworten mit Zitat
Benutzer-Profile anzeigen
Hehe, Bitte Surprised . Hier hab ich nen Pong Multiplayer in 50 Minuten gezaubert:

Server:
Code: [AUSKLAPPEN]

' gnetserver

AppTitle="GNet Server Example"
Graphics 640,480,0,80

Host=CreateGNetHost()


If Host
   Print "Einen Server erstellt"
Else
   Print "Konnte Server nicht erstellen"
EndIf

player1:TGNetObject=CreateGNetObject(Host)

Local player_x:Float=0
Local player_y:Float=460
Local ball_x:Float=320
Local ball_y:Float=240

SeedRnd(MilliSecs())
Local ball_dirx:Float=RndFloat()
Local ball_diry:Float=RndFloat()

Local punktestand:Int=0
Local punktestand_him:Int=0

Const GNET_PLAYER_X=0
Const GNET_PLAYER_Y=1
Const GNET_BALL_X=2
Const GNET_BALL_Y=3
Const GNET_BALL_DIRX=4
Const GNET_BALL_DIRY=5
Const GNET_PUNKTESTAND_ME=6
Const GNET_PUNKTESTAND_HIM=7


SetGNetFloat player1,GNET_BALL_DIRX,ball_dirx
SetGNetFloat player1,GNET_BALL_DIRY,ball_diry

erfolg=GNetListen(Host,12345)

If erfolg
   Print "Server horcht nun auf den Port 12345"
Else
   Print "Konnte Socket nicht binden"
EndIf

While Not KeyDown(KEY_ESCAPE)
   Cls
   GNetSync(Host)
   
   If (GNetAccept(Host))
      Print "Ein Client will sich verbinden"
      
      
   End If
   
   player_x=MouseX()
   'player_y=MouseY()
   
   SetGNetFloat player1,GNET_PLAYER_X,player_x
   SetGNetFloat player1,GNET_PLAYER_Y,player_y

   For Local obj:TGNetObject=EachIn GNetObjects( host,GNET_ALL )
      If obj=player1
         'DrawText "Me",player_x,player_y
         DrawRect(player_x,player_y,50,20)
      Else
         'DrawText "Him",GetGNetFloat(obj,GNET_PLAYER_X),GetGNetFloat(obj,GNET_PLAYER_Y)
         Local posenemy_x=GetGNetFloat(obj,GNET_PLAYER_X)
         Local posenemy_y=GetGNetFloat(obj,GNET_PLAYER_Y)

         DrawRect(posenemy_x,posenemy_y,50,20)
         If ball_x>=posenemy_x And ball_x<=posenemy_x+50 And ball_y<=20 And ball_y>=15
            ball_diry=RndFloat()+1
         EndIf
      EndIf
   Next
   
   ball_x:+ball_dirx
   ball_y:+ball_diry
   
   If ball_x>640 Then ball_dirx=-RndFloat()-1
   If ball_x<0 Then ball_dirx=RndFloat()+1
   
   If ball_y>480
      ball_diry=-RndFloat()-1
      punktestand_him:+1
      SetGNetInt player1,GNET_PUNKTESTAND_HIM,punktestand_him
      ball_y=320
   EndIf
   If ball_y<0
      ball_diry=RndFloat()+1
      punktestand:+1
      SetGNetInt player1,GNET_PUNKTESTAND_ME,punktestand
      ball_y=320
   EndIf
   
   If ball_x>=player_x And ball_x<=player_x+50 And ball_y<=460-15 And ball_y>=455-15
      ball_diry=-RndFloat()-1
   EndIf

   SetGNetFloat player1,GNET_BALL_X,ball_x
   SetGNetFloat player1,GNET_BALL_Y,ball_y

   DrawText "Me: "+punktestand+" Him: "+punktestand_him,10,10
   DrawOval ball_x,ball_y,30,30
   
   Flip
   FlushMem()
Wend


CloseGNetHost(Host)
Print "Server runtergefahren"


Client:
Code: [AUSKLAPPEN]

' gnetclient

AppTitle="GNet Client Example"
Graphics 640,480,0,80

Host=CreateGNetHost()

player2:TGNetObject=CreateGNetObject(Host)

Local player_x:Int=0
Local player_y:Int=20

Const GNET_PLAYER_X=0
Const GNET_PLAYER_Y=1
Const GNET_BALL_X=2
Const GNET_BALL_Y=3
Const GNET_BALL_DIRX=4
Const GNET_BALL_DIRY=5
Const GNET_PUNKTESTAND_ME=7
Const GNET_PUNKTESTAND_HIM=6

Client=GNetConnect(Host,"127.0.0.1",12345)

While Not KeyDown(KEY_ESCAPE)
   Cls
   GNetSync(Host)

   player_x=MouseX()
   'player_y=MouseY()

   SetGNetFloat player2,GNET_PLAYER_X,player_x
   SetGNetFloat player2,GNET_PLAYER_Y,player_y

   For Local obj:TGNetObject=EachIn GNetObjects( host,GNET_ALL )
      If obj=player2
         'DrawText "Me",player_x,player_y
         DrawRect(player_x,player_y,50,20)

      Else
         'DrawText "Him",GetGNetFloat(obj,GNET_PLAYER_X),GetGNetFloat(obj,GNET_PLAYER_Y)
         DrawRect(GetGNetFloat(obj,GNET_PLAYER_X),GetGNetFloat(obj,GNET_PLAYER_Y),50,20)
         DrawOval(GetGNetFloat(obj,GNET_BALL_X),GetGNetFloat(obj,GNET_BALL_Y),30,30)
         DrawText "Me: "+GetGNetInt(obj,GNET_PUNKTESTAND_ME)+" Him: "+GetGNetInt(obj,GNET_PUNKTESTAND_HIM),10,10
      EndIf
   Next
   
   

   Flip
   FlushMem()
Wend
UltraMixer Professional 3 - Download
QB,HTML,CSS,JS,PHP,SQL,>>B2D,B3D,BP,BlitzMax,C,C++,Java,C#,VB6 , C#, VB.Net

Suco-X

Betreff: .......

BeitragDo, Jun 30, 2005 9:14
Antworten mit Zitat
Benutzer-Profile anzeigen
So, habs mir heute nochmal mit klaren augen angeschaut. Dieses GNet scheint ja ne ziemliche Vereinfachung zu sein was den Netzcode in Bmax betrifft, bin überrascht.
Mfg Suco
Intel Core 2 Quad Q8300, 4× 2500 MHz, 4096 MB DDR2-Ram, GeForce 9600GT 512 MB
 

Hammlet

BeitragSa, Sep 17, 2005 17:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Wo kriegt man dieses GNet eigentlich her? Ich finde das nirgends zu downloaden. Confused

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group