Exemple #1
0
 public HitTestResultBehavior myHitTestResult(HitTestResult result)
 {
     if (result.VisualHit is System.Windows.Shapes.Ellipse && result.VisualHit != CurrentRec)
     {
         System.Windows.Shapes.Ellipse rect = result.VisualHit as System.Windows.Shapes.Ellipse;
         //    rect.Fill = new SolidColorBrush(Colors.Red);
         //if (currentshapX > oldpositionX + 25 || currentshapX < oldpositionX - 25 || currentshapY > oldpositionY + 25 || currentshapY < oldpositionY - 25)
         //if (((currentshapX - oldpositionX) * (currentshapX - oldpositionX) + (currentshapY - oldpositionY) * (currentshapY - oldpositionY)) > 1200)
         {
             double tempX = 0, tempY = 0;
             int    temp;
             tempX = (double)rect.GetValue(Canvas.LeftProperty);
             tempY = (double)rect.GetValue(Canvas.TopProperty);
             if (tempX != oldpositionX || tempY != oldpositionY)
             {
                 rect.SetValue(Canvas.LeftProperty, oldpositionX);
                 rect.SetValue(Canvas.TopProperty, oldpositionY);
                 //      lb1.Content = currentshapX;
                 //    lb2.Content = currentshapY;
                 temp = orb[(int)(oldpositionY - 40) / 55, (int)(oldpositionX - 40) / 55];
                 orb[(int)(oldpositionY - 40) / 55, (int)(oldpositionX - 40) / 55] = orb[(int)(tempY - 40) / 55, (int)(tempX - 40) / 55];
                 orb[(int)(tempY - 40) / 55, (int)(tempX - 40) / 55] = temp;
                 oldpositionX = tempX;
                 oldpositionY = tempY;
             }
             //   lb1.Content = oldpositionX;
             //  lb2.Content = oldpositionY;
         }
     }
     return(HitTestResultBehavior.Continue);
 }
Exemple #2
0
        private void Ellipse_MouseMove(object sender, MouseEventArgs e)
        {
            System.Windows.Shapes.Ellipse item = sender as System.Windows.Shapes.Ellipse;
            if (item.IsMouseCaptured)
            {
                System.Windows.Point pt = new System.Windows.Point(mouseX, mouseY);
                VisualTreeHelper.HitTest(this, null,
                                         new HitTestResultCallback(myHitTestResult),
                                         new PointHitTestParameters(pt));
                // Calculate the current position of the object.
                double deltaX  = e.GetPosition(null).X - mouseX;
                double deltaY  = e.GetPosition(null).Y - mouseY;
                double newLeft = deltaX + (double)item.GetValue(Canvas.LeftProperty);
                double newTop  = deltaY + (double)item.GetValue(Canvas.TopProperty);
                // Set new position of object.
                item.SetValue(Canvas.LeftProperty, newLeft);
                item.SetValue(Canvas.TopProperty, newTop);
                //add by me
                currentshapX = (double)item.GetValue(Canvas.LeftProperty);
                currentshapY = (double)item.GetValue(Canvas.TopProperty);
                // Update position global variables.
                mouseX = e.GetPosition(null).X;
                mouseY = e.GetPosition(null).Y;
                //  將正方形形圖轉成幾何圖形

                /*Geometry g = item.RenderedGeometry;
                 * //    座標位置轉換為視窗的座標
                 * g.Transform = item.TransformToAncestor(this) as MatrixTransform;
                 * VisualTreeHelper.HitTest(this, null,
                 *  new HitTestResultCallback(myHitTestResult),
                 *  new GeometryHitTestParameters(g));*/
            }
        }
