Hallo
hab mal ne frage zum kürzen beim udpsendungen.
hier ist mal ein abgewandelter beispielcode von netblitz
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN]
AppTitle \"NetBlitz 3d!\" SeedRnd MilliSecs() Type player Field x#,y#,z# Field name$,net_id$ Field ent,cam,piv Field speed End Type
Print \"NetBlitz Created By David Dawkins\" loca = Input(\"Local Game?(1 - Yes,0 - No) \") host = Input(\"Hosting Or Joining:(0 = Join,1 = Host) \") If host = 0 And loca = 0 ip$ = Input(\"Select IP: \") port = Input(\"Select Port: \") ElseIf host = 0 And loca = 1 port = Input(\"Select Port: \") ip = \"\" ElseIf host = 1 And loca = 0 ip = \"\" port = 80 ElseIf host = 1 And loca = 1 ip = \"\" port = 80 EndIf
Include \"nb.bb\" Global mainstream = startnbgame(port) If mainstream = 0 Then RuntimeError(\"Port Occupied\") : End
name$ = Input(\"Enter Name: \")
Graphics3D 640,480,0,2 Global level = LoadMesh(\"test3d.b3d\") EntityFX level,1 : MoveEntity level,0,-5,0 CreateLight()
EntityType level,2
Global play.player Global mastertime id$ = CreatenbPlayer( name$,ip,mainstream,host ) play = createplayer(name,id) If host = 0 For n.nbplayer = Each nbplayer If n\id <> nbuserid pack$ = play\x+\" \"+play\y+\" \"+play\z SendNBMsg(1,pack,n\id,mainstream) p.player = createplayer(n\name,n\id) FreeEntity p\cam EndIf Next EndIf
Collisions 1,2,2,2
Main()
play\speed=0 Function Main() mastertime = MilliSecs() While Not KeyHit(1)
If KeyDown(200) play\speed=play\speed*1.2 If play\speed>3 Then play\speed=3 MoveEntity play\ent,0,0,play\speed SendNBMsg(2,\"1\",0,mainstream) ElseIf KeyDown(208) MoveEntity play\ent,0,0,-.5 SendNBMsg(2,\"2\",0,mainstream) EndIf
If KeyDown(203) TurnEntity play\ent,0,4,0 SendNBMsg(2,\"3\",0,mainstream) ElseIf KeyDown(205) TurnEntity play\ent,0,-4,0 SendNBMsg(2,\"4\",0,mainstream) EndIf
TranslateEntity play\ent,0,-.2,0
dx#=EntityX( play\piv,True )-EntityX( play\cam,1 ) dy#=EntityY( play\piv,True )-EntityY( play\cam,1 ) dz#=EntityZ( play\piv,True )-EntityZ( play\cam,1 ) TranslateEntity play\cam,dx*.1,dy*.1,dz*.1 PointEntity play\cam,play\ent
If KeyHit(2) DebugLog(EntityX(play\ent)) DebugLog(EntityY(play\ent)) DebugLog(EntityZ(play\ent)) EndIf
UpdateNetwork()
UpdateWorld RenderWorld
play\x = EntityX(play\ent) : play\y = EntityY(play\ent) : play\z = EntityZ(play\ent)
If MilliSecs() - mastertime > 15000 pack$ = play\x+\" \"+play\y+\" \"+play\z SendNBMsg(1,pack,0,mainstream) mastertime = MilliSecs() EndIf
For p.player = Each player CameraProject(play\cam,EntityX(p\ent),EntityY(p\ent),EntityZ(p\ent)) If ProjectedZ() > 0 Then Text(ProjectedX(),ProjectedY(),p\name) Next Flip Wend deletenbplayer(mainstream) Stopnbgame(mainstream) End End Function
Function CreatePlayer.player(name$,id$) spawn = Rand(1,4) p.player = New player p\x = 0 : p\y = 0 : p\z = 0 p\name = name$ p\ent = CreateSphere():UpdateNormals p\ent cone = CreateCone() : RotateMesh(cone,90,0,0) PositionMesh cone,0,0,2 : ScaleMesh cone,.5,.5,.5 : AddMesh cone,p\ent FreeEntity cone p\cam = CreateCamera() p\piv = CreatePivot(p\ent) : MoveEntity p\piv,0,5,-10 EntityColor p\ent,Rnd(255),Rnd(255),Rnd(255) EntityType p\ent,1:EntityType p\cam,1 p\net_id = id If spawn = 1 p\x = 1 : p\y = -3 : p\z = 0 ElseIf spawn = 2 p\x = 63 : p\y = 5 : p\z = 21 ElseIf spawn = 3 p\x = -61 : p\y = 5 : p\z = -19 ElseIf spawn = 4 p\x = -31 : p\y = -11 : p\z = 2 EndIf PositionEntity p\ent,p\x,p\y,p\z : PositionEntity p\cam,p\x,p\y,p\z ResetEntity p\ent : ResetEntity p\cam Return p End Function
Function UpdateNetwork() While RecvNBMsg(mainstream) Select NBMsgType(mainstream) Case 100 serverid$ = converttoid(serverip,serverport) If nbuserid = serverid checknbdatabase(mainstream) ElseIf nbuserid <> serverid i.nbplayer = New nbplayer i\name = nbmsgdata(mainstream) i\ip = nbmsgip(mainstream) i\port = nbmsgport(mainstream) i\id = converttoid(i\ip,i\port) EndIf p.player = CreatePlayer(nbmsgdata(mainstream),nbmsgfrom(mainstream)) FreeEntity p\cam pack$ = play\x+\" \"+play\y+\" \"+play\z SendNBMsg(1,pack,nbmsgfrom(mainstream),mainstream) pitch# = EntityPitch(play\ent) roll# = EntityRoll(play\ent) pack$=LSet$( pitch,7 )+LSet$( EntityYaw(play\ent),7 )+LSet$( roll,7 ) SendNBMsg(3,pack,nbmsgfrom(mainstream),mainstream) Case 101 For p.player = Each player If p\net_id = nbmsgfrom(mainstream) FreeEntity p\ent For n.nbplayer = Each nbplayer If n\id = p\net_id Then Delete n Next Delete p : Exit EndIf Next Case 1 For p.player = Each player If p\net_id = nbmsgfrom(mainstream) dat$ = nbmsgdata$(mainstream) Local num1$,num2$,num3$,count For wc = 1 To Len(dat) let$ = Mid(dat,wc,1) If let = \" \" Then count = count + 1 If let <> \" \" If count = 0 num1 = num1 + let ElseIf count = 1 num2 = num2 + let ElseIf count = 2 num3 = num3 + let EndIf EndIf Next p\x = Float(num1) : p\y = Float(num2) : p\z = Float(num3) HideEntity p\ent PositionEntity p\ent,p\x,p\y,p\z : ShowEntity p\ent Exit EndIf Next Case 2 For p.player = Each player If p\net_id = nbmsgfrom(mainstream) move = nbmsgdata$(mainstream)
If move = 1 p\speed=p\speed*1.2 If p\speed>3 Then p\speed=3 MoveEntity p\ent,0,0,p\speed ElseIf move = 2 MoveEntity p\ent,0,0,-.5 ElseIf move = 3 TurnEntity p\ent,0,4,0 ElseIf move = 4 TurnEntity p\ent,0,-4,0 EndIf Exit EndIf Next Case 3 For p.player = Each player If p\net_id = nbmsgfrom(mainstream) dat$ = nbmsgdata$(mainstream) rotx# = Float(Mid(dat,1,7)) :roty#=Float(Mid(dat,8,7)) : rotz#=Float(Mid(dat,15,7)) RotateEntity p\ent,rotx,roty,rotz Exit EndIf Next End Select Wend
For p.player = Each player If p\net_id <> nbuserid TranslateEntity p\ent,0,-.2,0 EndIf Next End Function
Wie kann ich diesen teil abkürzen, ohne ihn nochmals in den case2 reinschreiben zu müssen? denn doppelt gemoppelt ist immer schlecht!
steht in der main funktion:
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] play\speed=play\speed*1.2 If play\speed>3 Then play\speed=3
das ist der teil (in case 2) den ich nicht nochmal darstehen haben will,
sondern abgekürzt, aber wie geht das(wenn überhaupt):
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] p\speed=p\speed*1.2 If p\speed>3 Then p\speed=3
meine originale berechnung für den speed ist noch wesendlich länger
und desshalb will ich ihn nicht doppelt berechnen müssen
|