==== SERVER
Type SVPlayer
Field Name:String = ""
Field id:Byte
Field client:TNetClient = Null
Field x:Float, y:Float, dir:Float, speed:Float
Field keys:Short
Method New()
Players.AddLast(Self)
End Method
Function Create:SVPlayer(name:String, id:Byte)
Local p:SVPlayer = New SVPlayer
p.Name = name
p.id = id
Print "Player created: " + name + " ID " + id
Return p
EndFunction
Method Think()
x = x + (speed * Cos(dir)) * Delta.Time
y = y - (speed * -Sin(dir)) * Delta.Time
If keys & 2 Then
speed = 0.0002
End If
If keys & 4 Then
speed = -0.0002
EndIf
If keys & 8 Then
dir = dir + 0.05 * Delta.Time
EndIf
If keys & 16 Then
dir = dir - 0.05 * Delta.Time
EndIf
If keys = 1 Then
speed = 0
End If
End Method
EndType
====== CLIENT
Type CLPlayer
Field Name:String = "-"
Field id:Byte
Field x:Float, y:Float, dir:Float, speed:Float
Field model:TMesh
Field keys:Short
Method New()
'model = CreateCube()
model = LoadMesh("media/models/tank.b3d")
ScaleEntity(model, 0.005, 0.005, 0.005)
Players.AddLast(Self)
End Method
Method Delete()
FreeEntity(model)
EndMethod
Method Think()
x = x + (speed * Cos(dir)) * Delta.Time
y = y - (speed * -Sin(dir)) * Delta.Time
PositionEntity(model, x, 0.2, y)
RotateEntity(model, 0, dir, 0)
If keys & 2 Then
speed = 0.0002
End If
If keys & 4 Then
speed = -0.0002
EndIf
If keys & 8 Then
dir = dir + 0.05 * Delta.Time
EndIf
If keys & 16 Then
dir = dir - 0.05 * Delta.Time
EndIf
If keys = 1 Then
speed = 0
End If
End Method
End Type