public Level(string background, int width, int height, int playerCount, bool useKeyboard, GameState gameType) { int diff = useKeyboard ? 0 : 1; if (playerCount < 2) { playerCount = 2; } if (playerCount > 4) { playerCount = 4; } _entities = new List <Entity>(); _toRemove = new Stack <Entity>(); _toAdd = new Stack <Entity>(); _bounds = new Rectangle(0, 0, width, height); _background = GameContent.LoadContent <Texture2D>(background); _font = GameContent.LoadContent <SpriteFont>("Fonts/SmallFont"); _winFont = GameContent.LoadContent <SpriteFont>("Fonts/BigFont"); _textOrigin = Vector2.Zero; _screenCenter = new Vector2(width / 2.0f, height / 2.0f); _fireballSfx = GameContent.LoadContent <SoundEffect>("SFX/Fireball"); _gameEnded = false; _winnerColor = Color.Black; _winnerText = String.Empty; if (gameType == GameState.PlayingLocal) { _connDelayTime = 0; for (int i = 0; i < playerCount; i++) { _entities.Add(new Player(this, positions[i], colors[i], inputs[i + diff], names[i])); } } else if (gameType == GameState.PlayingHost || gameType == GameState.PlayingClient) { _connDelayTime = 5000; int mod = (gameType == GameState.PlayingHost) ? 0 : 1; Player local = new Player(this, positions[mod], colors[mod], inputs[diff], GameMain.CurrentSession.LocalGamers[0].Gamertag); NetPlayerBehavior localController = new NetPlayerBehavior(local); local.Behaviors.Add(localController); GameMain.Connection.CreatePlayer(local); NetController = localController; _entities.Add(local); } }
public void CreatePlayer(Player player) { NetPlayerBehavior b = player.GetBehavior <NetPlayerBehavior>(); if (b != null) { _writer.Write("CreatePlayer"); _writer.Write(b.Id); _writer.Write(player.Name); _writer.Write(player.Position); _writer.Write(player.Health); _writer.Write(player.Color); _session.LocalGamers[0].SendData(_writer, SendDataOptions.ReliableInOrder); } else { throw new Exception("Could not create other player: Player doesn't have NetworkBehavior."); } }