Exemple #1
0
        /// <summary>
        /// Is called when the screen is active
        /// </summary>
        /// <param name="gameTime">The game's time</param>
        /// <param name="input">The input state object</param>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            var keyboardState = input.CurrentKeyboardStates[playerIndex];
            var gamePadState  = input.CurrentGamePadStates[playerIndex];

            // 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[playerIndex];

            PlayerIndex player;

            if (_pauseAction.Occurred(input, ControllingPlayer, out player) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(_game), ControllingPlayer);
            }
            else
            {
                //Levels state machine
                switch (levelState)
                {
                case LevelState.Start:
                    if (keyboardState.IsKeyDown(Keys.Space) && previousKeyboardState.IsKeyUp(Keys.Space))
                    {
                        levelState = LevelState.Zero;
                    }
                    break;

                case LevelState.Zero:
                    level0.Update(gameTime);
                    if (level0.Won)
                    {
                        levelTransport.Play();
                        levelState = LevelState.One;
                        level1     = new Level1(level0.HP, ScreenManager.StoredGame);
                        LoadState();
                    }
                    if (level0.Lost)
                    {
                        lose.Play();
                        _time      = gameTime.TotalGameTime.ToString();
                        levelState = LevelState.EndL;
                    }
                    break;

                case LevelState.One:
                    level1.Update(gameTime);
                    if (level1.Won)
                    {
                        levelTransport.Play();
                        levelState = LevelState.Two;
                        level2     = new Level2(level1.HP, ScreenManager.StoredGame);
                        LoadState();
                    }
                    if (level1.Lost)
                    {
                        lose.Play();
                        _time      = gameTime.TotalGameTime.ToString();
                        levelState = LevelState.EndL;
                    }
                    break;

                case LevelState.Two:
                    level2.Update(gameTime);
                    if (level2.Won)
                    {
                        levelComplete.Play();
                        _time      = gameTime.TotalGameTime.ToString();
                        levelState = LevelState.EndW;
                    }
                    if (level2.Lost)
                    {
                        lose.Play();
                        _time      = gameTime.TotalGameTime.ToString();
                        levelState = LevelState.EndL;
                    }
                    break;

                case LevelState.EndW:
                    if (keyboardState.IsKeyDown(Keys.Space) && previousKeyboardState.IsKeyUp(Keys.Space))
                    {
                        MainMenuScreen mms = new MainMenuScreen(_game);
                        mms.ContentPasser(_content);

                        LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(), mms);
                    }
                    break;

                case LevelState.EndL:
                    if (keyboardState.IsKeyDown(Keys.Space) && previousKeyboardState.IsKeyUp(Keys.Space))
                    {
                        MainMenuScreen mms = new MainMenuScreen(_game);
                        mms.ContentPasser(_content);

                        LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(), mms);
                    }
                    break;
                }
            }
        }
