public static bool WasKeyJustPressed(Keys key)
 {
     if (String.IsNullOrWhiteSpace(attachedKeyboardID))
     {
         return(Game1.game1.IsActive && Keyboard.GetState().IsKeyDown(key) && oldAttachedKeyboardState?.IsKeyUp(key) == true);
     }
     else
     {
         return(oldKeyboardStates.TryGetValue(attachedKeyboardID, out KeyboardState oldKeyboardState) && (GetAttachedKeyboardState() ?? new KeyboardState()).IsKeyDown(key) && oldKeyboardState.IsKeyUp(key));
     }
 }
Exemple #2
0
        public static void ProcessInputKeyboard()
        {
            KeyState = Keyboard.GetState();

            if (KeyState.IsKeyDown(Keys.W) == true)
            {
                KeysPressed[Keys.W] = true;
                OnMovedUp(1.0f);
            }
            if (KeyState.IsKeyUp(Keys.W) == true)
            {
                if (KeysPressed[Keys.W] == true)
                {
                    KeysPressed[Keys.W] = false;
                    OnHorizontalReleased();
                }
            }

            if (KeyState.IsKeyDown(Keys.S) == true)
            {
                KeysPressed[Keys.S] = true;
                OnMovedDown(1.0f);
            }
            if (KeyState.IsKeyUp(Keys.S) == true)
            {
                if (KeysPressed[Keys.S] == true)
                {
                    KeysPressed[Keys.S] = false;
                    OnHorizontalReleased();
                }
            }

            if (KeyState.IsKeyDown(Keys.A) == true)
            {
                KeysPressed[Keys.A] = true;
                OnMovedLeft(-1.0f);
            }
            if (KeyState.IsKeyUp(Keys.A) == true)
            {
                if (KeysPressed[Keys.A] == true)
                {
                    KeysPressed[Keys.A] = false;
                    OnVerticalReleased();
                }
            }

            if (KeyState.IsKeyDown(Keys.D) == true)
            {
                KeysPressed[Keys.D] = true;
                OnMovedRight(1.0f);
            }
            if (KeyState.IsKeyUp(Keys.D) == true)
            {
                if (KeysPressed[Keys.D] == true)
                {
                    KeysPressed[Keys.D] = false;
                    OnVerticalReleased();
                }
            }

            if (KeyState.IsKeyDown(Keys.E) == true)
            {
                if (KeysPressed[Keys.E] == false)
                {
                    KeysPressed[Keys.E] = true;
                    OnInteractPressed();
                }
            }
            if (KeyState.IsKeyUp(Keys.E) == true)
            {
                if (KeysPressed[Keys.E] == true)
                {
                    KeysPressed[Keys.E] = false;
                }
            }

            if (KeyState.IsKeyDown(Keys.I) == true)
            {
                if (KeysPressed[Keys.I] == false)
                {
                    KeysPressed[Keys.I] = true;
                    OnInventoryPressed();
                }
            }
            if (KeyState.IsKeyUp(Keys.I) == true)
            {
                if (KeysPressed[Keys.I] == true)
                {
                    KeysPressed[Keys.I] = false;
                }
            }

            if (KeyState.IsKeyDown(Keys.Space) == true)
            {
                if (KeysPressed[Keys.Space] == false)
                {
                    KeysPressed[Keys.Space] = true;
                    OnJumpPressed();
                }
            }
            if (KeyState.IsKeyUp(Keys.Space) == true)
            {
                if (KeysPressed[Keys.Space] == true)
                {
                    KeysPressed[Keys.Space] = false;
                }
            }

            if (KeyState.IsKeyDown(Keys.LeftShift) == true)
            {
                if (KeysPressed[Keys.LeftShift] == false)
                {
                    KeysPressed[Keys.LeftShift] = true;
                    OnRunPressed();
                }
            }
            if (KeyState.IsKeyUp(Keys.LeftShift) == true)
            {
                if (KeysPressed[Keys.LeftShift] == true)
                {
                    KeysPressed[Keys.LeftShift] = false;
                    OnRunReleased();
                }
            }
        }
Exemple #3
0
 public bool getInputRelease(Keys key)
 {
     return(_keyStatePrevious.IsKeyDown(key) && _keyStateCurrent.IsKeyUp(key));
 }
Exemple #4
0
 public static bool KeyUp(Keys key)
 {
     return(keystateNew.IsKeyUp(key));
 }
Exemple #5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            const string mark = "Update";

            try
            {
                base.Update(gameTime);

                //We must call StartFrame at the top of Update to indicate to the Profiler that a new frame has started.
                GS.StartFrame();
                GS.BeginMark(mark, FlatTheme.PeterRiver);

                _previousKeyboardState = _keyboardState;
                _keyboardState         = Keyboard.GetState();

                // Allows the game to exit
                                #if WINDOWS
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    Exit();
                    return;
                }
                                #endif

                if (_keyboardState.IsKeyUp(Keys.Escape) && _previousKeyboardState.IsKeyDown(Keys.Escape))
                {
                    Exit();
                    return;
                }

                #if USE_GEARSET
                //Test for CPU / GPU bound
                if (GS.GearsetComponent.Console.Profiler.DoUpdate() == false)
                {
                    return;
                }
                #endif

                //PLOT test
                GS.Plot("FPS", _fpsCounter.Fps);
