public void ReloadGameSaves() { CharSelectPreview preview; // Check to see if the previous player chose new game, if so, make a new "New Game" slot with an incremented file name CharSelectPlayer previousPlayer = players.ElementAt(currentPlayerIndex - 1); if (previousPlayer.gameSave.newGame) { preview = new CharSelectPreview(game.Content.Load <Texture2D>("Spritesheets/charSelectNewGame"), gameSavePosition, spriteFont, "New Game", " ", selected, ""); preview.fileNumber = previousPlayer.gameSave.fileNumber + 1; preview.fileName = "charSave" + preview.fileNumber; gameSaves.Insert(0, preview); } // Reload the game saves for (int i = 0; i < gameSaves.Count; i++) { preview = gameSaves.ElementAt(i); preview.SetPosition(gameSavePosition + (movementOffset * i)); if (i == 0) { preview.Color = selected; } else { preview.Color = unselected; } } selectedGameSave = 0; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> public void LoadContent() { // Set up the background titleTexture = game.Content.Load <Texture2D>("Spritesheets/charSelectBackground"); titleImage = new ImageSprite(titleTexture, viewport.Width / 2, viewport.Height / 2, Color.White); titleImage.Visible = true; titleImage.Scale = (float)(new Vector2(viewport.Width, viewport.Height).Length()) / (float)(new Vector2(titleTexture.Width, titleTexture.Height).Length()); // Set the control images buttonTexture = game.Content.Load <Texture2D>("Spritesheets/charSelectControls1"); buttonPos = new Vector2(center.X, center.Y - viewport.Height * 0.365f); controlsImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); controlsImage.Scale = 1; // Initialize the sprite font spriteFont = game.Content.Load <SpriteFont>("SpriteFonts/Pescadero"); playerOne = new CharSelectPlayer(new ImageSprite(game.Content.Load <Texture2D>("Spritesheets/charSelectPlayerOneCursor"), (int)buttonPos.X, (int)buttonPos.Y, selected), true, PlayerIndex.One); playerTwo = new CharSelectPlayer(new ImageSprite(game.Content.Load <Texture2D>("Spritesheets/charSelectPlayerTwoCursor"), (int)buttonPos.X, (int)buttonPos.Y, unselected), true, PlayerIndex.Two); playerThree = new CharSelectPlayer(new ImageSprite(game.Content.Load <Texture2D>("Spritesheets/charSelectPlayerThreeCursor"), (int)buttonPos.X, (int)buttonPos.Y, unselected), true, PlayerIndex.Three); playerFour = new CharSelectPlayer(new ImageSprite(game.Content.Load <Texture2D>("Spritesheets/charSelectPlayerFourCursor"), (int)buttonPos.X, (int)buttonPos.Y, unselected), true, PlayerIndex.Four); players.Add(playerOne); currentPlayer = playerOne; // Initialized the sound effect soundEffect = game.Content.Load <SoundEffect>("Audio/BClick_Menu"); }
/// <summary> /// Allows the game to run logic such as player input and character selection, /// also changes visual representation of selected/unselected characters /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Update(GameTime gameTime) { if (isConnected) { if (!isNewGame) { // Allows the game to exit if (InputHelper.GetInput(currentPlayer.playerIndex).IsPressed(Keys.Escape, Buttons.Back) && currentPlayer.timer <= 0) { if (currentPlayerIndex == 0) game.Exit(); else { currentPlayerIndex--; currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.Timer = controllerDelay; currentPlayer.Selected = false; } } if (InputHelper.GetInput(PlayerIndex.One).IsPressed(Keys.Enter, Buttons.Start)) { playerOne.Connected = true; if(!players.Contains(playerOne)) players.Add(playerOne); } if (InputHelper.GetInput(PlayerIndex.Two).IsPressed(Keys.Enter, Buttons.Start)) { playerTwo.Connected = true; if(!players.Contains(playerTwo)) players.Add(playerTwo); } if (InputHelper.GetInput(PlayerIndex.Three).IsPressed(Keys.Enter, Buttons.Start)) { playerThree.Connected = true; if(!players.Contains(playerThree)) players.Add(playerThree); } if (InputHelper.GetInput(PlayerIndex.Four).IsPressed(Keys.Enter, Buttons.Start)) { playerFour.Connected = true; if(!players.Contains(playerFour)) players.Add(playerFour); } #if XBOX // If windows we don't want to disconnect the keyboard, which is player one if (!UserInput.GetInput(PlayerIndex.One).IsGamePadConnected()) { players.Remove(playerOne); playerOne.Connected = false; } #endif if (!InputHelper.GetInput(PlayerIndex.Two).IsGamePadConnected()) { players.Remove(playerTwo); playerTwo.Connected = false; } if (!InputHelper.GetInput(PlayerIndex.Three).IsGamePadConnected()) { players.Remove(playerThree); playerThree.Connected = false; } if (!InputHelper.GetInput(PlayerIndex.Four).IsGamePadConnected()) { players.Remove(playerFour); playerFour.Connected = false; } if (currentPlayer.Connected) { currentPlayer.Timer -= (float)gameTime.ElapsedGameTime.Milliseconds; if (!currentPlayer.Selected && currentPlayer.Timer <= 0) { currentPlayer.timer = controllerDelay; if (InputHelper.GetInput(currentPlayer.playerIndex).IsPressed(Keys.Down, Buttons.DPadDown)) { selectedGameSave++; if (selectedGameSave < gameSaves.Count) { foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset(-movementOffset); preview.Color = unselected; } } else { selectedGameSave = 0; foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset((movementOffset * (gameSaves.Count - 1))); preview.Color = unselected; } } cursorMoved = true; gameSaves.ElementAt(selectedGameSave).Color = selected; } if (InputHelper.GetInput(currentPlayer.playerIndex).IsPressed(Keys.Up, Buttons.DPadUp)) { selectedGameSave--; if (selectedGameSave >= 0) { foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset((movementOffset)); preview.Color = unselected; } } else { selectedGameSave = gameSaves.Count - 1; foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset(-(movementOffset * (gameSaves.Count - 1))); preview.Color = unselected; } } cursorMoved = true; gameSaves.ElementAt(selectedGameSave).Color = selected; } if (InputHelper.GetInput(currentPlayer.playerIndex).IsPressed(Keys.Space, Buttons.A)) { currentPlayer.Timer = controllerDelay; if (selectedGameSave == 0) { isNewGame = true; CharacterSelectionScreen.selectionDone = false; currentPlayer.GameSave = gameSaves.ElementAt(selectedGameSave); //currentPlayer.GameSave.FileNumber = gameSaves.Count; currentPlayer.GameSave.NewGame = true; CharacterSelectionScreen.LoadContent(currentPlayer); } else { currentPlayer.GameSave = gameSaves.ElementAt(selectedGameSave); currentPlayer.Selected = true; currentPlayer.Cursor.Color = unselected; currentPlayerIndex++; // If we are on the last player in the wait list, go to the networking screen if (currentPlayerIndex == players.Count) GoToNetworking(); else { gameSaves.Remove(currentPlayer.GameSave); currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.Selected = false; currentPlayer.Cursor.Color = selected; ReloadGameSaves(); currentPlayer.Timer = controllerDelay; } } } if (InputHelper.GetInput(currentPlayer.playerIndex).IsPressed(Keys.Escape, Buttons.Back)) { currentPlayer.Timer = controllerDelay; if (selectedGameSave != 0) { DoGameDelete(LoadGameSave(gameSaves.ElementAt(selectedGameSave))); } } if (GamePad.GetState(currentPlayer.PlayerIndex).Buttons.B == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.B)) { //currentPlayer.selected = false; //currentPlayer.cursor.Color = Color.White; } } } // If there has been a cursor movement, play the sound if (cursorMoved) { soundEffect.Play(); cursorMoved = false; } } else { CharacterSelectionScreen.Update(gameTime); if (CharacterSelectionScreen.selectionDone) { isNewGame = false; CharacterSelectionScreen.selectionDone = false; if (currentPlayer.Selected) { currentPlayer.Cursor.Color = unselected; currentPlayerIndex++; // If we are on the last player in the wait list, go to the networking screen if (currentPlayerIndex == players.Count) GoToNetworking(); else { gameSaves.Remove(currentPlayer.GameSave); currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.Selected = false; currentPlayer.Cursor.Color = selected; ReloadGameSaves(); currentPlayer.Timer = controllerDelay; } } } } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> public void LoadContent() { // Set up the background titleTexture = game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectBackground"); titleImage = new ImageSprite(titleTexture, viewport.Width / 2, viewport.Height / 2, Color.White); titleImage.Visible = true; titleImage.Scale = (float)(new Vector2(viewport.Width, viewport.Height).Length()) / (float)(new Vector2(titleTexture.Width, titleTexture.Height).Length()); // Set the control images buttonTexture = game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectControls1"); buttonPos = new Vector2(center.X, center.Y - viewport.Height * 0.365f); controlsImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); controlsImage.Scale = 1; // Initialize the sprite font spriteFont = game.Content.Load<SpriteFont>("SpriteFonts/Pescadero"); playerOne = new CharSelectPlayer(new ImageSprite(game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectPlayerOneCursor"), (int)buttonPos.X, (int)buttonPos.Y, selected), true, PlayerIndex.One); playerTwo = new CharSelectPlayer(new ImageSprite(game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectPlayerTwoCursor"), (int)buttonPos.X, (int)buttonPos.Y, unselected), true, PlayerIndex.Two); playerThree = new CharSelectPlayer(new ImageSprite(game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectPlayerThreeCursor"), (int)buttonPos.X, (int)buttonPos.Y, unselected), true, PlayerIndex.Three); playerFour = new CharSelectPlayer(new ImageSprite(game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectPlayerFourCursor"), (int)buttonPos.X, (int)buttonPos.Y, unselected), true, PlayerIndex.Four); players.Add(playerOne); currentPlayer = playerOne; // Initialized the sound effect soundEffect = game.Content.Load<SoundEffect>("Audio/BClick_Menu"); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> public void LoadContent(CharSelectPlayer player) { // Set up the background titleTexture = game.Content.Load <Texture2D>("Spritesheets/charSelectBackground"); titleImage = new ImageSprite(titleTexture, viewport.Width / 2, viewport.Height / 2, Color.White); titleImage.Visible = true; titleImage.Scale = (float)(new Vector2(viewport.Width, viewport.Height).Length()) / (float)(new Vector2(titleTexture.Width, titleTexture.Height).Length()); // Set the control images buttonTexture = game.Content.Load <Texture2D>("Spritesheets/charSelectControls2"); buttonPos = new Vector2(center.X, center.Y - viewport.Height * 0.365f); controlsImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); controlsImage.Scale = 1; // Initialize the sprite font spriteFont = game.Content.Load <SpriteFont>("SpriteFonts/Pescadero"); // Initialize the character buttons and the text for each button and the character's aggregate // The Cultist Character buttonTexture = game.Content.Load <Texture2D>("Spritesheets/charSelectCultist"); buttonPos = new Vector2(center.X - viewport.Width / 4, center.Y - viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[0, 0] = buttonImage; buttonTextOffset = new Vector2(0, buttonImage.Image.Height); buttonText = new TextSprite(spriteFont, "Cultist", buttonPos + buttonTextOffset, Color.White); buttonTexts[0, 0] = buttonText; buttonAggregates[0, 0] = Aggregate.CultistPlayer; // The Earthian Character buttonTexture = game.Content.Load <Texture2D>("Spritesheets/charSelectEarthian"); buttonPos = new Vector2(center.X, center.Y - viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[0, 1] = buttonImage; buttonText = new TextSprite(spriteFont, "Earthian", buttonPos + buttonTextOffset, Color.White); buttonTexts[0, 1] = buttonText; buttonAggregates[0, 1] = Aggregate.EarthianPlayer; // The Cyborg Character buttonTexture = game.Content.Load <Texture2D>("Spritesheets/charSelectCyborg"); buttonPos = new Vector2(center.X + viewport.Width / 4, center.Y - viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[0, 2] = buttonImage; buttonText = new TextSprite(spriteFont, "Cyborg", buttonPos + buttonTextOffset, Color.White); buttonTexts[0, 2] = buttonText; buttonAggregates[0, 2] = Aggregate.CyborgPlayer; // The Gargranian Character buttonTexture = game.Content.Load <Texture2D>("Spritesheets/charSelectGargranian"); buttonPos = new Vector2(center.X - viewport.Width / 4, center.Y + viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[1, 0] = buttonImage; buttonText = new TextSprite(spriteFont, "Gargranian", buttonPos + buttonTextOffset, Color.White); buttonTexts[1, 0] = buttonText; buttonAggregates[1, 0] = Aggregate.GargranianPlayer; // The Space Pirate Character buttonTexture = game.Content.Load <Texture2D>("Spritesheets/charSelectSpacePirate"); buttonPos = new Vector2(center.X, center.Y + viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[1, 1] = buttonImage; buttonText = new TextSprite(spriteFont, "Space Pirate", buttonPos + buttonTextOffset, Color.White); buttonTexts[1, 1] = buttonText; buttonAggregates[1, 1] = Aggregate.SpacePiratePlayer; // The Zombie Character buttonTexture = game.Content.Load <Texture2D>("Spritesheets/charSelectZombie"); buttonPos = new Vector2(center.X + viewport.Width / 4, center.Y + viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[1, 2] = buttonImage; buttonText = new TextSprite(spriteFont, "Zombie", buttonPos + buttonTextOffset, Color.White); buttonTexts[1, 2] = buttonText; buttonAggregates[1, 2] = Aggregate.ZombiePlayer; currentPlayer = player; currentPlayer.cursor.Position = buttons[0, 0].Position; // Initialized the sound effect soundEffect = game.Content.Load <SoundEffect>("Audio/BClick_Menu"); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> public void LoadContent(CharSelectPlayer player) { // Set up the background titleTexture = game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectBackground"); titleImage = new ImageSprite(titleTexture, viewport.Width / 2, viewport.Height / 2, Color.White); titleImage.Visible = true; titleImage.Scale = (float)(new Vector2(viewport.Width, viewport.Height).Length()) / (float)(new Vector2(titleTexture.Width, titleTexture.Height).Length()); // Set the control images buttonTexture = game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectControls2"); buttonPos = new Vector2(center.X, center.Y - viewport.Height * 0.365f); controlsImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); controlsImage.Scale = 1; // Initialize the sprite font spriteFont = game.Content.Load<SpriteFont>("SpriteFonts/Pescadero"); // Initialize the character buttons and the text for each button and the character's aggregate // The Cultist Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectCultist"); buttonPos = new Vector2(center.X - viewport.Width / 4, center.Y - viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[0, 0] = buttonImage; buttonTextOffset = new Vector2(0, buttonImage.Image.Height); buttonText = new TextSprite(spriteFont, "Cultist", buttonPos + buttonTextOffset, Color.White); buttonTexts[0, 0] = buttonText; buttonAggregates[0, 0] = Aggregate.CultistPlayer; // The Earthian Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectEarthian"); buttonPos = new Vector2(center.X, center.Y - viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[0, 1] = buttonImage; buttonText = new TextSprite(spriteFont, "Earthian", buttonPos + buttonTextOffset, Color.White); buttonTexts[0, 1] = buttonText; buttonAggregates[0, 1] = Aggregate.EarthianPlayer; // The Cyborg Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectCyborg"); buttonPos = new Vector2(center.X + viewport.Width / 4, center.Y - viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[0, 2] = buttonImage; buttonText = new TextSprite(spriteFont, "Cyborg", buttonPos + buttonTextOffset, Color.White); buttonTexts[0, 2] = buttonText; buttonAggregates[0, 2] = Aggregate.CyborgPlayer; // The Gargranian Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectGargranian"); buttonPos = new Vector2(center.X - viewport.Width / 4, center.Y + viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[1, 0] = buttonImage; buttonText = new TextSprite(spriteFont, "Gargranian", buttonPos + buttonTextOffset, Color.White); buttonTexts[1, 0] = buttonText; buttonAggregates[1, 0] = Aggregate.GargranianPlayer; // The Space Pirate Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectSpacePirate"); buttonPos = new Vector2(center.X, center.Y + viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[1, 1] = buttonImage; buttonText = new TextSprite(spriteFont, "Space Pirate", buttonPos + buttonTextOffset, Color.White); buttonTexts[1, 1] = buttonText; buttonAggregates[1, 1] = Aggregate.SpacePiratePlayer; // The Zombie Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/CharSelect/charSelectZombie"); buttonPos = new Vector2(center.X + viewport.Width / 4, center.Y + viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[1, 2] = buttonImage; buttonText = new TextSprite(spriteFont, "Zombie", buttonPos + buttonTextOffset, Color.White); buttonTexts[1, 2] = buttonText; buttonAggregates[1, 2] = Aggregate.ZombiePlayer; currentPlayer = player; currentPlayer.Cursor.Position = buttons[0, 0].Position; // Initialized the sound effect soundEffect = game.Content.Load<SoundEffect>("Audio/BClick_Menu"); }
/// <summary> /// Allows the game to run logic such as player input and character selection, /// also changes visual representation of selected/unselected characters /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Update(GameTime gameTime) { if (isConnected) { if (!isNewGame) { // Allows the game to exit if ((GamePad.GetState(currentPlayer.playerIndex).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) && currentPlayer.timer <= 0) { if (currentPlayerIndex == 0) { game.Exit(); } else { currentPlayerIndex--; currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.timer = controllerDelay; currentPlayer.selected = false; } } if ((GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter)) && !playerOne.connected) { playerOne.connected = true; players.Add(playerOne); } if (GamePad.GetState(PlayerIndex.Two).Buttons.Start == ButtonState.Pressed && !playerTwo.connected) { playerTwo.connected = true; players.Add(playerTwo); } if (GamePad.GetState(PlayerIndex.Three).Buttons.Start == ButtonState.Pressed && !playerThree.connected) { playerThree.connected = true; players.Add(playerThree); } if (GamePad.GetState(PlayerIndex.Four).Buttons.Start == ButtonState.Pressed && !playerFour.connected) { playerFour.connected = true; players.Add(playerFour); } #if XBOX // If windows we don't want to disconnect the keyboard, which is player one if (!GamePad.GetState(PlayerIndex.One).IsConnected) { players.Remove(playerOne); playerOne.connected = false; } #endif if (!GamePad.GetState(PlayerIndex.Two).IsConnected) { players.Remove(playerTwo); playerTwo.connected = false; } if (!GamePad.GetState(PlayerIndex.Three).IsConnected) { players.Remove(playerThree); playerThree.connected = false; } if (!GamePad.GetState(PlayerIndex.Four).IsConnected) { players.Remove(playerFour); playerFour.connected = false; } if (currentPlayer.connected) { currentPlayer.timer -= (float)gameTime.ElapsedGameTime.Milliseconds; if (!currentPlayer.selected && currentPlayer.timer <= 0) { currentPlayer.timer = controllerDelay; if (GamePad.GetState(currentPlayer.playerIndex).DPad.Down == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Down)) { selectedGameSave++; if (selectedGameSave < gameSaves.Count) { foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset(-movementOffset); preview.Color = unselected; } } else { selectedGameSave = 0; foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset((movementOffset * (gameSaves.Count - 1))); preview.Color = unselected; } } cursorMoved = true; gameSaves.ElementAt(selectedGameSave).Color = selected; } if (GamePad.GetState(currentPlayer.playerIndex).DPad.Up == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Up)) { selectedGameSave--; if (selectedGameSave >= 0) { foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset((movementOffset)); preview.Color = unselected; } } else { selectedGameSave = gameSaves.Count - 1; foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset(-(movementOffset * (gameSaves.Count - 1))); preview.Color = unselected; } } cursorMoved = true; gameSaves.ElementAt(selectedGameSave).Color = selected; } if (GamePad.GetState(currentPlayer.playerIndex).Buttons.A == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.A)) { currentPlayer.timer = controllerDelay; if (selectedGameSave == 0) { isNewGame = true; CharacterSelectionScreen.selectionDone = false; currentPlayer.gameSave = gameSaves.ElementAt(selectedGameSave); //currentPlayer.gameSave.fileNumber = gameSaves.Count; currentPlayer.gameSave.newGame = true; CharacterSelectionScreen.LoadContent(currentPlayer); } else { currentPlayer.gameSave = gameSaves.ElementAt(selectedGameSave); currentPlayer.selected = true; currentPlayer.cursor.Color = unselected; currentPlayerIndex++; // If we are on the last player in the wait list, go to the networking screen if (currentPlayerIndex == players.Count) { GoToNetworking(); } else { gameSaves.Remove(currentPlayer.gameSave); currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.selected = false; currentPlayer.cursor.Color = selected; ReloadGameSaves(); currentPlayer.timer = controllerDelay; } } } if (GamePad.GetState(currentPlayer.playerIndex).Buttons.B == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.B)) { //currentPlayer.selected = false; //currentPlayer.cursor.Color = Color.White; } //if (GamePad.GetState(currentPlayer.playerIndex).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter)) //{ // // Check to see if all of the connected players (at least one) have selected a character and if so, create the selected players and move to the network setup stage // if ((!playerOne.connected || playerOne.selected) && (!playerTwo.connected || playerTwo.selected) && // (!playerThree.connected || playerThree.selected) && (!playerFour.connected || playerFour.selected) && // (playerOne.selected || playerTwo.selected || playerThree.selected || playerFour.selected)) // { // GoToNetworking(); // } } } // If there has been a cursor movement, play the sound if (cursorMoved) { soundEffect.Play(); cursorMoved = false; } } else { CharacterSelectionScreen.Update(gameTime); if (CharacterSelectionScreen.selectionDone) { isNewGame = false; CharacterSelectionScreen.selectionDone = false; if (currentPlayer.selected) { currentPlayer.cursor.Color = unselected; currentPlayerIndex++; // If we are on the last player in the wait list, go to the networking screen if (currentPlayerIndex == players.Count) { GoToNetworking(); } else { gameSaves.Remove(currentPlayer.gameSave); currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.selected = false; currentPlayer.cursor.Color = selected; ReloadGameSaves(); currentPlayer.timer = controllerDelay; } } } } } }
/// <summary> /// Allows the game to run logic such as player input and character selection, /// also changes visual representation of selected/unselected characters /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Update(GameTime gameTime) { if (isConnected) { if (!isNewGame) { // Allows the game to exit if ((GamePad.GetState(currentPlayer.playerIndex).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) && currentPlayer.timer <= 0) { if (currentPlayerIndex == 0) game.Exit(); else { currentPlayerIndex--; currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.timer = controllerDelay; currentPlayer.selected = false; } } if ((GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter)) && !playerOne.connected) { playerOne.connected = true; players.Add(playerOne); } if (GamePad.GetState(PlayerIndex.Two).Buttons.Start == ButtonState.Pressed && !playerTwo.connected) { playerTwo.connected = true; players.Add(playerTwo); } if (GamePad.GetState(PlayerIndex.Three).Buttons.Start == ButtonState.Pressed && !playerThree.connected) { playerThree.connected = true; players.Add(playerThree); } if (GamePad.GetState(PlayerIndex.Four).Buttons.Start == ButtonState.Pressed && !playerFour.connected) { playerFour.connected = true; players.Add(playerFour); } #if XBOX // If windows we don't want to disconnect the keyboard, which is player one if (!GamePad.GetState(PlayerIndex.One).IsConnected) { players.Remove(playerOne); playerOne.connected = false; } #endif if (!GamePad.GetState(PlayerIndex.Two).IsConnected) { players.Remove(playerTwo); playerTwo.connected = false; } if (!GamePad.GetState(PlayerIndex.Three).IsConnected) { players.Remove(playerThree); playerThree.connected = false; } if (!GamePad.GetState(PlayerIndex.Four).IsConnected) { players.Remove(playerFour); playerFour.connected = false; } if (currentPlayer.connected) { currentPlayer.timer -= (float)gameTime.ElapsedGameTime.Milliseconds; if (!currentPlayer.selected && currentPlayer.timer <= 0) { currentPlayer.timer = controllerDelay; if (GamePad.GetState(currentPlayer.playerIndex).DPad.Down == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Down)) { selectedGameSave++; if (selectedGameSave < gameSaves.Count) { foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset(-movementOffset); preview.Color = unselected; } } else { selectedGameSave = 0; foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset((movementOffset * (gameSaves.Count - 1))); preview.Color = unselected; } } cursorMoved = true; gameSaves.ElementAt(selectedGameSave).Color = selected; } if (GamePad.GetState(currentPlayer.playerIndex).DPad.Up == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Up)) { selectedGameSave--; if (selectedGameSave >= 0) { foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset((movementOffset)); preview.Color = unselected; } } else { selectedGameSave = gameSaves.Count - 1; foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset(-(movementOffset * (gameSaves.Count - 1))); preview.Color = unselected; } } cursorMoved = true; gameSaves.ElementAt(selectedGameSave).Color = selected; } if (GamePad.GetState(currentPlayer.playerIndex).Buttons.A == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.A)) { currentPlayer.timer = controllerDelay; if (selectedGameSave == 0) { isNewGame = true; CharacterSelectionScreen.selectionDone = false; currentPlayer.gameSave = gameSaves.ElementAt(selectedGameSave); //currentPlayer.gameSave.fileNumber = gameSaves.Count; currentPlayer.gameSave.newGame = true; CharacterSelectionScreen.LoadContent(currentPlayer); } else { currentPlayer.gameSave = gameSaves.ElementAt(selectedGameSave); currentPlayer.selected = true; currentPlayer.cursor.Color = unselected; currentPlayerIndex++; // If we are on the last player in the wait list, go to the networking screen if (currentPlayerIndex == players.Count) GoToNetworking(); else { gameSaves.Remove(currentPlayer.gameSave); currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.selected = false; currentPlayer.cursor.Color = selected; ReloadGameSaves(); currentPlayer.timer = controllerDelay; } } } if (GamePad.GetState(currentPlayer.playerIndex).Buttons.B == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.B)) { //currentPlayer.selected = false; //currentPlayer.cursor.Color = Color.White; } //if (GamePad.GetState(currentPlayer.playerIndex).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter)) //{ // // Check to see if all of the connected players (at least one) have selected a character and if so, create the selected players and move to the network setup stage // if ((!playerOne.connected || playerOne.selected) && (!playerTwo.connected || playerTwo.selected) && // (!playerThree.connected || playerThree.selected) && (!playerFour.connected || playerFour.selected) && // (playerOne.selected || playerTwo.selected || playerThree.selected || playerFour.selected)) // { // GoToNetworking(); // } } } // If there has been a cursor movement, play the sound if (cursorMoved) { soundEffect.Play(); cursorMoved = false; } } else { CharacterSelectionScreen.Update(gameTime); if (CharacterSelectionScreen.selectionDone) { isNewGame = false; CharacterSelectionScreen.selectionDone = false; if (currentPlayer.selected) { currentPlayer.cursor.Color = unselected; currentPlayerIndex++; // If we are on the last player in the wait list, go to the networking screen if (currentPlayerIndex == players.Count) GoToNetworking(); else { gameSaves.Remove(currentPlayer.gameSave); currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.selected = false; currentPlayer.cursor.Color = selected; ReloadGameSaves(); currentPlayer.timer = controllerDelay; } } } } } }
/// <summary> /// Allows the game to run logic such as player input and character selection, /// also changes visual representation of selected/unselected characters /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Update(GameTime gameTime) { if (isConnected) { if (!isNewGame) { // Allows the game to exit if (InputHelper.GetInput(currentPlayer.playerIndex).IsPressed(Keys.Escape, Buttons.Back) && currentPlayer.timer <= 0) { if (currentPlayerIndex == 0) { game.Exit(); } else { currentPlayerIndex--; currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.Timer = controllerDelay; currentPlayer.Selected = false; } } if (InputHelper.GetInput(PlayerIndex.One).IsPressed(Keys.Enter, Buttons.Start)) { playerOne.Connected = true; if (!players.Contains(playerOne)) { players.Add(playerOne); } } if (InputHelper.GetInput(PlayerIndex.Two).IsPressed(Keys.Enter, Buttons.Start)) { playerTwo.Connected = true; if (!players.Contains(playerTwo)) { players.Add(playerTwo); } } if (InputHelper.GetInput(PlayerIndex.Three).IsPressed(Keys.Enter, Buttons.Start)) { playerThree.Connected = true; if (!players.Contains(playerThree)) { players.Add(playerThree); } } if (InputHelper.GetInput(PlayerIndex.Four).IsPressed(Keys.Enter, Buttons.Start)) { playerFour.Connected = true; if (!players.Contains(playerFour)) { players.Add(playerFour); } } #if XBOX // If windows we don't want to disconnect the keyboard, which is player one if (!UserInput.GetInput(PlayerIndex.One).IsGamePadConnected()) { players.Remove(playerOne); playerOne.Connected = false; } #endif if (!InputHelper.GetInput(PlayerIndex.Two).IsGamePadConnected()) { players.Remove(playerTwo); playerTwo.Connected = false; } if (!InputHelper.GetInput(PlayerIndex.Three).IsGamePadConnected()) { players.Remove(playerThree); playerThree.Connected = false; } if (!InputHelper.GetInput(PlayerIndex.Four).IsGamePadConnected()) { players.Remove(playerFour); playerFour.Connected = false; } if (currentPlayer.Connected) { currentPlayer.Timer -= (float)gameTime.ElapsedGameTime.Milliseconds; if (!currentPlayer.Selected && currentPlayer.Timer <= 0) { currentPlayer.timer = controllerDelay; if (InputHelper.GetInput(currentPlayer.playerIndex).IsPressed(Keys.Down, Buttons.DPadDown)) { selectedGameSave++; if (selectedGameSave < gameSaves.Count) { foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset(-movementOffset); preview.Color = unselected; } } else { selectedGameSave = 0; foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset((movementOffset * (gameSaves.Count - 1))); preview.Color = unselected; } } cursorMoved = true; gameSaves.ElementAt(selectedGameSave).Color = selected; } if (InputHelper.GetInput(currentPlayer.playerIndex).IsPressed(Keys.Up, Buttons.DPadUp)) { selectedGameSave--; if (selectedGameSave >= 0) { foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset((movementOffset)); preview.Color = unselected; } } else { selectedGameSave = gameSaves.Count - 1; foreach (CharSelectPreview preview in gameSaves) { preview.MoveByOffset(-(movementOffset * (gameSaves.Count - 1))); preview.Color = unselected; } } cursorMoved = true; gameSaves.ElementAt(selectedGameSave).Color = selected; } if (InputHelper.GetInput(currentPlayer.playerIndex).IsPressed(Keys.Space, Buttons.A)) { currentPlayer.Timer = controllerDelay; if (selectedGameSave == 0) { isNewGame = true; CharacterSelectionScreen.selectionDone = false; currentPlayer.GameSave = gameSaves.ElementAt(selectedGameSave); //currentPlayer.GameSave.FileNumber = gameSaves.Count; currentPlayer.GameSave.NewGame = true; CharacterSelectionScreen.LoadContent(currentPlayer); } else { currentPlayer.GameSave = gameSaves.ElementAt(selectedGameSave); currentPlayer.Selected = true; currentPlayer.Cursor.Color = unselected; currentPlayerIndex++; // If we are on the last player in the wait list, go to the networking screen if (currentPlayerIndex == players.Count) { GoToNetworking(); } else { gameSaves.Remove(currentPlayer.GameSave); currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.Selected = false; currentPlayer.Cursor.Color = selected; ReloadGameSaves(); currentPlayer.Timer = controllerDelay; } } } if (InputHelper.GetInput(currentPlayer.playerIndex).IsPressed(Keys.Escape, Buttons.Back)) { currentPlayer.Timer = controllerDelay; if (selectedGameSave != 0) { DoGameDelete(LoadGameSave(gameSaves.ElementAt(selectedGameSave))); } } if (GamePad.GetState(currentPlayer.PlayerIndex).Buttons.B == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.B)) { //currentPlayer.selected = false; //currentPlayer.cursor.Color = Color.White; } } } // If there has been a cursor movement, play the sound if (cursorMoved) { soundEffect.Play(); cursorMoved = false; } } else { CharacterSelectionScreen.Update(gameTime); if (CharacterSelectionScreen.selectionDone) { isNewGame = false; CharacterSelectionScreen.selectionDone = false; if (currentPlayer.Selected) { currentPlayer.Cursor.Color = unselected; currentPlayerIndex++; // If we are on the last player in the wait list, go to the networking screen if (currentPlayerIndex == players.Count) { GoToNetworking(); } else { gameSaves.Remove(currentPlayer.GameSave); currentPlayer = players.ElementAt(currentPlayerIndex); currentPlayer.Selected = false; currentPlayer.Cursor.Color = selected; ReloadGameSaves(); currentPlayer.Timer = controllerDelay; } } } } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> public void LoadContent() { // Set up the background titleTexture = game.Content.Load<Texture2D>("Spritesheets/charSelectBackground"); titleImage = new ImageSprite(titleTexture, viewport.Width / 2, viewport.Height / 2, Color.White); titleImage.Visible = true; titleImage.Scale = (float)(new Vector2(viewport.Width, viewport.Height).Length()) / (float)(new Vector2(titleTexture.Width, titleTexture.Height).Length()); // Initialize the sprite font spriteFont = game.Content.Load<SpriteFont>("SpriteFonts/Pescadero"); // Initialize the character buttons and the text for each button and the character's aggregate // The Cultist Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/charSelectGargranian"); buttonPos = new Vector2(center.X - viewport.Width / 4, center.Y - viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[0, 0] = buttonImage; buttonTextOffset = new Vector2(0, buttonImage.Image.Height); buttonText = new TextSprite(spriteFont, "Cultist", buttonPos + buttonTextOffset, Color.White); buttonTexts[0, 0] = buttonText; buttonAggregates[0, 0] = Aggregate.CultistPlayer; // The Earthian Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/charSelectGargranian"); buttonPos = new Vector2(center.X, center.Y - viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[0, 1] = buttonImage; buttonText = new TextSprite(spriteFont, "Earthian", buttonPos + buttonTextOffset, Color.White); buttonTexts[0, 1] = buttonText; buttonAggregates[0, 1] = Aggregate.EarthianPlayer; // The Cyborg Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/charSelectGargranian"); buttonPos = new Vector2(center.X + viewport.Width / 4, center.Y - viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[0, 2] = buttonImage; buttonText = new TextSprite(spriteFont, "Cyborg", buttonPos + buttonTextOffset, Color.White); buttonTexts[0, 2] = buttonText; buttonAggregates[0, 2] = Aggregate.CyborgPlayer; // The Gargranian Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/charSelectGargranian"); buttonPos = new Vector2(center.X - viewport.Width / 4, center.Y + viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[1, 0] = buttonImage; buttonText = new TextSprite(spriteFont, "Gargranian", buttonPos + buttonTextOffset, Color.White); buttonTexts[1, 0] = buttonText; buttonAggregates[1, 0] = Aggregate.GargranianPlayer; // The Space Pirate Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/charSelectGargranian"); buttonPos = new Vector2(center.X, center.Y + viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[1, 1] = buttonImage; buttonText = new TextSprite(spriteFont, "Space Pirate", buttonPos + buttonTextOffset, Color.White); buttonTexts[1, 1] = buttonText; buttonAggregates[1, 1] = Aggregate.SpacePiratePlayer; // The Zombie Character buttonTexture = game.Content.Load<Texture2D>("Spritesheets/charSelectGargranian"); buttonPos = new Vector2(center.X + viewport.Width / 4, center.Y + viewport.Height / 6); buttonImage = new ImageSprite(buttonTexture, (int)buttonPos.X, (int)buttonPos.Y, Color.White * (1f / 1)); buttonImage.Scale = 1; buttons[1, 2] = buttonImage; buttonText = new TextSprite(spriteFont, "Zombie", buttonPos + buttonTextOffset, Color.White); buttonTexts[1, 2] = buttonText; buttonAggregates[1, 2] = Aggregate.ZombiePlayer; playerOne = new CharSelectPlayer(new ImageSprite(game.Content.Load<Texture2D>("Spritesheets/charSelectPlayerOneCursor"), (int)buttons[0, 0].Position.X, (int)buttons[0, 0].Position.Y, Color.White), true, PlayerIndex.One); playerTwo = new CharSelectPlayer(new ImageSprite(game.Content.Load<Texture2D>("Spritesheets/charSelectPlayerTwoCursor"), (int)buttons[0, 0].Position.X, (int)buttons[0, 0].Position.Y, Color.White), false, PlayerIndex.Two); playerThree = new CharSelectPlayer(new ImageSprite(game.Content.Load<Texture2D>("Spritesheets/charSelectPlayerThreeCursor"), (int)buttons[0, 0].Position.X, (int)buttons[0, 0].Position.Y, Color.White), false, PlayerIndex.Three); playerFour = new CharSelectPlayer(new ImageSprite(game.Content.Load<Texture2D>("Spritesheets/charSelectPlayerFourCursor"), (int)buttons[0, 0].Position.X, (int)buttons[0, 0].Position.Y, Color.White), false, PlayerIndex.Four); players.Add(playerOne); players.Add(playerTwo); players.Add(playerThree); players.Add(playerFour); // Initialized the sound effect soundEffect = game.Content.Load<SoundEffect>("Audio/BClick_Menu"); }