Ejemplo n.º 1
0
        public Game()
        {
            this.InitializeComponent();
            snake        = new Snake(Colors.DarkOrange, Colors.Black);
            currentColor = Colors.DarkOrange;
            //Add method to keydown event
            Window.Current.CoreWindow.KeyDown += Canvas_KeyDown;
            cantChangeDirection    = false; //prevents key down event from firing off twice
            turningLeft            = false;
            turningRight           = false;
            turningDown            = false;
            turningUp              = false;
            gameOver               = false;
            gameIsRunning          = false;
            canTurn                = true; //Serves different purpose than cantChangeDirection
            startPageDisplaying    = false;
            settingsPageDisplaying = false;
            IsColorColumn          = true;
            howToPlayDisplaying    = false;
            loading                = true;
            credits                = false;
            changeToDuckTales      = false;
            changeToOneMoreLine    = false;
            changeToGTO            = false;
            dpadDownIsPressed      = false;
            dpadUpIsPressed        = false;
            scoreScreen            = false;
            resetTheGame           = false;


            /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
            gameOverCounter            = 0;
            turnCounter                = 0;
            thankYouSoundEffectCounter = 0;
            delayForDPad               = 0;

            //Set width and height of window
            ApplicationView.PreferredLaunchViewSize      = new Size(600, 400);
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;

            //Start background music
            //Source: https://www.youtube.com/watch?v=2UuHesrJROw
            duckTalesSongPlayer             = new MediaPlayer();
            duckTalesSongPlayer.Source      = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/duck_tales_music.wav"));
            duckTalesSongPlayer.Volume      = 0.06;
            duckTalesSongPlayer.MediaEnded += resetDuckTalesSong;
            duckTalesSongPlayer.Play();
            backgroundMusic = duckTalesSongPlayer;

            //Source: https://www.youtube.com/watch?v=Uc6vF1PWdFY
            GTOSongPlayer             = new MediaPlayer();
            GTOSongPlayer.Source      = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/gto_theme.wav"));
            GTOSongPlayer.Volume      = 0.06;
            GTOSongPlayer.MediaEnded += resetGTOSong;

            //Source: https://www.youtube.com/watch?v=lYldC9K3hrg
            OneMoreLineSongPlayer             = new MediaPlayer();
            OneMoreLineSongPlayer.Source      = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/one_more_line_song.wav"));
            OneMoreLineSongPlayer.Volume      = 0.06;
            OneMoreLineSongPlayer.MediaEnded += resetOneMoreLineSong;

            //Gameover sound effect
            //Source: https://themushroomkingdom.net/media/sm64/wav
            gameoverSoundEffect        = new MediaPlayer();
            gameoverSoundEffect.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/sm64_mario_game_over.wav"));

            //Thank you sound effect
            //Source: https://themushroomkingdom.net/media/sm64/wav
            thankYouSoundEffect        = new MediaPlayer();
            thankYouSoundEffect.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/sm64_mario_thank_you.wav"));

            //I Got It Sound Effect
            //Source: http://www.realmofdarkness.net/sb/category/mp/mp3/
            iGotItSoundEffect        = new MediaPlayer();
            iGotItSoundEffect.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/i_got_it.wav"));

            menuSelector          = new menuSelector();
            menuSelector_Settings = new menuSelector_Settings();
        }
