Ejemplo n.º 1
0
        private void SetupDistanceJoint(object sender)
        {
            //remove old joints
            if (_joints.Count > 0)
            {
                foreach (DistanceJoint jnt in _joints)
                {
                    _physicsController.DeleteObject(jnt);
                }
            }

            const float breakpoint = 1000f;

            //translate coordinates relative to screen
            var touchedObject = sender as PhysicsSprite;
            //var list = BoundaryHelper.GetPointsForElement(touchedObject.uiElement, e.ManipulationContainer, false);

            //get reference to player
            PhysicsSprite player = _physicsController.PhysicsObjects["player"];


            //create distance joint between the two
            DistanceJoint joint = JointFactory.CreateDistanceJoint(_physicsController.Simulator, player.BodyObject,
                                                                   touchedObject.BodyObject, Vector2.Zero, Vector2.Zero);

            joint.Frequency        = 4.0f;
            joint.DampingRatio     = .5f;
            joint.Breakpoint       = breakpoint;
            joint.CollideConnected = true;
            joint.Broke           += joint_Broke;
            _joints.Add(joint);

            //create tounge


            //timer
            var timer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(33)
            };

            timer.Tick += delegate
            {
                //joint broke
                if (!joint.Enabled)
                {
                    timer.Stop();
                    _physicsController.DeleteObject(joint);
                    return;
                }

                //reduce distance
                if (joint.Length <= 0f)
                {
                    timer.Stop();
                    _physicsController.DeleteObject(joint);
                }
                joint.Length -= .1f;
            };
            timer.Start();
        }
Ejemplo n.º 2
0
        private void SetupReleaseTarget(object sender, PhysicsControllerMain physMain, ManipulationCompletedEventArgs e)
        {
            //remove old joints
            if (_joints.Count > 0)
            {
                foreach (DistanceJoint jnt in _joints)
                {
                    physMain.DeleteObject(jnt);
                }
            }

            const float breakpoint = 1000f;

            //translate coordinates relative to screen
            var touchedObject = sender as PhysicsSprite;
            //var list = BoundaryHelper.GetPointsForElement(touchedObject.uiElement, e.ManipulationContainer, false);

            //get reference to player
            PhysicsSprite player = physMain.PhysicsObjects["player"];

            var letgopoint = new Point((int) e.ManipulationOrigin.X + (int) e.TotalManipulation.Translation.X,
                                       (int) e.ManipulationOrigin.Y + (int) e.TotalManipulation.Translation.Y);

            Body testBody = BodyFactory.CreateCircle(physMain.Simulator, 25, 1, physMain.ScreenToWorld(letgopoint));

            //create distance joint between the two
            DistanceJoint joint = JointFactory.CreateDistanceJoint(physMain.Simulator, player.BodyObject,
                                                                   testBody, Vector2.Zero, Vector2.Zero);

            joint.Frequency = 4.0f;
            joint.DampingRatio = .5f;
            joint.Breakpoint = breakpoint;
            joint.CollideConnected = true;
            joint.Broke += joint_Broke;
            _joints.Add(joint);

            //create tounge

            //timer
            var timer = new DispatcherTimer {Interval = TimeSpan.FromMilliseconds(33)};

            timer.Tick += delegate
                              {
                                  //joint broke
                                  if (!joint.Enabled)
                                  {
                                      timer.Stop();
                                      physMain.DeleteObject(joint);
                                      return;
                                  }

                                  //reduce distance
                                  if (joint.Length <= 0f)
                                  {
                                      timer.Stop();
                                  }
                                  joint.Length -= .1f;
                              };
            timer.Start();
        }
Ejemplo n.º 3
0
        private void SetupReleaseTarget(object sender, PhysicsControllerMain physMain, ManipulationCompletedEventArgs e)
        {
            //remove old joints
            if (_joints.Count > 0)
            {
                foreach (DistanceJoint jnt in _joints)
                {
                    physMain.DeleteObject(jnt);
                }
            }

            const float breakpoint = 1000f;

            //translate coordinates relative to screen
            var touchedObject = sender as PhysicsSprite;
            //var list = BoundaryHelper.GetPointsForElement(touchedObject.uiElement, e.ManipulationContainer, false);

            //get reference to player
            PhysicsSprite player = physMain.PhysicsObjects["player"];


            var letgopoint = new Point((int)e.ManipulationOrigin.X + (int)e.TotalManipulation.Translation.X,
                                       (int)e.ManipulationOrigin.Y + (int)e.TotalManipulation.Translation.Y);

            Body testBody = BodyFactory.CreateCircle(physMain.Simulator, 25, 1, physMain.ScreenToWorld(letgopoint));

            //create distance joint between the two
            DistanceJoint joint = JointFactory.CreateDistanceJoint(physMain.Simulator, player.BodyObject,
                                                                   testBody, Vector2.Zero, Vector2.Zero);

            joint.Frequency        = 4.0f;
            joint.DampingRatio     = .5f;
            joint.Breakpoint       = breakpoint;
            joint.CollideConnected = true;
            joint.Broke           += joint_Broke;
            _joints.Add(joint);

            //create tounge


            //timer
            var timer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(33)
            };

            timer.Tick += delegate
            {
                //joint broke
                if (!joint.Enabled)
                {
                    timer.Stop();
                    physMain.DeleteObject(joint);
                    return;
                }

                //reduce distance
                if (joint.Length <= 0f)
                {
                    timer.Stop();
                }
                joint.Length -= .1f;
            };
            timer.Start();
        }