GNet Problem

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

Markus2

Betreff: GNet Problem

BeitragFr, Jul 01, 2005 19:09
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi,

habe aus dem Code Archiv das Pong Beispiel genommen und
ein wenig dran rumgespielt .

Ich habe das Problem das wenn ich den Server starte und
eine weile später erst den Client (auf gleicher Kiste oder andere ist egal)
das eine Fehlermeldung in Blitz erscheint .
Unhandled Exception Bla
Irgendwas mit GetFloat GetInt .

Weiß aber nicht was ich falsch gemacht habe und im
GNet Modul konnte ich auch nix feststellen .

Denke das ich BMax durcheinander gebracht habe mit
der Reihenfolge wie ich die Werte schreibe !?

Code: [AUSKLAPPEN]

' gnetserver

Strict

SetGraphicsDriver GLMax2DDriver()

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

Local Host=CreateGNetHost()

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

Local player1:TGNetObject=CreateGNetObject(Host)

Local player_x:Float=GraphicsWidth()/2
Local player_y:Float=GraphicsHeight()-10
Local ball_x:Float=GraphicsWidth()/2
Local ball_y:Float=GraphicsHeight()/2

SeedRnd(MilliSecs())
Local winkel:Float=Rand(-180,180)
Local ball_dirx:Float=Sin(winkel)*2.0
Local ball_diry:Float=Cos(winkel)*2.0
Global ball_radius:Int=15

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_PUNKTESTAND_ME=4
Const GNET_PUNKTESTAND_HIM=5

Local erfolg=GNetListen(Host,12345)

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

Local Players:Int=0
Local Peer:TGNetPeer
'Local Socket:TSocket

While Not KeyDown(KEY_ESCAPE)
   Cls

   Peer=GNetAccept(Host)
   If Peer<>Null Then
    Print "Ein Client will sich verbinden"
    'Socket=GNetPeerUDPSocket(Peer)
    'SocketAccept Socket
   End If

   GNetSync(Host) 'besser nach GNetAccept ?
   
   player_x=MouseX()
   'player_y=MouseY()
   
   Players=0
   For Local obj:TGNetObject=EachIn GNetObjects( host,GNET_ALL )
      Players=Players+1
      If GNetObjectLocal(obj)=True Then
      'If obj=player1
       'DrawText "Me",player_x,player_y
       DrawRect(player_x-25,player_y-10,50,20)
       'Collision
      If SpielerBallColli(ball_x,ball_y,player_x,player_y,1)=1 Then
        ball_y=player_y-(10+ball_radius)
        ball_diry=-2
        ball_dirx=-RndFloat()*2.0
      EndIf

      Else
         'DrawText "Him",GetGNetFloat(obj,GNET_PLAYER_X),GetGNetFloat(obj,GNET_PLAYER_Y)
         Local posenemy_x:Float=GetGNetFloat(obj,GNET_PLAYER_X)
         Local posenemy_y:Float=GetGNetFloat(obj,GNET_PLAYER_Y)

         DrawRect(posenemy_x-25,posenemy_y-10,50,20)
        If SpielerBallColli(ball_x,ball_y,posenemy_x,posenemy_y,2)=1 Then
          ball_y=posenemy_y+(10+ball_radius)
          ball_diry=2
          ball_dirx=-RndFloat()*2.0
        EndIf
      EndIf
   Next
   
   ball_x=ball_x+ball_dirx
   ball_y=ball_y+ball_diry

   'von den Wändern abprallen   
   If ball_x+ball_radius>GraphicsWidth()-1 Then ball_x=(GraphicsWidth()-1)-ball_radius;ball_dirx=-ball_dirx
   If ball_x-ball_radius<0 Then ball_x=ball_radius;ball_dirx=1

   If Players=1 Then
    If ball_y-ball_radius<0 Then ball_y=ball_radius;ball_diry=2
   EndIf
 
   'verlassen des Fensters !
   'Unten
   If ball_y-ball_radius>GraphicsHeight()-1
      ball_diry=-RndFloat()-1
      punktestand_him:+1
      ball_y=GraphicsHeight()/2
   EndIf
   If Players>1 Then
      'Oben
      If ball_y+ball_radius<0
         ball_diry=RndFloat()+1
         punktestand:+1
         ball_y=GraphicsHeight()/2
      EndIf
   EndIf

   'müssen beim Client auch so in der Reihenfolge ausgelesen werden wegen Float und Int

   SetGNetFloat player1,GNET_PLAYER_X,player_x
   SetGNetFloat player1,GNET_PLAYER_Y,player_y

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

   SetGNetInt player1,GNET_PUNKTESTAND_ME,punktestand
   SetGNetInt player1,GNET_PUNKTESTAND_HIM,punktestand_him
 
   DrawText "Ich: "+punktestand+" Gegner: "+punktestand_him,10,10
   DrawText "Pl.: "+Players,10,30
   
   DrawOval ball_x-ball_radius,ball_y-ball_radius,ball_radius*2,ball_radius*2
   
   Flip
   FlushMem()
   Delay 10
