Untitled diff

创建于 差异永不过期
1 删除
802 行
17 添加
816 行
SeedRnd MilliSecs()
SeedRnd MilliSecs()


Const gameLogicFPS = 60
Const gameLogicFPS = 60


Include "Hex8.bb"
Include "UDPNetwork_lib.bb"
Include "UDPNetwork_lib.bb"


Global localID
Global localID
Global localName$ = Input("Enter your name : ")
Global localName$ = Input("Enter your name : ")
If localName = "" Then localName = "player" + Rand(100,999)
If localName = "" Then localName = "player" + Rand(100,999)


Global localPlayerMesh
Global localPlayerMesh


Type player
Type player
Field id
Field id
Field name$
Field name$
Field ping
Field ping
Field life
Field life
Field kills
Field kills
Field deaths
Field deaths
Field mesh
Field mesh
Field r,g,b
Field r,g,b


Field nextX#,nextY#,nextZ#
Field nextX#,nextY#,nextZ#
Field previousX#,previousY#,previousZ#
Field previousX#,previousY#,previousZ#
Field nextYaw#
Field nextYaw#
Field previousYaw#
Field previousYaw#
Field nextTime
Field nextTime
Field previousTime
Field previousTime
Field lastPacket
Field lastPacket
Field currentY#
Field currentY#
Field velocityY#
Field velocityY#
End Type
End Type


Type bullet
Type bullet
Field mesh
Field mesh
Field angle#
Field angle#
Field time
Field time
Field id ; id of player who fired
Field id ; id of player who fired
End Type
End Type


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Camera code from jfk EO-11110, thanks
; Camera code from jfk EO-11110, thanks
Global bounce_cam=1 ; smooth camera motion? (0/1)
Global bounce_cam=1 ; smooth camera motion? (0/1)
Global bounce_div#=10.0 ; the higher, the more sluggish the camera will follow. Recc: 3.0 to 20.0
Global bounce_div#=10.0 ; the higher, the more sluggish the camera will follow. Recc: 3.0 to 20.0
; some globals used by ChaseCam
; some globals used by ChaseCam
Global old_x#,old_y#,old_z#
Global old_x#,old_y#,old_z#
; desired distance between camera and player mesh
; desired distance between camera and player mesh
Global x_dis#=7.0,y_dis#=3,z_dis#=7.0,y_dis_or#=y_dis#
Global x_dis#=7.0,y_dis#=3,z_dis#=7.0,y_dis_or#=y_dis#
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; network init ----------------------------------------;
; network init ----------------------------------------;
Global localMode = Net_StartInput() ; bring the library "console" to connect
Global localMode = Net_StartInput() ; bring the library "console" to connect


If localMode = 1 Or localMode = 2 ; 1 means we are client, 2 means we are server
If localMode = 1 Or localMode = 2 ; 1 means we are client, 2 means we are server
localId = Net_CreatePlayer(localName) ; this command inits the server or local client
localId = Net_CreatePlayer(localName) ; this command inits the server or local client
If localId = 0 ; error
If localId = 0 ; error
Net_StopNetwork() ; close the network properly
Net_StopNetwork() ; close the network properly
RuntimeError("Failed to create player.")
RuntimeError("Failed to create player.")
EndIf
EndIf
If localMode = 1 Then AppTitle("Client : " + localName + " (port:" + net_port + "/ ID=" + localID + ")")
If localMode = 1 Then AppTitle("Client : " + localName + " (port:" + net_port + "/ ID=" + localID + ")")
If localMode = 2 Then AppTitle("Server : " + localName + " (port:" + net_port + "/ ID=" + localID + ")")
If localMode = 2 Then AppTitle("Server : " + localName + " (port:" + net_port + "/ ID=" + localID + ")")
Else ; error
Else ; error
Net_StopNetwork()
Net_StopNetwork()
RuntimeError("Failed to start game.")
RuntimeError("Failed to start game.")
EndIf
EndIf
;------------------------------------------------------;
;------------------------------------------------------;


Graphics3D 640,480,32,2
Graphics3D 640,480,32,2
SetBuffer BackBuffer()
SetBuffer BackBuffer()


CreateScene()
CreateScene()


Global camera = CreateCamera()
Global camera = CreateCamera()
CameraRange camera,0.1,1000
CameraRange camera,0.1,1000


; create our own local player
; create our own local player
localPlayerMesh = CreatePlayer(localID,localName)
localPlayerMesh = CreatePlayer(localID,localName)
old_x = EntityX(localPlayerMesh):old_y = EntityY(localPlayerMesh):old_z = EntityZ(localPlayerMesh) ; update camera position
old_x = EntityX(localPlayerMesh):old_y = EntityY(localPlayerMesh):old_z = EntityZ(localPlayerMesh) ; update camera position


; we send our color to the server
; we send our color to the server
p.player = Object.player(GetPlayer(localID))
p.player = Object.player(GetPlayer(localID))
Net_SendMessage(3,p\r + "/" + p\g + "/" + p\b)
Net_SendMessage(3,p\r + "/" + p\g + "/" + p\b)


Global cR = p\r
Global cG = p\g
Global cB = p\b

; variables used to send our positions at a constant delay (saves bandwidth but makes a constant ping)
; variables used to send our positions at a constant delay (saves bandwidth but makes a constant ping)
Global updatePosition = MilliSecs()
Global updatePosition = MilliSecs()
Global updateTick = 50
Global updateTick = 50