예제 #1
0
        public byte Update(GameTime dt, KeyboardState prevStateKb, MouseState prevStateM)
        {
            state  = Mouse.GetState();
            mouseX = (int)(state.X * Game1.resMultiplier);
            mouseY = (int)(state.Y * Game1.resMultiplier);
            options.Update(dt, prevStateKb, prevStateM, mouseX, mouseY);
            //startButton.Update(x, y, state.LeftButton == ButtonState.Pressed);

            switch (phase)
            {
            case Phase.Title:
                switch (options.GetSelection(prevStateKb, prevStateM, mouseX, mouseY))
                {
                case 0:
                    return(1);

                case 1:
                    phase   = Phase.Settings;
                    options = new Menu(contentManager, new string[] { "Palette", "Controls", "P1", null, "P2", null, "P3", null, "P4", null, "P5", null }, 2, 40, offsetX: Game1.width / 3, offsetY: Game1.height / 2);
                    break;

                case 2:
                    if (!practiceUnlocked)
                    {
                        return(3);
                    }
                    return(2);

                //Exit game
                case 3:
                    return(3);

                default:
                    break;
                }

                break;

            case Phase.Settings:
                backButton.Update(mouseX, mouseY);
                if ((prevStateKb.IsKeyUp(Keys.Escape) && Keyboard.GetState().IsKeyDown(Keys.Escape)) ||
                    backButton.IsPressed(prevStateM))
                {
                    phase = Phase.Title;
                    if (practiceUnlocked)
                    {
                        options = new Menu(contentManager, new string[] { "Start Game", "Settings", "Practice", "Quit" }, 4, offsetX: Game1.width / 3, offsetY: Game1.height / 2);
                    }
                    else
                    {
                        options = new Menu(contentManager, new string[] { "Start Game", "Settings", "Quit" }, 3, offsetX: Game1.width / 3, offsetY: Game1.height / 2);
                    }
                }
                //Palette Selection
                if (options.GetSelectionY(prevStateKb, prevStateM, mouseX, mouseY) == 0)
                {
                    int indX = options.GetSelectionX(prevStateKb, prevStateM, mouseX, mouseY);
                    if (indX > 0)
                    {
                        SetColor(indX - 1);
                    }
                }
                else
                {
                    switch (options.GetSelectionY(prevStateKb, prevStateM, mouseX, mouseY))
                    {
                    //Controls
                    case 1:
                        if ((prevStateKb.IsKeyUp(Keys.Space) && Keyboard.GetState().IsKeyDown(Keys.Space)) ||
                            (prevStateM.LeftButton == ButtonState.Pressed && Mouse.GetState().LeftButton == ButtonState.Released))
                        {
                            //Trigger MainScreen to show Controls
                            return(4);
                        }
                        break;

                    default:
                        break;
                    }
                }
                break;
            }

            return(0);
        }
