예제 #1
0
        private void createApplesAndTrees()
        {
            setAppleSize();

            Point rangeMin = new Point();
            Point rangeMax = new Point();

            Canvas[] tree = new Canvas[treesCount];
            myApple = new Apple[treesCount * applesOnTree];
            ImageBrush treeBg = new ImageBrush();

            treeBg.ImageSource = new BitmapImage(new Uri(@"../../../Graphics/ApplesGame/tree.png", UriKind.Relative));

            int appleCounter = 0;

            for (int i = 0; i < treesCount; i++)
            {
                tree[i]        = new Canvas();
                tree[i].Width  = (int)(windowWidth / treesCount * 0.5) * 1.5;//*1.7 - full screen of trees;
                tree[i].Height = (int)(windowHeight / 1.25);
                Canvas.SetTop(tree[i], 50);
                Canvas.SetLeft(tree[i], (i * tree[i].Width + 20));
                tree[i].Margin = new Thickness((i * 0.2 * tree[i].Width), 0, 20, 0);
                tree[i].Name   = "tree" + i;
                playfield.Children.Add(tree[i]);
                tree[i].Background = treeBg;

                setApplesArena(ref rangeMin, ref rangeMax);
                colorsCount = basketCount;

                for (int j = 0; j < applesOnTree; j++)
                {
                    myApple[appleCounter] = new Apple(rangeMin, rangeMax, appleSize, appleCounter, i, colorsCount);
                    var button = myApple[appleCounter].Figure;
                    button.Foreground = new SolidColorBrush(Colors.Transparent);
                    KinectRegion.AddQueryInteractionStatusHandler(button, OnQuery);
                    KinectRegion.AddHandPointerGripHandler(button, OnHandPointerGrip);
                    tree[i].Children.Add(button);
                    button.MouseEnter  += button_MouseEnter;
                    button.StylusEnter += button_StylusEnter;
                    button.MouseLeave  += button_MouseLeave;
                    button.StylusLeave += button_StylusLeave;
                    appleCounter++;
                }
            }
        }
예제 #2
0
        private void OnHandPointerGrip(object sender, HandPointerEventArgs handPointerEventArgs)
        {
            var button = sender as KinectCircleButton;

            if (handPointerEventArgs.HandPointer.IsInGripInteraction == true)
            {
                int buttonContent;
                GripOverButton = true;
                KinectRegion.AddQueryInteractionStatusHandler(kinectRegion, OnQuery);
                KinectRegion.AddHandPointerGripReleaseHandler(kinectRegion, OnHandPointerGripRelase);

                var Tree = button.Parent as Canvas;
                Tree.Children.Remove(button);
                buttonContent = (int)button.Content;
                GripApple     = myApple[buttonContent];
                Tree.Children.Remove(myApple[buttonContent].Figure);
                Treenum = GripApple.TreeNumber;
                handPointerEventArgs.Handled = true;
            }
        }
예제 #3
0
        private void OnHandPointerGripRelase(object sender, HandPointerEventArgs handPointerEventArgs)
        {
            if (handPointerEventArgs.HandPointer.IsInGripInteraction == false && GripOverButton == true)
            {
                bool  check = false;
                Point point = handPointerEventArgs.HandPointer.GetPosition(playfield);
                for (int i = 0; i < basketCount; i++)
                {
                    if ((point.X >= basket[i].Position.X) &&
                        (point.X <= basket[i].EndPosition.X) &&
                        (point.Y >= basket[i].Position.Y) &&
                        (point.Y <= basket[i].EndPosition.Y))
                    {
                        if (GripApple.Color == basket[i].Color)
                        {
                            handPointerEventArgs.Handled = true;
                            gameScore.collectSuccess();
                            check = true;
                        }
                    }
                }

                if (!check)
                {
                    handPointerEventArgs.Handled = true;
                    gameScore.collectFail();
                    check = false;
                    Apple MovingApple = new Apple(GripApple, point.X, point.Y);
                    playfield.Children.Add(MovingApple.Figure);
                    MoveTo(MovingApple, GripApple.Pos.X, GripApple.Pos.Y, point.X, point.Y);
                    KinectRegion.AddQueryInteractionStatusHandler(MovingApple.Figure, OnQuery);
                    KinectRegion.AddHandPointerGripHandler(MovingApple.Figure, OnHandPointerGrip);
                    handPointerEventArgs.Handled = true;
                }
            }
            GripOverButton = false;
        }