Exemple #3
0
        static private void SetEllipsePosition(Ellipse ellipse, Joint joint)
        {
            var scaledJoint = joint.ScaleTo(1500, 900, k_xMaxJointScale, k_yMaxJointScale);

            Canvas.SetLeft(ellipse, scaledJoint.Position.X - (double)ellipse.GetValue(Canvas.WidthProperty) / 2);
            Canvas.SetTop(ellipse, scaledJoint.Position.Y - (double)ellipse.GetValue(Canvas.WidthProperty) / 2);
            Canvas.SetZIndex(ellipse, (int)Math.Floor(scaledJoint.Position.Z * 100));
            /*if (joint.ID == JointID.HandLeft || joint.ID == JointID.HandRight)
            {
                byte val = (byte)(Math.Floor((joint.Position.Z - 0.8) * 255 / 2));
                ellipse.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(val, val, val));
            }*/
        }
Exemple #4
0
        public void AnimateBall(ThrowResultDT result, int yPos)
        {
            resultThrow = result;
            DoubleAnimation anime = new DoubleAnimation();

            anime.From = Convert.ToDouble(ball.GetValue(Canvas.TopProperty));
            anime.To   = Convert.ToDouble(yPos);
            if (yPos > 360)
            {
                anime.Duration = TimeSpan.FromSeconds(0.1);
            }
            else if (yPos > 300)
            {
                anime.Duration = TimeSpan.FromSeconds(0.2);
            }
            else if (yPos > 240)
            {
                anime.Duration = TimeSpan.FromSeconds(0.3);
            }
            else if (yPos > 180)
            {
                anime.Duration = TimeSpan.FromSeconds(0.4);
            }
            else if (yPos > 120)
            {
                anime.Duration = TimeSpan.FromSeconds(0.5);
            }
            else
            {
                anime.Duration = TimeSpan.FromSeconds(0.6);
            }

            anime.Completed += new EventHandler(anime_Completed);
            //  anime.DecelerationRatio = 0.3;
            ball.BeginAnimation(Canvas.TopProperty, anime);
        }
Exemple #5
0
        private void SetEllipsePosition(Ellipse ellipse, Joint joint)
        {
            var scaledJoint = joint.ScaleTo(1024, 1280, k_xMaxJointScale, k_yMaxJointScale);

            Canvas.SetLeft(ellipse, scaledJoint.Position.X - (double)ellipse.GetValue(Canvas.WidthProperty) / 2);
            Canvas.SetTop(ellipse, scaledJoint.Position.Y - (double)ellipse.GetValue(Canvas.WidthProperty) / 2);
            Canvas.SetZIndex(ellipse, (int)-Math.Floor(scaledJoint.Position.Z * 100));
            if (joint.JointType == JointType.HandLeft || joint.JointType == JointType.HandRight)
            {
                byte val = (byte)(Math.Floor((joint.Position.Z - 0.8) * 255 / 2));
                ellipse.Fill = new SolidColorBrush(Color.FromRgb(val, val, val));
            }
        }