Wend

CloseGNetHost(Host)
Print "Server runtergefahren"

Function SpielerBallColli:Int(bx:Int,by:Int,px:Int,py:Int,pnr:Int)
 
 'posenemy_x-25,posenemy_y-10,50,20)
 
 If pnr=1 Then 'Ich
  If by+ball_radius>py-10 Then 'Y
   If bx=>px-25 And bx<=px+25 Then Return 1
  EndIf
 EndIf

 If pnr=2 Then 'Gegner
  If by-ball_radius<py+10 Then 'Y
   If bx=>px-25 And bx<=px+25 Then Return 1
  EndIf
 EndIf

End Function


Code: [AUSKLAPPEN]

' gnetclient

Strict

SetGraphicsDriver GLMax2DDriver()

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

Local Host=CreateGNetHost()

Local player2:TGNetObject=CreateGNetObject(Host)

Local player_x:Int=GraphicsWidth()/2
Local player_y:Int=10

Const GNET_PLAYER_X=0
Const GNET_PLAYER_Y=1
Const GNET_BALL_X=2
Const GNET_BALL_Y=3
Const GNET_PUNKTESTAND_ME=4
Const GNET_PUNKTESTAND_HIM=5

Local Client:TGNetPeer
Client=GNetConnect(Host,"192.168.52.11",12345) '"192.168.52.11"
If Client=Null Then
 Print "Konnte nicht zum Server verbinden :-("
EndIf

Local x:Float,y:Float
Local p1:Int,p2:Int

While Not KeyDown(KEY_ESCAPE)
   Cls
   GNetSync(Host)

   player_x=MouseX()
   'player_y=MouseY()

   For Local obj:TGNetObject=EachIn GNetObjects( host,GNET_ALL )
      If GNetObjectLocal(obj)=True Then
      'If obj=player2 Then
         SetGNetFloat player2,GNET_PLAYER_X,player_x
         SetGNetFloat player2,GNET_PLAYER_Y,player_y
         'DrawText "Me",player_x,player_y
         DrawRect(player_x-25,player_y-10,50,20)

      Else
         'DrawText "Him",GetGNetFloat(obj,GNET_PLAYER_X),GetGNetFloat(obj,GNET_PLAYER_Y)
         x=GetGNetFloat(obj,GNET_PLAYER_X)
         y=GetGNetFloat(obj,GNET_PLAYER_Y)
         DrawRect x-25,y-10,50,20

         x=GetGNetFloat(obj,GNET_BALL_X)
         y=GetGNetFloat(obj,GNET_BALL_Y)
         DrawOval x-15,y-15,30,30

         p1=GetGNetInt(obj,GNET_PUNKTESTAND_ME)
         p2=GetGNetInt(obj,GNET_PUNKTESTAND_HIM)

         DrawText "Ich: "+p1+" Gegner: "+p2,10,10
      EndIf
   Next

   FlushMem()
   Flip
   Delay 10

Wend

regaa

BeitragFr, Jul 01, 2005 22:10
Antworten mit Zitat
Benutzer-Profile anzeigen
Arrr, das Problem hatte ich gestern auch. Habe da 50 Minuten dran rumgebastelt, es schien ein Problem mit dem Ziel zu sein was du anschreibst, vom Client heraus, tjo, leider hab ich nach 20 Minuten basteln mit deinem Code den Fehler nicht raus Sad. Aber bei mir war es gestern definetiv der Fehler das ich player2 statt obj mit SetGNetx ansprechen wollte, ändert aber irgendwie nix an deinem Code Sad.

Vielleicht hilft die auch das hier weiter: http://www.blitzwiki.de/index....sharp=GNet
UltraMixer Professional 3 - Download
QB,HTML,CSS,JS,PHP,SQL,>>B2D,B3D,BP,BlitzMax,C,C++,Java,C#,VB6 , C#, VB.Net

Markus2

BeitragFr, Jul 01, 2005 22:32
Antworten mit Zitat
Benutzer-Profile anzeigen
Hm, danke für deine Bemühungen .

Werde mir das mal genauer ansehen Idea
www.blitzbasic.com/tmp/gnetdemo.zip

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group