/// <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) { // Allows the game to exit if (GamePad.GetState(currentPlayer.playerIndex).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { currentPlayer.timer = controllerDelay; selectionDone = true; } if (!currentPlayer.connected) { selectionDone = true; } if (currentPlayer.connected) { currentPlayer.timer -= (float)gameTime.ElapsedGameTime.Milliseconds; if (!currentPlayer.selected && currentPlayer.timer <= 0) { if (GamePad.GetState(currentPlayer.playerIndex).DPad.Down == ButtonState.Pressed || GamePad.GetState(currentPlayer.playerIndex).DPad.Up == ButtonState.Pressed || (Keyboard.GetState().IsKeyDown(Keys.Down) || Keyboard.GetState().IsKeyDown(Keys.Up))) { currentPlayer.MoveUpDown(); currentPlayer.cursor.Position = buttons[currentPlayer.yPos, currentPlayer.xPos].Position; currentPlayer.timer = controllerDelay; cursorMoved = true; } if (GamePad.GetState(currentPlayer.playerIndex).DPad.Left == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Left)) { currentPlayer.MoveLeft(); currentPlayer.cursor.Position = buttons[currentPlayer.yPos, currentPlayer.xPos].Position; currentPlayer.timer = controllerDelay; cursorMoved = true; } if (GamePad.GetState(currentPlayer.playerIndex).DPad.Right == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Right)) { currentPlayer.MoveRight(); currentPlayer.cursor.Position = buttons[currentPlayer.yPos, currentPlayer.xPos].Position; currentPlayer.timer = controllerDelay; cursorMoved = true; } if (GamePad.GetState(currentPlayer.playerIndex).Buttons.A == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.A)) { currentPlayer.selected = true; currentPlayer.gameSave.aggregate = (int)buttonAggregates[currentPlayer.yPos, currentPlayer.xPos]; currentPlayer.gameSave.charType.Text = buttonTexts[currentPlayer.yPos, currentPlayer.xPos].Text; selectionDone = true; currentPlayer.timer = controllerDelay; } } } // Update the color of the character images if the are/are not selected for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { if (currentPlayer.yPos == i && currentPlayer.xPos == j) { buttons[i, j].Color = selected; } else { buttons[i, j].Color = unselected; } } } // If there has been a cursor movement, play the sound if (cursorMoved) { soundEffect.Play(); cursorMoved = false; } }
/// <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) { // Allows the game to exit InputHelper state = InputHelper.GetInput(currentPlayer.playerIndex); if (state.IsPressed(Keys.Escape, Buttons.Back)) { currentPlayer.Timer = controllerDelay; selectionDone = true; } if (!currentPlayer.Connected) { selectionDone = true; } if (currentPlayer.Connected) { currentPlayer.Timer -= (float)gameTime.ElapsedGameTime.Milliseconds; if (!currentPlayer.Selected && currentPlayer.Timer <= 0) { if (state.IsPressed(Keys.Down, Buttons.DPadDown) || state.IsPressed(Keys.Up, Buttons.DPadUp)) { currentPlayer.MoveUpDown(); currentPlayer.Cursor.Position = buttons[currentPlayer.YPos, currentPlayer.XPos].Position; currentPlayer.Timer = controllerDelay; cursorMoved = true; } if (state.IsPressed(Keys.Left, Buttons.DPadLeft)) { currentPlayer.MoveLeft(); currentPlayer.Cursor.Position = buttons[currentPlayer.YPos, currentPlayer.XPos].Position; currentPlayer.Timer = controllerDelay; cursorMoved = true; } if (state.IsPressed(Keys.Right, Buttons.DPadRight)) { currentPlayer.MoveRight(); currentPlayer.Cursor.Position = buttons[currentPlayer.YPos, currentPlayer.XPos].Position; currentPlayer.Timer = controllerDelay; cursorMoved = true; } if (state.IsPressed(Keys.Enter, Buttons.A)) { currentPlayer.Selected = true; currentPlayer.GameSave.Aggregate = (int)buttonAggregates[currentPlayer.YPos, currentPlayer.XPos]; currentPlayer.GameSave.CharType.Text = buttonTexts[currentPlayer.YPos, currentPlayer.XPos].Text; selectionDone = true; currentPlayer.Timer = controllerDelay; } } } // Update the color of the character images if the are/are not selected for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { if (currentPlayer.YPos == i && currentPlayer.XPos == j) { buttons[i, j].Color = selected; } else { buttons[i, j].Color = unselected; } } } // If there has been a cursor movement, play the sound if (cursorMoved) { soundEffect.Play(); cursorMoved = false; } }