//                GS.Plot("Tick Memory K", _memoryMonitor.TickMemoryK);

                var mouseState = Mouse.GetState();
                var mousePos2  = new Vector2(mouseState.X, mouseState.Y);
                var mousePos3  = new Vector3(mousePos2, 0);

                //Label test
                GS.ShowLabel("I follow the mouse pointer!", mousePos2);

                //Line Test
                //Draw a line but then use the same key to reference it a second time and alter the postion / color
//                GS.ShowLine("TestLine", new Vector2(mouseState.X, mouseState.Y + 20), new Vector2(mouseState.X + 200, mouseState.Y + 20), Color.Green);
//                GS.ShowLine("TestLine", new Vector2(mouseState.X, mouseState.Y - 20), new Vector2(mouseState.X + 200, mouseState.Y - 20), Color.Violet);
                //Other lines...
                GS.ShowLineOnce(new Vector2(mouseState.X, mouseState.Y + 25), new Vector2(mouseState.X + 200, mouseState.Y + 25), Color.Pink);
                GS.ShowLineOnce(new Vector2(mouseState.X, mouseState.Y + 35), new Vector2(mouseState.X + 200, mouseState.Y + 35), Color.Red);

                //ALERT test - press SPACE for an alert message!
                if (_keyboardState.IsKeyUp(Keys.Space) && _previousKeyboardState.IsKeyDown(Keys.Space))
                {
                    GS.Alert("I am an alert message");
                }

                Thread.Sleep(1);//Let's trick the update into taking some time so that we can see some profile info

                //Update Gearset matrixes for 3d geometry
                GS.SetMatrices(ref _worldMatrix, ref _viewMatrix, ref _projectionMatrix);

                //Geometry tests...
//                GS.ShowSphere("TestSphere", mousePos3, 50, Color.Azure);
                GS.ShowSphereOnce(mousePos3, 50, Color.Azure);
//                GS.ShowBox("TestBox", new Vector3(mouseState.X + 50, mouseState.Y + 50, 0), new Vector3(mouseState.X + 100, mouseState.Y + 100, 0), Color.Blue);
                GS.ShowBoxOnce(new Vector3(mouseState.X + 100, mouseState.Y + 100, 0), new Vector3(mouseState.X + 150, mouseState.Y + 150, 0), Color.Red);
            }
            finally
            {
                //Must call EndMark
                GS.EndMark(mark);
            }
        }
