Exemple #1
0
        public override void Update(GameTime gameTime)
        {
            float deltaTime = (float)gameTime.ElapsedGameTime.Milliseconds;

            switch (CurrentScreen)
            {
            case ActiveScreen.MAIN:
                if (Active)
                {
                    if (MediaPlayer.State == MediaState.Stopped)
                    {
                        MediaPlayer.Play(MenuTrack);
                    }
                }
                else
                {
                    MediaPlayer.Stop();
                    MediaPlayer.Play(BackingTrack);
                    CurrentScreen = ActiveScreen.PLAY;
                }

                // Check Input
                if (InputEngine.IsKeyPressed(ActivationKey) ||
                    InputEngine.IsButtonPressed(ActivationButton))
                {
                    Active = !Active;
                    BlinkPlay.Play();
                    Helper.CurrentGameStatus = GameStatus.PLAYING;
                }
                break;

            case ActiveScreen.PLAY:
                TilePlayer player = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

                if (Active)
                {
                    MediaPlayer.Stop();
                    PauseTime     = gameTime.TotalGameTime;
                    CurrentScreen = ActiveScreen.PAUSE;
                }

                // Check Input
                if (InputEngine.IsKeyPressed(PauseKey) ||
                    InputEngine.IsButtonPressed(PauseButton))
                {
                    Active = !Active;
                    BlinkPause.Play();
                    Helper.CurrentGameStatus = GameStatus.PAUSED;
                }

                if (player.Health > 0 && TimeRemaining > 0)
                {
                    TimeRemaining -= deltaTime;
                }
                else
                {
                    MediaPlayer.Stop();
                    Active = !Active;
                    CurrentGameCondition = GameCondition.LOSE;
                    CurrentScreen        = ActiveScreen.LOSE;
                }

                if (CurrentGameCondition == GameCondition.WIN)
                {
                    MediaPlayer.Stop();
                    Active        = !Active;
                    CurrentScreen = ActiveScreen.WIN;
                }
                break;

            case ActiveScreen.PAUSE:
                if (MediaPlayer.State == MediaState.Stopped)
                {
                    MediaPlayer.Play(PauseTrack);
                }

                if (!Active)
                {
                    MediaPlayer.Stop();
                    MediaPlayer.Play(BackingTrack);
                    CurrentScreen          = ActiveScreen.PLAY;
                    gameTime.TotalGameTime = PauseTime;
                }

                // Check Input
                if (InputEngine.IsKeyPressed(PauseKey) ||
                    InputEngine.IsButtonPressed(PauseButton))
                {
                    Active = !Active;
                    BlinkPause.Play();
                    Helper.CurrentGameStatus = GameStatus.PLAYING;
                }
                break;

            case ActiveScreen.LOSE:

                if (MediaPlayer.State == MediaState.Stopped && TrackPlayCount < 1)
                {
                    MediaPlayer.Play(GameOverTrack);
                    TrackPlayCount++;
                    MediaPlayer.IsRepeating = false;
                }
                Helper.CurrentGameStatus = GameStatus.PAUSED;
                break;

            case ActiveScreen.WIN:
                if (MediaPlayer.State == MediaState.Stopped && TrackPlayCount < 1)
                {
                    MediaPlayer.Play(WinTrack);
                    TrackPlayCount++;
                }
                Helper.CurrentGameStatus = GameStatus.PAUSED;
                break;

            default:
                break;
            }

            base.Update(gameTime);
        }
