コード例 #1
0
 public void fireBallModelAdded(BallModel ball)
 {
     foreach (BallModelsListener listener in this._listeners)
     {
         listener.handleBallAdded(ball);
     }
 }
コード例 #2
0
 void BallModelsListener.handleBallRemoved(BallModel ball)
 {
     int id = ball.ID;
     Ellipse ellipse = balls[id];
     balls.Remove(id);
     MainCanvas.Children.Remove(ellipse);
 }
コード例 #3
0
 public BallModel createBall(double x, double y, double r, double angle, double velocity)
 {
     int id = this.generateNextId();
     BallModel ball = new BallModel(id, x, y, r, angle, velocity);
     ball.addBallModelListener(this._window);
     this._balls.Add(id, ball);
     this.fireBallModelAdded(ball);
     return ball;
 }
コード例 #4
0
 void BallModelsListener.handleBallAdded(BallModel ball)
 {
     int id = ball.ID;
     Ellipse ellipse = generateEllipse(ball);
     balls.Add(id, ellipse);
     if (!MainCanvas.Children.Contains(ellipse))
     {
         MainCanvas.Children.Add(ellipse);
     }
 }
コード例 #5
0
 void BallModelListener.handleBallModelChanged(BallModel ball)
 {
     int id = ball.ID;
     Ellipse ellipse = balls[id];
     if (ellipse != null)
     {
         ellipse.Height = ball.R * 2;
         ellipse.Width = ball.R * 2;
         Canvas.SetLeft(ellipse, ball.X);
         Canvas.SetTop(ellipse, ball.Y);
         Canvas.SetZIndex(ellipse, 100);
     }
 }
コード例 #6
0
 private static Ellipse generateEllipse(BallModel ball)
 {
     var circle = new Ellipse();
     circle.Width = ball.R * 2;
     circle.Height = ball.R * 2;
     circle.Stroke = new SolidColorBrush(Colors.Black);
     circle.StrokeThickness = 1;
     circle.Fill = ball.TargetColor;
     return circle;
 }
コード例 #7
0
        /**
         * Determines whether the ball is in bounds of canvas
        */
        private Boolean isInBounds(BallModel ball)
        {
            double width = this._window.Width;
            double height = this._window.Height;

            if (ball.Velocity > 0)
            {
                double x = ball.X;
                double y = ball.Y;
                if (x < 0 || x > width)
                {
                    return false;
                }
                if (y < 0 || y > height)
                {
                    return false;
                }
            }
            return true;
        }
コード例 #8
0
        private static Boolean ballIntersectsTarget(BallModel ball, Target target)
        {
            double ballX = ball.X;
            double ballY = ball.Y;
            double ballR = ball.R;
            double targetX = target.getXPosition();
            double targetY = target.getYPosition();
            double targetR = target.getTargetRadius();
            double distance = Math.Sqrt(Math.Pow(ballX - targetX,2) + Math.Pow(ballY - targetY,2));

            return distance < targetR+ballR*0.3;
        }
コード例 #9
0
 public Boolean removeBall(BallModel ball)
 {
     int id = ball.ID;
     return this.removeBall(id);
 }
コード例 #10
0
        public override void processSkeletonFrame(SkeletonData skeleton, Dictionary<int, Target> targets)
        {
            // x,y launch angle,
            if (areWristsTogether(skeleton) &&
                isCloseToBody(skeleton))            // charging
            {
                // here is where we should put a non-moving ball at X,Y
                double[] ballCoords = getJointForBall(skeleton);

                double ballX = ballCoords[0];
                double ballY = ballCoords[1];
                double ballR = BallModel.MIN_R;
                if (curBall == null)
                {

                    ballX -= ballR;
                    ballY -= ballR;
                    curBall = _balls.createBall(ballX, ballY, ballR);
                }
                else
                {
                    ballR = computeGrownRadius(curBall.R);
                    ballX -= ballR;
                    ballY -= ballR;
                    curBall.setPosition(ballX, ballY);
                    curBall.R = ballR;
                }
            }
            else if (areArmsStraight(skeleton) &&
                areWristsTogether(skeleton) &&
                !isCloseToBody(skeleton))           // launching
            {
                // get angle

                double angle = computeLaunchAngle(skeleton);
                double velocity = BallModel.MAX_V;
                if (curBall != null)
                {
                    curBall.Velocity = velocity;
                    curBall.Angle = angle;
                    curBall = null;
                    _pastBallLocations.Clear();
                }
            }
            else if (areWristsTogether(skeleton))   // moving around
            {
                if (curBall != null)
                {
                    // here is where we should put a non-moving ball at X,Y
                    double[] ballCoords = getJointForBall(skeleton);
                    double ballR = curBall.R;
                    double ballX = ballCoords[0] - ballR;
                    double ballY = ballCoords[1] - ballR;

                    curBall.setPosition(ballX, ballY);
                }
            }
            else                                    // no ball / cancel
            {
                // if there is a curball cancel it
                if (curBall != null)
                {
                    _balls.removeBall(curBall);
                    curBall = null;
                    _pastBallLocations.Clear();
                }
                // if no ball, keep having no ball
            }
            if (curBall != null)
            {
                this.addPastBallLocation(curBall.X, curBall.Y);
            }

            _balls.animateBalls();
            _balls.removeOutOfBoundsBalls();
            _balls.removeIntersectingBalls(this.validTargets, new ProcessTargetIntersectedDelegate(handleTargetIntersected));
        }