Exemple #6
0
        public void Update(GameTime gametime)
        {
            base.Update(gametime);
            RAM.camera.SetPosition(new Vector2(640 - GetPosition().X, 360 - GetPosition().Y));
            float         a             = 640 - GetPosition().X;
            float         b             = 360 - GetPosition().Y;
            KeyboardState keyboardState = Keyboard.GetState();

            if (RAM.OnFoot == true)
            {
                if (time.GetTimeFlag() == true)
                {
                    if (keyboardState.IsKeyDown(Keys.Up) &&
                        keyboardState.IsKeyDown(Keys.Left))
                    {
                        if (RAM.MapArea.MoveOnFoot((int)GetPosition().X - (RAM.TILESIZE / 8), (int)GetPosition().Y - (RAM.TILESIZE / 8)) == true)
                        {
                            SetPosition(new Vector2(GetPosition().X - (RAM.TILESIZE / 8), GetPosition().Y - (RAM.TILESIZE / 8)));
                            RAM.camera.TextBoxPos = new Vector2(RAM.camera.TextBoxPos.X - (RAM.TILESIZE / 8), RAM.camera.GetTextBoxPosition().Y - (RAM.TILESIZE / 8));
                        }
                    }
                    else if (keyboardState.IsKeyDown(Keys.Up) &&
                             keyboardState.IsKeyDown(Keys.Right))
                    {
                        if (RAM.MapArea.MoveOnFoot((int)GetPosition().X + (RAM.TILESIZE / 8), (int)GetPosition().Y - (RAM.TILESIZE / 8)) == true)
                        {
                            SetPosition(new Vector2(GetPosition().X + (RAM.TILESIZE / 8), GetPosition().Y - (RAM.TILESIZE / 8)));
                            RAM.camera.TextBoxPos = new Vector2(RAM.camera.TextBoxPos.X + (RAM.TILESIZE / 8), RAM.camera.GetTextBoxPosition().Y - (RAM.TILESIZE / 8));
                        }
                    }
                    else if (keyboardState.IsKeyDown(Keys.Down) &&
                             keyboardState.IsKeyDown(Keys.Left))
                    {
                        if (RAM.MapArea.MoveOnFoot((int)GetPosition().X - (RAM.TILESIZE / 8), (int)GetPosition().Y + (RAM.TILESIZE / 8)) == true)
                        {
                            SetPosition(new Vector2(GetPosition().X - (RAM.TILESIZE / 8), GetPosition().Y + (RAM.TILESIZE / 8)));
                            RAM.camera.TextBoxPos = new Vector2(RAM.camera.TextBoxPos.X - (RAM.TILESIZE / 8), RAM.camera.GetTextBoxPosition().Y + (RAM.TILESIZE / 8));
                        }
                    }
                    else if (keyboardState.IsKeyDown(Keys.Down) &&
                             keyboardState.IsKeyDown(Keys.Right))
                    {
                        if (RAM.MapArea.MoveOnFoot((int)GetPosition().X + (RAM.TILESIZE / 8), (int)GetPosition().Y + (RAM.TILESIZE / 8)) == true)
                        {
                            SetPosition(new Vector2(GetPosition().X + (RAM.TILESIZE / 8), GetPosition().Y + (RAM.TILESIZE / 8)));
                            RAM.camera.TextBoxPos = new Vector2(RAM.camera.TextBoxPos.X + (RAM.TILESIZE / 8), RAM.camera.GetTextBoxPosition().Y + (RAM.TILESIZE / 8));
                        }
                    }
                    else if (keyboardState.IsKeyDown(Keys.Up))
                    {
                        if (RAM.MapArea.MoveOnFoot((int)GetPosition().X, (int)GetPosition().Y - (RAM.TILESIZE / 8)) == true)
                        {
                            SetPositionY(GetPosition().Y - (RAM.TILESIZE / 8));
                            RAM.camera.TextBoxPos = new Vector2(RAM.camera.TextBoxPos.X, RAM.camera.GetTextBoxPosition().Y - (RAM.TILESIZE / 8));
                        }
                    }
                    else if (keyboardState.IsKeyDown(Keys.Down))
                    {
                        if (RAM.MapArea.MoveOnFoot((int)GetPosition().X, (int)GetPosition().Y + (RAM.TILESIZE / 8)) == true)
                        {
                            SetPositionY(GetPosition().Y + (RAM.TILESIZE / 8));
                            RAM.camera.TextBoxPos = new Vector2(RAM.camera.TextBoxPos.X, RAM.camera.GetTextBoxPosition().Y + (RAM.TILESIZE / 8));
                        }
                    }
                    else if (keyboardState.IsKeyDown(Keys.Left))
                    {
                        if (RAM.MapArea.MoveOnFoot((int)GetPosition().X - (RAM.TILESIZE / 8), (int)GetPosition().Y) == true)
                        {
                            SetPositionX(GetPosition().X - (RAM.TILESIZE / 8));
                            RAM.camera.TextBoxPos = new Vector2(RAM.camera.GetTextBoxPosition().X - (RAM.TILESIZE / 8), RAM.camera.TextBoxPos.Y);
                        }
                    }
                    else if (keyboardState.IsKeyDown(Keys.Right))
                    {
                        if (RAM.MapArea.MoveOnFoot((int)GetPosition().X + (RAM.TILESIZE / 8), (int)GetPosition().Y) == true)
                        {
                            SetPositionX(GetPosition().X + (RAM.TILESIZE / 8));
                            RAM.camera.TextBoxPos = new Vector2(RAM.camera.GetTextBoxPosition().X + (RAM.TILESIZE / 8), RAM.camera.TextBoxPos.Y);
                        }
                    }
                    CheckOnBoat();
                }

                if (keyboardState.IsKeyUp(Keys.Up) &&
                    keyboardState.IsKeyUp(Keys.Down) &&
                    keyboardState.IsKeyUp(Keys.Left) &&
                    keyboardState.IsKeyUp(Keys.Right))
                {
                    switch (GetLookDirection())
                    {
                    case (int)Looking.kUp:
                    {
                        SetCurrentAnimation(WalkBackwardAnimation);
                        break;
                    }

                    case (int)Looking.kDown:
                    {
                        SetCurrentAnimation(WalkForwardAnimation);
                        break;
                    }

                    case (int)Looking.kLeft:
                    {
                        SetCurrentAnimation(WalkLeftAnimation);
                        break;
                    }

                    case (int)Looking.kRight:
                    {
                        SetCurrentAnimation(WalkRightAnimation);
                        break;
                    }

                    case (int)Looking.kUpLeft:
                    {
                        SetCurrentAnimation(WalkUpLeftAnimation);
                        break;
                    }

                    case (int)Looking.kUpRight:
                    {
                        SetCurrentAnimation(WalkUpRightAnimation);
                        break;
                    }

                    case (int)Looking.kDownLeft:
                    {
                        SetCurrentAnimation(WalkDownLeftAnimation);
                        break;
                    }

                    case (int)Looking.kDownRight:
                    {
                        SetCurrentAnimation(WalkDownRightAnimation);
                        break;
                    }
                    }
                }
                else if (keyboardState.IsKeyDown(Keys.Up) &&
                         keyboardState.IsKeyDown(Keys.Left))
                {
                    SetLookDirection((int)Looking.kUpLeft);
                    SetCurrentAnimation(WalkUpLeftAnimation);
                }
                else if (keyboardState.IsKeyDown(Keys.Up) &&
                         keyboardState.IsKeyDown(Keys.Right))
                {
                    SetLookDirection((int)Looking.kUpRight);
                    SetCurrentAnimation(WalkUpRightAnimation);
                }
                else if (keyboardState.IsKeyDown(Keys.Down) &&
                         keyboardState.IsKeyDown(Keys.Left))
                {
                    SetLookDirection((int)Looking.kDownLeft);
                    SetCurrentAnimation(WalkDownLeftAnimation);
                }
                else if (keyboardState.IsKeyDown(Keys.Down) &&
                         keyboardState.IsKeyDown(Keys.Right))
                {
                    SetLookDirection((int)Looking.kDownRight);
                    SetCurrentAnimation(WalkDownRightAnimation);
                }
                else if (keyboardState.IsKeyDown(Keys.Up))
                {
                    SetLookDirection((int)Looking.kUp);
                    SetCurrentAnimation(WalkBackwardAnimation);
                }
                else if (keyboardState.IsKeyDown(Keys.Down))
                {
                    SetLookDirection((int)Looking.kDown);
                    SetCurrentAnimation(WalkForwardAnimation);
                }
                else if (keyboardState.IsKeyDown(Keys.Left))
                {
                    SetLookDirection((int)Looking.kLeft);
                    SetCurrentAnimation(WalkLeftAnimation);
                }
                else if (keyboardState.IsKeyDown(Keys.Right))
                {
                    SetLookDirection((int)Looking.kRight);
                    SetCurrentAnimation(WalkRightAnimation);
                }
            }
        }
