Example #1
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
                    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;
                            }
                        }
                    }
                }
            }
        }
Example #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
                    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;
                            }
                        }
                    }
                }
            }
        }