/// <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.IsHeld(Inputs.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 (state.IsHeld(Inputs.DOWN) || state.IsHeld(Inputs.UP))
                    {
                        currentPlayer.MoveUpDown();
                        currentPlayer.Cursor.Position = buttons[currentPlayer.YPos, currentPlayer.XPos].Position;
                        currentPlayer.Timer           = controllerDelay;
                        cursorMoved = true;
                    }
                    if (state.IsHeld(Inputs.LEFT))
                    {
                        currentPlayer.MoveLeft();
                        currentPlayer.Cursor.Position = buttons[currentPlayer.YPos, currentPlayer.XPos].Position;
                        currentPlayer.Timer           = controllerDelay;
                        cursorMoved = true;
                    }
                    if (state.IsHeld(Inputs.RIGHT))
                    {
                        currentPlayer.MoveRight();
                        currentPlayer.Cursor.Position = buttons[currentPlayer.YPos, currentPlayer.XPos].Position;
                        currentPlayer.Timer           = controllerDelay;
                        cursorMoved = true;
                    }

                    if (state.IsHeld(Inputs.ENTER))
                    {
                        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;
            }
        }
Пример #2
0
        /// <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
                    InputHelper state = InputHelper.GetInput(currentPlayer.PlayerIndex);
                    if (state.IsHeld(Inputs.ESCAPE) &&
                        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).IsHeld(Inputs.ENTER))
                    {
                        playerOne.Connected = true;
                        if (!players.Contains(playerOne))
                        {
                            players.Add(playerOne);
                        }
                    }
                    if (InputHelper.GetInput(PlayerIndex.Two).IsHeld(Inputs.ENTER))
                    {
                        playerTwo.Connected = true;
                        if (!players.Contains(playerTwo))
                        {
                            players.Add(playerTwo);
                        }
                    }
                    if (InputHelper.GetInput(PlayerIndex.Three).IsHeld(Inputs.ENTER))
                    {
                        playerThree.Connected = true;
                        if (!players.Contains(playerThree))
                        {
                            players.Add(playerThree);
                        }
                    }
                    if (InputHelper.GetInput(PlayerIndex.Four).IsHeld(Inputs.ENTER))
                    {
                        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 (state.IsHeld(Inputs.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 (state.IsHeld(Inputs.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 (state.IsHeld(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 (state.IsHeld(Inputs.DELETE))
                            {
                                currentPlayer.Timer = controllerDelay;
                                if (selectedGameSave != 0)
                                {
                                    DoGameDelete(LoadGameSave(gameSaves.ElementAt(selectedGameSave)));
                                }
                            }
                        }
                    }

                    // 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;
                            }
                        }
                    }
                }
            }
        }