Exemple #7
0
        public void Update(GameTime gametime)
        {
            KeyboardState keyboardState = Keyboard.GetState();

            if (GetLayerLevel() == RAM.VRAM.LayerLevel)
            {
                foreach (BaseEnitiy obj in RAM.VRAM.ObjectList[RAM.VRAM.LayerLevel])
                {
                    if (obj is AvatarSprite)
                    {
                        if (keyboardState.IsKeyDown(Keys.Space))
                        {
                            if (GetRec().GetInteractiveRectangle().Intersects(obj.GetRec().GetCollisionRectangle()))
                            {
                                if (((AvatarSprite)obj).GetLookDirection() == (int)Looking.kUp)
                                {
                                    SetLookDirection((int)Looking.kDown);
                                }
                                else if (((AvatarSprite)obj).GetLookDirection() == (int)Looking.kDown)
                                {
                                    SetLookDirection((int)Looking.kUp);
                                }
                                else if (((AvatarSprite)obj).GetLookDirection() == (int)Looking.kRight)
                                {
                                    SetLookDirection((int)Looking.kLeft);
                                }
                                else if (((AvatarSprite)obj).GetLookDirection() == (int)Looking.kLeft)
                                {
                                    SetLookDirection((int)Looking.kRight);
                                }
                                if (RAM.TalkFlag == false)
                                {
                                    RAM.Storytext.AddText("Load Files/TextFile1dfd.txt");
                                }
                                RAM.TalkFlag = true;
                            }
                        }
                    }
                }
                if (keyboardState.IsKeyUp(Keys.Up) &&
                    keyboardState.IsKeyUp(Keys.Down) &&
                    keyboardState.IsKeyUp(Keys.Left) &&
                    keyboardState.IsKeyUp(Keys.Right))
                {
                    switch (GetLookDirection())
                    {
                    case (int)Looking.kUp:
                    {
                        SetCurrentAnimation(ForwardStandAnimation);
                        break;
                    }

                    case (int)Looking.kDown:
                    {
                        SetCurrentAnimation(BackwardStandAnimation);
                        break;
                    }

                    case (int)Looking.kLeft:
                    {
                        SetCurrentAnimation(LeftStandAnimation);
                        break;
                    }

                    case (int)Looking.kRight:
                    {
                        SetCurrentAnimation(RightStandAnimation);
                        break;
                    }

                    case (int)Looking.kUpLeft:
                    {
                        SetCurrentAnimation(ForwardStandAnimation);
                        break;
                    }

                    case (int)Looking.kUpRight:
                    {
                        SetCurrentAnimation(ForwardStandAnimation);
                        break;
                    }

                    case (int)Looking.kDownLeft:
                    {
                        SetCurrentAnimation(BackwardStandAnimation);
                        break;
                    }

                    case (int)Looking.kDownRight:
                    {
                        SetCurrentAnimation(BackwardStandAnimation);
                        break;
                    }
                    }
                }
            }
        }
 public static bool Pressed(Keys key)
 {
     return(_state.IsKeyDown(key) && ((_lastState == null) || _lastState.IsKeyUp(key)));
 }
        public void Update()
        {
            // Left Arrow - move left, change mario to appropriate left moving sprite
            // Right Arrow - move right, change mario to appropriate right moving sprite
            // Down Arrow - change mario to appropriate crouching state, if possible
            // Up Arrow - climb vine
            // Z Key - run, throw fireball if fire mario
            // X Key - jump, change mario to appropriate jumping state

            bool foundInput = false;

            keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Enter) && !startPressed)
            {
                startPressed = true;
                new StartButtonCommand().Execute();
            }
            else if (keyboardState.IsKeyUp(Keys.Enter) && startPressed)
            {
                startPressed = false;
            }
            if (playableObject.IsEnteringPipe || playableObject.IsExitingPipe)
            {
                new MarioNoInputCommand(playableObject).Execute();
            }

            else
            {
                if (keyboardState.IsKeyDown(Keys.X) && !jumpPressed)
                {
                    jumpPressed = true;
                    new MarioJumpCommand(playableObject).Execute();
                    foundInput = true;
                }
                else if (keyboardState.IsKeyDown(Keys.X))
                {
                    foundInput = true;
                }
                else if (keyboardState.IsKeyUp(Keys.X) && jumpPressed)
                {
                    jumpPressed = false;
                }

                if (keyboardState.IsKeyDown(Keys.Z))
                {
                    playableObject.MaxHorizontalVelocity = GameValues.MarioRunningSpeed;
                    new MarioRunCommand(playableObject).Execute();
                }
                else
                {
                    playableObject.MaxHorizontalVelocity = GameValues.MarioWalkingSpeed;
                }

                Keys[] keysPressed = keyboardState.GetPressedKeys();

                for (int i = 0; i < keysPressed.Length; i++)
                {
                    if (keyMap.ContainsKey(keysPressed[i]))
                    {
                        keyMap[keysPressed[i]].Execute();
                        foundInput = true;
                    }
                }

                if (keyboardState.IsKeyDown(Keys.Down))
                {
                    new MarioCrouchCommand(playableObject).Execute();
                    foundInput = true;
                }

                if (!foundInput)
                {
                    new MarioNoInputCommand(playableObject).Execute();
                }
            }
        }
