Ejemplo n.º 1
0
        public void LoadStatics()
        {
            JointFactory.CreateFixedRevoluteJoint(
                Platform.Instance.PhysicsWorld,
                GameWorldManager.Instance.GetEntity("bridge").PhysicsEntity.GetBody("FloorBody"),
                UnitsConverter.ToSimUnits(new Vector2(-120f, 0f)),
                UnitsConverter.ToSimUnits(new Vector2(2040f + 60f * 16, -43))
                );


            FixedDistanceJoint dj = JointFactory.CreateFixedDistanceJoint(
                Platform.Instance.PhysicsWorld,
                GameWorldManager.Instance.GetEntity("bridge").PhysicsEntity.GetBody("FloorBody"),
                UnitsConverter.ToSimUnits(new Vector2(120f, -5f)),
                UnitsConverter.ToSimUnits(new Vector2(2040f + 60f * 20, -180f))
                );

            dj.Frequency    = 2f;
            dj.DampingRatio = 0.4f;
        }
Ejemplo n.º 2
0
        private void CreateVirusSprings()
        {
            if (_grabbedVirus.Body.Position.X == float.NaN || _handCenter.X == float.NaN)
            {
                return;
            }

            if (_joints[0] != null)
            {
                RemoveVirusSprings();
            }

            float length = 0.1f;

            for (int i = 0; i < _joints.Count(); i++)
            {
                _joints[i]              = JointFactory.CreateFixedDistanceJoint(_world, _grabbedVirus.Body, Vector2.Zero, _handCenter + _jointOffsets[i]);
                _joints[i].Length       = length;
                _joints[i].Frequency    = 5.0f;
                _joints[i].DampingRatio = 1.5f;
            }
        }
Ejemplo n.º 3
0
        public void LoadSemiStatics()
        {
            GameWorldManager.Instance.GetEntity("button1").RegisterComponent(
                "active",
                new ButtonComponent("ButtonJoint1")
                );

            GameWorldManager.Instance.GetEntity("button0").RegisterComponent(
                "active",
                new ButtonComponent("ButtonJoint1", false, true)
                );

            GameWorldManager.Instance.GetEntity("lifteddoor0").RegisterComponent(
                "doorHandle",
                new LiftedDoorComponent(GameWorldManager.Instance.GetEntity("button1").GetComponent("active"), "DoorJoint1")
                );

            _gravityButton = GameWorldManager.Instance.GetEntity("button0").GetComponent("active") as ButtonComponent;

            JointFactory.CreateFixedRevoluteJoint(
                Platform.Instance.PhysicsWorld,
                GameWorldManager.Instance.GetEntity("floorbridge0").PhysicsEntity.GetBody("FloorBody"),
                UnitsConverter.ToSimUnits(new Vector2(120f, 0f)),
                UnitsConverter.ToSimUnits(new Vector2(2689f, 564))
                );


            FixedDistanceJoint dj = JointFactory.CreateFixedDistanceJoint(
                Platform.Instance.PhysicsWorld,
                GameWorldManager.Instance.GetEntity("floorbridge0").PhysicsEntity.GetBody("FloorBody"),
                UnitsConverter.ToSimUnits(new Vector2(-120f, -5f)),
                UnitsConverter.ToSimUnits(new Vector2(2466f, 244f))
                );

            dj.Frequency    = 1.5f;
            dj.DampingRatio = 0.355f;
        }
 protected override Joint CreateJoint(Body bodyA, Body bodyB)
 {
     return(bodyA != null?JointFactory.CreateFixedDistanceJoint(Scene.PhysicsWorld, bodyA, Vector2.Zero, Vector2.Zero) : null);
 }
Ejemplo n.º 5
0
        public Spiderweb(World world, Vector2 position, float radius, int rings, int sides)
        {
            const float breakpoint = 100f;

            _world  = world;
            _radius = radius;

            List <List <Body> > ringBodys = new List <List <Body> >(rings);

            for (int i = 1; i < rings; ++i)
            {
                Vertices    vertices = PolygonTools.CreateCircle(i * 2.9f, sides);
                List <Body> bodies   = new List <Body>(sides);

                //Create the first goo
                Body prev = BodyFactory.CreateCircle(world, radius, 0.2f, vertices[0]);
                prev.FixedRotation = true;
                prev.Position     += position;
                prev.BodyType      = BodyType.Dynamic;

                bodies.Add(prev);

                //Connect the first goo to the next
                for (int j = 1; j < vertices.Count; ++j)
                {
                    Body bod = BodyFactory.CreateCircle(world, radius, 0.2f, vertices[j]);
                    bod.FixedRotation = true;
                    bod.BodyType      = BodyType.Dynamic;
                    bod.Position     += position;

                    DistanceJoint dj = JointFactory.CreateDistanceJoint(world, prev, bod, Vector2.Zero, Vector2.Zero);
                    dj.Frequency    = 4.0f;
                    dj.DampingRatio = 0.5f;
                    dj.Breakpoint   = breakpoint;

                    prev = bod;
                    bodies.Add(bod);
                }

                //Connect the first and the last box
                DistanceJoint djEnd = JointFactory.CreateDistanceJoint(world, bodies[0], bodies[bodies.Count - 1],
                                                                       Vector2.Zero, Vector2.Zero);
                djEnd.Frequency    = 4.0f;
                djEnd.DampingRatio = 0.5f;
                djEnd.Breakpoint   = breakpoint;

                ringBodys.Add(bodies);
            }

            //Create an outer ring
            Vertices lastRing = PolygonTools.CreateCircle(rings * 2.9f, sides);

            lastRing.Translate(ref position);

            List <Body> lastRingFixtures = ringBodys[ringBodys.Count - 1];

            //Fix each of the fixtures of the outer ring
            for (int j = 0; j < lastRingFixtures.Count; ++j)
            {
                FixedDistanceJoint fdj = JointFactory.CreateFixedDistanceJoint(world, lastRingFixtures[j], Vector2.Zero,
                                                                               lastRing[j]);
                fdj.Frequency    = 4.0f;
                fdj.DampingRatio = 0.5f;
                fdj.Breakpoint   = breakpoint;
            }

            //Interconnect the rings
            for (int i = 1; i < ringBodys.Count; i++)
            {
                List <Body> prev    = ringBodys[i - 1];
                List <Body> current = ringBodys[i];

                for (int j = 0; j < prev.Count; j++)
                {
                    Body prevFixture    = prev[j];
                    Body currentFixture = current[j];

                    DistanceJoint dj = JointFactory.CreateDistanceJoint(world, prevFixture, currentFixture, Vector2.Zero,
                                                                        Vector2.Zero);
                    dj.Frequency    = 4.0f;
                    dj.DampingRatio = 0.5f;
                }
            }
        }