コード例 #1
0
ファイル: Structs.cs プロジェクト: narfman0/BountyBandits
        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);
        }
コード例 #2
0
ファイル: Network.cs プロジェクト: narfman0/BountyBandits
        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;
                    }
                }
            }
        }
コード例 #3
0
ファイル: Network.cs プロジェクト: narfman0/BountyBandits
        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);
        }