private void ChangePressedDirection(InputDirection newDirection) { if (newDirection != _lastPressedDirection) { _pressedDirectionDelay = FULL_PRESSED_DIRECTION_DELAY; _lastPressedDirection = newDirection; } }
private void ResetPressedDirection(InputDirection direction) { if (direction == _lastPressedDirection) { _pressedDirectionDelay = FULL_PRESSED_DIRECTION_DELAY; _lastPressedDirection = InputDirection.None; } }
public static bool isOppositeDirection(InputDirection dir_1, InputDirection dir_2) { switch (dir_1) { case InputDirection.Left: return dir_2 == InputDirection.Right; case InputDirection.Right: return dir_2 == InputDirection.Left; } return false; }
private bool CheckDirectional(InputDetectionType detectionType, InputDirection direction, DirectionalInputTypes inputTypes, Keys arrowKey, Keys WASDKey, Buttons leftThumbstick, Buttons rightThumbstick, Buttons dPadDirection) { switch (detectionType) { case InputDetectionType.PressedOnce: return CheckDirectionalPressedOnce(direction, inputTypes, arrowKey, WASDKey, leftThumbstick, rightThumbstick, dPadDirection); case InputDetectionType.HeldDown: return CheckDirectionalHeldDown(inputTypes, arrowKey, WASDKey, leftThumbstick, rightThumbstick, dPadDirection); case InputDetectionType.Released: return CheckDirectionalReleased(inputTypes, arrowKey, WASDKey, leftThumbstick, rightThumbstick, dPadDirection); } return false; }
private bool HoldDownPress(InputDirection direction) { // returns true if there is a hold down press for this frame. if (_lastPressedDirection == direction) { _pressedDirectionDelay -= 0.1f; if (_pressedDirectionDelay <= 0.0f) { _pressedDirectionDelay = RESET_PRESSED_DIRECTION_DELAY; return true; } } return false; }
/// <summary> /// Checks if there is input in a given direction, this function takes into account the player /// </summary> /// <param name="inputDirection">The input direction to test for</param> /// <returns>If there is input in the specified direction</returns> bool HasInput(InputDirection inputDirection) { switch (inputDirection) { case InputDirection.up: if (player == 1) { return(Input.GetKeyDown(KeyCode.UpArrow)); } else { return(Input.GetKeyDown(KeyCode.W)); } case InputDirection.down: if (player == 1) { return(Input.GetKeyDown(KeyCode.DownArrow)); } else { return(Input.GetKeyDown(KeyCode.S)); } case InputDirection.left: if (player == 1) { return(Input.GetKeyDown(KeyCode.LeftArrow)); } else { return(Input.GetKeyDown(KeyCode.A)); } case InputDirection.right: if (player == 1) { return(Input.GetKeyDown(KeyCode.RightArrow)); } else { return(Input.GetKeyDown(KeyCode.D)); } } return(false); }
private bool setInput = false; //保证一次手势进行一次赋值 private void GetTouch() { if (Input.GetMouseButtonDown(0)) { touchFirst = Input.mousePosition; } if (Input.GetMouseButton(0)) { timer += Time.deltaTime; if (timer > offsetTime && !setInput) { setInput = true; touchSecond = Input.mousePosition; float disX = touchSecond.x - touchFirst.x; float disY = touchSecond.y - touchFirst.y; if (Mathf.Abs(disX) >= Mathf.Abs(disY)) { if (disX > 0) { input = InputDirection.Right; } else { input = InputDirection.Left; } } else { if (disY > 0) { input = InputDirection.Up; } else { input = InputDirection.Down; } } } } else if (Input.GetMouseButtonUp(0)) { timer = 0; input = InputDirection.Null; setInput = false; } }
/// <summary> /// 获取输入方向 /// </summary> void GetInputDirection() { //默认为空 inputDirection = InputDirection.NULL; if (Input.GetMouseButtonDown(0)) //鼠标按下 { activeInput = true; //开始输入 mousePos = Input.mousePosition; //记录按下的位置 } if (Input.GetMouseButton(0) && activeInput) //鼠标没有松开,并且曾经按下过 { Vector3 vec = Input.mousePosition - mousePos; //滑动方向 if (vec.magnitude > 20) //距离大于20才处理 { //滑动方向与+y轴夹角 var angleY = Mathf.Acos(Vector3.Dot(vec.normalized, Vector2.up)) * Mathf.Rad2Deg; //滑动方向与+x轴夹角 var anglex = Mathf.Acos(Vector3.Dot(vec.normalized, Vector2.right)) * Mathf.Rad2Deg; if (angleY <= 45) //y夹角小于45度,为向上滑动 { inputDirection = InputDirection.Up; AudioManager.instance.PlaySlideAudio(); //播放滑动音效 } else if (angleY >= 135) //y夹角大于135度,为向下滑动 { inputDirection = InputDirection.Down; AudioManager.instance.PlaySlideAudio(); //播放滑动音效 } else if (anglex <= 45) //x夹角小于45度,为向右移动 { inputDirection = InputDirection.Right; AudioManager.instance.PlaySlideAudio(); //播放滑动音效 } else if (anglex >= 135) //x夹角大于135度,为向左移动 { inputDirection = InputDirection.Left; AudioManager.instance.PlaySlideAudio(); //播放滑动音效 } //输入结束 activeInput = false; } } }
/** * @brief ブロックを落下させる */ private void FallBlock() { timerCount += Time.deltaTime; // 一定時間を超えて未設置かつ未衝突かつ衝突リストが空かつ回転可能のとき if (timerCount > TIMER_SPAN && !canSet && !isCollide && colliders.Count == 0 && canRotate) { blockPosMaxX = 40; // x座標の最大値を格納 blockPosMinX = 0; // x座標の最小値を格納 blockPosMaxZ = 40; // z座標の最大値を格納 blockPosMinZ = 0; // z座標の最小値を格納 inputDirect = InputDirection.no; // 落下したため入力なしとする timerCount = 0; // タイマーをリセットする beforeBlockPosY = blockPosition.y; blockPosition.y -= blockScale; // ブロックを下へ移動 } }
public override IEnumerator Move() { while (BattleManagerScript.Instance.CurrentBattleState != BattleState.Battle) { yield return(new WaitForFixedUpdate()); } while (MoveCoOn) { float timer = 0; InputDirection dir = (InputDirection)Random.Range(0, 4); float MoveTime = Random.Range(CharInfo.MovementTimer.x, CharInfo.MovementTimer.y); while (timer < 1) { yield return(new WaitForFixedUpdate()); while (BattleManagerScript.Instance.CurrentBattleState != BattleState.Battle) { yield return(new WaitForFixedUpdate()); } timer += Time.fixedDeltaTime / MoveTime; } if (CharInfo.Health > 0) { MoveCharOnDirection(dir); } timer = 0; MoveTime = Random.Range(CharInfo.MovementTimer.x, CharInfo.MovementTimer.y); while (timer < 1) { yield return(new WaitForFixedUpdate()); while (BattleManagerScript.Instance.CurrentBattleState != BattleState.Battle) { yield return(new WaitForFixedUpdate()); } timer += Time.fixedDeltaTime / MoveTime; } if (CharInfo.Health > 0) { MoveCharOnDirection(dir == InputDirection.Down ? InputDirection.Up : dir == InputDirection.Up ? InputDirection.Down : dir == InputDirection.Left ? InputDirection.Right : InputDirection.Left); } } }
/// <summary> /// Checks if any of the given directions are down. /// </summary> /// <param name="inputTypes">All input types to check.</param> private bool CheckDirectionalDown(PlayerIndex playerIndex, InputDirection direction, Keys WASDKey, Keys arrowKey, Buttons leftThumbStickDirection, Buttons rightThumbStickDirection, Buttons dPadDirection, InputDirectionType[] inputTypes) { //When we should check for any input type, check if the handler's inputDown is pressed. var checkForAll = inputTypes.Contains(InputDirectionType.All); if ((inputTypes.Contains(InputDirectionType.WASD) || checkForAll) && playerIndex == PlayerIndex.One) { if (GameInstanceProvider.IGame.GetComponentManager().GetComponent <KeyboardHandler>().KeyDown(WASDKey)) { return(true); } } if ((inputTypes.Contains(InputDirectionType.ArrowKeys) || checkForAll) && playerIndex == PlayerIndex.One) { if (GameInstanceProvider.IGame.GetComponentManager().GetComponent <KeyboardHandler>().KeyDown(arrowKey)) { return(true); } } if (inputTypes.Contains(InputDirectionType.LeftThumbStick) || checkForAll) { if (GameInstanceProvider.IGame.GetComponentManager().GetComponent <GamePadHandler>().ButtonDown(playerIndex, leftThumbStickDirection)) { return(true); } } if (inputTypes.Contains(InputDirectionType.RightThumbStick) || checkForAll) { if (GameInstanceProvider.IGame.GetComponentManager().GetComponent <GamePadHandler>().ButtonDown(playerIndex, rightThumbStickDirection)) { return(true); } } if (inputTypes.Contains(InputDirectionType.DPad) || checkForAll) { if (GameInstanceProvider.IGame.GetComponentManager().GetComponent <GamePadHandler>().ButtonDown(playerIndex, dPadDirection)) { return(true); } } //No handler has the button down? return false. return(false); }
public void Update(GameMatch match) { if (!enabled) { _UpdateValidCommand(match); return; } _UpdateValidCommand(match); InputDirection dir = ConvertToDirection(GameSystem.Instance.mClient.mInputManager.mHVDirection); Command cmd = Command.None; if (match.m_uiController == null) { return; } if (GameSystem.Instance.mClient.mInputManager.m_CmdBtn1Click && match.m_uiController.m_btns[0].cmd != Command.None) { cmd = match.m_uiController.m_btns[0].cmd; } else if (GameSystem.Instance.mClient.mInputManager.m_CmdBtn2Click && match.m_uiController.m_btns[1].cmd != Command.None) { cmd = match.m_uiController.m_btns[1].cmd; } else if (GameSystem.Instance.mClient.mInputManager.m_CmdBtn3Click && match.m_uiController.m_btns[2].cmd != Command.None) { cmd = match.m_uiController.m_btns[2].cmd; } else if (GameSystem.Instance.mClient.mInputManager.m_CmdBtn4Click && match.m_uiController.m_btns[3].cmd != Command.None) { cmd = match.m_uiController.m_btns[3].cmd; } if (curCmd != cmd || curDir != dir) { GameMsgSender.SendInput(dir, cmd); } curCmd = cmd; curDir = dir; }
public Vector2Int GetVectorFromDirection(InputDirection dir) { switch (dir) { case InputDirection.Up: return(new Vector2Int(-1, 0)); case InputDirection.Down: return(new Vector2Int(1, 0)); case InputDirection.Left: return(new Vector2Int(0, 1)); case InputDirection.Right: return(new Vector2Int(0, -1)); } return(new Vector2Int(0, -1)); }
// kinda hacky crap aaa public IEnumerator toggleChoices(ChoiceLine choiceLine, ChoiceBubble choiceBubble) { while (!ready) { InputDirection dir = Controls.getInputDirectionDown(); if (dir == InputDirection.N) { choiceLine.PreviousOption(); choiceBubble.UpdateOption(choiceLine.GetOptionIndex()); } else if (dir == InputDirection.S) { choiceLine.NextOption(); choiceBubble.UpdateOption(choiceLine.GetOptionIndex()); } yield return(null); } }
// Private functions /** @return whether the given direction is pressed or not */ private static bool IsDirectionPressed(InputDirection dir) { switch (dir) { case InputDirection.MAIN_UP: return(GetAxis(InputAxis.MAIN_VERTICAL) > DIRECTION_THRESHOLD); case InputDirection.MAIN_DOWN: return(GetAxis(InputAxis.MAIN_VERTICAL) < -DIRECTION_THRESHOLD); case InputDirection.MAIN_LEFT: return(GetAxis(InputAxis.MAIN_HORIZONTAL) > DIRECTION_THRESHOLD); case InputDirection.MAIN_RIGHT: return(GetAxis(InputAxis.MAIN_HORIZONTAL) < -DIRECTION_THRESHOLD); } return(false); }
// Update is called once per frame void Update() { previous_axis_value = axis_value; axis_value = Input.GetAxis("Horizontal"); if (axis_value > 0.0f && previous_axis_value == 0.0f) { Direction = InputDirection.RIGHT; } else if (axis_value < 0.0f && previous_axis_value == 0.0f) { Direction = InputDirection.LEFT; } else { Direction = InputDirection.NONE; } }
public static InputDirection getInputDirectionDown() { if (!gameplayEnabled) { return(InputDirection.None); } InputDirection currentDir = getInputDirection(); //Hacky, probably should fix to be correct later if (currentHeldDir == currentDir) { return(InputDirection.None); } currentHeldDir = currentDir; return(currentHeldDir); }
private void Reset() { inputDirection = InputDirection.NONE; JUMP_PRESS = false; ATTACK_PRESS = false; if (UP && currentKeyboardState.IsKeyUp(Keys.Up)) { player.VelZ(0f); walkPressTime = 0f; UP = false; } if (DOWN && currentKeyboardState.IsKeyUp(Keys.Down)) { player.VelZ(0f); walkPressTime = 0f; DOWN = false; } if (RIGHT && currentKeyboardState.IsKeyUp(Keys.Right)) { player.VelX(0f); walkPressTime = 0f; RIGHT = false; } if (LEFT && currentKeyboardState.IsKeyUp(Keys.Left)) { player.VelX(0f); walkPressTime = 0f; LEFT = false; } if (JUMP_PRESS && currentKeyboardState.IsKeyUp(Keys.Space)) { JUMP_PRESS = false; } if (ATTACK_PRESS && currentKeyboardState.IsKeyUp(Keys.A)) { ATTACK_PRESS = false; } }
private void Update() { _inputPos = transform.position; _isPressed = false; #if UNITY_STANDALONE || UNITY_EDITOR if (Input.GetMouseButtonDown(0)) { _inputPos = _camera.ScreenToWorldPoint(Input.mousePosition); _isPressed = true; } #elif UNITY_ANDROID if (Input.touchCount > 0) { inputPos = _camera.ScreenToWorldPoint(Input.GetTouch(0).position); isPressed = true; } #endif if (_isPressed) { InputDirection direction = InputDirection.None; if (IsRight(transform.position, _inputPos)) { direction = InputDirection.Right; } else if (IsUpper(transform.position, _inputPos)) { direction = InputDirection.Up; } else if (IsLeft(transform.position, _inputPos)) { direction = InputDirection.Left; } else if (IsBottom(transform.position, _inputPos)) { direction = InputDirection.Down; } _OnInput?.Invoke(direction); } }
/** * @brief 最初のフレームに入る前に呼び出される関数 */ void Start() { blockPosition = new Vector3Int(20, 180, 20); blockQuaternion = transform.rotation; blockTransform = transform; blockTransform.position = blockPosition; blockTransform.rotation = blockQuaternion; blockScale = (int)transform.GetChild(0).lossyScale.x; canSet = false; isCollide = false; inputDirect = InputDirection.no; colliders = new List <ColliderList>(); beforeBlockPosX = blockPosition.x; beforeBlockPosY = blockPosition.y; beforeBlockPosZ = blockPosition.z; beforeQuaternion = blockQuaternion; canRotate = true; moveBlocks = new List <Transform>(); }
//Touch方法不管用。。。。(弃用) //private void GetTouch() //{ // if (Input.touchCount <= 0) // { // Debug.Log(Input.touchCount); // return; // } // else if (Input.touchCount == 1) // { // Debug.Log(Input.touchCount); // if (Input.touches[0].phase == TouchPhase.Began) // { // touchFirst = Input.touches[0].position; // } // else if (Input.touches[0].phase == TouchPhase.Moved) // { // timer += Time.deltaTime; // if (timer > offsetTime && !setInput) // { // setInput = true; // touchSecond = Input.touches[0].position; // float disX = touchSecond.x - touchFirst.x; // float disY = touchSecond.y - touchFirst.y; // if (Mathf.Abs(disX) >= Mathf.Abs(disY)) // { // if (disX > 0) // { // input = InputDirection.Right; // } // else // { // input = InputDirection.Left; // } // } // else // { // if (disY > 0) // { // input = InputDirection.Up; // } // else // { // input = InputDirection.Down; // } // } // } // } // else if(Input.touches[0].phase == TouchPhase.Ended) // { // timer = 0; // input = InputDirection.Null; // setInput = false; // } // } //} //void OnGUI() // 滑动方法 //{ // if (Event.current.type == EventType.MouseDown) // //判断当前手指是按下事件 // { // touchFirst = Event.current.mousePosition;//记录开始按下的位置 // } // if (Event.current.type == EventType.MouseDrag) // //判断当前手指是拖动事件 // { // touchSecond = Event.current.mousePosition; // timer += Time.deltaTime; //计时器 // if (timer > offsetTime) // { // touchSecond = Event.current.mousePosition; //记录结束下的位置 // Vector2 slideDirection = touchFirst - touchSecond; // float x = slideDirection.x; // float y = slideDirection.y; // if (y + SlidingDistance < x && y > -x - SlidingDistance) // { // if (input == InputDirection.Left) // { // return; // } // //Debug.Log("right"); // input = InputDirection.Left; // } // else if (y > x + SlidingDistance && y < -x - SlidingDistance) // { // if (input == InputDirection.Right) // { // return; // } // //Debug.Log("left"); // input = InputDirection.Right; // } // else if (y > x + SlidingDistance && y - SlidingDistance > -x) // { // if (input == InputDirection.Up) // { // return; // } // //Debug.Log("up"); // input = InputDirection.Up; // } // else if (y + SlidingDistance < x && y < -x - SlidingDistance) // { // if (input == InputDirection.Down) // { // return; // } // //Debug.Log("Down"); // input = InputDirection.Down; // } // timer = 0; // touchFirst = touchSecond; // } // if (Event.current.type == EventType.MouseUp) // {//滑动结束 // input = InputDirection.Null; // } // } //} //键盘输入 private void GetInput() { input = InputDirection.Null; if (Input.GetKeyDown(KeyCode.W)) { input = InputDirection.Up; } else if (Input.GetKeyDown(KeyCode.S)) { input = InputDirection.Down; } else if (Input.GetKeyDown(KeyCode.A)) { input = InputDirection.Left; } else if (Input.GetKeyDown(KeyCode.D)) { input = InputDirection.Right; } }
public InputControl(Entity player, PlayerIndex index) { this.player = player; this.playerIndex = index; inputDirection = InputDirection.NONE; currentKeyboardState = new KeyboardState(); currentPadState = new GamePadState(); pressedState = new InputBuffer(InputHelper.ButtonState.Pressed); releasedState = new InputBuffer(InputHelper.ButtonState.Released); heldState = new InputBuffer(InputHelper.ButtonState.Held, 200); UP = false; DOWN = false; LEFT = false; RIGHT = false; JUMP_PRESS = false; ATTACK_PRESS = false; }
public static float DirectionToAngle(InputDirection dir) { if (dir == InputDirection.Right) { return(0.0f); } if (dir == InputDirection.Up) { return(90.0f); } if (dir == InputDirection.Left) { return(180.0f); } if (dir == InputDirection.Down) { return(-90.0f); } return(0.0f); }
void GetInputDirection() { inputDirection = InputDirection.NULL; if (Input.GetMouseButtonDown(0)) { activeInput = true; mousePos = Input.mousePosition; } if (Input.GetMouseButton(0) && activeInput) { Vector3 vec = Input.mousePosition - mousePos; if (vec.magnitude > 20) { var angleY = Mathf.Acos(Vector3.Dot(vec.normalized, Vector2.up)) * Mathf.Rad2Deg; var angleX = Mathf.Acos(Vector3.Dot(vec.normalized, Vector2.right)) * Mathf.Rad2Deg; //Debug.Log(angle); if (angleY <= 45) { inputDirection = InputDirection.Up; AudioManager.instance.PlaySlideAudio(); } else if (angleY >= 135) { inputDirection = InputDirection.Down; AudioManager.instance.PlaySlideAudio(); } if (angleX <= 45) { inputDirection = InputDirection.Right; AudioManager.instance.PlaySlideAudio(); } else if (angleX >= 135) { inputDirection = InputDirection.Left; AudioManager.instance.PlaySlideAudio(); } activeInput = false; //Debug.Log(inputDirection); } } }
public void ResetAll() { speed = init_speed; inputDirection = InputDirection.None; activeInput = false; standPosition = Position.Middle; xDirection = Vector3.zero; moveDirection = Vector3.zero; isRoll = false; canDoubleJumo = false; isQuickMove = false; quickMoveTimeLeft = 0; magnetTimeLeft = 0; shoeTimeLeft = 0; mulipltTimeLeft = 0; gameObject.transform.position = new Vector3(0, 0, -64); Camera.main.transform.position = new Vector3(0, 5, -70); Debug.Log("Reset"); AnimationManager._instance.animationHandler = AnimationManager._instance.PlayRun; }
private void StoreAxesDirections() { //Wheel _lastWheelState = _wheelState; _wheelAxisValue = Input.GetAxis("Mouse ScrollWheel"); _wheelState = (_wheelAxisValue > 0.8f ? InputDirection.Positive : (_wheelAxisValue < -0.8f ? InputDirection.Negative : InputDirection.None)); //Controllers StoreLastAxesDirections(); for (int controllerId = 0; controllerId < _controllerTypes.Length; controllerId++) { for (int axis = 0; axis < AXES_COUNT; axis++) { float axisValue = Axis(controllerId + 1, (ControllerAxis)axis); _axesInputs[controllerId, axis] = (axisValue > 0.8f ? InputDirection.Positive : (axisValue < -0.8f ? InputDirection.Negative : InputDirection.None)); } } }
private void Instance_LeftJoystickUsedEvent(int player, InputDirection dir) { if (Time.time > TimeOffset + CoolDown) { Debug.Log(dir.ToString()); switch (dir) { case InputDirection.Up: selectedButton--; TimeOffset = Time.time; break; case InputDirection.Down: selectedButton++; TimeOffset = Time.time; break; } selectedButton = selectedButton >= Buttons.Count ? Buttons.Count - 1 : selectedButton < 0 ? 0 : selectedButton; SelectButton(); } }
void SetDirection(float input) { if (input > 0.1) { m_inputDirection = InputDirection.RIGHT; Vector2 scale = transform.localScale; scale.x = -1.0f; transform.localScale = scale; } else if (input < -0.1) { m_inputDirection = InputDirection.LEFT; Vector2 scale = transform.localScale; scale.x = 1.0f; transform.localScale = scale; } else { m_inputDirection = InputDirection.IDLE; } }
public virtual void Update() { if (!InFocus()) { if (gainFocus) { inFocus = true; } return; } if (!gainFocus) { inFocus = false; return; } ; InputDirection dir = Controls.getInputDirectionDown(); group.FocusNextElementInDirection(dir); if (Controls.confirmInputDown()) { group.SelectElement(group.currentMenuElementIndex); } if (Controls.cancelInputDown()) { AudioMaster.instance.PlayCancelSfx(); if (!isGameplayMenu) { CloseReopen(); } else { Close(); RpgGameManager.instance.ResumeGameplay(); } } }
void FlipCharacter(InputDirection pDirection) { Vector3 tScale = transform.localScale; switch (pDirection) { case InputDirection.Left: tScale.x = -1; break; case InputDirection.Right: tScale.x = 1; break; default: break; } if (tScale != transform.localScale) { transform.localScale = tScale; } }
public void InputHandle(InputDirection direction) { if (!_isMyTurn) //Only play if its turn of player { return; } if (direction != InputDirection.None) { int x = (int)transform.position.x; int y = (int)transform.position.y; if (direction == InputDirection.Right) { x++; } else if (direction == InputDirection.Left) { x--; } else if (direction == InputDirection.Up) { y++; } else if (direction == InputDirection.Down) { y--; } if (MakeAction(x, y)) { _isMyTurn = false; _OnAction?.Invoke(); } _subject?.Notify(ObserverEvent.FirstInput); } }
public void Reset() { Debug.Log("reset"); speed = init_speed = 1; inputDirection = InputDirection.NULL; activeInput = false; //left & right standPosition = Position.Middle; LeftRightDirection = Vector3.zero; moveDirection = Vector3.zero; //sideOnRunning sideOnRunning = SideOnRunning.Side1; transform.localEulerAngles = new Vector3(0, 0, 0); //jump & roll isJumping = false; isRolling = false; //speed up quickMoveTimeLeft = 0; isQuickMoving = false; //magnet magnetTimeLeft = 0; //multiply multiplyTimeLeft = 0; //add speed speedAddCount = 0; //life life = 1; gameObject.transform.position = new Vector3(574f, 91.66f, -560f); Camera.main.transform.position = new Vector3(574f, 156.16f, -525.5f); anim.SetBool("isRunning", true); RoadSetter.instance.RemoveItem(RoadSetter.instance.Side1); RoadSetter.instance.RemoveItem(RoadSetter.instance.Side2); RoadSetter.instance.RemoveItem(RoadSetter.instance.Side3); RoadSetter.instance.RemoveItem(RoadSetter.instance.Side4); RoadSetter.instance.AddItem(RoadSetter.instance.Side1); }
public static float DistanceInDirection(Vector2 originObj, Vector2 distanceObj, InputDirection direction, Vector2 offsets) { switch (direction) { case (InputDirection.Up): return(distanceObj.y - originObj.y - offsets.y); case (InputDirection.Down): return(originObj.y - distanceObj.y - offsets.y); case (InputDirection.Right): return(distanceObj.x - originObj.x - offsets.x); case (InputDirection.Left): return(originObj.x - distanceObj.x - offsets.x); default: Debug.LogError("input direction not an option"); break; } Debug.LogError("Returning a default length, please fix the switch error"); return(0f); }
public Grid_UIButton GetButtonFurthestInDirection(InputDirection comparison) { if (ActiveButtons.Length == 0) { return(null); } Grid_UIButton furthestInDirection = null; for (int i = 0; i < ActiveButtons.Length; i++) { if (furthestInDirection == null) { furthestInDirection = ActiveButtons[i]; } else if (Compare.InDirectionTo(ActiveButtons[i].transform.position, furthestInDirection.transform.position, comparison)) { furthestInDirection = ActiveButtons[i]; } } return(furthestInDirection); }
/// <summary> /// adds a GamePad DPad press to this VirtualButton /// </summary> /// <returns>The game pad DP ad.</returns> /// <param name="gamepadIndex">Gamepad index.</param> /// <param name="direction">Direction.</param> public VirtualButton AddGamePadDPad(int gamepadIndex, InputDirection direction) { switch (direction) { case InputDirection.Up: Nodes.Add(new GamePadDPadUp(gamepadIndex)); break; case InputDirection.Down: Nodes.Add(new GamePadDPadDown(gamepadIndex)); break; case InputDirection.Left: Nodes.Add(new GamePadDPadLeft(gamepadIndex)); break; case InputDirection.Right: Nodes.Add(new GamePadDPadRight(gamepadIndex)); break; } return(this); }
public static bool isOppositeDirection(InputDirection dir_1, InputDirection dir_2) { switch (dir_1) { case InputDirection.North: return (dir_2 == InputDirection.SouthEast || dir_2 == InputDirection.South || dir_2 == InputDirection.SouthWest); case InputDirection.NorthEast: return (dir_2 == InputDirection.West || dir_2 == InputDirection.South || dir_2 == InputDirection.SouthWest); case InputDirection.East: return (dir_2 == InputDirection.NorthWest || dir_2 == InputDirection.West || dir_2 == InputDirection.SouthWest); case InputDirection.SouthEast: return (dir_2 == InputDirection.NorthWest || dir_2 == InputDirection.West || dir_2 == InputDirection.North); case InputDirection.South: return (dir_2 == InputDirection.NorthEast || dir_2 == InputDirection.North || dir_2 == InputDirection.NorthWest); case InputDirection.SouthWest: return (dir_2 == InputDirection.East || dir_2 == InputDirection.North || dir_2 == InputDirection.NorthEast); case InputDirection.West: return (dir_2 == InputDirection.SouthEast || dir_2 == InputDirection.East || dir_2 == InputDirection.NorthEast); case InputDirection.NorthWest: return (dir_2 == InputDirection.SouthEast || dir_2 == InputDirection.South || dir_2 == InputDirection.East); } return false; }
public static bool InDirectionTo(Vector2 isObject, Vector2 comparedToObject, InputDirection comparison) { switch (comparison) { case (InputDirection.Up): return(isObject.y > comparedToObject.y); case (InputDirection.Down): return(isObject.y < comparedToObject.y); case (InputDirection.Right): return(isObject.x > comparedToObject.x); case (InputDirection.Left): return(isObject.x < comparedToObject.x); default: Debug.LogError("input direction not an option"); break; } Debug.LogError("Positions of comparison are equal, neither is larger"); return(false); }
public void AnimManager(InputDirection dir) { string targetClip = null; switch (dir) { case InputDirection.Right: targetClip = m_constRightJump; break; case InputDirection.Left: targetClip = m_constLeftJump; break; case InputDirection.Down: targetClip = m_constRoll; break; case InputDirection.Up: targetClip = m_constJump; break; } PlayAnimClip(targetClip); }
public static Vector2 getVector(InputDirection dir) { switch (dir) { case Parameters.InputDirection.North: return new Vector2(0, 1); case Parameters.InputDirection.NorthEast: return new Vector2(Mathf.Sin(Mathf.PI / 2), Mathf.Sin(Mathf.PI / 2)); case Parameters.InputDirection.East: return new Vector2(1, 0); case Parameters.InputDirection.SouthEast: return new Vector2(Mathf.Sin(Mathf.PI / 2), Mathf.Sin(3 * Mathf.PI / 2)); case Parameters.InputDirection.South: return new Vector2(0, -1); case Parameters.InputDirection.SouthWest: return new Vector2(Mathf.Sin(3 * Mathf.PI / 2), Mathf.Sin(3 * Mathf.PI / 2)); case Parameters.InputDirection.West: return new Vector2(-1, 0); case Parameters.InputDirection.NorthWest: return new Vector2(Mathf.Sin(3 * Mathf.PI / 2), Mathf.Sin(Mathf.PI / 2)); } return Vector2.zero; }
public static InputDirection getOppositeDirection(InputDirection dir) { switch (dir) { case InputDirection.North: return InputDirection.South; case InputDirection.NorthEast: return InputDirection.SouthWest; case InputDirection.East: return InputDirection.West; case InputDirection.SouthEast: return InputDirection.NorthWest; case InputDirection.South: return InputDirection.North; case InputDirection.SouthWest: return InputDirection.NorthEast; case InputDirection.West: return InputDirection.East; case InputDirection.NorthWest: return InputDirection.SouthEast; } return InputDirection.Stop; }
void SetDirection(float input) { if (input > 0.1) { m_inputDirection = InputDirection.RIGHT; Vector2 scale = transform.localScale; scale.x = -1.0f; transform.localScale = scale; } else if(input < -0.1) { m_inputDirection = InputDirection.LEFT; Vector2 scale = transform.localScale; scale.x = 1.0f; transform.localScale = scale; } else { m_inputDirection = InputDirection.IDLE; } }
public bool IsInputDirection(InputDirection input) { return (inputDirection == input); }
public static InputDirection getOppositeDirection(InputDirection dir) { switch (dir) { case InputDirection.Left: return InputDirection.Right; case InputDirection.Right: return InputDirection.Left; } return InputDirection.Left; }
public void UpdateDefaultControls(GameTime gameTime) { Reset(); if (player.IsNonActionState()) { if (!DOWN && currentKeyboardState.IsKeyDown(Keys.Up)) { if (!RIGHT && currentKeyboardState.IsKeyDown(Keys.Left)) { inputDirection = InputDirection.UP_LEFT; player.VelX(-5); player.SetIsLeft(true); LEFT = true; } else if (!LEFT && currentKeyboardState.IsKeyDown(Keys.Right)) { inputDirection = InputDirection.UP_RIGHT; player.VelX(5); player.SetIsLeft(false); RIGHT = true; } else { inputDirection = InputDirection.UP; } player.SetAnimationState(Animation.State.WALK_TOWARDS); player.VelZ(-5); UP = true; } else if (!UP && currentKeyboardState.IsKeyDown(Keys.Down)) { if (!RIGHT && currentKeyboardState.IsKeyDown(Keys.Left)) { inputDirection = InputDirection.DOWN_LEFT; player.VelX(-5); player.SetIsLeft(true); LEFT = true; } else if (!LEFT && currentKeyboardState.IsKeyDown(Keys.Right)) { inputDirection = InputDirection.DOWN_RIGHT; player.VelX(5); player.SetIsLeft(false); RIGHT = true; } else { inputDirection = InputDirection.DOWN; } player.SetAnimationState(Animation.State.WALK_TOWARDS); player.VelZ(5); DOWN = true; } } if (!IsDirectionalPress() && player.IsNonActionState()) { if (!RIGHT && currentKeyboardState.IsKeyDown(Keys.Left)) { inputDirection = InputDirection.LEFT; walkPressTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (walkPressTime >= 120) { player.SetAnimationState(Animation.State.WALK_TOWARDS); player.VelX(-5); walkPressTime = 0f; } player.SetIsLeft(true); LEFT = true; } else if (!LEFT && currentKeyboardState.IsKeyDown(Keys.Right)) { inputDirection = InputDirection.RIGHT; walkPressTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (walkPressTime >= 120) { player.SetAnimationState(Animation.State.WALK_TOWARDS); player.VelX(5); walkPressTime = 0f; } player.SetIsLeft(false); RIGHT = true; } } if ((currentKeyboardState.IsKeyDown(Keys.Space)) && (!oldKeyboardState.IsKeyDown(Keys.Space))) { JUMP_PRESS = true; } if ((currentKeyboardState.IsKeyDown(Keys.A)) && (!oldKeyboardState.IsKeyDown(Keys.A))) { ATTACK_PRESS = true; } if ((currentKeyboardState.IsKeyDown(Keys.Z)) && (!oldKeyboardState.IsKeyDown(Keys.Z))) { player.GetCurrentSprite().IncrementFrame(); } if (player.IsNonActionState()) { if (JUMP_PRESS) { if (LEFT) { player.SetJump(-29f, -5f); } else if (RIGHT) { player.SetJump(-29f, 5f); } else { player.SetJump(-29f); } } } if (ATTACK_PRESS) { if (!player.IsToss()) { player.AttackChainStep(); } else { if (!player.IsInAnimationAction(Animation.Action.ATTACKING) && !player.IsInAnimationAction(Animation.Action.RECOVERY)) { if (player.GetTossInfo().velocity.X == 0.0) { if (!player.InAir()) { player.SetAnimationState(Animation.State.JUMP_START); player.SetJumpLink(Animation.State.JUMP_ATTACK1); } else { player.SetAnimationState(Animation.State.JUMP_ATTACK1); } player.SetAnimationLink(Animation.State.JUMP_ATTACK1, Animation.State.JUMP_RECOVER1, player.GetSprite(Animation.State.JUMP_ATTACK1).GetFrames()); } else { if (!player.InAir()) { player.SetAnimationState(Animation.State.JUMP_START); player.SetJumpLink(Animation.State.JUMP_TOWARD_ATTACK1); } else { player.SetAnimationState(Animation.State.JUMP_TOWARD_ATTACK1); } player.SetAnimationLink(Animation.State.JUMP_TOWARD_ATTACK1, Animation.State.JUMP_RECOVER1, player.GetSprite(Animation.State.JUMP_TOWARD_ATTACK1).GetFrames()); } } } } }
/// <summary> /// Initializes a new instance of the <see cref="InputDirectionAttribute" /> class. /// </summary> /// <param name="inputDirection">The input direction.</param> public InputDirectionAttribute(InputDirection inputDirection) { this.InputDirection = inputDirection; }
public static Vector2 VectorToDir(InputDirection dir) { switch (dir) { case Parameters.InputDirection.Left: return new Vector2(-1, 0); case Parameters.InputDirection.Right: return new Vector2(1, 0); } return Vector2.zero; }
private bool CheckDirectionalPressedOnce(InputDirection direction, DirectionalInputTypes inputTypes, Keys arrowKey, Keys WASDKey, Buttons leftThumbstick, Buttons rightThumbstick, Buttons dPadDirection) { bool hasAnyCommand = false; if (inputTypes.HasFlag(DirectionalInputTypes.WASD)) { if (Keyboard.IsKeyDown(WASDKey)) { hasAnyCommand = true; if (HoldDownPress(direction)) { return true; } else { if (Keyboard.IsKeyDownOnce(WASDKey)) { ChangePressedDirection(direction); return true; } } } } if (inputTypes.HasFlag(DirectionalInputTypes.ArrowKeys)) { if (Keyboard.IsKeyDown(arrowKey)) { hasAnyCommand = true; if (HoldDownPress(direction)) { return true; } else { if (Keyboard.IsKeyDownOnce(arrowKey)) { ChangePressedDirection(direction); return true; } } } } if (inputTypes.HasFlag(DirectionalInputTypes.LeftThumbstick)) { if (GamePad.IsButtonDown(leftThumbstick)) { hasAnyCommand = true; if (HoldDownPress(direction)) { return true; } else { if (GamePad.IsButtonDownOnce(leftThumbstick)) { ChangePressedDirection(direction); return true; } } } } if (inputTypes.HasFlag(DirectionalInputTypes.RightThumbstick)) { if (GamePad.IsButtonDown(rightThumbstick)) { hasAnyCommand = true; if (HoldDownPress(direction)) { return true; } else { if (GamePad.IsButtonDownOnce(rightThumbstick)) { ChangePressedDirection(direction); return true; } } } } if (inputTypes.HasFlag(DirectionalInputTypes.DPad)) { if (GamePad.IsButtonDown(dPadDirection)) { hasAnyCommand = true; if (HoldDownPress(direction)) { return true; } else { if (GamePad.IsButtonDownOnce(dPadDirection)) { ChangePressedDirection(direction); return true; } } } } if (!hasAnyCommand) ResetPressedDirection(direction); return false; }