Beispiel #1
0
        private void ShootTimerTickEventHandler(object sender, EventArgs e)
        {
            isRunning = true;

            restOfBalls--;
            UcBall ball = new UcBall();
            //Canvas.SetTop(ball, 0);
            // Canvas.SetLeft(ball, 0);
            TranslateTransform transform = ball.RenderTransform as TranslateTransform;

            transform.X = canvasWidth / 2;
            transform.Y = 10;
            ball.Vx     = initialVelocity * Math.Cos(currentAngle);
            ball.Vy     = initialVelocity * Math.Sin(currentAngle);
            if (transform.Y != 0)
            {
            }
            cvs.Children.Add(ball);
            balls.Add(ball);

            if (restOfBalls <= 0)
            {
                timer.Stop();
                // return;
            }
        }
Beispiel #2
0
        private Turn CheckCollision(UcBall ball)
        {
            Turn result     = new Turn(1, 1);
            var  tempResult = CheckCollisionWithLine(ball, 1, 0, -canvasWidth);

            if (tempResult != null)
            {
                result.Add(tempResult);
            }
            tempResult = CheckCollisionWithLine(ball, 1, 0, 0);
            if (tempResult != null)
            {
                result.Add(tempResult);
            }

            foreach (var block in blocks.ToArray())
            {
                if (block.Count == 0)
                {
                    blocks.Remove(block);
                    cvs.Children.Remove(block as UIElement);
                }
                tempResult = block.CheckCollision(ball);
                if (tempResult != null)
                {
                    result.Add(tempResult);
                }
            }

            return(result);
        }
Beispiel #3
0
 private bool CheckDie(UcBall ball)
 {
     if (Mode == GameMode.UpToDownWithGravity)
     {
         if (ball.Y + R > canvasHeight)
         {
             ball.Visibility = Visibility.Collapsed;
             cvs.Children.Remove(ball);
             balls.Remove(ball);
         }
     }
     return(false);
 }
Beispiel #4
0
        private Turn CheckCollisionWithLine(UcBall ball, double a, double b, double c)
        {
            if (!(a == 0 || b == 0))
            {
                throw new Exception("a和b必须有一个为0");
            }
            double distance = Math.Abs(a * ball.X + b * ball.Y + c) / Math.Sqrt(a * a + b * b);

            if (distance > R)
            {
                return(null);
            }
            if (b == 0)
            {
                return(new Turn(-1, 1));
            }
            else
            {
                return(new Turn(1, -1));
            }
        }
Beispiel #5
0
 public void TurnBall(UcBall ball)
 {
     ball.Vx *= Vx;
     ball.Vy *= Vy;
 }