Example #1
0
        public override void Update(GameTime gameTime)
        {
            if (Path == null)
            {
                Path = new FarseerPhysics.Common.Path();
                Path.Add(position / Level.PixelPerMeter);
                Path.Add(new Vector2(position.X, position.Y + Length) / Level.PixelPerMeter);
                Path.Closed = false;

                float rectLength = (Length / Segments) / Level.PixelPerMeter;
                float rectWidth  = (Width) / Level.PixelPerMeter;

                List <Shape> shapes = new List <Shape>(1);
                //shapes.Add(new PolygonShape(PolygonTools.CreateRectangle(Width/Level.PixelPerMeter, (Length/Segments)/Level.PixelPerMeter, new Vector2(0, 0), 0f), 1));
                shapes.Add(new PolygonShape(PolygonTools.CreateRectangle(rectWidth, rectLength, new Vector2(rectWidth, rectLength), 0f), 1));
                Bodies = PathManager.EvenlyDistributeShapesAlongPath(Level.Physics, Path, shapes, BodyType.Dynamic, Segments);


                if (Object1 == null)
                {
                    Bodies.ElementAt(0).BodyType = BodyType.Static;
                }
                else
                {
                    WeldJoint joint = JointFactory.CreateWeldJoint(Level.Physics, Object1.fixture.Body, Bodies.ElementAt(0), Vector2.Zero, Vector2.Zero);
                    foreach (Body body in Bodies)
                    {
                        foreach (Fixture fix in body.FixtureList)
                        {
                            fix.IgnoreCollisionWith(Object1.fixture);
                        }
                    }
                }
                if (Object2 != null)
                {
                    WeldJoint joint = JointFactory.CreateWeldJoint(Level.Physics, Object2.fixture.Body, Bodies.ElementAt(Bodies.Count - 1), Vector2.Zero, Vector2.Zero);
                    foreach (Body body in Bodies)
                    {
                        foreach (Fixture fix in body.FixtureList)
                        {
                            fix.IgnoreCollisionWith(Object2.fixture);
                        }
                    }
                }

                PathManager.AttachBodiesWithRevoluteJoint(Level.Physics, Bodies, new Vector2(0, 0.25f), new Vector2(0, -0.25f), false, false);
            }


            Circle.position = position;
        }