Ejemplo n.º 1
0
        Screen parentScreen; // used to calculate absolute center position

        #endregion Fields

        #region Constructors

        // popup without menu
        public scrPopup(Game game, SpriteBatch spriteBatch, Texture2D backgroundImage, Screen parentScreen, int width = 300, int height = 400)
            : base(game, spriteBatch, backgroundImage)
        {
            this.parentScreen = parentScreen;

            this.backgroundImage = backgroundImage;
            this.backgroundShadow = new ContentManager(game.Services, Settings.Content_Background).Load<Texture2D>("Shadow");

            this.width = width;
            this.height = height;
            MeasureScreen();
        }
Ejemplo n.º 2
0
        // popup with menu
        public scrPopup(Game game, SpriteBatch spriteBatch, Texture2D backgroundImage, Screen parentScreen, string[] menuItems, int width = 300, int height = 400)
            : base(game, spriteBatch, backgroundImage)
        {
            this.parentScreen = parentScreen;

            this.backgroundImage = backgroundImage;
            this.backgroundShadow = new ContentManager(game.Services, Settings.Content_Background).Load<Texture2D>("Shadow");

            this.width = width;
            this.height = height;
            MeasureScreen();

            menu = new Menu(game, this, spriteBatch, spriteFont, menuItems);
            components.Add(menu);
        }
Ejemplo n.º 3
0
        //------------------------------------------------------------------------------------
        public Menu(Game game, Screen activeScreen, SpriteBatch spriteBatch, SpriteFont spriteFont, string[] menuItems)
            : base(game)
        {
            this.parentScreen = activeScreen;
            this.spriteBatch = spriteBatch;
            this.spriteFont = spriteFont;
            this.menuItems = menuItems;

            content = new ContentManager(game.Services, Settings.Content_Background);
            menuSprite = content.Load<Texture2D>("Menu");
            backgroundShadow = content.Load<Texture2D>("Shadow");

            position = Vector2.Zero;
            menuAreas = new Rectangle[menuItems.Length];
            MeasureMenu();
        }
Ejemplo n.º 4
0
        private void CloseGame()
        {
            scrGameOver.Dispose();
            scrPause.Dispose();
            scrPlay.Dispose();

            scrActive = scrStart;
            scrActive.Show();
        }
Ejemplo n.º 5
0
        protected override void Update(GameTime gameTime)
        {
            Rectangle cursor = new Rectangle(mouseState.X, mouseState.Y, 1, 1);

            previousKeyboardState = currentKeyboardState;
            oldMouseState = mouseState;

            currentKeyboardState = Keyboard.GetState();
            mouseState = Mouse.GetState();

            // check if player is in main menu
            if (scrActive == scrStart)
            {
                if (scrInstructions.Enabled)
                {
                    if (UniqueKeyPress(Keys.Escape))
                    {
                        scrActive.Enabled = true;
                        scrInstructions.Hide();
                    }
                }
                else
                {
                    if (UniqueKeyPress(Keys.Enter) || (cursor.Intersects(scrStart.MenuAreas[scrStart.SelectedIndex]) && LeftClicked()))
                    {
                        switch (scrStart.SelectedIndex)
                        {
                            case (int)MENU_OPTIONS.START_GAME:
                                scrActive.Hide();
                                StartGame();
                                scrActive = scrPlay;
                                scrActive.Show();
                                break;

                            case (int)MENU_OPTIONS.INSTRUCTIONS:
                                scrActive.Enabled = false;
                                scrInstructions.Show();
                                break;

                            case (int)MENU_OPTIONS.HIGH_SCORES:
                                frmHighScores.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
                                frmHighScores.UpdateScores(currentAccount.Scores());
                                frmHighScores.ShowDialog();
                                break;

                            case (int)MENU_OPTIONS.EXIT:
                                this.Exit();
                                break;
                        }
                    }
                }
            }

            // check if player is in game screen
            else if (scrActive == scrPlay)
            {
                if (UniqueKeyPress(Keys.Escape) && !scrPlay.GameOver)
                {
                    // quick pause/unpause
                    if (scrPause.Enabled)
                    {
                        UnPause();
                    }
                    else
                    {
                        Pause();
                    }
                }
                else if (scrPause.Enabled)
                {
                    // choose options in pause menu
                    if (UniqueKeyPress(Keys.Enter) || (cursor.Intersects(scrPause.MenuAreas[scrPause.SelectedIndex]) && LeftClicked()))
                    {
                        switch (scrPause.SelectedIndex)
                        {
                            case (int)PAUSE_OPTIONS.RESUME:
                                UnPause();
                                break;

                            case (int)PAUSE_OPTIONS.LEAVE_GAME:
                                CloseGame();
                                break;
                        }
                    }
                }
                else if (scrPlay.GameOver)
                {
                    // when player has no lifes left
                    scrActive.Enabled = false;
                    scrGameOver.Show();

                    // close game over screen
                    if (UniqueKeyPress(Keys.Enter) || (cursor.Intersects(scrPause.MenuAreas[scrPause.SelectedIndex]) && LeftClicked()))
                    {
                        currentAccount.SaveScore(scrPlay.Score);
                        CloseGame();
                    }
                }
            }

            base.Update(gameTime);
        }
Ejemplo n.º 6
0
        protected override void LoadContent()
        {
            frmHighScores = new frmHighScores();

            spriteBatch = new SpriteBatch(GraphicsDevice);
            spriteFont = Content.Load<SpriteFont>("GameFont");
            spriteFont.LineSpacing = 20;

            scrStart = new Screen_Basic(this, spriteBatch, Content.Load<Texture2D>("Graphics/Backgrounds/Start"), Menu.MenuItems(new MENU_OPTIONS()));
            Components.Add(scrStart);
            scrStart.Hide();

            scrInstructions = new scrPopup(this, spriteBatch, Content.Load<Texture2D>("Graphics/Backgrounds/Instructions"), scrStart, 500, 500);
            Components.Add(scrInstructions);
            scrInstructions.Hide();

            scrActive = scrStart;
            scrActive.Show();
        }