예제 #4
0
 void restoreAppleBackground(Apple sender)
 {
     ImageBrush bg = new ImageBrush();
     //conditions
     {
         if (sender.Color == Colors.Red)
         {
             bg.ImageSource = convertBitmapToBitmapSource(Properties.Resources.red_apple);
         }
         if (sender.Color == Colors.Yellow)
         {
             bg.ImageSource = convertBitmapToBitmapSource(Properties.Resources.yellow_apple);
         }
         if (sender.Color == Colors.Green)
         {
             bg.ImageSource = convertBitmapToBitmapSource(Properties.Resources.green_apple);
         }
         if (sender.Color == Colors.Orange)
         {
             bg.ImageSource = convertBitmapToBitmapSource(Properties.Resources.orange_apple);
         }
         if (sender.Color == Colors.Brown)
         {
             bg.ImageSource = convertBitmapToBitmapSource(Properties.Resources.brown_apple);
         }
     }
     sender.Figure.Background = bg;
 }
예제 #5
0
 void appleHoverBackground(Apple sender)
 {
     ImageBrush bg = new ImageBrush();
     //conditions
     {
         if (sender.Color == Colors.Red)
         {
             bg.ImageSource = convertBitmapToBitmapSource(Properties.Resources.bgl_red);
         }
         if (sender.Color == Colors.Yellow)
         {
             bg.ImageSource = convertBitmapToBitmapSource(Properties.Resources.bgl_yellow);
         }
         if (sender.Color == Colors.Green)
         {
             bg.ImageSource = convertBitmapToBitmapSource(Properties.Resources.bgl_green);
         }
         if (sender.Color == Colors.Orange)
         {
             bg.ImageSource = convertBitmapToBitmapSource(Properties.Resources.bgl_orange);
         }
         if (sender.Color == Colors.Brown)
         {
             bg.ImageSource = convertBitmapToBitmapSource(Properties.Resources.bgl_brown);
         }
     }
     sender.Figure.Background = bg;
 }
예제 #6
0
        public void MoveTo(Apple target, double NewX, double NewY, double HandX, double HandY)
        {
                TranslateTransform trans = new TranslateTransform();
                target.Figure.RenderTransform = trans;
                //tree[] Canvas and [0,0] differences
                NewX += ((windowWidth / treesCount * 0.5) * 1.5 * Treenum + 20) + (70 * Treenum);
                NewY += windowHeight - (windowHeight / 1.25);

                //tree[i].Width = (int)(windowWidth / treesCount * 0.5) * 1.5;//*1.7 - full screen of trees;
                //tree[i].Height = (int)(windowHeight / 1.25);
                //Canvas.SetTop(tree[i], 50);
                //Canvas.SetLeft(tree[i], (i * tree[i].Width + 20));
                //tree[i].Margin = new Thickness((i * 0.2 * tree[i].Width), 0, 20, 0);

                //ActualHand and [0,0] differences
                NewX -= HandX;
                NewY -= HandY;

                NewY -= target.Size / 2;
                // NewX += target.Size / 2;
                DoubleAnimation anim1 = new DoubleAnimation(0, NewX, TimeSpan.FromSeconds(1));
                DoubleAnimation anim2 = new DoubleAnimation(0, NewY, TimeSpan.FromSeconds(1));
                trans.BeginAnimation(TranslateTransform.XProperty, anim1);
                trans.BeginAnimation(TranslateTransform.YProperty, anim2);
        }
예제 #7
0
        private void OnHandPointerGripRelase(object sender, HandPointerEventArgs handPointerEventArgs)
        {
            if (handPointerEventArgs.HandPointer.IsInGripInteraction == false && GripOverButton == true)
            {
                bool check = false;
                Point point = handPointerEventArgs.HandPointer.GetPosition(playfield);
                for (int i = 0; i < basketCount; i++)
                {
                    if ((point.X >= basket[i].Position.X)
                        && (point.X <= basket[i].EndPosition.X)
                        && (point.Y >= basket[i].Position.Y)
                        && (point.Y <= basket[i].EndPosition.Y))
                    {
                        if (GripApple.Color == basket[i].Color)
                        {
                            handPointerEventArgs.Handled = true;
                            gameScore.collectSuccess();
                            check = true;
                            if (gameScore.ApplesLeft == 0)
                            {
                                this.EndGame();
                            }
                        }
                    }
                }

                if (!check)
                {
                    handPointerEventArgs.Handled = true;
                    gameScore.collectFail();
                    check = false;
                    Apple MovingApple = new Apple(GripApple, point.X, point.Y);
                    playfield.Children.Add(MovingApple.Figure);
                    MoveTo(MovingApple, GripApple.Pos.X, GripApple.Pos.Y, point.X, point.Y);
                    KinectRegion.AddQueryInteractionStatusHandler(MovingApple.Figure, OnQuery);
                    KinectRegion.AddHandPointerGripHandler(MovingApple.Figure, OnHandPointerGrip);
                    handPointerEventArgs.Handled = true;
                }
            }
            GripOverButton = false;
        }
