Exemplo n.º 1
0
        private void receivePlayersUpdate(NetIncomingMessage im)
        {
            int count = im.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                BeingNetworkState state = BeingNetworkState.readState(im);
                if (gameref.players.ContainsKey(state.guid))
                {
                    Being player = gameref.players[state.guid];
                    if (!player.isLocal)
                    {
                        player.body.LinearVelocity = state.velocity;
                        Vector2 difference = state.position - player.body.Position;
                        player.body.Position = player.body.Position + (difference * .1f);
                        player.isFacingLeft  = state.isFacingLeft;
                        player.CurrentHealth = state.currentHP;
                        player.stunDuration  = state.stunDuration;
                        player.body.Tag      = state.tag;
                        if (state.depth != player.getDepth())
                        {
                            player.timeOfLastDepthChange = Environment.TickCount;
                            player.setDepth(state.depth);
                            player.isMovingUp = state.isMovingUp;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void sendPlayersUpdateClient()
        {
            if (!gameref.network.isClient())
            {
                return;
            }
            List <Being> localList = new List <Being>();

            foreach (Being player in gameref.players.Values)
            {
                if (player.isLocal)
                {
                    localList.Add(player);
                }
            }

            NetOutgoingMessage msg = client.CreateMessage();

            msg.Write((int)MessageType.PlayersUpdateClient);
            msg.Write((int)localList.Count);
            foreach (Being player in localList)
            {
                BeingNetworkState.writeState(msg, player);
            }
            client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
        }
Exemplo n.º 3
0
        private void sendEnemiesUpdate()
        {
            NetOutgoingMessage stateUpdate = server.CreateMessage();

            stateUpdate.Write((int)MessageType.EnemiesUpdate);
            stateUpdate.Write((int)gameref.spawnManager.enemies.Count);
            foreach (Enemy enemy in gameref.spawnManager.enemies.Values)
            {
                BeingNetworkState.writeState(stateUpdate, enemy);
            }
            serverSendToAllUnordered(stateUpdate);
        }
Exemplo n.º 4
0
        public void sendPlayersUpdateServer()
        {
            NetOutgoingMessage stateUpdate = server.CreateMessage();

            stateUpdate.Write((int)MessageType.PlayersUpdate);
            stateUpdate.Write((int)gameref.players.Count);
            foreach (Being player in gameref.players.Values)
            {
                BeingNetworkState.writeState(stateUpdate, player);
            }
            serverSendToAllUnordered(stateUpdate);
        }
Exemplo n.º 5
0
        public static BeingNetworkState readState(NetIncomingMessage msg)
        {
            BeingNetworkState state = new BeingNetworkState();

            state.position     = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            state.velocity     = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            state.guid         = new Guid(msg.ReadString());
            state.isFacingLeft = msg.ReadBoolean();
            state.depth        = msg.ReadByte();
            state.isMovingUp   = msg.ReadBoolean();
            state.currentHP    = msg.ReadFloat();
            state.stunDuration = msg.ReadInt32();
            if (msg.ReadBoolean())
            {
                state.tag = msg.ReadInt16();
            }
            return(state);
        }
Exemplo n.º 6
0
        private void receiveEnemiesUpdate(NetIncomingMessage im)
        {
            int count = im.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                BeingNetworkState state = BeingNetworkState.readState(im);
                if (gameref.spawnManager.enemies.ContainsKey(state.guid))
                {
                    Enemy enemy = gameref.spawnManager.enemies[state.guid];
                    enemy.body.LinearVelocity = state.velocity;
                    Vector2 difference = state.position - enemy.body.Position;
                    enemy.body.Position = enemy.body.Position + (difference * .1f);
                    enemy.isFacingLeft  = state.isFacingLeft;
                    enemy.CurrentHealth = state.currentHP;
                    if (state.depth != enemy.getDepth())
                    {
                        enemy.timeOfLastDepthChange = Environment.TickCount;
                        enemy.setDepth(state.depth);
                    }
                }
            }
        }