Пример #1
0
        /// <summary>
        /// Allows the points to determine if it has been rolled over by a
        /// pin ball. Returns the points' value if rolled over by pin ball
        /// </summary>
        /// <param name="pinBall">The moving pin ball.</param>
        public int In(PinBall pinBall)
        {
            int     value = 0;
            Vector2 norm  = pinBall.ballCenter - pointsCenter;

            if (norm.Length() <= pointsRadius + pinBall.ballRadius)
            {
                if (IN == false)
                {
                    value = pointsValue;
                }
                IN           = true;
                whichTexture = numTextures - 1;
            }
            else
            {
                IN           = false;
                whichTexture = 0;
            }
            return(value);
        }
Пример #2
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
            foregroundTexture = game1.Content.Load <Texture2D>("Foreground800x600");
            backgroundTexture = game1.Content.Load <Texture2D>("Background800x600");

            pinBall = new PinBall(this, new Vector2(743, 535));
            game1.Components.Add(pinBall);

            // Initialize bumpers


            // Initialize points
            points.Add(new Points(this, new Vector2(200.0f, 300.0f), 40, 20, new string[] { "Circle110Blue", "Circle110BlueGrad", "Circle110BlueGrad" }));
            points.Add(new Points(this, new Vector2(350.0f, 325.0f), 50, 30, new string[] { "Circle110Blue", "Circle110BlueGrad", "Circle110BlueGrad" }));
            points.Add(new Points(this, new Vector2(500.0f, 300.0f), 40, 30, new string[] { "Circle110Blue", "Circle110BlueGrad", "Circle110BlueGrad" }));
            numPoints     = points.Count();
            numDrawPoints = points.Count();
            for (int i = 0; i < numPoints; i++)
            {
                points[i].Initialize();
            }

            textFont = game1.Content.Load <SpriteFont>(@"Tahoma");
            score    = 0;
            turns    = 5;

            // Initialize the flippers
            leftFlipper = new LeftFlipper(this, new Vector2[] { new Vector2(200.0f, 500.0f), new Vector2(312.0f, 515.0f), new Vector2(200.0f, 530.0f),
                                                                new Vector2(192.0f, 515.0f) }, new Vector2(200.0f, 515.0f), new Vector2(9, 15), "LeftFlipper120x30");
            game1.Components.Add(leftFlipper);

            rightFlipper = new RightFlipper(this, new Vector2[] { new Vector2(500.0f, 500.0f), new Vector2(388.0f, 515.0f), new Vector2(500.0f, 530.0f),
                                                                  new Vector2(508.0f, 515.0f) }, new Vector2(500.0f, 515.0f), new Vector2(111, 15), "RightFlipper120x30");
            game1.Components.Add(rightFlipper);


            base.Initialize();
        }
Пример #3
0
        public bool Hit(PinBall pinBall, ref Vector2 normal, ref float bounceFactor)
        {
            Vector2 closestPoint;
            float   ratio = ((flipperPoints[0].Y - pinBall.ballCenter.Y) * (flipperPoints[0].Y - flipperPoints[1].Y) - (flipperPoints[0].X - pinBall.ballCenter.X)
                             * (flipperPoints[1].X - flipperPoints[0].X)) / (flipperPoints[0] - flipperPoints[1]).LengthSquared();

            if (ratio <= 0)
            {
                closestPoint = flipperPoints[0];
            }
            else if (ratio >= 1)
            {
                closestPoint = flipperPoints[1];
            }
            else
            {
                closestPoint.X = flipperPoints[0].X + ratio * (flipperPoints[1].X - flipperPoints[0].X);
                closestPoint.Y = flipperPoints[0].Y + ratio * (flipperPoints[1].Y - flipperPoints[0].Y);
            }
            Vector2 norm = pinBall.ballCenter - closestPoint;

            if (norm.Length() > pinBall.ballRadius)
            {
                return(false);
            }
            norm.Normalize();
            if (Vector2.Dot(norm, pinBall.ballSpeed) > 0)
            {
                return(false);
            }
            normal = norm;
            float dist = (flipperPivot - closestPoint).Length();

            bounceFactor = flipperBounceFactor;
            // Add code here to modify the bounceFactor

            return(true);
        }
