public bool CollisionDetect(BlockPhysic b1, BlockPhysic b2)
        {
            double err = -1;

            return(b1.Position.X <= b2.Position.X + b2.Size.X + err &&
                   b1.Position.X + b1.Size.X + err >= b2.Position.X &&
                   b1.Position.Y <= b2.Position.Y + b2.Size.Y + err &&
                   b1.Position.Y + b1.Size.Y + err >= b2.Position.Y);
        }
Esempio n. 2
0
        //MainWindow window = new MainWindow();
        //private Rectangle MakeRectangle(Vector position, Vector size, Brush brush)
        //{
        //    var rect = new Rectangle();
        //    rect.Width = size.X;
        //    rect.Height = size.Y;
        //    rect.Fill = brush;
        //    Canvas.SetLeft(rect, position.X);
        //    Canvas.SetTop(rect, position.Y);
        //    return rect;
        //}



        public Image CreateNewImage(BlockPhysic block, string path)
        {
            var image = new Image
            {
                Source  = BitmapFrame.Create(new Uri(path)),// орефакторить
                Stretch = Stretch.Fill,
                Width   = block.Size.X,
                Height  = block.Size.Y
            };

            //window.SetCanvasPosition(image, block.Position.X, block.Position.Y);
            return(image);
        }
Esempio n. 3
0
        public void GoingDownAnimation(BlockPhysic block, Image im, double stepY, double distance, bool isLastBlock)
        {
            StraightMoveAnimation(block, im, 0, stepY);
            if (isLastBlock)
            {
                goingDownDistance -= stepY;
            }

            if (goingDownDistance < 0)
            {
                GoingDown         = false;
                goingDownDistance = distance;
            }
        }
 /// <summary>
 /// Функция высчитавающая процент касания блоков.
 /// Возвращает значение от -100 до 100.
 /// Если блок касается правой стороны, то от правой точки нижнего блока идет подсчет положительных процентов
 /// касание на 50,30 процентов справа
 /// Если бок касается с левой стороны, то подсчет идет от левого края. Процент отрицательный.
 /// </summary>
 public double GetProcentOfTouching(BlockPhysic above, BlockPhysic under)
 {
     if (above.Position.X + above.Size.X < under.Position.X)
     {
         return(-1);
     }
     else if (above.Position.X >= under.Position.X && above.Position.X < under.Position.X + under.Size.X)
     {
         return((int)((((under.Position.X + under.Size.X) - above.Position.X) / under.Size.X) * 100));
     }
     else if (above.Position.X + above.Size.X > under.Position.X && above.Position.X + above.Size.X < under.Position.X + under.Size.X)
     {
         return(-1 * (int)(((above.Position.X + above.Size.X - under.Position.X) / under.Size.X) * 100));
     }
     else
     {
         return(1);
     }
 }
Esempio n. 5
0
 public void SwingMoveAnimation(BlockPhysic block, Image im)
 {
     block.SetNewPosition(parabola.DynamicPosition.X - block.Size.X / 2 + block.Size.X / 2, parabola.DynamicPosition.Y + block.Size.Y / 2);
     window.SetCanvasPosition(im, block.Position.X, block.Position.Y);
 }
Esempio n. 6
0
 public void StraightMoveAnimation(BlockPhysic block, Image im, double stepX, double stepY)
 {
     window.SetCanvasPosition(im, block.Position.X, block.Position.Y);
     block.SetNewPosition(block.Position.X + stepX, block.Position.Y + stepY);
 }