Exemple #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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            levelOne.Update(gameTime);
            levelTwo.Update(gameTime);
            levelThree.Update(gameTime);
            levelFour.Update(gameTime);
            levelFive.Update(gameTime);
            levelSix.Update(gameTime);
            levelSeven.Update(gameTime);
            levelEight.Update(gameTime);
            levelNine.Update(gameTime);
            levelTen.Update(gameTime);
            levelEle.Update(gameTime);
            levelTwe.Update(gameTime);
            levelTteen.Update(gameTime);
            levelFourteen.Update(gameTime);
            levelFifteen.Update(gameTime);
            levelSixteen.Update(gameTime);
            levelSeventeen.Update(gameTime);

            bool notPlayed = true;

            switch (levelNumber)
            {
            case 3:

                if (theOne.posX == 320)
                {
                    notPlayed = true;
                }
                else if (theOne.posX == 500)
                {
                    notPlayed = true;
                }
                else if (theOne.posX == 600)
                {
                    notPlayed = true;
                }
                else if (theOne.posX == 860)
                {
                    notPlayed = true;
                }

                if (theOne.posX < 140)
                {
                    levelThree.convoNumber = 1;
                }
                else if (theOne.posX < 320)
                {
                    levelThree.convoNumber = 2;
                    if (notPlayed)
                    {
                        level3Inst.Play();
                        notPlayed = false;
                    }
                }
                else if (theOne.posX < 500)
                {
                    levelThree.convoNumber = 3;
                    if (notPlayed)
                    {
                        level3Inst.Play();
                        notPlayed = false;
                    }
                }
                else if (theOne.posX < 680)
                {
                    levelThree.convoNumber = 4;
                    if (notPlayed)
                    {
                        level3Inst.Play();
                        notPlayed = false;
                    }
                }
                else if (theOne.posX < 860)
                {
                    levelThree.convoNumber = 5;
                    if (notPlayed)
                    {
                        level3Inst.Play();
                        notPlayed = false;
                    }
                }
                break;

            case 4:
            case 5:
                if (theOne.posX < 200)
                {
                    levelFive.convoSpeed = 1;
                }
                else if (theOne.posX < 400)
                {
                    levelFive.convoSpeed = 2;
                }
                else if (theOne.posX < 600)
                {
                    levelFive.convoSpeed = 3;
                }
                break;
            }


            if (transition)
            {
                transitionPos.X -= 6;
            }
            if (transitionPos.X + transitionBackground.Width <= 0)
            {
                transition      = false;
                transitionPos.X = 0;
                transitionPos.Y = 0;
                if (levelNumber == 10)
                {
                    MediaPlayer.Play(sunshine);
                    MediaPlayer.Volume      = 0.1f;
                    MediaPlayer.IsRepeating = false;
                }
            }


            if (theOne.posX < 0)
            {
                theOne.posX = 0;
            }


            if (CheckIntersection())
            {
                if (typingInst.State == SoundState.Playing)
                {
                    typingInst.Stop();
                }
                if (level7Inst.State == SoundState.Playing)
                {
                    level7Inst.Stop();
                }

                theOne.posX          = (int)startPos.X;
                theOne.posY          = (int)startPos.Y;
                levelNumber         += 1;
                levelFour.convoSpeed = 1;
                levelFive.convoSpeed = 1;
                transition           = true;
            }


            if (!transition)
            {
                // TODO: Add your update logic here
                if (Keyboard.GetState().IsKeyDown(Keys.A))
                {
                    walkingRight = false;
                    theOneSprLeft.Update();
                    theOne.posX -= 2;
                }

                Random rand = new Random();
                if (Keyboard.GetState().IsKeyUp(Keys.D))
                {
                    if (typingInst.State == SoundState.Playing)
                    {
                        typingInst.Stop();
                    }
                }


                if (Keyboard.GetState().IsKeyDown(Keys.D))
                {
                    if (levelNumber >= 2)
                    {
                        if (levelNumber != 3)
                        {
                            if (textStillToType)
                            {
                                if (typingInst.State != SoundState.Playing)
                                {
                                    typingInst.Play();
                                }
                            }
                            else
                            {
                                if (typingInst.State == SoundState.Playing)
                                {
                                    typingInst.Stop();
                                }
                            }
                        }
                    }
                    walkingRight = true;
                    switch (levelNumber)
                    {
                    case 2:

                        if (!transition)
                        {
                            textStillToType = !levelTwo.textDone;
                            levelTwo.UpdateText();
                        }
                        break;

                    case 4:
                        if (!transition)
                        {
                            textStillToType = !levelFour.textDone;
                            levelFour.UpdateConvo();
                            levelFour.UpdateText();
                        }
                        break;

                    case 5:
                        if (!transition)
                        {
                            textStillToType = !levelFive.textDone;
                            levelFive.UpdateConvo();
                            levelFive.UpdateText();
                        }
                        break;

                    case 6:
                        if (!transition)
                        {
                            textStillToType = !levelSix.textDone;
                            levelSix.UpdateText();
                        }
                        break;

                    case 7:
                        if (!transition)
                        {
                            textStillToType = !levelSeven.textDone;
                            levelSeven.UpdateText();
                        }
                        break;

                    case 8:
                        if (!transition)
                        {
                            textStillToType = !levelEight.textDone;
                            levelEight.UpdateText();
                        }
                        break;

                    case 9:
                        if (!transition)
                        {
                            textStillToType = !levelNine.textDone;
                            levelNine.UpdateText();
                        }
                        break;

                    case 10:
                        if (!transition)
                        {
                            textStillToType = !levelTen.textDone;
                            levelTen.UpdateText();
                        }
                        break;

                    case 11:
                        if (!transition)
                        {
                            textStillToType = !levelEle.textDone;
                            levelEle.UpdateText();
                        }
                        break;

                    case 12:
                        if (!transition)
                        {
                            textStillToType = !levelTwe.textDone;
                            levelTwe.UpdateText();
                        }
                        break;

                    case 13:
                        if (!transition)
                        {
                            textStillToType = !levelTteen.textDone;
                            levelTteen.UpdateText();
                        }
                        break;

                    case 14:
                        if (!transition)
                        {
                            textStillToType = !levelFourteen.textDone;
                            levelFourteen.UpdateText();
                        }
                        break;

                    case 15:
                        if (!transition)
                        {
                            textStillToType = !levelFifteen.textDone;
                            levelFifteen.UpdateText();
                        }
                        break;

                    case 16:
                        if (!transition)
                        {
                            textStillToType = !levelSixteen.textDone;
                            levelSixteen.UpdateText();
                        }
                        break;

                    case 17:
                        if (!transition)
                        {
                            textStillToType = !levelSeventeen.textDone;
                            levelSeventeen.UpdateText();
                        }
                        break;
                    }


                    theOneSprRight.Update();
                    theOne.posX += 2;
                }
            }
            base.Update(gameTime);
        }