Exemple #6
0
        private void Ellipse_MouseDown(object sender, MouseButtonEventArgs e)
        {
            clearTB();
            if (changemode)  //換色模式
            {
                double x, y;
                System.Windows.Shapes.Ellipse item = sender as System.Windows.Shapes.Ellipse;
                // item.Fill = new SolidColorBrush(Colors.Red);  //delete later, just for mouse test
                ImageBrush brush = null;
                //image1.Source = new BitmapImage(new Uri("images/dark.png", UriKind.Relative));
                //brush = new ImageBrush(image1.Source);
                //item.Fill = brush;
                y = (double)item.GetValue(Canvas.LeftProperty);
                x = (double)item.GetValue(Canvas.TopProperty);
                x = (x - 40) / 55;
                y = (y - 40) / 55;
                //      lb1.Content = x;
                //     lb2.Content = y;
                if (adv_ChangeMode)
                {
                    switch (orb[(int)x, (int)y])
                    {
                    case 6:
                        heart--;
                        break;

                    case 1:
                        gold--;
                        break;

                    case 2:
                        dark--;
                        break;

                    case 3:
                        fire--;
                        break;

                    case 4:
                        water--;
                        break;

                    case 5:
                        wood--;
                        break;

                    default:
                        //  MessageBox.Show("no NUBER!!!!!");
                        break;
                    }
                    switch (adv_type)
                    {
                    case 1:
                        image1.Source = new BitmapImage(new Uri("images/gold.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        gold++;
                        orb[(int)x, (int)y] = 1;
                        break;

                    case 2:
                        image1.Source = new BitmapImage(new Uri("images/dark.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        dark++;
                        orb[(int)x, (int)y] = 2;
                        break;

                    case 3:
                        image1.Source = new BitmapImage(new Uri("images/fire.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        fire++;
                        orb[(int)x, (int)y] = 3;
                        break;

                    case 4:
                        image1.Source = new BitmapImage(new Uri("images/water.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        water++;
                        orb[(int)x, (int)y] = 4;
                        break;

                    case 5:
                        image1.Source = new BitmapImage(new Uri("images/wood.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        wood++;
                        orb[(int)x, (int)y] = 5;
                        break;

                    case 6:
                        image1.Source = new BitmapImage(new Uri("images/heart.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        heart++;
                        orb[(int)x, (int)y] = 6;
                        break;

                    default:
                        MessageBox.Show("adv no puzzle!!!!!");
                        break;
                    }
                }
                else
                {
                    if (zero[(int)x, (int)y] == 0)
                    {
                        zero[(int)x, (int)y] = 1;
                        switch (orb[(int)x, (int)y])
                        {
                        case 6:
                            heart--;
                            break;

                        case 1:
                            gold--;
                            break;

                        case 2:
                            dark--;
                            break;

                        case 3:
                            fire--;
                            break;

                        case 4:
                            water--;
                            break;

                        case 5:
                            wood--;
                            break;

                        default:
                            //  MessageBox.Show("no NUBER!!!!!");
                            break;
                        }
                        orb[(int)x, (int)y] = 6;
                        heart++;
                    }
                    switch (orb[(int)x, (int)y])
                    {
                    case 6:
                        image1.Source = new BitmapImage(new Uri("images/gold.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        heart--;
                        gold++;
                        orb[(int)x, (int)y] = 1;
                        break;

                    case 1:
                        image1.Source = new BitmapImage(new Uri("images/dark.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        gold--;
                        dark++;
                        orb[(int)x, (int)y] = 2;
                        break;

                    case 2:
                        image1.Source = new BitmapImage(new Uri("images/fire.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        dark--;
                        fire++;
                        orb[(int)x, (int)y] = 3;
                        break;

                    case 3:
                        image1.Source = new BitmapImage(new Uri("images/water.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        fire--;
                        water++;
                        orb[(int)x, (int)y] = 4;
                        break;

                    case 4:
                        image1.Source = new BitmapImage(new Uri("images/wood.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        water--;
                        wood++;
                        orb[(int)x, (int)y] = 5;
                        break;

                    case 5:
                        image1.Source = new BitmapImage(new Uri("images/heart.png", UriKind.Relative));
                        brush         = new ImageBrush(image1.Source);
                        item.Fill     = brush;
                        wood--;
                        heart++;
                        orb[(int)x, (int)y] = 6;
                        break;

                    default:
                        MessageBox.Show("no puzzle!!!!!");
                        break;
                    }
                }
                lbdark.Content  = dark + "顆";
                lbwater.Content = water + "顆";
                lbfire.Content  = fire + "顆";
                lbwood.Content  = wood + "顆";
                lbgold.Content  = gold + "顆";
                lbheart.Content = heart + "顆";
                lbcombo.Content = "最大combo數: " + ((dark / 3) + (water / 3) + (fire / 3) + (wood / 3) + (gold / 3) + (heart / 3));
            }
            else  //轉珠模式
            {
                int time;//轉珠時間
                if (comboTime.SelectionBoxItem.ToString() == "無限制")
                {
                    time = 100;
                }
                else
                {
                    time = int.Parse(comboTime.SelectionBoxItem.ToString());
                }

                //MessageBox.Show(comboTime.SelectionBoxItem.ToString());
                //timer
                timersec          = new DispatcherTimer();
                timersec.Interval = TimeSpan.FromSeconds(time);
                timersec.Tick    += timersec_Tick;
                timersec.Start();
                //
                timershow            = new DispatcherTimer();
                timershow.Interval   = TimeSpan.FromSeconds(1.0);
                timershow.Tick      += timershow_Tick;
                this.lbtimer.Content = "0";
                timershow.Start();
                //

                curmouse = e;

                System.Windows.Shapes.Ellipse item = sender as System.Windows.Shapes.Ellipse;
                CurrentRec = item;           //記錄下要移動的正方形(hittest才可以判斷)
                // item.Fill = new SolidColorBrush(Colors.Red);  //delete later, just for mouse test
                Canvas.SetZIndex(item, 100); //移動的物體總是在最上方
                mouseX = e.GetPosition(null).X;
                mouseY = e.GetPosition(null).Y;
                item.CaptureMouse();
                oldpositionX = (double)item.GetValue(Canvas.LeftProperty);
                oldpositionY = (double)item.GetValue(Canvas.TopProperty);
                //    lb1.Content = oldpositionX;
                //     lb2.Content = oldpositionY;
            }
        }
Exemple #7
0
        //private Storyboard setAnimation(Rectangle rect)
        //{
        //    // Create a duration of 2 seconds.
        //    Duration duration = new Duration(TimeSpan.FromSeconds(1));
        //    ObjectAnimationUsingKeyFrames oA = new ObjectAnimationUsingKeyFrames();
        //    ColorAnimation clorAnimation = new ColorAnimation();
        //    clorAnimation.From = Color.FromArgb(255, Convert.ToByte(new Random().Next(180, 255)), Convert.ToByte(new Random().Next(0, 255)), Convert.ToByte(new Random().Next(0, 255)));
        //    clorAnimation.To = Color.FromArgb(255, Convert.ToByte(new Random().Next(0, 255)), Convert.ToByte(new Random().Next(100, 255)), Convert.ToByte(new Random().Next(0, 255)));
        //    clorAnimation.Duration = duration;
        //    clorAnimation.AutoReverse = true;
        //    clorAnimation.RepeatBehavior = RepeatBehavior.Forever;
        //    LinearGradientBrush tempBrush = new LinearGradientBrush();
        //    tempBrush.StartPoint = new Point(0, 0);
        //    tempBrush.EndPoint = new Point(1, 1);
        //    GradientStop gs = new GradientStop();
        //    gs.Color = Color.FromArgb(Convert.ToByte(new Random().Next(100, 255)), Convert.ToByte(new Random().Next(200, 255)), Convert.ToByte(new Random().Next(50, 255)), Convert.ToByte(new Random().Next(0, 120)));
        //    gs.Offset = 0.25;
        //    tempBrush.GradientStops.Add(gs);
        //    gs = new GradientStop();
        //    gs.Color = Color.FromArgb(Convert.ToByte(new Random().Next(100, 255)), Convert.ToByte(new Random().Next(200, 255)), Convert.ToByte(new Random().Next(100, 255)), Convert.ToByte(new Random().Next(0, 120)));
        //    gs.Offset = 0.55;
        //    gs = new GradientStop();
        //    gs.Color = Color.FromArgb(Convert.ToByte(new Random().Next(100, 255)), Convert.ToByte(new Random().Next(200, 255)), Convert.ToByte(new Random().Next(150, 255)), Convert.ToByte(new Random().Next(0, 120)));
        //    gs.Offset = 0.75;
        //    tempBrush.GradientStops.Add(gs);
        //    rect.Fill = tempBrush;
        //    Storyboard sb = new Storyboard();
        //    sb.AutoReverse = true;
        //    sb.RepeatBehavior = RepeatBehavior.Forever;
        //    sb.Duration = duration;
        //    sb.Children.Add(clorAnimation);
        //    Storyboard.SetTarget(clorAnimation, gs);
        //    Storyboard.SetTargetProperty(clorAnimation, new PropertyPath(GradientStop.ColorProperty));
        //    return sb;
        //}
        public static Int16 DetectCollision(Canvas cnv,Ellipse els, Double speedX, Double speedY)
        {
            Int16 dir = 0;
            Double ballX = Convert.ToDouble(els.GetValue(Canvas.LeftProperty));
            Double ballY = Convert.ToDouble(els.GetValue(Canvas.TopProperty));
            for (int i = 0; i < rectList.Count; i++)
            {
                Rectangle tempRect = rectList.ElementAt(i);
                Double x = Convert.ToDouble(tempRect.Tag.ToString().Split(',').ElementAt(1));
                Double y = Convert.ToDouble(tempRect.Tag.ToString().Split(',').ElementAt(0));
                if (ballY + els.Height > y && ballY + els.Height < y + height / 16 && ballX + els.Width / 2 > x && ballX + els.Width / 2 < x + width / 16)
                {
                    dir += 2;
                    cnv.Children.Remove(tempRect);
                    rectList.Remove(tempRect);
                    cnv.Resources.Remove("sotryboard" + tempRect.Tag);
                    SoundManager.BrickSound();
                    if (rectList.Count == 0)
                    {
                        saveLevel();
                        dir = 9;
                    }
                    break;
                }
                if (ballY < y + height / 16 && ballY > y && ballX + els.Width / 2 > x && ballX + els.Width / 2 < x + width / 16)
                {
                    dir += 2;
                    cnv.Children.Remove(tempRect);
                    rectList.Remove(tempRect);
                    cnv.Resources.Remove("sotryboard" + tempRect.Tag);
                    SoundManager.BrickSound();
                    if (rectList.Count == 0)
                    {
                        saveLevel();
                        dir = 9;
                    }
                    break;
                }

                if (ballX + els.Width > x && ballX + width < x + width / 16 && ballY + els.Height / 2 > y && ballY + els.Height / 2 < y + height / 16)
                {
                    dir += 1;
                    cnv.Children.Remove(tempRect);
                    rectList.Remove(tempRect);
                    cnv.Resources.Remove("sotryboard" + tempRect.Tag);
                    SoundManager.BrickSound();
                    if (rectList.Count == 0)
                    {
                        saveLevel();
                        dir = 9;
                    }
                    break;
                }
                if (ballX < x + width / 16 && ballX > x && ballY + els.Height / 2 > y && ballY + els.Height / 2 < y + height / 16)
                {
                    dir += 1;
                    cnv.Children.Remove(tempRect);
                    rectList.Remove(tempRect);
                    cnv.Resources.Remove("sotryboard" + tempRect.Tag);
                    SoundManager.BrickSound();
                    if (rectList.Count == 0)
                    {
                        saveLevel();
                        dir = 9;
                    }
                    break;
                }
            }

            #region Wrong Logic
            //    if (speedX > 0)
            //    {
            //        if (ballX + els.Width > x)
            //        {
            //            if (ballY + els.Height / 2 > y && ballY + els.Height < y + height)
            //            {
            //                dir += 1;
            //                break;
            //            }
            //        }
            //    }
            //    else
            //    {
            //        if (ballX < x + width)
            //        {
            //            if (ballY + els.Height / 2 > y && ballY + els.Height < y + height)
            //            {
            //                dir += 1;
            //                break;
            //            }
            //        }

            //    }

            //    if (speedY > 0)
            //    {
            //        if (ballY + els.Height > y)
            //        {
            //            if (ballX + els.Width / 2 > x && ballX + els.Width / 2 < x + width)
            //            {
            //                dir += 2;
            //                break;
            //            }
            //        }
            //    }
            //    else
            //    {
            //        if (ballY < y + height)
            //        {
            //            if (ballX + els.Width / 2 > x && ballX + els.Width / 2 < x + width)
            //            {
            //                dir+=2;
            //                break;
            //            }
            //        }

            //    }

            //}
            #endregion Wrong Logic

            return dir;
        }