Ejemplo n.º 2
0
        private void gameControllerLogic_StartMenu_SettingsMenu()
        {
            bool startedAtStartPage = startPageDisplaying;

            if (Gamepad.Gamepads.Count > 0)
            {
                controller = Gamepad.Gamepads.First();
                GamepadReading reading = controller.GetCurrentReading();

                if (startPageDisplaying)
                {
                    if (reading.Buttons.HasFlag(GamepadButtons.DPadDown) && !dpadDownIsPressed)
                    {
                        menuSelector.moveDown();
                        dpadDownIsPressed = true;
                    }

                    else if (!reading.Buttons.HasFlag(GamepadButtons.DPadDown) && dpadDownIsPressed)
                    {
                        dpadDownIsPressed = false;
                    }

                    if (reading.Buttons.HasFlag(GamepadButtons.DPadUp) && !dpadUpIsPressed)
                    {
                        menuSelector.moveUp();
                        dpadUpIsPressed = true;
                    }

                    else if (!reading.Buttons.HasFlag(GamepadButtons.DPadUp) && dpadUpIsPressed)
                    {
                        dpadUpIsPressed = false;
                    }


                    if (reading.Buttons.HasFlag(GamepadButtons.A))
                    {
                        if (menuSelector.selection == startPageSelection.Play)
                        {
                            startPageDisplaying = false;
                            gameIsRunning       = true;
                        }

                        else if (menuSelector.selection == startPageSelection.Settings)
                        {
                            startPageDisplaying    = false;
                            settingsPageDisplaying = true;
                        }

                        else if (menuSelector.selection == startPageSelection.HowToPlay)
                        {
                            startPageDisplaying = false;
                            howToPlayDisplaying = true;
                        }

                        else if (menuSelector.selection == startPageSelection.Credits)
                        {
                            startPageDisplaying = false;
                            credits             = true;
                            thankYouSoundEffect.Play();
                        }
                    }
                }

                if (settingsPageDisplaying)
                {
                    if (reading.Buttons.HasFlag(GamepadButtons.DPadUp) && IsColorColumn && !dpadUpIsPressed)
                    {
                        menuSelector_Settings.moveUp_Color();
                        dpadUpIsPressed = true;
                    }

                    else if (!reading.Buttons.HasFlag(GamepadButtons.DPadUp) && IsColorColumn && dpadUpIsPressed)
                    {
                        dpadUpIsPressed = false;
                    }

                    if (reading.Buttons.HasFlag(GamepadButtons.DPadDown) && IsColorColumn && !dpadDownIsPressed)
                    {
                        menuSelector_Settings.moveDown_Color();
                        dpadDownIsPressed = true;
                    }

                    else if (!reading.Buttons.HasFlag(GamepadButtons.DPadDown) && IsColorColumn && dpadDownIsPressed)
                    {
                        dpadDownIsPressed = false;
                    }

                    if (reading.Buttons.HasFlag(GamepadButtons.DPadRight) && IsColorColumn)
                    {
                        IsColorColumn = false;
                    }

                    if (reading.Buttons.HasFlag(GamepadButtons.DPadLeft) && !IsColorColumn)
                    {
                        IsColorColumn = true;
                    }

                    if (reading.Buttons.HasFlag(GamepadButtons.DPadUp) && !IsColorColumn && !dpadUpIsPressed)
                    {
                        menuSelector_Settings.moveUp_Music();
                        dpadUpIsPressed = true;
                    }

                    else if (!reading.Buttons.HasFlag(GamepadButtons.DPadUp) && !IsColorColumn && dpadUpIsPressed)
                    {
                        dpadUpIsPressed = false;
                    }

                    if (reading.Buttons.HasFlag(GamepadButtons.DPadDown) && !IsColorColumn && !dpadDownIsPressed)
                    {
                        menuSelector_Settings.moveDown_Music();
                        dpadDownIsPressed = true;
                    }

                    else if (!reading.Buttons.HasFlag(GamepadButtons.DPadDown) && !IsColorColumn && dpadDownIsPressed)
                    {
                        dpadDownIsPressed = false;
                    }
                }
                //Go to start menu from how to play menu
                if (!startedAtStartPage && howToPlayDisplaying && reading.Buttons.HasFlag(GamepadButtons.X))
                {
                    howToPlayDisplaying = false;
                    startPageDisplaying = true;
                    menuSelector        = new menuSelector();
                }

                //Go back to start menu from credits
                if (!startedAtStartPage && credits && reading.Buttons.HasFlag(GamepadButtons.X))
                {
                    credits             = false;
                    startPageDisplaying = true;
                    menuSelector        = new menuSelector();
                }

                //Go back to start menu from settings page
                if (!startedAtStartPage && settingsPageDisplaying && reading.Buttons.HasFlag(GamepadButtons.X))
                {
                    if (menuSelector_Settings.selection_color == ColorSelection.DarkOrange)
                    {
                        currentColor = Colors.DarkOrange;
                    }
                    else if (menuSelector_Settings.selection_color == ColorSelection.Cyan)
                    {
                        currentColor = Colors.Cyan;
                    }
                    else if (menuSelector_Settings.selection_color == ColorSelection.Green)
                    {
                        currentColor = Colors.Green;
                    }
                    else if (menuSelector_Settings.selection_color == ColorSelection.HotPink)
                    {
                        currentColor = Colors.HotPink;
                    }
                    snake.resetGame(currentColor);


                    // Menu

                    if (menuSelector_Settings.selection_music == MusicSelection.Song1)
                    {
                        changeToDuckTales = true;
                    }
                    else if (menuSelector_Settings.selection_music == MusicSelection.Song2)
                    {
                        // One more line
                        changeToOneMoreLine = true;
                    }
                    else if (menuSelector_Settings.selection_music == MusicSelection.Song3)
                    {
                        // GTO theme
                        // source   https://www.youtube.com/watch?v=Uc6vF1PWdFY
                        changeToGTO = true;
                    }
                    settingsPageDisplaying = false;
                    startPageDisplaying    = true;
                    menuSelector           = new menuSelector();
                }
            }
        }