Exemple #10
0
        public static string getKeysPressed()
        {
            string pressedKeys = "";
            string keyString   = "";

            Keys[] press = keys.GetPressedKeys(), oldPress = oldKeys.GetPressedKeys();

            for (int i = 0; i < keys.GetPressedKeys().Length; i++)
            {
                bool foundCharacter = false;

                for (int j = 0; j < oldKeys.GetPressedKeys().Length; j++)
                {
                    if (oldPress != null)
                    {
                        if (press[i] == oldPress[j])
                        {
                            foundCharacter = true;
                            break;
                        }
                    }
                }
                if (foundCharacter == false)
                {
                    switch (press[i])
                    {
                    case Keys.D0:
                        keyString = "0";
                        break;

                    case Keys.D1:
                        keyString = "1";
                        break;

                    case Keys.D2:
                        keyString = "2";
                        break;

                    case Keys.D3:
                        keyString = "3";
                        break;

                    case Keys.D4:
                        keyString = "4";
                        break;

                    case Keys.D5:
                        keyString = "5";
                        break;

                    case Keys.D6:
                        keyString = "6";
                        break;

                    case Keys.D7:
                        keyString = "7";
                        break;

                    case Keys.D8:
                        keyString = "8";
                        break;

                    case Keys.D9:
                        keyString = "9";
                        break;

                    case Keys.A:
                        keyString = "A";
                        break;

                    case Keys.B:
                        keyString = "B";
                        break;

                    case Keys.C:
                        keyString = "C";
                        break;

                    case Keys.D:
                        keyString = "D";
                        break;

                    case Keys.E:
                        keyString = "E";
                        break;

                    case Keys.F:
                        keyString = "F";
                        break;

                    case Keys.G:
                        keyString = "G";
                        break;

                    case Keys.H:
                        keyString = "H";
                        break;

                    case Keys.I:
                        keyString = "I";
                        break;

                    case Keys.J:
                        keyString = "J";
                        break;

                    case Keys.K:
                        keyString = "K";
                        break;

                    case Keys.L:
                        keyString = "L";
                        break;

                    case Keys.M:
                        keyString = "M";
                        break;

                    case Keys.N:
                        keyString = "N";
                        break;

                    case Keys.O:
                        keyString = "O";
                        break;

                    case Keys.P:
                        keyString = "P";
                        break;

                    case Keys.Q:
                        keyString = "Q";
                        break;

                    case Keys.R:
                        keyString = "R";
                        break;

                    case Keys.S:
                        keyString = "S";
                        break;

                    case Keys.T:
                        keyString = "T";
                        break;

                    case Keys.U:
                        keyString = "U";
                        break;

                    case Keys.W:
                        keyString = "W";
                        break;

                    case Keys.V:
                        keyString = "V";
                        break;

                    case Keys.X:
                        keyString = "X";
                        break;

                    case Keys.Y:
                        keyString = "Y";
                        break;

                    case Keys.Z:
                        keyString = "Z";
                        break;

                    case Keys.Space:
                        keyString = " ";
                        break;

                    case Keys.OemComma:
                        keyString = ",";
                        break;

                    case Keys.OemPeriod:
                        keyString = ".";
                        break;
                    }
                    if (keys.IsKeyUp(Keys.LeftShift) && keys.IsKeyUp(Keys.RightShift))
                    {
                        keyString = keyString.ToLower();
                    }
                }
            }

            pressedKeys = keyString;


            return(pressedKeys);
        }
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }
            bool pausedNow = false;

            if (state == GameState.Playing)
            {
                if (state != GameState.Pause && lastState.IsKeyUp(Keys.P) && Keyboard.GetState().IsKeyDown(Keys.P))
                {
                    lastGameState = state;
                    state         = GameState.Pause;
                    pausedNow     = true;
                }
                player.CheckIfCanLook();
                if (lastState.IsKeyUp(Keys.Space) && Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    stringIndex = 0;
                    player.UseNearest();
                    if (state == GameState.Dialog)
                    {
                        if (currentSpeaker != null)
                        {
                            currentDialog = currentSpeaker.Speak();
                        }
                        NormalizeDialog();
                    }
                }
                player.Update(gameTime);
                currentMap.Update(gameTime);
            }
            else if (state == GameState.Dialog)
            {
                if (lastState.IsKeyUp(Keys.Space) && Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    if (stringIndex == currentDialog.Length)
                    {
                        stringIndex = 0;
                        if (dialogLeftovers != "")
                        {
                            currentDialog = dialogLeftovers;
                            NormalizeDialog();
                        }
                        else
                        {
                            state = GameState.Playing;
                        }
                    }
                    else
                    {
                        stringIndex = currentDialog.Length;
                    }
                }
            }
            else if (state == GameState.Fading)
            {
                Fade();
            }
            else if (state == GameState.Pause)
            {
                if (!pausedNow && lastState.IsKeyUp(Keys.P) && Keyboard.GetState().IsKeyDown(Keys.P))
                {
                    state = lastGameState;
                }
            }

            cam.Update(player.Position);
            lastState = Keyboard.GetState();
            base.Update(gameTime);
        }
        protected override void Update(GameTime gameTime)
        {
            KeyboardInput = Keyboard.GetState();
            bool mazeSizeUpdated = false;

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || KeyboardInput.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // Reset: layout lost
            if (KeyboardInput.IsKeyDown(Keys.R) && PreviousKeyboardInput.IsKeyUp(Keys.R))
            {
                aMazIng.Reset();
                aMazIng.GenerateTWMaze_GrowingTree(methodArray[currMethod]);
            }


            if (KeyboardInput.IsKeyDown(Keys.P) && PreviousKeyboardInput.IsKeyUp(Keys.P))
            {
                currMethod++;
                currMethod %= (byte)methodArray.Length;
            }

            if (KeyboardInput.IsKeyDown(Keys.NumPad7) && PreviousKeyboardInput.IsKeyUp(Keys.NumPad7))
            {
                mazeW--;
                backgroundsW   -= 5;
                mazeSizeUpdated = true;
            }
            if (KeyboardInput.IsKeyDown(Keys.NumPad9) && PreviousKeyboardInput.IsKeyUp(Keys.NumPad9))
            {
                mazeW++;
                backgroundsW   += 5;
                mazeSizeUpdated = true;
            }
            if (KeyboardInput.IsKeyDown(Keys.NumPad2) && PreviousKeyboardInput.IsKeyUp(Keys.NumPad2))
            {
                mazeH--;
                backgroundsH   -= 5;
                mazeSizeUpdated = true;
            }
            if (KeyboardInput.IsKeyDown(Keys.NumPad8) && PreviousKeyboardInput.IsKeyUp(Keys.NumPad8))
            {
                mazeH++;
                backgroundsH   += 5;
                mazeSizeUpdated = true;
            }
            if (KeyboardInput.IsKeyDown(Keys.NumPad6) && PreviousKeyboardInput.IsKeyUp(Keys.NumPad6))
            {
                holesCount++;
                mazeSizeUpdated = true;
            }
            if (KeyboardInput.IsKeyDown(Keys.NumPad4) && PreviousKeyboardInput.IsKeyUp(Keys.NumPad4))
            {
                holesCount--;
                if (holesCount < 0)
                {
                    holesCount = 0;
                }

                mazeSizeUpdated = true;
            }
            if (KeyboardInput.IsKeyDown(Keys.NumPad3) && PreviousKeyboardInput.IsKeyUp(Keys.NumPad3))
            {
                holesMaxRadius++;
                mazeSizeUpdated = true;
            }
            if (KeyboardInput.IsKeyDown(Keys.NumPad1) && PreviousKeyboardInput.IsKeyUp(Keys.NumPad1))
            {
                holesMaxRadius--;
                if (holesMaxRadius < 0)
                {
                    holesMaxRadius = 0;
                }

                mazeSizeUpdated = true;
            }

            if (KeyboardInput.IsKeyDown(Keys.U) && PreviousKeyboardInput.IsKeyUp(Keys.U))
            {
                layoutIndex--;
            }
            if (KeyboardInput.IsKeyDown(Keys.I) && PreviousKeyboardInput.IsKeyUp(Keys.I))
            {
                layoutIndex++;
            }

            layoutIndex = (Byte)MathHelper.Clamp(layoutIndex, 0, 9);

            if (KeyboardInput.IsKeyDown(Keys.L) && PreviousKeyboardInput.IsKeyUp(Keys.L))
            {
                //load layout
                mlayout.LoadLayout(layoutIndex);

                // ISSUE: maze not adjuster to layout size !
                mlayout.GenerateMazeLayout();

                mazeSizeUpdated = true;
            }


            if (mazeSizeUpdated == true)
            {
                aMazIng.UpdateSize(mazeW, mazeH, mlayout, holesCount, holesMaxRadius);

                // need to update total grid size too (+x cells = +n pixels)
                //unneeded aMazIng.Reset();
                aMazIng.GenerateTWMaze_GrowingTree(methodArray[currMethod]);
            }

            PreviousKeyboardInput = KeyboardInput;

            base.Update(gameTime);
        }
