private static void PollTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { lock (locker) { try { var thisCount = mQSB.GetCount(); uint countDelta = 0; bool positiveChange = false; if (thisCount > lastCount) { positiveChange = true; countDelta = thisCount - lastCount; } else { countDelta = lastCount - thisCount; } lastCount = thisCount; DirectionOfRotation oldDirection = DirectionOfRotation; if (countDelta < 40) { //not changed since last interval if (stopCount < 4) //must read a stopped value 4 times (for 400ms) to trigger a stop event { stopCount++; } else { DirectionOfRotation = DirectionOfRotation.Stopped; stopCount = 0; } } else if (countDelta >= 40 && positiveChange) { DirectionOfRotation = DirectionOfRotation.RotatingClockwise; } else if (countDelta >= 40) { DirectionOfRotation = DirectionOfRotation.RotatingCounterClockwise; } if (oldDirection != DirectionOfRotation) { if (oldDirection != DirectionOfRotation.Stopped && DirectionOfRotation != DirectionOfRotation.Stopped) { FireStopStateChange(); } FireStateChange(); } } catch (Exception exc) { Logging.Logger.Log(exc); } } pollTimer.Start(); }
public Point Rotate(DirectionOfRotation dirOfRotation) { var x0 = AbsX - RelX; var y0 = AbsY - RelY; return dirOfRotation == DirectionOfRotation.Clockwise ? new Point(-RelY, RelX,x0 - AbsY + y0,y0 + AbsX - x0) : new Point(RelY, -RelX, x0 + AbsY - y0, y0 - AbsX + x0); }
/* Comment * Does 2 things * When mouseButtonDown: Selects a Hexagon * When mouseButtonUp : Calculates Direction of Rotation, then Rotates Hexagonal Group */ void Update() { //if the screen is touched, the menu is not open, the game is not finished, can play, the rotation animation is not active if (Input.GetMouseButtonDown(0) && !UIManager.Instance.isCanvasActive && GameController.Instance.isGamePlaying && GameController.Instance.playable && HexagonalGroup.Instance.isAnimating == false) { firstClickPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y); } //if the mouse button up, the menu is not open, the game is not finished, can play, the rotation animation is not active if (Input.GetMouseButtonUp(0) && !UIManager.Instance.isCanvasActive && GameController.Instance.isGamePlaying && GameController.Instance.playable && HexagonalGroup.Instance.isAnimating == false) { secondClickPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y); currentSwipe = new Vector3(secondClickPos.x - firstClickPos.x, secondClickPos.y - firstClickPos.y); //===Tap=== if (currentSwipe.magnitude < minSwipeLength) { GameController.Instance.playable = false; SelectObject(); GameController.Instance.playable = true; return; } //===Swipe=== //if doesn't have hexagonalGroup, return if (HexagonalGroup.Instance.HasHexagonalGroup == false) { return; } GameController.Instance.playable = false; currentSwipe.Normalize(); firstClickPos = Camera.main.ScreenToWorldPoint(firstClickPos); //Swipe directional check // Swipe up if (currentSwipe.y > 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f) { swipeDirection = Swipe.Up; //rotation direction calculation if (firstClickPos.x < vectorHexagonalGroup.x) { directionOfRotation = DirectionOfRotation.Clockwise; } else { directionOfRotation = DirectionOfRotation.CounterClockwise; } } // Swipe down else if (currentSwipe.y < 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f) { swipeDirection = Swipe.Down; //rotation direction calculation if (firstClickPos.x > vectorHexagonalGroup.x) { directionOfRotation = DirectionOfRotation.Clockwise; } else { directionOfRotation = DirectionOfRotation.CounterClockwise; } } // Swipe left else if (currentSwipe.x < 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f) { swipeDirection = Swipe.Left; //rotation direction calculation if (firstClickPos.y < vectorHexagonalGroup.y) { directionOfRotation = DirectionOfRotation.Clockwise; } else { directionOfRotation = DirectionOfRotation.CounterClockwise; } } // Swipe right else if (currentSwipe.x > 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f) { swipeDirection = Swipe.Right; //rotation direction calculation if (firstClickPos.y > vectorHexagonalGroup.y) { directionOfRotation = DirectionOfRotation.Clockwise; } else { directionOfRotation = DirectionOfRotation.CounterClockwise; } } //rotate hexagon group HexagonalGroup.Instance.DoRotate(directionOfRotation); } }
public Piece Rotate(DirectionOfRotation directionOfRotation) { return new Piece(Coordinates .Select(x => x.Rotate(directionOfRotation)) .ToImmutableArray()); }