public static GameItemNetworkState readState(NetIncomingMessage msg) { GameItemNetworkState state = new GameItemNetworkState(); state.position = new Vector2(msg.ReadFloat(), msg.ReadFloat()); state.velocity = new Vector2(msg.ReadFloat(), msg.ReadFloat()); state.rotation = msg.ReadFloat(); state.angularVelocity = msg.ReadFloat(); state.tag = msg.ReadInt16(); state.guid = new Guid(msg.ReadString()); return(state); }
private void receiveObjectsUpdate(NetIncomingMessage im) { int count = im.ReadInt32(); for (int i = 0; i < count; i++) { GameItemNetworkState state = GameItemNetworkState.readState(im); if (gameref.activeItems.ContainsKey(state.guid)) { GameItem item = gameref.activeItems[state.guid]; Vector2 positiondifference = state.position - item.body.Position; item.body.LinearVelocity = state.velocity; item.body.Position = item.body.Position + (positiondifference * .1f); item.body.Rotation = state.rotation; item.body.AngularVelocity = state.angularVelocity; if (state.tag > 1) { item.body.Tag = state.tag; } } } }
private void sendObjectsUpdate() { List <GameItem> gameItems = new List <GameItem>(); foreach (GameItem item in gameref.activeItems.Values) { if (!item.immovable && !item.body.IsStatic) { gameItems.Add(item); } } NetOutgoingMessage msg = server.CreateMessage(); msg.Write((int)MessageType.ObjectsUpdate); msg.Write(gameItems.Count); foreach (GameItem item in gameItems) { GameItemNetworkState.writeState(msg, item); } serverSendToAllUnordered(msg); }