コード例 #1
0
 private bool ballsCollide(HandleObject ballA, HandleObject ballB)
 {
     double a = ballA.getRadius() + ballB.getRadius();
     double dx = ballA.center().X - ballB.center().X;
     double dy = ballA.center().Y - ballB.center().Y;
     return a * a > (dx * dx + dy * dy);
 }
コード例 #2
0
        public BasketballManager(int displayWidth, int displayHeight)
        {
            width = displayWidth;
            scoreBoard = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\../../../Images\\court_scoreboard.jpg"));
            leftBall = new HandleObject(new Point(400, -100), 100, new Point(0, 1), displayWidth, displayHeight, 2);
            rightBall = new HandleObject(new Point(1520, -100), 100, new Point(0, 1), displayWidth, displayHeight);

            leftHoop = new PlayerHoop(true, displayWidth, displayHeight);
            rightHoop = new PlayerHoop(false, displayWidth, displayHeight);
        }
コード例 #3
0
        private void updateBall(Player p, HandleObject b)
        {
            Point leftPoint = p.jointPoints[JointType.HandLeft];
            HandState leftHand = p.body.HandLeftState;
            float leftDepth = p.jointPointDepths[JointType.HandLeft];

            Point rightPoint = p.jointPoints[JointType.HandRight];
            HandState rightHand = p.body.HandRightState;
            float rightDepth = p.jointPointDepths[JointType.HandRight];

            if (ballsCollide(leftBall, rightBall))
            {
                if (!(leftBall.isBoundToHand || rightBall.isBoundToHand))
                {
                    Point leftVel = leftBall.getVelocity();
                    Point rightVel = rightBall.getVelocity();

                    leftBall.onCollide(rightVel.X, rightVel.Y);
                    rightBall.onCollide(leftVel.X, leftVel.Y);
                }
            }

            b.update(leftHand, rightHand, leftPoint, rightPoint, leftDepth, rightDepth);
        }
コード例 #4
0
 public bool isBallScored(HandleObject ball)
 {
     if (box.isPointInside(ball.center()) && ball.getVelocity().Y > 0 )
     {
         score++;
         cheer.Play();
         ball.processed();
         return true;
     }
     return false;
 }