예제 #8
0
        private void OnHandPointerGrip(object sender, HandPointerEventArgs handPointerEventArgs)
        {

            var button = sender as KinectCircleButton;
            if (handPointerEventArgs.HandPointer.IsInGripInteraction == true)
            {
                int buttonContent;
                GripOverButton = true;
                KinectRegion.AddQueryInteractionStatusHandler(kinectRegion, OnQuery);
                KinectRegion.AddHandPointerGripReleaseHandler(kinectRegion, OnHandPointerGripRelase);

                var Tree = button.Parent as Canvas;
                Tree.Children.Remove(button);
                buttonContent = (int)button.Content;
                GripApple = myApple[buttonContent];
                Tree.Children.Remove(myApple[buttonContent].Figure);
                Treenum = GripApple.TreeNumber;
                handPointerEventArgs.Handled = true;
            }
        }
예제 #9
0
        private void createApplesAndTrees()
        {
            setAppleSize();

            Point rangeMin = new Point();
            Point rangeMax = new Point();
            Canvas[] tree = new Canvas[treesCount];
            myApple = new Apple[treesCount * applesOnTree];
            ImageBrush treeBg = new ImageBrush();
            treeBg.ImageSource = convertBitmapToBitmapSource(Properties.Resources.tree);

            int appleCounter = 0;
            for (int i = 0; i < treesCount; i++)
            {
                tree[i] = new Canvas();
                tree[i].Width = (int)(windowWidth / treesCount * 0.5) * 1.5;//*1.7 - full screen of trees;
                tree[i].Height = (int)(windowHeight / 1.25);
                Canvas.SetTop(tree[i], 50);
                Canvas.SetLeft(tree[i], (i * tree[i].Width + 20));
                tree[i].Margin = new Thickness((i * 0.2 * tree[i].Width), 0, 20, 0);
                tree[i].Name = "tree" + i;
                playfield.Children.Add(tree[i]);
                tree[i].Background = treeBg;

                setApplesArena(ref rangeMin, ref rangeMax);
                colorsCount = basketCount;

                for (int j = 0; j < applesOnTree; j++)
                {
                    myApple[appleCounter] = new Apple(rangeMin, rangeMax, appleSize, appleCounter, i, colorsCount);
                    var button = myApple[appleCounter].Figure;
                    button.Foreground = new SolidColorBrush(Colors.Transparent);
                    KinectRegion.AddQueryInteractionStatusHandler(button, OnQuery);
                    KinectRegion.AddHandPointerGripHandler(button, OnHandPointerGrip);
                    tree[i].Children.Add(button);
                    button.MouseEnter += button_MouseEnter;
                    button.StylusEnter += button_StylusEnter;
                    button.MouseLeave += button_MouseLeave;
                    button.StylusLeave += button_StylusLeave;
                    appleCounter++;
                }
            }
        }
예제 #10
0
        public Apple(Apple target, double x, double y)
        {

            //Setting point 
            Pos = new Point(x, y);
            Size = target.Size;

            //Creating Ellipse filled with image
            Figure = new KinectCircleButton();

            if (target.Color == Colors.Red)
                setAppleGraphics(1);
            if (target.Color == Colors.Green)
                setAppleGraphics(2);
            if (target.Color == Colors.Yellow)
                setAppleGraphics(3);
            if (target.Color == Colors.Orange)
                setAppleGraphics(4);
            if (target.Color == Colors.Brown)
                setAppleGraphics(5);

            // Set the width and height of the Ellipse.
            Figure.Width = target.Size;
            Figure.Height = target.Size;

            // Set position of figure
            Figure.Margin = new Thickness(Pos.X, Pos.Y, 0, 0);
            Figure.Name = "Apple" + target.Number;
            Figure.Content = int.Parse(Figure.Name.Substring(5));
            Figure.Foreground = new SolidColorBrush(Colors.Transparent);
            TreeNumber = target.TreeNumber;
        }