예제 #2
0
        void Screen.Update(GameTime dt)
        {
            if (!prevStateKb.GetPressedKeys().Equals(Keyboard.GetState().GetPressedKeys()))
            {
                game.IsMouseVisible = false;
            }

            MouseState state = Mouse.GetState();

            if (prevStateM.X != state.X || prevStateM.Y != state.Y)
            {
                game.IsMouseVisible = true;
            }

            int mouseX = (int)(state.X * Game1.resMultiplier);
            int mouseY = (int)(state.Y * Game1.resMultiplier);

            pauseButton.Update(mouseX, mouseY);
            if ((curPhase == Phase.Transition || curPhase == Phase.BetweenGames) &&
                ((Keyboard.GetState().IsKeyUp(Keys.Escape) && prevStateKb.IsKeyDown(Keys.Escape)) ||
                 (curPhase != Phase.Paused && pauseButton.IsPressed(prevStateM))))
            {
                prevStateM = state;
                prevPhase  = curPhase;
                MediaPlayer.Pause();
                curPhase = Phase.Paused;
                pauseMenu.SetSelectionY(0);
                //timer = 0.2;
            }
            else
            {
                switch (curPhase)
                {
                case Phase.Introduction:
                    exitButton.Update(mouseX, mouseY);
                    introText.Update(dt, prevStateKb, prevStateM);

                    if (controlHint)
                    {
                        if ((prevStateKb.IsKeyUp(Keys.Escape) && Keyboard.GetState().IsKeyDown(Keys.Escape)) || exitButton.IsPressed(prevStateM))
                        {
                            controlHint = false;
                            introText.finishMessage();
                            introText.finishText();
                            if (controlRevisit)
                            {
                                curPhase = Phase.MainMenu;
                            }
                            else
                            {
                                curPhase  = Phase.FinalMessage;
                                introText = new Hud(new string[] { "You can revisit that screen in Settings.\nHave fun!" }, cm, 30, 2, posY: -1, canClose: true);
                            }
                        }
                    }
                    if (introText.messageComplete())
                    {
                        if (controlHint)
                        {
                            controlHint = false;
                            //exitButton.Update(mouseX, mouseY);

                            if ((prevStateKb.IsKeyUp(Keys.Escape) && Keyboard.GetState().IsKeyDown(Keys.Escape)) || exitButton.IsPressed(prevStateM))
                            {
                                if (controlRevisit)
                                {
                                    curPhase = Phase.MainMenu;
                                }
                                else
                                {
                                    curPhase  = Phase.FinalMessage;
                                    introText = new Hud(new string[] { "You can revisit that screen in Settings.\nHave fun!" }, cm, 30, 2, posY: -1, canClose: true);
                                }
                            }
                        }
                        else if (!controlsShown)
                        {
                            controlsShown = true;
                            break;
                        }
                        else
                        {
                            //exitButton.Update(mouseX, mouseY);

                            //Hit the wrong buttons to continue
                            if ((prevStateKb.IsKeyUp(Keys.Space) && Keyboard.GetState().IsKeyDown(Keys.Space)) ||
                                !exitButton.IsPressed(prevStateM) && (prevStateM.LeftButton == ButtonState.Pressed && Mouse.GetState().LeftButton == ButtonState.Released))
                            {
                                controlHint = true;
                                introText   = new Hud(new string[] { "You can click the button in the upper left corner\nor hit the Escape key to exit this screen." }, cm, 30, 2, posY: -1, canClose: true);
                            }
                            else if ((prevStateKb.IsKeyUp(Keys.Escape) && Keyboard.GetState().IsKeyDown(Keys.Escape)) || exitButton.IsPressed(prevStateM))
                            {
                                if (controlRevisit)
                                {
                                    curPhase = Phase.MainMenu;
                                }
                                else
                                {
                                    curPhase  = Phase.FinalMessage;
                                    introText = new Hud(new string[] { "You can revisit that screen in Settings.\nHave fun!" }, cm, 30, 2, posY: -1, canClose: true);
                                }
                            }
                        }
                    }
                    else
                    {
                    }
                    break;

                case Phase.FinalMessage:
                    if (controlRevisit)
                    {
                        curPhase = Phase.MainMenu;
                        break;
                    }
                    introText.Update(dt, prevStateKb, prevStateM);
                    if (introText.messageComplete())
                    {
                        //TODO: Make an exit button
                        if (prevStateKb.IsKeyUp(Keys.Space) && Keyboard.GetState().IsKeyDown(Keys.Space) || (prevStateM.LeftButton == ButtonState.Pressed && Mouse.GetState().LeftButton == ButtonState.Released))
                        {
                            byte[] bytes = Encoding.UTF8.GetBytes("Palette: 0\nPractice: 0\nBattle: 0W 0L\nApples: 0W 0L\n");
                            fs.Write(bytes, 0, bytes.Length);
                            fs.Close();

                            curPhase = Phase.MainMenu;
                        }
                    }
                    break;

                case Phase.PracticeUnlock:
                    introText.Update(dt, prevStateKb, prevStateM);
                    if (introText.messageComplete())
                    {
                        //TODO: Make an exit button
                        if (prevStateKb.IsKeyUp(Keys.Space) && Keyboard.GetState().IsKeyDown(Keys.Space) || (prevStateM.LeftButton == ButtonState.Pressed && Mouse.GetState().LeftButton == ButtonState.Released))
                        {
                            UpdateSaveElem("Practice", 1);
                            curPhase = Phase.MainMenu;
                        }
                    }
                    break;

                case Phase.MainMenu:
                    switch (microgame.Update(dt, prevStateKb, prevStateM))
                    {
                    case 1:
                        microgame.Unload();
                        cm.Dispose();
                        cm = new ContentManager(contentManager.ServiceProvider);
                        cm.RootDirectory = contentManager.RootDirectory;
                        practiceMode     = false;
                        microgame        = ChooseGame();
                        //microgame = new TitleScreen(cm);
                        curPhase = Phase.Transition;
                        break;

                    case 2:
                        microgame.Unload();
                        cm.Dispose();
                        cm = new ContentManager(contentManager.ServiceProvider);
                        cm.RootDirectory = contentManager.RootDirectory;
                        practiceMode     = true;
                        microgame        = GetMostLost();
                        //microgame = new TitleScreen(cm);
                        curPhase = Phase.Transition;
                        break;

                    case 3:
                        game.Exit();
                        break;

                    case 4:
                        controlRevisit = true;
                        curPhase       = Phase.Introduction;
                        break;
                    }
                    break;

                case Phase.Transition:
                    if (beginSong)
                    {
                        if (microgame is BetweenGames)
                        {
                            MediaPlayer.Play(transitionSong);
                        }
                        else
                        {
                            MediaPlayer.Play(previewSong);
                        }
                        beginSong = false;
                    }

                    if ((currentFlashes & 1) == 0)
                    {
                        timer += dt.ElapsedGameTime.TotalSeconds;
                    }
                    else
                    {
                        timer -= dt.ElapsedGameTime.TotalSeconds;
                    }

                    transition.Parameters["time"].SetValue((float)timer * 4);

                    //Lets the transition animation start while borders are still animating
                    if (microgame is BetweenGames && currentFlashes > maxFlashes)
                    {
                        microgame.Update(dt, prevStateKb, prevStateM);
                    }

                    break;

                case Phase.InGame:
                    if (beginSong)
                    {
                        //if (microgame is Battle)
                        MediaPlayer.Stop();
                        MediaPlayer.Play(battleSong);
                        //else
                        //MediaPlayer.Play(previewSong);

                        beginSong = false;
                    }

                    byte result = microgame.Update(dt, prevStateKb, prevStateM);

                    if (result != 254)
                    {
                        countdownTimer += dt.ElapsedGameTime.TotalSeconds * timerMult;
                    }

                    //Won game
                    if (result == 255)
                    {
                        UpdateSaveGame(microgame.ToString(), true);
                        score++;
                        if (score == 10)
                        {
                            timerMult = 1.25;
                        }
                        else if (score == 20)
                        {
                            timerMult = 1.5;
                        }

                        countdownTimer = 0.0;
                        microgame.Unload();
                        cm.Dispose();
                        cm = new ContentManager(contentManager.ServiceProvider);
                        cm.RootDirectory = contentManager.RootDirectory;

                        if (continues <= 2)
                        {
                            if (score % 10 == 0)
                            {
                                microgame = new BetweenGames(cm, score, betweenGamesOffset, pauseButton, continues, false, true);
                                continues++;
                            }
                            else
                            {
                                microgame = new BetweenGames(cm, score, betweenGamesOffset, pauseButton, continues, false, false);
                            }
                        }
                        else
                        {
                            microgame = new BetweenGames(cm, score, betweenGamesOffset, pauseButton, continues, false);
                        }

                        curPhase  = Phase.Transition;
                        beginSong = true;
                        fromGame  = true;
                    }
                    //Lost game
                    else if (countdownTimer >= 11 || result == 2)
                    {
                        UpdateSaveGame(microgame.ToString(), false);
                        countdownTimer = 0.0;

                        microgame.Unload();
                        cm.Dispose();
                        cm = new ContentManager(contentManager.ServiceProvider);
                        cm.RootDirectory = contentManager.RootDirectory;

                        continues--;
                        microgame = new BetweenGames(cm, score, betweenGamesOffset, pauseButton, continues, true);

                        curPhase  = Phase.Transition;
                        beginSong = true;
                        fromGame  = true;
                        //BetweenGames phase will handle switching to TitleScreen on 0 continues
                    }

                    break;

                case Phase.BetweenGames:
                    if (beginSong)
                    {
                        beginSong = false;
                        MediaPlayer.Stop();
                        MediaPlayer.Play(previewSong);
                        //MediaPlayer.IsRepeating = true;
                    }
                    if (microgame.Update(dt, prevStateKb, prevStateM) == 255)
                    {
                        microgame.Unload();
                        cm.Dispose();
                        cm = new ContentManager(contentManager.ServiceProvider);
                        cm.RootDirectory = contentManager.RootDirectory;

                        if (continues > 0)
                        {
                            if (microgame is BetweenGames)
                            {
                                betweenGamesOffset = ((BetweenGames)microgame).GetAnimOffset();
                                microgame          = ChooseGame();
                            }
                            else
                            {
                                betweenGamesOffset = 0.0;
                                //beginSong = true;
                                goto case Phase.InGame;
                            }
                        }
                        else
                        {
                            //Out of continues
                            score              = 0;
                            timerMult          = 1.0;
                            timer              = 0.2;
                            betweenGamesOffset = 0.0;
                            lio = contentManager.Load <Texture2D>("Menus/TransitionQuit");
                            MediaPlayer.Stop();
                            continues = 3;

                            //First time getting a game over
                            if (!practiceUnlocked)
                            {
                                practiceIntro    = true;
                                practiceUnlocked = true;
                                introText        = new Hud(new string[] { "You've unlocked practice mode!\nYou can play the games you've lost more frequently.", "Check it out in the menu!" }, cm, 30, 2, posY: -1, canClose: true);
                            }
                            microgame = new TitleScreen(cm, paletteShader, practiceUnlocked);
                        }

                        curPhase  = Phase.Transition;
                        fromGame  = false;
                        beginSong = false;
                    }

                    break;

                case Phase.Paused:
                    resumeButton.Update(mouseX, mouseY);
                    if (!exitConfirm && (Keyboard.GetState().IsKeyUp(Keys.Escape) && prevStateKb.IsKeyDown(Keys.Escape) || resumeButton.IsPressed(prevStateM)))
                    {
                        prevStateM = state;
                        curPhase   = prevPhase;
                        MediaPlayer.Resume();
                    }
                    else
                    {
                        pauseMenu.Update(dt, prevStateKb, prevStateM, mouseX, mouseY);

                        if (!exitConfirm)
                        {
                            switch (pauseMenu.GetSelectionY(prevStateKb, prevStateM, mouseX, mouseY))
                            {
                            case 0:
                                int indX = pauseMenu.GetSelectionX(prevStateKb, prevStateM, mouseX, mouseY);
                                if (indX > 0)
                                {
                                    Console.WriteLine("tryna set color");
                                    SetColor(indX - 1);
                                }
                                break;

                            case 1:
                                if (Mouse.GetState().LeftButton == ButtonState.Released && prevStateM.LeftButton == ButtonState.Pressed ||
                                    Keyboard.GetState().IsKeyUp(Keys.Space) && prevStateKb.IsKeyDown(Keys.Space))
                                {
                                    exitConfirm = true;
                                }
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            //Check for OK, No
                            yesButton.Update(mouseX, mouseY);
                            noButton.Update(mouseX, mouseY);
                            backButton.Update(mouseX, mouseY);

                            if (yesButton.IsPressed(prevStateM) || (prevStateKb.IsKeyDown(Keys.Enter)) && Keyboard.GetState().IsKeyUp(Keys.Enter))
                            {
                                microgame.Unload();
                                cm.Dispose();
                                cm = new ContentManager(contentManager.ServiceProvider);
                                cm.RootDirectory = contentManager.RootDirectory;

                                lio = contentManager.Load <Texture2D>("Menus/TransitionQuit");
                                if (score < 10)
                                {
                                    timer = 1.8;
                                }
                                else
                                {
                                    timer = 1.4;
                                }
                                betweenGamesOffset = 0.0;
                                MediaPlayer.Stop();
                                microgame = new TitleScreen(cm, paletteShader, practiceUnlocked);
                                //microgame = new Battle(cm, mainTarget, graphicsDevice, pp);

                                curPhase  = Phase.Transition;
                                beginSong = false;
                                fromGame  = true;
                            }
                            else if (noButton.IsPressed(prevStateM) || backButton.IsPressed(prevStateM) ||
                                     ((prevStateKb.IsKeyDown(Keys.Escape)) && Keyboard.GetState().IsKeyUp(Keys.Escape)))
                            {
                                exitConfirm = false;
                            }
                        }
                        //pauseMenu.GetSelection(prevStateKb, prevStateM, mouseX, mouseY);
                    }
                    break;
                }
            }

            //microgame.Update(dt, prevStateKb, prevStateM);
            prevStateKb = Keyboard.GetState();
            prevStateM  = Mouse.GetState();
        }