Exemple #2
0
        public override void Update(GameTime gameTime)
        {
            float deltaTime = gameTime.ElapsedGameTime.Milliseconds;

            switch (CurrentScreen)
            {
            case ActiveScreen.MAIN:
                if (Active)
                {
                    if (MediaPlayer.State == MediaState.Stopped)
                    {
                        MediaPlayer.Play(MenuTrack);
                    }
                }
                else
                {
                    MediaPlayer.Stop();
                    MediaPlayer.Play(BackingTrack);
                    CurrentScreen = ActiveScreen.PLAY;
                }

                if (fadeIn && OverlayAlpha <= 1)
                {
                    OverlayAlpha -= FADE_AMOUNT;
                }

                // Check Input
                if (InputEngine.IsKeyPressed(ActivationKey) ||
                    InputEngine.IsButtonPressed(ActivationButton))
                {
                    OverlayAlpha = 1;
                    BlinkPlay.Play();
                    Active = !Active;
                    Helper.CurrentGameStatus = GameStatus.PLAYING;
                }

                break;

            case ActiveScreen.PLAY:
                TilePlayer player = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

                if (Active)
                {
                    MediaPlayer.Stop();
                    PauseTime     = gameTime.TotalGameTime;
                    CurrentScreen = ActiveScreen.PAUSE;
                }

                if (player.Health > 0 && TimeRemaining > 0)
                {
                    TimeRemaining -= deltaTime;

                    // Check Input
                    if (InputEngine.IsKeyPressed(PauseKey) ||
                        InputEngine.IsButtonPressed(PauseButton))
                    {
                        Active = !Active;
                        BlinkPause.Play();
                        Helper.CurrentGameStatus = GameStatus.PAUSED;
                    }

                    if (OverlayAlpha <= 0)
                    {
                        fadeIn = false;
                    }
                    if (fadeIn && OverlayAlpha > 0)
                    {
                        OverlayAlpha -= FADE_AMOUNT;
                    }
                }
                else
                {
                    MediaPlayer.Stop();

                    // Wait for Input
                    if (InputEngine.IsPadInputChanged(true) ||
                        InputEngine.IsKeyInputChanged())
                    {
                        fadeOut = true;
                    }

                    if (fadeOut)
                    {
                        OverlayAlpha += FADE_AMOUNT;
                        if (OverlayAlpha >= 1)
                        {
                            Active = !Active;
                            CurrentGameCondition = GameCondition.LOSE;
                            CurrentScreen        = ActiveScreen.LOSE;
                            fadeIn = true;
                        }
                    }
                }

                if (CurrentGameCondition == GameCondition.WIN)
                {
                    OverlayAlpha += FADE_AMOUNT;
                    if (OverlayAlpha >= 1)
                    {
                        MediaPlayer.Stop();
                        Active        = !Active;
                        CurrentScreen = ActiveScreen.WIN;
                    }
                }
                break;

            case ActiveScreen.PAUSE:
                if (MediaPlayer.State == MediaState.Stopped)
                {
                    OverlayAlpha = 0.5f;
                    MediaPlayer.Play(PauseTrack);
                }

                if (!Active)
                {
                    MediaPlayer.Stop();
                    MediaPlayer.Play(BackingTrack);
                    CurrentScreen          = ActiveScreen.PLAY;
                    gameTime.TotalGameTime = PauseTime;
                }

                // Check Input
                if (InputEngine.IsKeyPressed(PauseKey) ||
                    InputEngine.IsButtonPressed(PauseButton))
                {
                    OverlayAlpha = 0;
                    Active       = !Active;
                    BlinkPause.Play();
                    Helper.CurrentGameStatus = GameStatus.PLAYING;
                }
                break;

            case ActiveScreen.LOSE:
                if (OverlayAlpha <= 1 || OverlayAlpha > 0)
                {
                    OverlayAlpha -= FADE_AMOUNT;
                }

                if (MediaPlayer.State == MediaState.Stopped && TrackPlayCount < 1)
                {
                    MediaPlayer.Play(GameOverTrack);
                    TrackPlayCount++;
                    MediaPlayer.IsRepeating = false;
                }
                Helper.CurrentGameStatus = GameStatus.PAUSED;
                break;

            case ActiveScreen.WIN:
                if (OverlayAlpha <= 1 || OverlayAlpha > 0)
                {
                    OverlayAlpha -= FADE_AMOUNT;
                }

                if (MediaPlayer.State == MediaState.Stopped && TrackPlayCount < 1)
                {
                    MediaPlayer.Play(WinTrack);
                    TrackPlayCount++;
                }

                frameTime += gameTime.ElapsedGameTime;

                if (frameTime.Milliseconds > FRAME_SPEED)
                {
                    txWin = txWinQueue.Dequeue();
                    txWinQueue.Enqueue(txWin);
                    frameTime = TimeSpan.Zero;
                }

                Helper.CurrentGameStatus = GameStatus.PAUSED;
                break;

            default:
                break;
            }

            base.Update(gameTime);
        }