Example #1
0
        public virtual void Update()
        {
            MouseState mouseState    = Mouse.GetState();
            Vector2    mouseLocation = new Vector2(mouseState.X, mouseState.Y);

            // mouse events
            if (mouseState.LeftButton == ButtonState.Pressed && box.ContainsPoint(mouseLocation) && !highlightMode)
            {
                OnMouseClick(mouseState, mouseLocation);
            }
            else if (mouseState.LeftButton == ButtonState.Released)
            {
                highlightMode = false;
                doubleClicked = false;
            }

            if (singleClicked && clickTimer.IsTimeUp())
            {
                singleClicked = false;
            }

            if (highlightMode && cursorChangeTimer.IsTimeUp())
            {
                if (mouseState.X != (int)previousMouseLocation.X)
                {
                    OnMouseDrag(mouseState, mouseLocation);
                }
            }

            // keyboard events
            KeyboardState keyboardState = Keyboard.GetState();

            OnKeyPress(keyboardState);

            // state changes
            if (cursorBlinkTimer.IsTimeUp())
            {
                showCursor = !showCursor;
                cursorBlinkTimer.Reset();
            }
            if (cursorChangeTimer.IsTimeUp())
            {
                keyLocker.UnlockKey(Keys.Left);
                keyLocker.UnlockKey(Keys.Right);
            }
            if (keyboardState.IsKeyUp(Keys.C))
            {
                keyLocker.UnlockKey(Keys.C);
            }
            if (keyboardState.IsKeyUp(Keys.V))
            {
                keyLocker.UnlockKey(Keys.V);
            }

            // text scrolling (if cursor is moved out of view, text needs to scroll)
            UpdateTextScroll();

            previousMouseLocation = new Vector2(mouseState.X, mouseState.Y);
        }
Example #2
0
 protected void UpdateLockedKeys(KeyboardState keyboardState)
 {
     if (keyboardState.IsKeyUp(JUMP_KEY))
     {
         keyLocker.UnlockKey(JUMP_KEY);
     }
 }
        public override void Update(GameTime gameTime)
        {
            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyUp(Keys.Space))
            {
                keyLocker.UnlockKey(Keys.Space);
            }
            if (keyboardState.IsKeyUp(Keys.Escape))
            {
                keyLocker.UnlockKey(Keys.Escape);
            }

            // if space is pressed, reset level. if escape is pressed, go back to main menu
            if (keyboardState.IsKeyDown(Keys.Space))
            {
                playLevelScreen.ResetLevel();
            }
            else if (keyboardState.IsKeyDown(Keys.Escape))
            {
                playLevelScreen.GoBackToMenu();
            }
        }
Example #4
0
        public override void Update(GameTime gameTime)
        {
            //background.update(null);

            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyUp(Keys.Space))
            {
                keyLocker.UnlockKey(Keys.Space);
            }

            // if space is pressed, go back to main menu
            if (!keyLocker.IsKeyLocked(Keys.Space) && keyboardState.IsKeyDown(Keys.Space))
            {
                screenCoordinator.GameState = GameState.MENU;
            }
        }
Example #5
0
        public override void Update(GameTime gameTime)
        {
            //keyTimer.Tick(gameTime.ElapsedGameTime.TotalMilliseconds);

            // update background map (to play tile animations)
            background.Update(null);

            KeyboardState keyboardState = Keyboard.GetState();

            // if down or up is pressed, change menu item "hovered" over (blue square in front of text will move along with currentMenuItemHovered changing)
            if (keyboardState.IsKeyDown(Keys.Down) && keyTimer.IsTimeUp())
            {
                keyTimer.Reset();
                currentMenuItemHovered++;
            }
            else if (keyboardState.IsKeyDown(Keys.Up) && keyTimer.IsTimeUp())
            {
                keyTimer.Reset();
                currentMenuItemHovered--;
            }

            // if down is pressed on last menu item or up is pressed on first menu item, "loop" the selection back around to the beginning/end
            if (currentMenuItemHovered > 2)
            {
                currentMenuItemHovered = 0;
            }
            else if (currentMenuItemHovered < 0)
            {
                currentMenuItemHovered = 2;
            }

            // sets location for blue square in front of text (pointerLocation) and also sets color of spritefont text based on which menu item is being hovered
            if (currentMenuItemHovered == 0)
            {
                playGameText.Color = new Color(255, 215, 0);
                creditsText.Color  = new Color(49, 207, 240);
                settingsText.Color = new Color(49, 207, 240);
                pointerLocationX   = 170;
                pointerLocationY   = 155;
            }
            else if (currentMenuItemHovered == 1)
            {
                playGameText.Color = new Color(49, 207, 240);
                creditsText.Color  = new Color(255, 215, 0);
                settingsText.Color = new Color(49, 207, 240);
                pointerLocationX   = 170;
                pointerLocationY   = 255;
            }
            else if (currentMenuItemHovered == 2)
            {
                playGameText.Color = new Color(49, 207, 240);
                creditsText.Color  = new Color(49, 207, 240);
                settingsText.Color = new Color(255, 215, 0);
                pointerLocationX   = 170;
                pointerLocationY   = 355;
            }

            // if space is pressed on menu item, change to appropriate screen based on which menu item was chosen
            if (keyboardState.IsKeyUp(Keys.Space))
            {
                keyLocker.UnlockKey(Keys.Space);
            }
            if (!keyLocker.IsKeyLocked(Keys.Space) && keyboardState.IsKeyDown(Keys.Space))
            {
                menuItemSelected = currentMenuItemHovered;
                if (menuItemSelected == 0)
                {
                    screenCoordinator.GameState = GameState.LEVEL;
                }
                else if (menuItemSelected == 1)
                {
                    screenCoordinator.GameState = GameState.CREDITS;
                }
                else if (menuItemSelected == 2)
                {
                    screenCoordinator.GameState = GameState.SETTINGS;
                }
            }
        }