Ejemplo n.º 1
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(Managers.InputManager input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            KeyboardState keyboardState = input.CurrentKeyboardState;
            GamePadState gamePadState = input.CurrentGamePadState;

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected;

            if (input.IsPauseGame() || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseScreen());
            }
            else if (this.IsActive && player.IsReady && this.TransitionPosition == 0)
            {
                #region Tutorial Popups
                // grey
                if (StateManager.Instance.GetState("tutorial_grey") < 100 && StateManager.Instance.GetState(StateManager.STATE_PLAYERSTATUS) == 50)
                {
                    StateManager.Instance.SetState("tutorial_grey", 100);
                    ShowTutorial("Oh no! When you do not take care of the environment\nin your house, you become grey. You lose the ability to\ntime travel until you solve a problem in your house the next\nday.");
                }
                // square
                else if (StateManager.Instance.GetState("tutorial_square") < 100 && StateManager.Instance.GetState(StateManager.STATE_PLAYERSTATUS) == 0)
                {
                    StateManager.Instance.SetState("tutorial_square", 100);
                    ShowTutorial("You are a square head! You are not caring about\nthe environment. You'll have a hard time convincing other people\nnow. Press D to start a new day and improve yourself.");
                }
                #endregion

                // check for action button, only if player is over interactive object, and if player is either dropping an object or has no object in hand
                if (interactingObject != null)
                {
                    #region Action Button
                    if (input.IsMenuSelect()
                        && (StateManager.Instance.GetState(StateManager.STATE_PLAYERSTATUS) > 0 || LevelManager.Instance.CurrentLevel.name.Equals("bedroom") || LevelManager.Instance.CurrentLevel.name.Equals("kitchen"))
                        && (StateManager.Instance.GetState("progress") != 100 || (interactingObject.interaction.callback == "news" && StateManager.Instance.GetState("progress") == 100)))
                    {
                        // play sound if available
                        if (interactingObject.interaction.sound != null)
                            SoundManager.PlaySound(interactingObject.interaction.sound.name, interactingObject.interaction.sound.looping);

                        if (interactingObject.interaction.thought != null)
                            player.Thought = interactingObject.interaction.thought;

                        // Handling callbacks (aka special interactions)
                        if (!String.IsNullOrEmpty(interactingObject.interaction.callback))
                        {
                            switch (interactingObject.interaction.callback)
                            {
                                case "news":
                                    StateManager.Instance.tutorialNewsSeen = true;
                                    StateManager.Instance.SetState("tutorial_computer", 100);   // do not show computer tutorial if already interacted with
                                    ScreenManager.AddScreen(new ComputerScreen());
                                    break;
                                case "map":
                                    ScreenManager.AddScreen(new MapScreen());
                                    break;
                            }
                        }

                        // Handling talking
                        if ( interactingObject.interaction.chat != null && pickedObject == null)
                        {
                            // flip NPC to face player
                            if ( interactingObject.sprite != null)
                                interactingObject.sprite.flipped = interactingObject.sprite.flippable && (interactingObject.sprite.position.X < player.Position.X);

                            player.Thought = null;
                            ScreenManager.AddScreen(new ChatScreen(interactingObject.interaction.chat, true, interactingObject.interaction.mouth, interactingObject.interaction.startChatIndex));
                        }

                        // Pick up the object
                        if (pickedObject == null && !String.IsNullOrEmpty(interactingObject.interaction.pickUpName))
                        {
                            SoundManager.PlaySound(SoundManager.SOUND_PICK);
                            PickupObject(interactingObject);
                        }

                        // This prevents the player from picking up more than one object at a time
                        if (pickedObject == null || String.IsNullOrEmpty(interactingObject.interaction.pickUpName))
                        {
                            // Handling affected states
                            if (interactingObject.interaction.affectedStates != null)
                            {
                                StateManager.Instance.ModifyStates(interactingObject.interaction.affectedStates);
                                LoadGameObjects();
                            }
                        }

                        // Drop the picked up item into this object
                        if (pickedObject != null && interactingObject.interaction.dropper != null) {
                            if (interactingObject.interaction.sound == null)
                                SoundManager.PlaySound(SoundManager.SOUND_DROP);
                            else
                                SoundManager.PlaySound(interactingObject.interaction.sound.name, interactingObject.interaction.sound.looping);
                            DropObject(interactingObject);
                            LoadGameObjects();
                        }
                    }
                    #endregion

                    #region Time Warp Button
                    else if (input.IsReverseTime() && StateManager.Instance.CanTimeTravel())
                    {
                        // transition into past; an extra condition is added below to check if the interacting object can be picked up, then it is not picked up currently (prevents going to the past with garbage bag picked up)
                        if (!String.IsNullOrEmpty(interactingObject.interaction.transition) && !( !String.IsNullOrEmpty(interactingObject.interaction.pickUpName) && StateManager.Instance.GetState("item_picked") == 100 ) )
                        {
                            LevelManager.Instance.MovePast(interactingObject.interaction.transition);
                            LoadingScreen.Load(ScreenManager, false, new PlayScreen(TransitionType.FromPresent));
                            this.transition = TransitionType.ToPast;
                            ScreenManager.timeTravelInterval = 0f;
                            TransitionOffTime = TimeSpan.FromSeconds(2.0f);
                        }
                    }
                    #endregion
                }

                // TEST CODE: D key advances the day
                #region Advance Day
                if (keyboardState.IsKeyDown(Keys.D))
                {
                    if (StateManager.Instance.IsInPast())
                    {
                        StateManager.Instance.SetState(StateManager.STATE_BACKTOPRESENT, 100);
                    }
                    else
                    {
                        StateManager.Instance.AdvanceDay();
                        LoadingScreen.Load(ScreenManager, false, new PlayScreen());
                    }
                }
                #endregion

                // Check movement keys and move the player
                #region Movement
                float movement = 0.0f;

                if (keyboardState.IsKeyDown(Keys.Left))     --movement;
                if (keyboardState.IsKeyDown(Keys.Right))    ++movement;

                if (movement == 0.0f)
                    SoundManager.StopFootsteps();
                else
                    SoundManager.PlayFootsteps();

                // Checking gamepad controls only if we have one
                if (input.GamePadWasConnected) {
                    movement += gamePadState.ThumbSticks.Left.X;
                    if (movement != 0)
                        movement /= Math.Abs(movement);
                }

                /*
                // uncomment this if you wanna be shufflin'
                if (keyboardState.IsKeyDown(Keys.Space))
                    movement = 0;

                player.move( movement * -2 );
                */

                // Update movement if we have any
                if (movement != 0.0f) {
                    player.move(movement * 6);
                    player.walk();
                }
                else /* if ( !keyboardState.IsKeyDown(Keys.Space) )  // more shufflin' */
                    player.idle();
                #endregion
            }
            else
            {
                player.Sprite.Play( FrameSet.IDLE );
            }
        }