Exemple #13
0
 /// <summary>
 /// Checks if the provided key was pressed at this frame.
 /// </summary>
 /// <param name="key"></param>
 /// <returns>Return true if so.</returns>
 public bool KeyPressed(Keys i_Key)
 {
     return(m_PrevKeyboardState.IsKeyUp(i_Key) && m_KeyboardState.IsKeyDown(i_Key));
 }
 public static bool Released(Keys key)
 {
     return(_state.IsKeyUp(key) && ((_lastState != null) && _lastState.IsKeyDown(key)));
 }
Exemple #15
0
 public bool IsNewKeyRelease(Keys key)
 {
     return(PreviousKeyboardState.IsKeyDown(key) && KeyboardState.IsKeyUp(key));
 }
        public void handleInput(GameTime gameTime)
        {
            KeyboardState currentState = Keyboard.GetState();

            if (Keyboard.GetState().IsKeyDown(right))
            {
                position              += new Vector2(moveSpeed, 0) * (float)gameTime.ElapsedGameTime.TotalSeconds;
                orientation            = "right";
                rightAnimation.playing = true;
                playerVelocity         = moveSpeed;

                leftAnimation.playing = false; upAnimation.playing = false; downAnimation.playing = false;
            }
            else if (Keyboard.GetState().IsKeyDown(left))
            {
                position             += new Vector2(-moveSpeed, 0) * (float)gameTime.ElapsedGameTime.TotalSeconds;
                orientation           = "left";
                leftAnimation.playing = true;
                playerVelocity        = moveSpeed;

                rightAnimation.playing = false; upAnimation.playing = false; downAnimation.playing = false;
            }
            else if (Keyboard.GetState().IsKeyDown(up))
            {
                position           += new Vector2(0, -moveSpeed) * (float)gameTime.ElapsedGameTime.TotalSeconds;
                orientation         = "up";
                upAnimation.playing = true;
                playerVelocity      = moveSpeed;

                leftAnimation.playing = false; rightAnimation.playing = false; downAnimation.playing = false;
            }
            else if (Keyboard.GetState().IsKeyDown(down))
            {
                position             += new Vector2(0, moveSpeed) * (float)gameTime.ElapsedGameTime.TotalSeconds;
                orientation           = "down";
                downAnimation.playing = true;
                playerVelocity        = moveSpeed;

                leftAnimation.playing = false; upAnimation.playing = false; rightAnimation.playing = false;
            }
            else if (Keyboard.GetState().IsKeyDown(swordStrike))
            {
                usingSword = true;
                switch (orientation)
                {
                case "up":
                    swordTexturePlayer = upSword;
                    swordCollider      = new Rectangle((int)(this.position.X + 16.5), (int)this.position.Y - 25, upSword.Bounds.Width - 10, upSword.Bounds.Height - 5);
                    break;

                case "down":
                    swordTexturePlayer = downSword;
                    swordCollider      = new Rectangle((int)(this.position.X + 14.5), (int)this.position.Y + 32, upSword.Bounds.Width - 10, upSword.Bounds.Height - 6);
                    break;

                case "right":
                    swordTexturePlayer = rightSword;
                    swordCollider      = new Rectangle((int)(this.position.X + 31.5), (int)(this.position.Y + 13.5), upSword.Bounds.Width + 7, (upSword.Bounds.Height / 4));
                    break;

                case "left":
                    swordTexturePlayer = leftSword;
                    swordCollider      = new Rectangle((int)(this.position.X - 24.5), (int)(this.position.Y + 13.5), upSword.Bounds.Width + 7, (upSword.Bounds.Height / 4));
                    break;
                }
                leftAnimation.playing = false; rightAnimation.playing = false; downAnimation.playing = false; upAnimation.playing = false;
            }
            else if (currentState.IsKeyDown(wandKey))
            {
                usingWand = true;
                switch (orientation)
                {
                case "up":
                    wandTex = upWand;
                    break;

                case "down":
                    wandTex = downWand;
                    break;

                case "right":
                    wandTex = rightWand;
                    break;

                case "left":
                    wandTex = leftWand;
                    break;
                }
            }
            else
            {
            }

            if (usingWand && allowWand)
            {
                switch (orientation)
                {
                case "up":
                    swordProjectileList.Add(new SwordProjectile(_texture: upWave, _velocity: new Vector2(0, -wandSpeed - playerVelocity), _position: this.position, _orientation: this.orientation, _damage: this.wandDamge));
                    break;

                case "down":
                    swordProjectileList.Add(new SwordProjectile(_texture: downWave, _velocity: new Vector2(0, wandSpeed + playerVelocity), _position: this.position, _orientation: this.orientation, _damage: this.wandDamge));
                    break;

                case "right":
                    swordProjectileList.Add(new SwordProjectile(_texture: rightWave, _velocity: new Vector2(wandSpeed + playerVelocity, 0), _position: this.position, _orientation: this.orientation, _damage: this.wandDamge));
                    break;

                case "left":
                    swordProjectileList.Add(new SwordProjectile(_texture: leftWave, _velocity: new Vector2(-wandSpeed - playerVelocity, 0), _position: this.position, _orientation: this.orientation, _damage: this.wandDamge));
                    break;
                }
                swordProjectileList[swordProjectileList.Count - 1].orientation = this.orientation.ToString().ToLower();
                allowWand = false;
            }

            if (currentState.IsKeyDown(swordBeamKey) && allowShoot)
            {
                switch (orientation)
                {
                case "up":
                    swordProjectileList.Add(new SwordProjectile(_texture: upProjectile, _velocity: new Vector2(0, -projectileSpeed - playerVelocity), _position: this.position, _orientation: this.orientation, _damage: this.projectileDamage));
                    break;

                case "down":
                    swordProjectileList.Add(new SwordProjectile(_texture: downProjectile, _velocity: new Vector2(0, projectileSpeed + playerVelocity), _position: this.position, _orientation: this.orientation, _damage: this.projectileDamage));
                    break;

                case "right":
                    swordProjectileList.Add(new SwordProjectile(_texture: rightProjectile, _velocity: new Vector2(projectileSpeed + playerVelocity, 0), _position: this.position, _orientation: this.orientation, _damage: this.projectileDamage));
                    break;

                case "left":
                    swordProjectileList.Add(new SwordProjectile(_texture: leftProjectile, _velocity: new Vector2(-projectileSpeed - playerVelocity, 0), _position: this.position, _orientation: this.orientation, _damage: this.projectileDamage));
                    break;
                }
                swordProjectileList[swordProjectileList.Count - 1].orientation = this.orientation.ToString().ToLower();
                allowShoot = false;
            }

            if (currentState.IsKeyUp(wandKey) && oldState.IsKeyDown(wandKey))
            {
                usingWand = false;
            }

            if (currentState.IsKeyUp(swordBeamKey) && oldState.IsKeyDown(swordBeamKey))
            {
            }

            if (currentState.IsKeyUp(right) && oldState.IsKeyDown(right))
            {
                rightAnimation.playing = false;
                playerVelocity         = 0;
            }

            if (currentState.IsKeyUp(left) && oldState.IsKeyDown(left))
            {
                leftAnimation.playing = false;
                playerVelocity        = 0;
            }

            if (currentState.IsKeyUp(up) && oldState.IsKeyDown(up))
            {
                upAnimation.playing = false;
                playerVelocity      = 0;
            }

            if (currentState.IsKeyUp(down) && oldState.IsKeyDown(down))
            {
                downAnimation.playing = false;
                playerVelocity        = 0;
            }

            if (currentState.IsKeyUp(swordStrike) && oldState.IsKeyDown(swordStrike))
            {
                usingSword  = false;
                swordJabbed = false;
            }

            if (coolDownCount >= coolDownTime)
            {
                coolDownCount = 0;
                allowShoot    = true;
            }

            if (coolDownCountWand >= coolDownTimeWand)
            {
                coolDownCountWand = 0;
                allowWand         = true;
            }

            for (int i = 0; i < swordProjectileList.Count; i++)
            {
                swordProjectileList[i].updatePosition(gameTime);
                if (swordProjectileList[i].position.X <0 || swordProjectileList[i].position.X> Game1.windowWidth || swordProjectileList[i].position.Y <0 || swordProjectileList[i].position.Y> Game1.windowHeight)
                {
                    swordProjectileList.RemoveAt(i);
                }
            }

            coolDownCount     += gameTime.ElapsedGameTime.TotalSeconds * 50;
            coolDownCountWand += gameTime.ElapsedGameTime.TotalSeconds * 50;

            oldState = currentState;
        }
