protected override void Deserialize(NetworkBinaryReader reader)
 {
     base.Deserialize(reader);
     PlayerID = reader.ReadByte();
     for (int i = 0; i < PlayerControls.CONTROL_COUNT; ++i)
     {
         var value = reader.ReadByte();
         var force = (value & 0x7f) / 127f;
         var pulse = (value & 0x80) != 0;
         ControlStates[i] = new ControlState(force, pulse);
     }
 }
 public void Setup()
 {
     _predicter = new ShipLocationPredicter(() => _shipData, SetShipLocation);
     var on = new ControlState(1, true);
     var off = new ControlState(0, false);
     _turningLeft = new[] { off, on, off, off, off, off, off };
     _shipData = new ShipLocationPredicter.ShipData
     {
         ShipLocationEntry = new ShipLocationEntry
         {
             Rotation = 0,
             Pos = Vector2.Zero,
             Move = Vector2.Zero,
             GameTime = TimeSpan.Zero,
             ControlStates = _turningLeft,
         },
         TargetElapsedTime = TimeSpan.FromSeconds(1f / 20),
         ThrustForce = 120000,
         TurnSpeed = 1,
         Mass = 350,
     };
     _entry1 = new ShipLocationEntry
     {
         GameTime = TimeSpan.FromSeconds(1),
         Pos = new Vector2(100, 100),
         Move = new Vector2(1000, 0),
         Rotation = 1,
         ControlStates = _turningLeft,
     };
     _entry2 = new ShipLocationEntry
     {
         GameTime = TimeSpan.FromSeconds(1.1),
         Pos = new Vector2(200, 100),
         Move = new Vector2(1000, 0),
         Rotation = 1.1f,
         ControlStates = _turningLeft,
     };
     _entry3 = new ShipLocationEntry
     {
         GameTime = TimeSpan.FromSeconds(1.2),
         Pos = new Vector2(300, 100),
         Move = new Vector2(1000, 0),
         Rotation = 1.2f,
         ControlStates = _turningLeft,
     };
 }
示例#3
0
 static Ship()
 {
     g_defaultControlStates = new ControlState[PlayerControls.CONTROL_COUNT];
     for (int i = 0; i < g_defaultControlStates.Length; i++)
         g_defaultControlStates[i] = new ControlState();
 }
 public void AddControlState(PlayerControlType controlType, ControlState state)
 {
     ControlStates[(int)controlType] = ControlStates[(int)controlType].Add(state);
 }
 public ClientGameStateUpdateMessage()
 {
     ControlStates = new ControlState[PlayerControls.CONTROL_COUNT];
 }
示例#6
0
 /// <summary>
 /// Merge two ControlStates together additively;
 /// control pulses are OR'ed; control forces are MAX'ed.
 /// </summary>
 public ControlState Add(ControlState other)
 {
     return new ControlState(Math.Max(Force, other.Force), Pulse || other.Pulse);
 }