private void PiecesMatched(StaticLetter staticLetter, MoveableLetter moveableLetter) { moveableLetter.HoverButton.IsHitTestVisible = false; staticLetter.IsMatched = moveableLetter.IsMatched = true; double newLeft = Canvas.GetLeft(lettersStackPanel) + staticLetter.Border.Width * staticLetter.Index; double newTop = Canvas.GetTop(lettersStackPanel); Storyboard sb = new Storyboard(); DoubleAnimation daX = new DoubleAnimation(); daX.To = newLeft; daX.Duration = new Duration(TimeSpan.FromMilliseconds(500)); DoubleAnimation daY = new DoubleAnimation(); daY.To = newTop; daY.Duration = new Duration(TimeSpan.FromMilliseconds(500)); Storyboard.SetTarget(daX, movingButton); Storyboard.SetTarget(daY, movingButton); Storyboard.SetTargetProperty(daX, new PropertyPath("(Canvas.Left)")); Storyboard.SetTargetProperty(daY, new PropertyPath("(Canvas.Top)")); sb.Children.Add(daX); sb.Children.Add(daY); sb.Begin(); //Canvas.SetLeft(movingButton, newLeft); //Canvas.SetTop(movingButton, newTop); }
private void CheckForCollision() { //get stackpanel top and left compared to the canvas double stackPanelLeft = Canvas.GetLeft(lettersStackPanel); double stackPanelTop = Canvas.GetTop(lettersStackPanel); //get moving letter's top and left double letterLeft = Canvas.GetLeft(movingButton); double letterTop = Canvas.GetTop(movingButton); int width = 0; //check for collision for (int i = 0; i < lettersStackPanel.Children.Count; i++) { Border b = lettersStackPanel.Children[i] as Border; if (staticLetters[i].IsMatched) { width += (int)b.Width; continue; //already matched } double distance = Math.Sqrt(Math.Pow(stackPanelLeft + width - letterLeft, 2) + Math.Pow(stackPanelTop - letterTop, 2)); StaticLetter staticLetter = staticLetters.Where(x => x.Border == b).Single(); MoveableLetter moveableLetter = movingLetters.Where(x => x.HoverButton == movingButton).Single(); if (distance < Utilities.DistanceForSucking && staticLetter.Index == moveableLetter.Index) //if it's the same letter { kinectState = KinectState.MovingCursor; PiecesMatched(staticLetter, moveableLetter); return; } width += (int)b.Width; } }