예제 #1
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {
                _selectedEntry--;

                if (_selectedEntry < 0)
                    _selectedEntry = _menuEntries.Count - 1;
            }

            // Move to the next menu entry?
            if (input.IsMenuDown(ControllingPlayer))
            {
                _selectedEntry++;

                if (_selectedEntry >= _menuEntries.Count)
                    _selectedEntry = 0;
            }

            // Accept or cancel the menu? We pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(_selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
        }
예제 #3
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");


            var currentKeyboardState = Keyboard.GetState();

            if (currentKeyboardState.IsKeyDown(Keybinds.DeveloperDiagnostics) && !_previousKeyboardState.IsKeyDown(Keybinds.DeveloperDiagnostics))
            {
                Global.IsDiagnosticsOpen = !Global.IsDiagnosticsOpen;
            }

            #region Developer Kill Cheat

            if (currentKeyboardState.IsKeyDown(Keybinds.DeveloperKillAll) && !_previousKeyboardState.IsKeyDown(Keybinds.DeveloperKillAll))
            {
                foreach (var z in _lZombies.Where(z => !z.Dead && z.Visible))
                {
                    z.Visible = false;
                    z.Dead = true;
                    _deadZombies++;
                    _diagZombieCount--;
                    if (_deadZombies % Global.ZombieSpawnTicker == 0)
                    {
                        foreach (var d in _lZombies.Where(d => !d.Dead && !d.Visible && _zombieSpawnChecker < Global.ZombieSpawnTicker))
                        {
                            d.Visible = true;
                            _zombieSpawnChecker++;
                        }

                    }
                    _zombieSpawnChecker = 0;
                }
            }

            #endregion

            _previousKeyboardState = currentKeyboardState;

            if (input.IsPauseGame(ControllingPlayer))
            {
                // Pause (esc)
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            }
            else
            {
                #region Player Movement

                if (_currentGameMode == GameMode.Singleplayer)
                {
                    _singlePlayerPlayer.Update(_gT, _cam);
                }
                else
                {
                    _multiPlayerOne.Update(_gT, _cam);
                }

                #endregion

            }

            #region Zombie Movement

            foreach (var z in _lZombies)
            {
                z.Update(_gT, _currentGameMode == GameMode.Singleplayer ? _singlePlayerPlayer : _multiPlayerOne);
            }

            #endregion

            #region Old Collision

            foreach (var z in _lZombies)
            {
                #region Bullet - Zombie Collision

                if (_currentGameMode == GameMode.Singleplayer)
                {
                    foreach (var b in _singlePlayerPlayer.Bullets)
                    {
                        if (z.BoundingBox.Intersects(b.BoundingBox) && z.Visible && b.Visible)
                        {

                            b.Visible = false;
                            KillZombie(z, _zombieSpawnChecker);

                        }
                    }
                }
                else
                {
                    foreach (var b in _multiPlayerOne.Bullets)
                    {
                        if (z.BoundingBox.Intersects(b.BoundingBox) && z.Visible && b.Visible)
                        {

                            b.Visible = false;
                            KillZombie(z, _zombieSpawnChecker);

                        }
                    }
                }

                #endregion

                #region Zombie - Player Collision

                if (_currentGameMode == GameMode.Singleplayer)
                {
                    if (z.BoundingBox.Intersects(_singlePlayerPlayer.BoundingBox) && z.Visible && _singlePlayerPlayer.CurrentState != Player.State.Dodging && !_singlePlayerPlayer.Invulnerable)
                    {

                        #region Vibration
                        /*
                    if (Global.Gamepad)
                    {
                        if (!Vibrate)
                        {
                            Vibrate = true;
                        }

                        if (Vibrate)
                        {
                            GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f);
                            vibrationCounterStart += (float)_gT.ElapsedGameTime.TotalSeconds;
                            if (vibrationCounterStart >= VibrationTime)
                            {
                                GamePad.SetVibration(PlayerIndex.One, 0f, 0f);
                                Vibrate = false;
                                vibrationCounterStart = 0f;
                            }

                        }


                    } 
                     */
                        #endregion

                        _singlePlayerPlayer.Health -= 10;
                        _singlePlayerPlayer.Invulnerable = true;

                    }
                }
                else
                {
                    if (z.BoundingBox.Intersects(_multiPlayerOne.BoundingBox) && z.Visible && _multiPlayerOne.CurrentState != Player.State.Dodging && !_multiPlayerOne.Invulnerable)
                    {

                        _multiPlayerOne.Health -= 10;
                        _multiPlayerOne.Invulnerable = true;

                    }
                }


                #endregion

                #region Sword - Zombie Collision

                if (_currentGameMode == GameMode.Singleplayer)
                {
                    if (z.BoundingBox.Intersects(_singlePlayerPlayer.Sword.BoundingBox) && z.Visible && _singlePlayerPlayer.Sword.Visible)
                    {
                        KillZombie(z, _zombieSpawnChecker);
                    }
                }
                else
                {
                    if (z.BoundingBox.Intersects(_multiPlayerOne.Sword.BoundingBox) && z.Visible && _multiPlayerOne.Sword.Visible)
                    {
                        KillZombie(z, _zombieSpawnChecker);
                    }
                }


                #endregion
            }

            #region Zombie - Zombie Collision
            /*
            for (var i = 0; i < _lZombies.Count; i++)
            {
                foreach (var z in _lZombies)
                {
                    if (_lZombies[i].BoundingBox.Intersects(z.BoundingBox) && z.Visible && _lZombies[i].Visible &&
                        _lZombies[i].Id != z.Id)
                    {

                    }
                }
            } 
            */
            #endregion

            #endregion

            #region Player Death & Game Over

            if (_currentGameMode == GameMode.Singleplayer)
            {
                if (_singlePlayerPlayer.Health <= 0 && !_singlePlayerPlayer.Dead)
                {
                    _singlePlayerPlayer.Dead = true;
                    _singlePlayerPlayer.Visible = false;
                    ScreenManager.AddScreen(new GameOverScreen(), ControllingPlayer);
                }
            }
            else
            {
                if (_multiPlayerOne.Health <= 0 && !_multiPlayerOne.Dead)
                {
                    _multiPlayerOne.Dead = true;
                    _multiPlayerOne.Visible = false;
                    ScreenManager.AddScreen(new GameOverScreen(), ControllingPlayer);
                }
            }

            #endregion

        }
예제 #4
0
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(InputState input) { }