public override void update(AICharacter character) { IGravityClient gravityClient = character.getEntity().getGravityClient(); KeysPressed keysPressed = character.getEntity().getKeysPressed(); RayInformation rayInformation = character.getEntity().getGravityClient().getRayInformation(); RayHitboxes rayHitboxes = gravityClient.getRayHitboxes(); gravityClient.getRayInformation().checkRaysFront(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 0.0f, layermask, false); gravityClient.getRayInformation().checkRaysBelow(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 270.0f, layermask, false); float minimalSpaceBetweenTileBelow = rayInformation.MinimalSpaceBetweenTileBelow; float topFrontDistance = (rayHitboxes.HitTopFront.distance * 0.9f); bool turned = false; gravityClient.getRayInformation().checkRaysFront(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 0.0f, layermask, true); keysPressed = turnIfWallIsNear(gravityClient, topFrontDistance, rayInformation.MinimalSpaceBetweenTileFront, keysPressed, out turned); if (!turned && (rayHitboxes.HitMiddleBelow.collider.tag.CompareTo("Slope") != 0)) { keysPressed = turnIfOnAnEdge(keysPressed, minimalSpaceBetweenTileBelow, character); } character.setKeysPressed(keysPressed); }
private KeysPressed turnIfOnAnEdge(KeysPressed keysPressed, float minimalSpaceBetweenTileBelow, AICharacter character) { IGravityClient gravityClient = character.getEntity().getGravityClient(); RayHitboxes rayHitboxes = gravityClient.getRayHitboxes(); if (gravityClient.isFlipped() && rayHitboxes.HitLeftBelow.distance > 1.0f) { keysPressed.left = false; keysPressed.right = true; } else if (gravityClient.isFlipped() && rayHitboxes.HitLeftBelow.distance <= minimalSpaceBetweenTileBelow) { keysPressed.left = true; keysPressed.right = false; } if (!gravityClient.isFlipped() && rayHitboxes.HitRightBelow.distance > 1.0f) { keysPressed.left = true; keysPressed.right = false; } else if (!gravityClient.isFlipped() && rayHitboxes.HitRightBelow.distance <= minimalSpaceBetweenTileBelow) { keysPressed.left = false; keysPressed.right = true; } return(keysPressed); }
public void OnDisable() { timer.Stop(); App.Window.KeyPressed -= KeyDown; App.Window.KeyReleased -= KeyUp; KeysPressed.Clear(); }
public void ClearKeyCache() { KeysPressed.Clear(); KeysReleased.Clear(); MousePressed = MouseButtons.None; MouseReleased = MouseButtons.None; MouseWheelDelta = 0; }
public EconEventArgs RemoveKeys(params KeyCode[] codes) { foreach (var code in codes) { KeysPressed.Remove(code); } return(this); }
public void ClearKeyCache() { KeysPressed.Clear(); KeysReleased.Clear(); MousePressed = MouseButtonFlags.None; MouseWheelDelta = 0; _mouseDelta.X = 0; _mouseDelta.Y = 0; }
public void KeyDown(object sender, KeyEventArgs e) { KeysPressed.Add(e.Code); if (Settings.Keybindings.ContainsKey(e.Code)) { Settings.Keybindings[e.Code](this); } Scene.ProcessKey(e); }
void form_KeyDown(object sender, KeyEventArgs e) { Keys key = e.KeyData & ~Keys.Shift; if (KeysDown.Contains(key) == false) { KeysPressed.Add(key); KeysDown.Add(key); } }
public override void update(IEntity entity) { Gravity gravity = entity.getGravity(); KeysPressed keysPressed = entity.getKeysPressed(); IGravityClient gravityClient = entity.getGravityClient(); moveEntity(entity, keysPressed, gravity, entity.getMovementSpeed()); switchState(entity, keysPressed, gravity, gravityClient); }
private static void AddOrSet(Keys key, bool value) { if (KeysPressed.ContainsKey(key)) { KeysPressed[key] = value; } else { KeysPressed.Add(key, value); } }
public override void update(IEntity entity) { KeysPressed keysPressed = entity.getKeysPressed(); if (!keysPressed.actionButtonOne) { entity.getTransform().gameObject.GetComponent <Player>().isDefending = false; IBehaviourStateFactory behaviourStateFactory = entity.getBehaviourStateFactory(); entity.setState(((BehaviourStateFactory)behaviourStateFactory).getIdleState(entity)); } }
public bool moveEntityDown(IEntity entity, KeysPressed keysPressed, Gravity gravity, float movementSpeed) { IGravityClient gravityClient = entity.getGravityClient(); bool moving = false; #if USE_3D_RAYS RayHitboxes3D rayHitboxes = gravityClient.getRayHitboxes3D(); #else RayHitboxes rayHitboxes = gravityClient.getRayHitboxes(); #endif Vector3 angles = new Vector3(entity.getTransform().eulerAngles.x, entity.getTransform().eulerAngles.y, entity.getTransform().eulerAngles.z); #if USE_3D_RAYS RayInformation3D rayInformation = gravityClient.getRayInformation3D(); #else RayInformation rayInformation = gravityClient.getRayInformation(); #endif if (!keysPressed.up && keysPressed.down) { rayInformation.checkRaysBelow(gravityClient, 0.0f, angles.z + 270.0f, layermask); } bool isWalking = !entity.getGravity().isFalling() && !entity.getGravity().Jumping; float frontDistance = rayHitboxes.DistanceBelow; if (frontDistance > rayInformation.MinimalSpaceBetweenTileBelow) { if (!keysPressed.up && keysPressed.down) { moving = true; if (!entity.getRotateHorizontalMovement()) { Vector3 pos = entity.getTransform().position; if (angles.z > 90.0f && angles.z < 270.0f) { pos.y -= ((frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) < movementSpeed * Time.fixedDeltaTime) ? (frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) : movementSpeed * Time.fixedDeltaTime; } else { pos.y -= ((frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) < movementSpeed * Time.fixedDeltaTime) ? (frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) : movementSpeed * Time.fixedDeltaTime; } entity.getTransform().position = pos; } gravity.Reset = false; } } return(moving); }
public override void update(GameLib.Entity.NonPlayerCharacter.AICharacter character) { //Add your code below. KeysPressed keysPressed = character.getEntity().getKeysPressed(); keysPressed.reset(); if (isWaiting) { if (character.transform.position.x > player.transform.position.x) { character.SpriteRenderer.flipX = true; } if (character.transform.position.x < player.transform.position.x) { character.SpriteRenderer.flipX = false; } } else { if (newPosition.x > 0.0f) { keysPressed.right = true; } if (newPosition.x < 0.0f) { keysPressed.left = true; } if (newPosition.y > 0.0f) { keysPressed.up = true; } if (newPosition.y < 0.0f) { keysPressed.down = true; } } character.KeysPressed = keysPressed; maxTimeForWalking -= Time.deltaTime; if (!isWaiting && maxTimeForWalking < 0.0f) { maxTimeForWalking = Random.Range(0.50f, 2.0f); isWaiting = true; } else if (isWaiting && maxTimeForWalking < 0.0f) { character.AiCharacterController.switchBrain(((BrainFactory)character.AiCharacterController.Factory).getAttackBrain(character)); } }
/// <summary> /// Handles keyboard input. /// </summary> /// <param name="clickData"></param> /// <param name="time"></param> public static void UpdateKeyboardInput(GameTime time) { GetChanges(out List <Keys> pressed, out List <Keys> down, out List <Keys> released); if (pressed.Count > 0) { int length = pressed.Count; for (int i = 0; i < length; i++) { KeysPressed?.Invoke(null, pressed[i]); } } if (down.Count > 0) { int length = down.Count; for (int i = 0; i < length; i++) { KeysDown?.Invoke(null, down[i]); } } if (released.Count > 0) { int length = released.Count; for (int i = 0; i < length; i++) { KeysReleased?.Invoke(null, released[i]); } } KeyboardState keyboardState = Keyboard.GetState(); Modifiers = KeyboardModifiers.None; if (keyboardState.IsKeyDown(Keys.LeftControl) || keyboardState.IsKeyDown(Keys.RightControl)) { Modifiers |= KeyboardModifiers.Control; } if (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift)) { Modifiers |= KeyboardModifiers.Shift; } if (keyboardState.IsKeyDown(Keys.LeftAlt) || keyboardState.IsKeyDown(Keys.RightAlt)) { Modifiers |= KeyboardModifiers.Alt; } }
public override void update(IEntity entity) { if (doMovement) { KeysPressed keysPressed = entity.getKeysPressed(); if (direction == -1) { keysPressed.right = (doMovement && !entity.isFlipped()); keysPressed.left = (doMovement && entity.isFlipped()); } /*else * { * keysPressed.right = false; * keysPressed.left = false; * } * /* * up = 0 * up-left = 7 up-right = 1 * left = 6 right = 2 * down-left = 5 down-right = 3 * down = 4 * * if(direction >= 1 && direction <= 3) * { * keysPressed.right = true; * } * if (direction >= 5 && direction <= 7) * { * keysPressed.left = true; * } * * if ((direction >= 0 && direction <= 1) || direction == 7) * { * keysPressed.up = true; * } * if (direction >= 3 && direction <= 5) * { * keysPressed.down = true; * } */ Gravity gravity = entity.getGravity(); moveEntityUp(entity, keysPressed, gravity, entity.getMovementSpeed()); moveEntityDown(entity, keysPressed, gravity, entity.getMovementSpeed()); moveEntity(entity, keysPressed, gravity, entity.getMovementSpeed()); } }
public void Device_KeyboardInput(object sender, KeyboardInputEventArgs e) { if (e.State == KeyState.Pressed) { if (KeysDown.Contains(e.Key) == false) { KeysPressed.Add(e.Key); KeysDown.Add(e.Key); } } else if (e.State == KeyState.Released) { KeysReleased.Add(e.Key); KeysDown.Remove(e.Key); } }
protected virtual void switchState(IEntity entity, KeysPressed keysPressed, Gravity gravity, IGravityClient gravityClient) { if (!keysPressed.jump) { if (gravity.Y_velocity >= 0.0f && (gravityClient.getJumpForce() * 0.85f) > gravity.Y_velocity) { gravity.Y_velocity = -0.01f; } } if (gravity.isFalling() || gravity.isStanding()) { gravity.Jumping = false; IBehaviourStateFactory behaviourStateFactory = entity.getBehaviourStateFactory(); entity.setState(behaviourStateFactory.getFallState(entity)); } }
public override void update(GameLib.Entity.NonPlayerCharacter.AICharacter character) { //Add your code below. KeysPressed keysPressed = character.getEntity().getKeysPressed(); keysPressed.reset(); character.KeysPressed = keysPressed; respawnTimer -= Time.deltaTime; if (respawnTimer < 0.0f) { Sun sun = GameObject.FindGameObjectWithTag("Sun").GetComponent <Sun>(); sun.respawn(character.gameObject); } }
public override void update(IEntity entity) { Gravity gravity = entity.getGravity(); KeysPressed keysPressed = entity.getKeysPressed(); if (keysPressed.attack) { Player player = entity.getTransform().gameObject.GetComponent <Player>(); IBehaviourStateFactory behaviourStateFactory = entity.getBehaviourStateFactory(); if (player != null && player.IsNearShop) { if (keysPressed.actionButtonOne) { entity.setState(((BehaviourStateFactory)behaviourStateFactory).getShopState(entity)); } } else { int direction = (!keysPressed.left && !keysPressed.right && !keysPressed.up && !keysPressed.down) ? -1 : getDirection(keysPressed); entity.setState(((BehaviourStateFactory)behaviourStateFactory).getAttackState(entity, direction)); } } else { IGravityClient gravityClient = entity.getGravityClient(); bool moving = false; moving = moveEntityUp(entity, keysPressed, gravity, entity.getMovementSpeed()); if (!moving) { moving = moveEntityDown(entity, keysPressed, gravity, entity.getMovementSpeed()); } if (moveEntity(entity, keysPressed, gravity, entity.getMovementSpeed())) { moving = true; } entity.setMoving(moving); if (!keysPressed.left && !keysPressed.right && !keysPressed.up && !keysPressed.down) { goIdle(entity); } } }
public bool moveEntityUp(IEntity entity, KeysPressed keysPressed, Gravity gravity, float movementSpeed) { IGravityClient gravityClient = entity.getGravityClient(); bool moving = false; #if USE_3D_RAYS RayHitboxes3D rayHitboxes = gravityClient.getRayHitboxes3D(); #else RayHitboxes rayHitboxes = gravityClient.getRayHitboxes(); #endif Vector3 angles = new Vector3(entity.getTransform().eulerAngles.x, entity.getTransform().eulerAngles.y, entity.getTransform().eulerAngles.z); #if USE_3D_RAYS RayInformation3D rayInformation = gravityClient.getRayInformation3D(); #else RayInformation rayInformation = gravityClient.getRayInformation(); #endif if (keysPressed.up && !keysPressed.down) { rayInformation.checkRaysTop(gravityClient, 0.0f, angles.z + 90.0f, layermask); } bool isWalking = !entity.getGravity().isFalling() && !entity.getGravity().Jumping; float frontDistance = rayHitboxes.DistanceTop; if (frontDistance > rayInformation.MinimalSpaceBetweenTileTop) { if (keysPressed.up && !keysPressed.down) { moving = true; Vector3 pos = entity.getTransform().position; pos.y += ((frontDistance - rayInformation.MinimalSpaceBetweenTileTop) < movementSpeed * Time.fixedDeltaTime) ? (frontDistance - rayInformation.MinimalSpaceBetweenTileTop) : movementSpeed * Time.fixedDeltaTime; entity.getTransform().position = pos; gravity.Reset = false; } } return(moving); }
public override void update(IEntity entity) { Gravity gravity = entity.getGravity(); KeysPressed keysPressed = entity.getKeysPressed(); IBehaviourStateFactory behaviourStateFactory = entity.getBehaviourStateFactory(); if (keysPressed.jump && gravity.isStanding() && entity.getJumpedReleased()) { entity.setState(behaviourStateFactory.getJumpUpState(entity)); } else if (gravity.isStanding() && ((keysPressed.left && !keysPressed.right) || (!keysPressed.left && keysPressed.right))) { entity.setState(behaviourStateFactory.getMoveState(entity)); } else if (!gravity.isStanding()) { entity.setState(behaviourStateFactory.getFallState(entity)); } }
/// <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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } var keyboardState = Keyboard.GetState(); var input = new KeysPressed { Up = keyboardState.IsKeyDown(Keys.Up), Down = keyboardState.IsKeyDown(Keys.Down), Left = keyboardState.IsKeyDown(Keys.Left), Right = keyboardState.IsKeyDown(Keys.Right) }; _gameState.Update(input, gameTime.ElapsedGameTime); base.Update(gameTime); }
public void Action(string action) { var actionData = action.Split(' '); switch (actionData[0]) { case "key_down": { Enum.TryParse <ControlActions>(actionData[1], true, out var result); KeysPressed.Add(result); break; } case "key_up": { Enum.TryParse <ControlActions>(actionData[1], true, out var result); KeysPressed.Remove(result); break; } } }
public override void update(GameLib.Entity.NonPlayerCharacter.AICharacter character) { //Add your code below. // Debug.Log("Dog is attacking"); //1 if in position do the attack posTar = ((NonPlayerCharacter.Dog)character).target.transform.position; pos = ((NonPlayerCharacter.Dog)character).transform.position; KeysPressed keysPressed = character.getEntity().getKeysPressed(); keysPressed.reset(); attackCoolDown -= Time.deltaTime; if (attackCoolDown <= 0.0f && maxAttackDistance >= Vector2.Distance(posTar, pos)) { attackCoolDown = Random.Range(2.0f, 4.0f); keysPressed.attack = true; } if ((pos.y) < (posTar.y - 0.1f)) { keysPressed.up = true; } if (pos.y > (posTar.y + 0.1f)) { keysPressed.down = true; } if (pos.x < (posTar.x - 0.1f)) { keysPressed.right = true; } if (pos.x > (posTar.x + 0.1f)) { keysPressed.left = true; } character.KeysPressed = keysPressed; }
public override void update(IEntity entity) { Gravity gravity = entity.getGravity(); KeysPressed keysPressed = entity.getKeysPressed(); moveEntity(entity, keysPressed, gravity, entity.getMovementSpeed()); if (gravity.isStanding() || gravity.isNotFalling()) { entity.playAudio(AudioAttributes.LANDING_SOUND); IBehaviourStateFactory behaviourStateFactory = entity.getBehaviourStateFactory(); if (!keysPressed.left && !keysPressed.right) { entity.setState(behaviourStateFactory.getIdleState(entity)); } else { entity.setState(behaviourStateFactory.getMoveState(entity)); } } }
public static int getDirection(KeysPressed keysPressed) { int direction = -1; if (keysPressed.right) { direction = 2; if (keysPressed.up) { direction = 1; } if (keysPressed.down) { direction = 3; } } else if (keysPressed.left) { direction = 6; if (keysPressed.up) { direction = 7; } if (keysPressed.down) { direction = 5; } } else if (keysPressed.up) { direction = 0; } else if (keysPressed.down) { direction = 4; } return(direction); }
public override void update(IEntity entity) { Gravity gravity = entity.getGravity(); KeysPressed keysPressed = entity.getKeysPressed(); IGravityClient gravityClient = entity.getGravityClient(); #if USE_3D_RAYS gravityClient.getRayInformation3D().checkRaysFront(gravityClient, 0.0f, entity.getTransform().eulerAngles.z + 0.0f, entity.getGravityClient().getLayerToIgnore()); #else gravityClient.getRayInformation().checkRaysFront(gravityClient, 0.0f, entity.getTransform().eulerAngles.z + 0.0f, layermask); #endif if (keysPressed.jump && (gravity.isStanding() || #if USE_3D_RAYS (gravityClient.getRayHitboxes().DistanceBelow <= (gravityClient.getRayInformation3D().MinimalSpaceBetweenTileBelow))) && #else (gravityClient.getRayHitboxes().DistanceBelow <= (gravityClient.getRayInformation().MinimalSpaceBetweenTileBelow))) && #endif entity.getJumpedReleased()) { IBehaviourStateFactory behaviourStateFactory = entity.getBehaviourStateFactory(); entity.setState(behaviourStateFactory.getJumpUpState(entity)); moveEntity(entity, keysPressed, gravity, entity.getMovementSpeed()); }
public override void update(IEntity entity) { Gravity gravity = entity.getGravity(); KeysPressed keysPressed = entity.getKeysPressed(); Player player = entity.getTransform().gameObject.GetComponent <Player>(); IBehaviourStateFactory behaviourStateFactory = entity.getBehaviourStateFactory(); if (gravity.isStanding() && (keysPressed.down || keysPressed.up || keysPressed.left || keysPressed.right)) { entity.setState(behaviourStateFactory.getMoveState(entity)); } if (player != null && player.IsNearShop) { if (keysPressed.actionButtonOne) { entity.setState(((BehaviourStateFactory)behaviourStateFactory).getShopState(entity)); } } else { if (keysPressed.attack) { entity.setState(((BehaviourStateFactory)behaviourStateFactory).getAttackState(entity, Move.getDirection(keysPressed))); } else if (keysPressed.actionButtonOne) { entity.setState(((BehaviourStateFactory)behaviourStateFactory).getDefendState(entity)); } else { base.update(entity); } } }
/// <summary> /// Clears the <see cref="KeysPressed"/>, <see cref="KeysDown"/>, <see cref="KeysReleased"/> collections. /// </summary> public void Clear() { KeysPressed.Clear(); KeysDown.Clear(); KeysReleased.Clear(); }
public virtual void Update() { keysPressed = controller.updateInput(); }