Ejemplo n.º 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 (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;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (InputHelper.GetInput(PlayerIndex.One).IsPressed(Keys.Escape, Buttons.Back))
            {
                this.Exit();
            }

            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            switch (GameState)
            {
            case GameState.SplashScreen:
                // TODO: Update splash screens
                break;

            case GameState.SignIn:
                // Requires at least one player to sign in
                if (Gamer.SignedInGamers.Count == 0)
                {
                    if (IsActive)
                    {
                        Guide.ShowSignIn(4, false);
                        InputHelper.DisableAll();
                    }
                }
                else
                {
                    GameState = GameState.CharacterSelection;
                    InputHelper.EnableAll();
                    if (!ContinueNewGameScreen.isConnected)
                    {
                        ContinueNewGameScreen.LoadContent();
                        ContinueNewGameScreen.isConnected = true;
                        ContinueNewGameScreen.loadGameSaves();
                    }
                }
                break;

            case GameState.CharacterSelection:
                // TODO: Update character selection screen
                SpriteAnimationSystem.Update(elapsedTime);
                ContinueNewGameScreen.Update(gameTime);
                break;

            case GameState.NetworkSetup:
                NetworkSystem.Update(elapsedTime);
                break;

            case GameState.GameMenu:
                // TODO: Update game menu screen

                // Game Menu does not pause game!
                // Update game systems
                NetworkSystem.Update(elapsedTime);
                MovementSystem.Update(elapsedTime);
                break;

            case GameState.Gameplay:
                // Update game systems
                InputSystem.Update(elapsedTime);
                NetworkSystem.Update(elapsedTime);
                MovementSystem.Update(elapsedTime);
                WeaponSystem.Update(elapsedTime);
                SkillSystem.Update(elapsedTime);
                LevelManager.Update(elapsedTime);
                CollisionSystem.Update(elapsedTime);
                HUDSystem.Update(elapsedTime);
                QuestLogSystem.Update(elapsedTime);
                SpriteAnimationSystem.Update(elapsedTime);
                NpcAISystem.Update(elapsedTime);
                EnemyAISystem.Update(elapsedTime);
                TextSystem.Update(elapsedTime);
                EngineeringOffenseSystem.Update(elapsedTime);

                GarbagemanSystem.Update(elapsedTime);
                break;

            case GameState.Credits:
                // TODO: Update credits
                break;

            case GameState.RoomChange:
                NetworkSystem.Update(elapsedTime);
                RoomChangingSystem.Update(elapsedTime);
                break;
            }

            base.Update(gameTime);
        }
        /// <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;
            }
        }