Exemple #17
0
        // Ecrit dans la string passée en paramètre, le bool verrouille les chiffres
        public bool SaisirTexte(ref string text, bool OnlyChiffre)
        {
            keyboardState    = SceneEngine2.BaseScene.keyboardState;
            oldKeyboardState = SceneEngine2.BaseScene.oldKeyboardState;
            pressedKeys      = keyboardState.GetPressedKeys();
            prevPressedKeys  = oldKeyboardState.GetPressedKeys();

            char c = ' ';
            bool shiftPressed;

            shiftPressed = keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift);

            if (keyboardState.IsKeyDown(Keys.Space) && oldKeyboardState.IsKeyUp(Keys.Space))
            {
                c = ' ';
            }

            foreach (Keys key in pressedKeys)
            {
                if (!prevPressedKeys.Contains(key))
                {
                    string keyString = key.ToString();

                    if (!OnlyChiffre)
                    {
                        if (keyString.Length == 1)
                        {
                            c = keyString[0];
                            if (!shiftPressed)
                            {
                                c += (char)('a' - 'A');
                            }
                        }
                        if (keyString.Length == 7)
                        {
                            c = keyString[6];
                        }

                        text += c;
                    }
                    // SI WANNACHIFFRE
                    if (keyString.Length == 7 && OnlyChiffre)
                    {
                        c     = keyString[6];
                        text += c;
                    }
                }
            }

            // Delete
            if (keyboardState.IsKeyDown(Keys.Back) && oldKeyboardState.IsKeyUp(Keys.Back))
            {
                oldKeyboardState = keyboardState;
                prevPressedKeys  = pressedKeys;
                string text2 = "";
                for (int i = 0; i < text.Length - 2; i++)
                {
                    text2 += text[i];
                }

                text = text2;
            }

            // Enter
            if (keyboardState.IsKeyDown(Keys.Enter) && oldKeyboardState.IsKeyUp(Keys.Enter))
            {
                string text2 = "";
                for (int i = 0; i < text.Length; i++)
                {
                    if (i == 0 && text[i] == ' ' || i == text.Length - 1 && text[i] == ' ')
                    {
                    }
                    else
                    {
                        text2 += text[i];
                    }
                }
                text = text2;
                return(true);
            }
            else
            {
                return(false);
            }
        }