public void Update(GameTime gameTime) { while (LocalHost.IsDataAvailable) { NetworkGamer sender; LocalHost.ReceiveData(_reader, out sender); string type = _reader.ReadString(); int id; if (type == "Player") { id = _reader.ReadInt32(); NetworkBehavior net = _behaviors.OfType <NetPlayerBehavior>().FirstOrDefault((b) => b.Id == id); if (net != null) { net.ReceiveData(_reader); } } if (type == "Fireball") { id = _reader.ReadInt32(); NetworkBehavior net = _behaviors.OfType <NetFireballBehavior>().FirstOrDefault((b) => b.Id == id); if (net != null) { net.ReceiveData(_reader); } } if (type == "CreatePlayer") { id = _reader.ReadInt32(); string name = _reader.ReadString(); Vector2 position = _reader.ReadVector2(); int health = _reader.ReadInt32(); Color color = _reader.ReadColor(); if (id != _session.LocalGamers[0].Id) { Player player = new Player(GameMain.CurrentLevel, position, color, new GenericInput(), name) { Health = health }; player.Behaviors.Add(new NetPlayerBehavior(player, id)); GameMain.CurrentLevel.AddEntity(player); } } if (type == "CreateFireball") { id = _reader.ReadInt32(); Vector2 position = _reader.ReadVector2(); Direction direction = (Direction)_reader.ReadInt32(); Color color = _reader.ReadColor(); Fireball fireball = new Fireball(GameMain.CurrentLevel, position, color, direction); fireball.Behaviors.Add(new NetFireballBehavior(fireball, id)); GameMain.CurrentLevel.AddEntity(fireball); } if (type == "RequestFireball") { Vector2 position = _reader.ReadVector2(); Direction direction = (Direction)_reader.ReadInt32(); Color color = _reader.ReadColor(); Fireball fireball = new Fireball(GameMain.CurrentLevel, position, color, direction); fireball.Behaviors.Add(new NetFireballBehavior(fireball, 0)); //GameMain.CurrentLevel.AddEntity(fireball); CreateFireball(fireball); } } _session.Update(); }