Пример #4
0
        public bool Hit(PinBall pinBall, ref Vector2 normal, ref float bounceFactor)
        {
            Vector2 closestPoint;
            float ratio = ((flipperPoints[0].Y - pinBall.ballCenter.Y) * (flipperPoints[0].Y - flipperPoints[1].Y) -(flipperPoints[0].X - pinBall.ballCenter.X)
                         * (flipperPoints[1].X - flipperPoints[0].X)) / (flipperPoints[0] - flipperPoints[1]).LengthSquared();
            if (ratio <= 0)
                closestPoint = flipperPoints[0];
            else if (ratio >= 1)
                closestPoint = flipperPoints[1];
            else
            {
                closestPoint.X = flipperPoints[0].X + ratio * (flipperPoints[1].X - flipperPoints[0].X);
                closestPoint.Y = flipperPoints[0].Y + ratio * (flipperPoints[1].Y - flipperPoints[0].Y);
            }
            Vector2 norm = pinBall.ballCenter - closestPoint;
            if (norm.Length() > pinBall.ballRadius)
                return false;
            norm.Normalize();
            if (Vector2.Dot(norm, pinBall.ballSpeed) > 0)
                return false;
            normal = norm;
            float dist = (flipperPivot - closestPoint).Length();
            bounceFactor = flipperBounceFactor;
            // Add code here to modify the bounceFactor

            return true;
        }
Пример #5
0
 /// <summary> 
 /// Allows the points to determine if it has been rolled over by a 
 /// pin ball. Returns the points' value if rolled over by pin ball 
 /// </summary> 
 /// <param name="pinBall">The moving pin ball.</param> 
 public int In(PinBall pinBall)
 {
     int value = 0;
     Vector2 norm = pinBall.ballCenter - pointsCenter;
     if (norm.Length() <= pointsRadius + pinBall.ballRadius)
     {
         if (IN == false)
             value = pointsValue;
         IN = true;
         whichTexture = numTextures - 1;
     }
     else
     {
         IN = false;
         whichTexture = 0;
     }
     return value;
 }
Пример #6
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
            foregroundTexture = game1.Content.Load<Texture2D>("Foreground800x600");
            backgroundTexture = game1.Content.Load<Texture2D>("Background800x600");

            pinBall = new PinBall(this, new Vector2(743, 535));
            game1.Components.Add(pinBall);

            // Initialize bumpers

            // Initialize points
            points.Add(new Points(this, new Vector2(200.0f, 300.0f), 40, 20, new string[] { "Circle110Blue", "Circle110BlueGrad", "Circle110BlueGrad" }));
            points.Add(new Points(this, new Vector2(350.0f, 325.0f), 50, 30, new string[] { "Circle110Blue", "Circle110BlueGrad", "Circle110BlueGrad" }));
            points.Add(new Points(this, new Vector2(500.0f, 300.0f), 40, 30, new string[] { "Circle110Blue", "Circle110BlueGrad", "Circle110BlueGrad" }));
            numPoints = points.Count();
            numDrawPoints = points.Count();
            for (int i = 0; i < numPoints; i++)
                points[i].Initialize();

            textFont = game1.Content.Load<SpriteFont>(@"Tahoma");
            score = 0;
            turns = 5;

            // Initialize the flippers
            leftFlipper = new LeftFlipper(this, new Vector2[] { new Vector2(200.0f, 500.0f), new Vector2(312.0f, 515.0f), new Vector2(200.0f, 530.0f),
                                          new Vector2(192.0f, 515.0f) }, new Vector2(200.0f, 515.0f), new Vector2(9, 15), "LeftFlipper120x30");
            game1.Components.Add(leftFlipper);

            rightFlipper = new RightFlipper(this, new Vector2[] { new Vector2(500.0f, 500.0f), new Vector2(388.0f, 515.0f), new Vector2(500.0f, 530.0f),
                                            new Vector2(508.0f, 515.0f) }, new Vector2(500.0f, 515.0f), new Vector2(111, 15), "RightFlipper120x30");
            game1.Components.Add(rightFlipper);

            base.Initialize();
        }
Пример #7
0
 /// <summary>
 /// Allows the bumper to determine if it has been hit by a pin ball.
 /// Returns true if hit by pin ball
 /// </summary>
 /// <param name="pinBall">The moving pin ball.</param>
 public virtual bool Hit(PinBall pinBall, ref Vector2 normal)
 {
     return false;
 }
Пример #8
0
 /// <summary>
 /// Allows the bumper to determine if it has been hit by a pin ball.
 /// Returns true if hit by pin ball
 /// </summary>
 /// <param name="pinBall">The moving pin ball.</param>
 public virtual bool Hit(PinBall pinBall, ref Vector2 normal)
 {
     return(false);
 }