public override void Update() { Microsoft.Xna.Framework.Input.KeyboardState stateKey = Keyboard.GetState(); if (stateKey.IsKeyDown(Keys.Left)) { left = true; } if (stateKey.IsKeyUp(Keys.Left)) { left = false; } if (stateKey.IsKeyDown(Keys.Right)) { right = true; } if (stateKey.IsKeyUp(Keys.Right)) { right = false; } if (stateKey.IsKeyDown(Keys.Up)) { jump = true; } if (stateKey.IsKeyUp(Keys.Up)) { jump = false; } }
public void Update(GameTime gameTime, Vector2 mapSize) { lastKeyboardState = keyboardState; keyboardState = Keyboard.GetState(); position = new Vector2((int)deplacement.X * 16, (int)deplacement.Y * 16); //choisis la texture if (keyboardState.IsKeyDown(Keys.F5) && lastKeyboardState.IsKeyUp(Keys.F5)) Texture = ressource.ARBRE; else if (keyboardState.IsKeyDown(Keys.F6) && lastKeyboardState.IsKeyUp(Keys.F6)) Texture = ressource.SOL; else if (keyboardState.IsKeyDown(Keys.F7) && lastKeyboardState.IsKeyUp(Keys.F7)) Texture = ressource.STATUT; //deplace le curseur if (keyboardState.IsKeyDown(Keys.J) && lastKeyboardState.IsKeyUp(Keys.J) && position.X > 0) deplacement.X--; if (keyboardState.IsKeyDown(Keys.L) && lastKeyboardState.IsKeyUp(Keys.L) && position.X < mapSize.X - 1) deplacement.X++; if (keyboardState.IsKeyDown(Keys.I) && lastKeyboardState.IsKeyUp(Keys.I) && position.Y > 0) deplacement.Y--; if (keyboardState.IsKeyDown(Keys.K) && lastKeyboardState.IsKeyUp(Keys.K) && position.Y < mapSize.Y - 1) deplacement.Y++; }
public override void Update(GameTime gameTime) { base.Update(gameTime); MouseState mouseState = Mouse.GetState(); deltaMousePos = new Point(mouseState.X - mousePosition.X, mouseState.Y - mousePosition.Y); mousePosition.X = mouseState.X; mousePosition.Y = mouseState.Y; deltaScroll = mouseState.ScrollWheelValue - mouseScrollValue; mouseScrollValue = mouseState.ScrollWheelValue; leftMouseDown = mouseState.LeftButton == ButtonState.Pressed; rightMouseDown = mouseState.RightButton == ButtonState.Pressed; prevState = curState; curState = Keyboard.GetState(); int posX = (curState.IsKeyDown(Keys.D) || curState.IsKeyDown(Keys.Right)) ? 1 : 0; int negX = (curState.IsKeyDown(Keys.A) || curState.IsKeyDown(Keys.Left)) ? -1 : 0; int posY = (curState.IsKeyDown(Keys.W) || curState.IsKeyDown(Keys.Up)) ? 1 : 0; int negY = (curState.IsKeyDown(Keys.S) || curState.IsKeyDown(Keys.Down)) ? -1 : 0; movementDir = new Vector2(posX + negX, posY + negY); if (movementDir != Vector2.Zero) movementDir.Normalize(); spaceBarPressed = curState.IsKeyDown(Keys.Space) && prevState.IsKeyUp(Keys.Space); shiftDown = curState.IsKeyDown(Keys.LeftShift) || curState.IsKeyDown(Keys.RightShift); shiftUp = curState.IsKeyUp(Keys.LeftShift) && curState.IsKeyUp(Keys.RightShift); enterDown = curState.IsKeyDown(Keys.Enter); escapeDown = curState.IsKeyDown(Keys.Escape); }
public void Update(KeyboardState clavier, Menu menu) { if (clavier.IsKeyDown(Keys.Escape)) pauseactive = true; if (clavier.IsKeyUp(Keys.Escape) && pauseactive) { if (Etat == etat.InGame) { Etat = etat.Pause; menu.mode = Menu.Mode.Pause; } pauseactive = false; } if (clavier.IsKeyDown(Keys.Space)) combatactive = true; if (clavier.IsKeyUp(Keys.Space) && combatactive) { if (Etat == etat.InGame) { combat = !combat; } combatactive = false; } }
private bool jump; //True if able to jump #endregion Fields #region Methods public void HandleInput(KeyboardState keys) { if (keys.IsKeyDown(Keys.Right)) { xAcl = 5; xDcl = 0; } if (keys.IsKeyDown(Keys.Left)) { xAcl = -5; xDcl = 0; } if (keys.IsKeyDown(Keys.Down)) { posY += 5; } if (keys.IsKeyDown(Keys.Up)) { posY -= 5; } if (keys.IsKeyUp(Keys.Right) && (!keys.IsKeyDown(Keys.Left))) xAcl = 0; if (keys.IsKeyUp(Keys.Left) && (!keys.IsKeyDown(Keys.Right))) xAcl = 0; }
public void Update(KeyboardState clavier, Menu menu) { #region GestionPause if (clavier.IsKeyDown(Keys.Escape)) pauseactive = true; if (clavier.IsKeyUp(Keys.Escape) && pauseactive) { if (Etat == etat.InGame) { menu.mode = Menu.Mode.Pause; Etat = etat.Pause; } pauseactive = false; } #endregion #region Gestion Combat if (clavier.IsKeyDown(Keys.Space)) combatactive = true; if (clavier.IsKeyUp(Keys.Space) && combatactive) { if (Etat == etat.InGame) { combat = !combat; } combatactive = false; } #endregion }
public static void HandleInput(GameTime gameTime, PlayableCharacter unit) { previousKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(); //if (currentKeyboardState.GetPressedKeys().Length == 0) //{ // // Idle //} //Reset any currently ongoing animation if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R)) { unit.ResetAnimation(); } if (currentKeyboardState != previousKeyboardState) { if (!unit.IsAttackingRanged) { //unit.ResetAnimationCounter(); } unit.MakeUnitIdle(); } // Move Right if (currentKeyboardState.IsKeyDown(Keys.Right)) { unit.ValidateMovementRight(); } // Move Left if (currentKeyboardState.IsKeyDown(Keys.Left)) { unit.ValidateMovementLeft(); } // Jumping if (currentKeyboardState.IsKeyDown(Keys.Up) && previousKeyboardState.IsKeyUp(Keys.Up)) { unit.ValidateJump(); } // RangedAttack if (currentKeyboardState.IsKeyDown(Keys.A) && currentKeyboardState.IsKeyDown(Keys.S) && previousKeyboardState.IsKeyUp(Keys.S)) { unit.ComboStageCounter += 2; unit.ValidateRangedAttack(); } else if (currentKeyboardState.IsKeyDown(Keys.A) && previousKeyboardState.IsKeyUp(Keys.A)) { unit.ValidateRangedAttack(); } }
public override void Update(GameTime gameTime, GamePadState newGamePadState, GamePadState oldGamePadState, KeyboardState newKeyboardState, KeyboardState oldKeyboardState) { if ((newGamePadState.Buttons.B != oldGamePadState.Buttons.B && newGamePadState.Buttons.B == ButtonState.Pressed) || (newKeyboardState.IsKeyDown(Keys.Enter) && oldKeyboardState.IsKeyUp(Keys.Enter)) || (newKeyboardState.IsKeyDown(Keys.B) && oldKeyboardState.IsKeyUp(Keys.B))) { Game.GameStartingScreen = GameStartingScreen.SetupScreen; } }
void InputKeyBoard_KeyEvent(KeyboardState keyNewState, KeyboardState keyOldState) { if (keyNewState.IsKeyDown(Keys.Escape) && keyOldState.IsKeyUp(Keys.Escape)) game.Exit(); if (keyNewState.IsKeyDown(Keys.Up) && keyOldState.IsKeyUp(Keys.Up)) game.Window.Title = "Up"; if (keyNewState.IsKeyDown(Keys.Down) && keyOldState.IsKeyUp(Keys.Down)) game.Window.Title = "Down"; if (keyNewState.IsKeyDown(Keys.Left) && keyOldState.IsKeyUp(Keys.Left)) game.Window.Title = "Left"; if (keyNewState.IsKeyDown(Keys.Right) && keyOldState.IsKeyUp(Keys.Right)) game.Window.Title = "Right"; }
public void Update(GameTime gameTime) { guiSystem.Update(); CurrentKeyboardState = Keyboard.GetState(); if ((CurrentKeyboardState.IsKeyUp(Keys.Enter) && PreviousKeyboardState.IsKeyDown(Keys.Enter)) || (CurrentKeyboardState.IsKeyUp(Keys.E) && PreviousKeyboardState.IsKeyDown(Keys.E))) { if (btnControlUp.IsSelected) if (btnReturn.IsSelected) Game1.gameState = Game1.GameState.StartMenu; } PreviousKeyboardState = Keyboard.GetState(); }
public void Update(GameTime gameTime) { keyState = Keyboard.GetState(); if (keyState.IsKeyUp(Keys.D1) == true && oldKeyState.IsKeyDown(Keys.D1) == true) { one = true; } else { one = false; } if (keyState.IsKeyUp(Keys.D2) == true && oldKeyState.IsKeyDown(Keys.D2) == true) { two = true; } else { two = false; } if (keyState.IsKeyUp(Keys.D3) == true && oldKeyState.IsKeyDown(Keys.D3) == true) { three = true; } else { three = false; } if (keyState.IsKeyUp(Keys.D4) == true && oldKeyState.IsKeyDown(Keys.D4) == true) { four = true; } else { four = false; } if (keyState.IsKeyUp(Keys.D5) == true && oldKeyState.IsKeyDown(Keys.D5) == true) { five = true; } else { five = false; } oldKeyState = keyState; }
public void Update(float elapsed, KeyboardState currentKey, KeyboardState oldKey, MouseState currentMouse, MouseState oldMouse) { totalElapsed += elapsed; if (animated) { if (totalElapsed > animationSpeed) { currentFrame++; if (currentFrame == totalFrames - 2) currentFrame = 0; totalElapsed = 0; } } Vector2 direction = new Vector2(Mouse.GetState().X, Mouse.GetState().Y - World.HUD) - Position; if (direction != Vector2.Zero) direction.Normalize(); Rotation = (float)Math.Atan2(direction.Y, direction.X); Weapon.Update(elapsed); if (currentMouse.LeftButton == ButtonState.Pressed && oldMouse.LeftButton == ButtonState.Released) { Weapon.Execute(new Vector2((float)Math.Cos(Rotation), (float)Math.Sin(Rotation)), Position); } if (invTmr > 0) { invTmr -= elapsed / 1000; } #region CurrentMovement //Can be changed if (currentKey.IsKeyDown(Keys.W)) Velocity = new Vector2((float)Math.Cos(Rotation), (float)Math.Sin(Rotation)); if (currentKey.IsKeyDown(Keys.S)) Velocity = new Vector2((float)Math.Cos(Rotation + MathHelper.ToRadians(180)), (float)Math.Sin(Rotation + MathHelper.ToRadians(180))); if (currentKey.IsKeyDown(Keys.D)) Velocity = new Vector2((float)Math.Cos(Rotation + MathHelper.ToRadians(90)), (float)Math.Sin(Rotation + MathHelper.ToRadians(90))); if (currentKey.IsKeyDown(Keys.A)) Velocity = new Vector2((float)Math.Cos(Rotation + MathHelper.ToRadians(-90)), (float)Math.Sin(Rotation + MathHelper.ToRadians(-90))); if (currentKey.IsKeyDown(Keys.W) && currentKey.IsKeyDown(Keys.D)) Velocity = new Vector2((float)Math.Cos(Rotation + MathHelper.ToRadians(45)), (float)Math.Sin(Rotation + MathHelper.ToRadians(45))); if (currentKey.IsKeyDown(Keys.W) && currentKey.IsKeyDown(Keys.A)) Velocity = new Vector2((float)Math.Cos(Rotation + MathHelper.ToRadians(-45)), (float)Math.Sin(Rotation + MathHelper.ToRadians(-45))); if (currentKey.IsKeyDown(Keys.S) && currentKey.IsKeyDown(Keys.D)) Velocity = new Vector2((float)Math.Cos(Rotation + MathHelper.ToRadians(135)), (float)Math.Sin(Rotation + MathHelper.ToRadians(135))); if (currentKey.IsKeyDown(Keys.S) && currentKey.IsKeyDown(Keys.A)) Velocity = new Vector2((float)Math.Cos(Rotation + MathHelper.ToRadians(-135)), (float)Math.Sin(Rotation + MathHelper.ToRadians(-135))); if (currentKey.IsKeyUp(Keys.W) && currentKey.IsKeyUp(Keys.A) && currentKey.IsKeyUp(Keys.S) && currentKey.IsKeyUp(Keys.D)) { Velocity = Vector2.Zero; currentFrame = totalFrames - 1; } else if (currentFrame == totalFrames - 1) currentFrame = 0; animationSpeed = currentKey.IsKeyUp(Keys.W) && currentKey.IsKeyUp(Keys.A) && currentKey.IsKeyUp(Keys.S) && currentKey.IsKeyUp(Keys.D) ? int.MaxValue : storedAnimationSpeed; if (Velocity != null) Velocity.Normalize(); OldPos = Position; Position += Velocity * speed; #endregion }
public static void Update(GameTime gameTime, KeyboardState state, KeyboardState prevState) { if (!GameScene.player.projectileLaunched) { if (spells ["fireball"] && state.IsKeyDown (Keys.H) && prevState.IsKeyUp (Keys.H) && GameScene.player.HasEnoughMana (2)) { GameScene.player.Fireball (); } else if (spells ["frostbreath"] && state.IsKeyDown (Keys.J) && prevState.IsKeyUp (Keys.J) && GameScene.player.HasEnoughMana (1)) { GameScene.player.FrostBreath (); } } if (spells ["earthen shield"]) { if (state.IsKeyDown (Keys.K) && prevState.IsKeyUp (Keys.K)) { if (activeSpell == "") { GameScene.player.EarthenStrength (); } else { GameScene.player.DestroyOverlay (); if (activeSpell != "earthen shield") { if (GameScene.player.HasEnoughMana (1)) { GameScene.player.EarthenStrength (); } } else { activeSpell = ""; } } } } if (spells ["windwalk"]) { if (state.IsKeyDown (Keys.L) && prevState.IsKeyUp (Keys.L)) { if (activeSpell == "") { GameScene.player.WindWalk (); } else { GameScene.player.DestroyOverlay (); if (activeSpell != "windwalk") { if (GameScene.player.HasEnoughMana (1)) { GameScene.player.WindWalk (); } } else { activeSpell = ""; } } } } if (activeSpell != "") { drainTimer -= gameTime.ElapsedGameTime; if (drainTimer.Milliseconds <= 0) { DrainMana (); } } }
public override void Keyboard(KeyboardState state, KeyboardState oldState) { if (state.IsKeyDown(Keys.L) && oldState.IsKeyUp(Keys.L)) { _joint.EnableLimit(!_joint.IsLimitEnabled()); } if (state.IsKeyDown(Keys.M) && oldState.IsKeyUp(Keys.M)) { _joint.EnableMotor(!_joint.IsMotorEnabled()); } if (state.IsKeyDown(Keys.P) && oldState.IsKeyUp(Keys.P)) { _joint.SetMotorSpeed(-_joint.GetMotorSpeed()); } }
public virtual void Update(GameTime gameTime, EventManager events) { // Keyboard lastKeyboard = keyboard; keyboard = Keyboard.GetState(); bool pressUp = keyboard.IsKeyUp(Keys.Up) && lastKeyboard.IsKeyDown(Keys.Up); bool pressDown = keyboard.IsKeyUp(Keys.Down) && lastKeyboard.IsKeyDown(Keys.Down); bool pressLeft = keyboard.IsKeyUp(Keys.Left) && lastKeyboard.IsKeyDown(Keys.Left); bool pressRight = keyboard.IsKeyUp(Keys.Right) && lastKeyboard.IsKeyDown(Keys.Right); bool downUp = keyboard.IsKeyDown(Keys.Up); bool downDown = keyboard.IsKeyDown(Keys.Down); bool downLeft = keyboard.IsKeyDown(Keys.Left); bool downRight = keyboard.IsKeyDown(Keys.Right); bool keyT = keyboard.IsKeyUp(Keys.T) && lastKeyboard.IsKeyDown(Keys.T); //bool keyN = keyboard.IsKeyUp(Keys.N) && lastKeyboard.IsKeyDown(Keys.N); // Key Press Events if (pressUp) events.Notify(Event.PressUP, null); if (pressDown) events.Notify(Event.PressDOWN, null); if (pressLeft) events.Notify(Event.PressLEFT, null); if (pressRight) events.Notify(Event.PressRIGHT, null); // Key Down Events if (downUp) events.Notify(Event.KeyDownUP, null); if (downDown) events.Notify(Event.KeyDownDOWN, null); if (downLeft) events.Notify(Event.KeyDownLEFT, null); if (downRight) events.Notify(Event.KeyDownRIGHT, null); //if (keyN) // events.Notify(Event.NextScene, null); }
public void localUpdate(KeyboardState ks) { if (ks.IsKeyDown(Keys.Up) && ks.IsKeyUp(Keys.Down)) { if(position.Y > 0){ position.Y -=5 ; } } else if (ks.IsKeyDown(Keys.Down) && ks.IsKeyUp(Keys.Up)) { if (position.Y + 60 < 480) { position.Y += 5; } } }
public char Update(KeyboardState ks, Tempo Time, Song[] Musicas) { if (Time.tempoRestante <= TimeSpan.FromSeconds(0)) { MediaPlayer.Play(Musicas[2]); Time.tempoRestante = TimeSpan.FromSeconds(5); return '0'; } if (Restante <= 0) { Time.ConverteTempo(); Time.ResetaTempo(); return '4'; } if (ks.IsKeyUp(Keys.J)) { apertado = false; } if (ks.IsKeyDown(Keys.J) && apertado == false) { apertado = true; //if (Time.Total.Milliseconds % 30 == 0) //{ Restante--; //} } return '3'; }
public bool CheckKeyState(Keys key, bool ClickOnceButton) { ks=Keyboard.GetState(); for (int i = 0; i < PressedKeys.Count; i++) { if (ks.IsKeyUp(PressedKeys[i])) { PressedKeys.Remove(PressedKeys[i]); i--; } } if (ClickOnceButton == false) { if (ks.IsKeyDown(key)) { return true; } } else { foreach (Keys pressedKey in PressedKeys) { if (pressedKey == key) { return false; } } if (ks.IsKeyDown(key)) { PressedKeys.Add(key); return true; } } return false; }
protected void AmbientToggle(KeyboardState currentKeyboardState, GamePadState currentGamePadState) { // toggle Ambient - Night/Day effect if (previousKeyboardState.IsKeyDown(Keys.E) && currentKeyboardState.IsKeyUp(Keys.E) || previousGamePadState.IsButtonDown(Buttons.RightShoulder) && currentGamePadState.IsButtonUp(Buttons.RightShoulder)) { ambient = !ambient; currentMusic.Stop(); currentMusic.Dispose(); // Ambient true sets to day time effect, false sets to night time effect if(ambient) { skyColor = Color.DeepSkyBlue; effect.Parameters["material"].StructureMembers["ambient"].SetValue(new Vector4(0.65f, 0.65f, 0.6f, 1.0f)); currentMusic = musicDay.CreateInstance(); } else { skyColor = Color.DarkSlateGray; effect.Parameters["material"].StructureMembers["ambient"].SetValue(new Vector4(0.1f, 0.1f, 0.15f, 1.0f)); currentMusic = musicNight.CreateInstance(); } enemy.Apply3DAudio(listener, enemy.Position, currentMusic); currentMusic.Play(); } }
public static void Handler(KeyboardState KeyState, GameTime gameTime) { float _speed = 5; //Clear attack state on every update _attack = false; if (KeyState.IsKeyDown(Keys.W) | KeyState.IsKeyDown(Keys.Up)) { Player.hiLocation.Y = Player.hiLocation.Y - _speed; //Move up } if (KeyState.IsKeyDown(Keys.A) | KeyState.IsKeyDown(Keys.Left)) { //Move left Player.hiLocation.X = Player.hiLocation.X - _speed; } if (KeyState.IsKeyDown(Keys.S) | KeyState.IsKeyDown(Keys.Down)) { //Move down Player.hiLocation.Y = Player.hiLocation.Y + _speed; } if (KeyState.IsKeyDown(Keys.D) | KeyState.IsKeyDown(Keys.Right)) { //Move right Player.hiLocation.X = Player.hiLocation.X + _speed; } if (KeyState.IsKeyDown(Keys.Space)) { //Attack if (attackHold <= 250 && attackWait <= 0) { //If not held attack _attack = true; attackHold++; timer = ((int)250 - (int)attackHold).ToString(); } if(attackHold >= 250) { //If held to long block attack for 125 frames attackHold = 0; attackWait = 125; timer = "125C"; } } if(KeyState.IsKeyUp(Keys.Space) && attackWait <= 0 || PositionChecker.dead) { //Reset hold and pause on key up attackHold = 0; attackWait = 0; timer = "250"; } if (attackWait > 0) { timer = String.Format("{0}C", attackWait.ToString()); attackWait--; } if (KeyState.IsKeyDown(Keys.F1) && Game1.debug) Game1.spawn = !Game1.spawn; //Validate new position PositionChecker.PosChecker(); }
//Uses the player's skill public static void UseSkill(Character player, KeyboardState state, KeyboardState oldState, int time) { //Checks to see if the key is pressed if (state.IsKeyDown(Keys.D1) && oldState.IsKeyUp(Keys.D1) && !CheckActiveSkills() && skills[0].Obtained) { //Activate the skill and sets the timers skills[0].ActivateSkill(); } else if (state.IsKeyDown(Keys.D2) && oldState.IsKeyUp(Keys.D2) && !CheckActiveSkills() && skills[1].Obtained) { //Activate the skill and sets the timers skills[1].ActivateSkill(); } else if (state.IsKeyDown(Keys.D3) && oldState.IsKeyUp(Keys.D3) && !CheckActiveSkills() && skills[2].Obtained) { //Activate the skill and sets the timers skills[2].ActivateSkill(); } foreach (Skill s in skills) { s.Status(time); } }
/// <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) { if (xnaInput.GamePad.GetState(PlayerIndex.One).Buttons.Back == xnaInput.ButtonState.Pressed || xnaInput.Keyboard.GetState().IsKeyDown(xnaInput.Keys.Escape)) { Exit(); } xnaInput.KeyboardState state = xnaInput.Keyboard.GetState(); if (state.IsKeyDown(xnaInput.Keys.Left)) { Camera.Move(new Vector2(1, 0) * CAMERASPEED); } if (state.IsKeyDown(xnaInput.Keys.Right)) { Camera.Move(new Vector2(-1, 0) * CAMERASPEED); } if (state.IsKeyDown(xnaInput.Keys.Up)) { Camera.Move(new Vector2(0, 1) * CAMERASPEED); } if (state.IsKeyDown(xnaInput.Keys.Down)) { Camera.Move(new Vector2(0, -1) * CAMERASPEED); } xnaInput.KeyboardState lastFrame = keyboardState; keyboardState = xnaInput.Keyboard.GetState(); if (keyboardState.IsKeyDown(xnaInput.Keys.D1)) { lineDrawer.NumberBeingDrawn = 0; } if (keyboardState.IsKeyDown(xnaInput.Keys.D2)) { lineDrawer.NumberBeingDrawn = 1; } if (keyboardState.IsKeyDown(xnaInput.Keys.D3)) { lineDrawer.NumberBeingDrawn = 2; } if (keyboardState.IsKeyDown(xnaInput.Keys.D4)) { lineDrawer.NumberBeingDrawn = 3; } if (keyboardState.IsKeyUp(xnaInput.Keys.A) && lastFrame.IsKeyDown(xnaInput.Keys.A)) { if (lineDrawer.DrawSingle) { lineDrawer.DrawSingle = false; } else { lineDrawer.DrawSingle = true; } } base.Update(gameTime); }
public static void getState() { oldTeclado = teclado; oldMouse = mouse; teclado = Keyboard.GetState(); mouse = Mouse.GetState(); Keys[] keys = teclado.GetPressedKeys(); foreach (Keys keyPressed in keys) { if (!keysPressed.Contains(keyPressed)) { keysPressed.Add(keyPressed); } } foreach (Keys keyPressed in keysPressed) { if (teclado.IsKeyUp(keyPressed)) { keysPressed.Remove(keyPressed); break; } } }
public List<char> ReturnDigitORNumberKeyAsChar(KeyboardState keyboardstate, KeyboardState oldKeyboardstate) { List<char> chars = new List<char>(); char c; bool shift = false; if (keyboardstate.IsKeyDown(Keys.LeftShift) || keyboardstate.IsKeyDown(Keys.RightShift)) shift = true; foreach (Keys a in keyboardstate.GetPressedKeys()) { if (oldKeyboardstate.IsKeyUp(a) && a != Keys.RightShift && a != Keys.LeftShift) { int i = a.GetHashCode(); c = (char)i; if (Char.IsLetterOrDigit(c)) if (shift) chars.Add(c); else chars.Add(Convert.ToChar(c.ToString().ToLower())); } } return chars; }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); // Read the keyboard and set actions to be performed newKeyState = Keyboard.GetState(); if (oldKeyState.IsKeyUp(Keys.Space) && newKeyState.IsKeyDown(Keys.Space)) { // Space was pressed isRecordData = true; dataText = "Recording data..."; countText = ""; meanPosition = Vector3.Zero; } else if (oldKeyState.IsKeyDown(Keys.Space) && newKeyState.IsKeyUp(Keys.Space)) { // Space was released isRecordData = false; dataText = String.Format("Camera position: {0:0.00}, {1:0.00}, {2:0.00}", meanPosition.X, meanPosition.Y, meanPosition.Z); countText = "Number of instances recorded: " + recordCount; ResetData(); } oldKeyState = newKeyState; if (isRecordData) RecordData(); }
//Methods //Update & Draw public void Update(MouseState mouse, KeyboardState keyboard, GamePadState gamePadState) { if (keyboard.IsKeyUp(Keys.Escape) && gamePadState.Buttons.Start == ButtonState.Released) pauseAllowed = true; if ((keyboard.IsKeyDown(Keys.Escape) || gamePadState.Buttons.Start == ButtonState.Pressed) && pauseAllowed) { pauseAllowed = false; Game1.gameState = GameState.Pause; } if (mouse.X > 800) { Map.Current.position.X++; player.position.X++; } if (mouse.X < 200) { Map.Current.position.X--; player.position.X--; } Map.Current.Update(); player.Update(mouse, keyboard, gamePadState); }
public override void HandleKeyboardInput(KeyboardState oldKeyboardState) { KeyboardState currentKeyboardState = Keyboard.GetState(); if (currentKeyboardState.IsKeyDown(Keys.Escape) && oldKeyboardState.IsKeyUp(Keys.Escape)) videoPlayer.Stop(); }
// Adds an attack when the attack button is pressed accompanied by sound and animation public static void AttackAdd(ContentManager Content, Player ninja, List<PlayerAttack> ninjaAttacks, KeyboardState presentKey, KeyboardState pastKey, GamePadState pressentButton, GamePadState pastButton) { if (presentKey.IsKeyDown(Keys.Space) && pastKey.IsKeyUp(Keys.Space) || pressentButton.IsButtonDown(Buttons.A) && pastButton.IsButtonUp(Buttons.A)) { // if the attack button is pressed a new attack will be added to the list ninjaAttacks.Add(new PlayerAttack(Content.Load<Texture2D>("Images\\Attack"), new Vector2(ninja.PositionX + (int)(ninja.Texture.Width * 0.8), ninja.PositionY + (int)(ninja.Texture.Height / 2.25)))); // A sound effect will be played each time we press the attack button ninja.PlaySound(); } // The animation texture of the character will change with each attack if (presentKey.IsKeyDown(Keys.Space) || pressentButton.IsButtonDown(Buttons.A)) { ninja.Texture = Content.Load<Texture2D>("Images\\NinjaFrame1-2"); } else { ninja.Texture = Content.Load<Texture2D>("Images\\NinjaFrame1-1"); } }
public void Update(KeyboardState prevKeyState) { if (Keyboard.GetState ().IsKeyDown (Keys.Enter) && prevKeyState.IsKeyUp(Keys.Enter)) menuItems [selectedMenuItem].Activate (); if ((Keyboard.GetState ().IsKeyDown (Keys.W) && prevKeyState.IsKeyUp (Keys.W)) || (Keyboard.GetState ().IsKeyDown (Keys.Up) && prevKeyState.IsKeyUp (Keys.Up))) selectedMenuItem--; if ((Keyboard.GetState ().IsKeyDown (Keys.S) && prevKeyState.IsKeyUp (Keys.S)) || (Keyboard.GetState ().IsKeyDown (Keys.Down) && prevKeyState.IsKeyUp (Keys.Down))) selectedMenuItem++; //Wrap-around if (selectedMenuItem < 0) selectedMenuItem += menuItems.Count; if (selectedMenuItem >= menuItems.Count) selectedMenuItem -= menuItems.Count; }
public void Code(KeyboardState keyboard, KeyboardState oldkeyboard, Extra extra) { if (keyboard.IsKeyDown(Keys.Enter) && oldkeyboard.IsKeyUp(Keys.Enter)) { SelectionMade = true; } if (keyboard.IsKeyDown(Keys.Up)) { if (selection > 0) selection--; } if (keyboard.IsKeyDown(Keys.Down)) { if (selection < 1) selection++; } switch (selection) { case 0: nimbusX = 140; nimbusY = 400; break; case 1: nimbusX = 170; nimbusY = 430; break; } extra.NimbusRect = new Rectangle(nimbusX, nimbusY, 25, 25); }
public void InputsPlayer(GameTime gameTime, bool move, bool jump, Player player) { // Save previous keyboard/gamepad states previousKeyboardState = currentKeyboardState; previousGamepadState = currentGamepadState; // Read current keyboard/gamepad currentKeyboardState = Keyboard.GetState(); currentGamepadState = GamePad.GetState(PlayerIndex.One); if (move && player.CanMove) { if (currentKeyboardState.IsKeyDown(Keys.Left) || currentGamepadState.ThumbSticks.Left.X < 0) player.Move(-1f); else if (currentKeyboardState.IsKeyDown(Keys.Right) || currentGamepadState.ThumbSticks.Left.X > 0) player.Move(1f); else player.Move(0f); } if (player.CanJump && jump) { if (currentGamepadState.IsButtonDown(Buttons.A) && previousGamepadState.IsButtonUp(Buttons.A)) player.Jump(); else if (currentKeyboardState.IsKeyDown(Keys.Z) && previousKeyboardState.IsKeyUp(Keys.Z)) player.Jump(); } if (player.IsOverDoor) { if (currentGamepadState.ThumbSticks.Left.Y < 0 && previousGamepadState.ThumbSticks.Left.Y < 0 && player.Velocity.X == 0 ) player.EnterDoor(); else if (currentKeyboardState.IsKeyDown(Keys.Up) && previousKeyboardState.IsKeyUp(Keys.Up) && player.Velocity.X == 0 ) player.EnterDoor(); } if (currentGamepadState.IsButtonDown(Buttons.B) && previousGamepadState.IsButtonUp(Buttons.B)) player.Attack(gameTime); else if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) player.Attack(gameTime); }
public void TurnUp(Matrix[] cubeMeshes, KeyboardState keyboardState, KeyboardState oldKeyboardState) { if (keyboardState.IsKeyDown(Keys.Up) && oldKeyboardState.IsKeyUp(Keys.Up)) { Debug.WriteLine(counter); counter++; float rotateAgain = MathHelper.PiOver2 + counter * MathHelper.PiOver2; if (counter == 4) counter = 0; Vector3 firstTurn = new Vector3(0, 0, 0); Vector3 secondTurn = new Vector3(0, 0, 0); if (counter < 2) { firstTurn = new Vector3(0, -2.85f, -4.7f); if (counter == 0) secondTurn = new Vector3(0, 2, 0); } if (counter == 1) secondTurn = new Vector3(0, 6.7f, -0.85f); if (counter == 2) firstTurn = new Vector3(0, -6.7f, 2.8f); Matrix rotate = Matrix.CreateTranslation(firstTurn) * Matrix.CreateRotationX(rotateAgain) * Matrix.CreateTranslation(secondTurn); cubeMeshes[12] = rotate; cubeMeshes[16] = rotate; cubeMeshes[4] = rotate; cubeMeshes[0] = rotate; cubeMeshes[13] = rotate; cubeMeshes[2] = rotate; cubeMeshes[19] = rotate; cubeMeshes[5] = rotate; cubeMeshes[14] = rotate; } if (keyboardState.IsKeyDown(Keys.Down) && oldKeyboardState.IsKeyUp(Keys.Down)) { Debug.WriteLine(counter); float rotateAgain = -MathHelper.PiOver2 - counter * MathHelper.PiOver2; if (counter == 4) counter = 0; Vector3 firstTurn = new Vector3(0, 0, 0); Vector3 secondTurn = new Vector3(0, 0, 0); if (counter < 2) { firstTurn = new Vector3(0, -2.85f, -4.7f); if (counter == 0) secondTurn = new Vector3(0, 7.5f, 3.85f); } if (counter == 1) secondTurn = new Vector3(0, 6.7f, -0.85f); if (counter == 2) firstTurn = new Vector3(0, -2.7f, -6.6f); Matrix rotate = Matrix.CreateTranslation(firstTurn) * Matrix.CreateRotationX(rotateAgain) * Matrix.CreateTranslation(secondTurn); cubeMeshes[12] = rotate; cubeMeshes[16] = rotate; cubeMeshes[4] = rotate; cubeMeshes[0] = rotate; cubeMeshes[13] = rotate; cubeMeshes[2] = rotate; cubeMeshes[19] = rotate; cubeMeshes[5] = rotate; cubeMeshes[14] = rotate; counter++; } }
internal void updateInput(Microsoft.Xna.Framework.Input.KeyboardState currentKState, Microsoft.Xna.Framework.Input.KeyboardState previousKState) { if (currentKState.IsKeyDown(Keys.Up) && previousKState.IsKeyUp(Keys.Up)) { incForward(); } if (currentKState.IsKeyDown(Keys.Down) && previousKState.IsKeyUp(Keys.Down)) { incBackward(); } if (currentKState.IsKeyDown(Keys.Left) && previousKState.IsKeyUp(Keys.Left)) { incLeft(); } if (currentKState.IsKeyDown(Keys.Right) && previousKState.IsKeyUp(Keys.Right)) { incRight(); } if (currentKState.IsKeyDown(Keys.Space) && previousKState.IsKeyUp(Keys.Space)) { reset(); } }
public static bool IsKeyReleased(input.Keys key) { return(currentKeyboard.IsKeyDown(key) && oldKeyboard.IsKeyUp(key)); }
public static bool IsKeyUp(input.Keys key) { return(currentKeyboard.IsKeyUp(key)); }