Ejemplo n.º 3
0
        //Runs when key is pressed down.
        private void Canvas_KeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs e)
        {
            bool startedAtStartPage = startPageDisplaying;

            //When game is running
            //Left key is pressed when the user was not already going left or right
            if (e.VirtualKey == Windows.System.VirtualKey.Left && !snake.snakeHead.goingRight && !snake.snakeHead.goingLeft &&
                !cantChangeDirection && gameIsRunning && canTurn)
            {
                cantChangeDirection = true;
                turningLeft         = true;
                canTurn             = false;
                cantChangeDirection = false;
            }

            //Right key is pressed when we are not going right or left
            else if (e.VirtualKey == Windows.System.VirtualKey.Right && !snake.snakeHead.goingLeft && !snake.snakeHead.goingRight &&
                     !cantChangeDirection && gameIsRunning && canTurn)
            {
                cantChangeDirection = true;
                turningRight        = true;
                canTurn             = false;
                cantChangeDirection = false;
            }

            //Down key is pressed when we are not going up or down
            else if (e.VirtualKey == Windows.System.VirtualKey.Down && !snake.snakeHead.goingUp && !snake.snakeHead.goingDown &&
                     !cantChangeDirection && gameIsRunning && canTurn)
            {
                cantChangeDirection = true;
                turningDown         = true;
                canTurn             = false;
                cantChangeDirection = false;
            }

            //Up key is pressed when we are not going up or down
            else if (e.VirtualKey == Windows.System.VirtualKey.Up && !snake.snakeHead.goingDown && !snake.snakeHead.goingUp &&
                     !cantChangeDirection && gameIsRunning && canTurn)
            {
                cantChangeDirection = true;
                turningUp           = true;
                canTurn             = false;
                cantChangeDirection = false;
            }

            if (startPageDisplaying)
            {
                if (e.VirtualKey == Windows.System.VirtualKey.Up)
                {
                    menuSelector.moveUp();
                }

                else if (e.VirtualKey == Windows.System.VirtualKey.Down)
                {
                    menuSelector.moveDown();
                }

                if (e.VirtualKey == Windows.System.VirtualKey.Enter)
                {
                    if (menuSelector.selection == startPageSelection.Play)
                    {
                        startPageDisplaying = false;
                        gameIsRunning       = true;
                    }

                    else if (menuSelector.selection == startPageSelection.Settings)
                    {
                        startPageDisplaying    = false;
                        settingsPageDisplaying = true;
                    }

                    else if (menuSelector.selection == startPageSelection.HowToPlay)
                    {
                        startPageDisplaying = false;
                        howToPlayDisplaying = true;
                    }

                    else if (menuSelector.selection == startPageSelection.Credits)
                    {
                        startPageDisplaying = false;
                        credits             = true;
                        thankYouSoundEffect.Play();
                    }
                }
            }
            // Peter's Part
            if (settingsPageDisplaying)
            {
                if (e.VirtualKey == Windows.System.VirtualKey.Up && IsColorColumn)
                {
                    menuSelector_Settings.moveUp_Color();
                }

                else if (e.VirtualKey == Windows.System.VirtualKey.Down && IsColorColumn)
                {
                    menuSelector_Settings.moveDown_Color();
                }
                else if (e.VirtualKey == Windows.System.VirtualKey.Right && IsColorColumn)
                {
                    IsColorColumn = false;
                }
                else if (e.VirtualKey == Windows.System.VirtualKey.Left && !IsColorColumn)
                {
                    IsColorColumn = true;
                }
                else if (e.VirtualKey == Windows.System.VirtualKey.Up && !IsColorColumn)
                {
                    menuSelector_Settings.moveUp_Music();
                }
                else if (e.VirtualKey == Windows.System.VirtualKey.Down && !IsColorColumn)
                {
                    menuSelector_Settings.moveDown_Music();
                }
            }

            //Go to start menu from how to play menu
            if (!startedAtStartPage && howToPlayDisplaying && e.VirtualKey == Windows.System.VirtualKey.Enter)
            {
                howToPlayDisplaying = false;
                startPageDisplaying = true;
                menuSelector        = new menuSelector();
            }

            //Go back to start menu from credits
            if (!startedAtStartPage && credits && e.VirtualKey == Windows.System.VirtualKey.Enter)
            {
                credits             = false;
                startPageDisplaying = true;
                menuSelector        = new menuSelector();
            }

            //Go back to start menu from settings page
            if (!startedAtStartPage && settingsPageDisplaying && e.VirtualKey == Windows.System.VirtualKey.Enter)
            {
                if (menuSelector_Settings.selection_color == ColorSelection.DarkOrange)
                {
                    currentColor = Colors.DarkOrange;
                }
                else if (menuSelector_Settings.selection_color == ColorSelection.Cyan)
                {
                    currentColor = Colors.Cyan;
                }
                else if (menuSelector_Settings.selection_color == ColorSelection.Green)
                {
                    currentColor = Colors.Green;
                }
                else if (menuSelector_Settings.selection_color == ColorSelection.HotPink)
                {
                    currentColor = Colors.HotPink;
                }
                snake.resetGame(currentColor);


                // Menu

                if (menuSelector_Settings.selection_music == MusicSelection.Song1)
                {
                    changeToDuckTales = true;
                }
                else if (menuSelector_Settings.selection_music == MusicSelection.Song2)
                {
                    // One more line
                    changeToOneMoreLine = true;
                }
                else if (menuSelector_Settings.selection_music == MusicSelection.Song3)
                {
                    // GTO theme
                    // source   https://www.youtube.com/watch?v=Uc6vF1PWdFY
                    changeToGTO = true;
                }
                settingsPageDisplaying = false;
                startPageDisplaying    = true;
                menuSelector           = new menuSelector();
            }

            if (e.VirtualKey == Windows.System.VirtualKey.Enter && scoreScreen)
            {
                scoreScreen         = false;
                startPageDisplaying = true;
            }
        }