本文整理汇总了C#中FarseerPhysics.Common.Path.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Path.Add方法的具体用法?C# Path.Add怎么用?C# Path.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Common.Path
的用法示例。
在下文中一共展示了Path.Add方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateChain
/// <summary>
/// Creates a chain.
/// </summary>
/// <param name="world">The world.</param>
/// <param name="start">The start.</param>
/// <param name="end">The end.</param>
/// <param name="linkWidth">The width.</param>
/// <param name="linkHeight">The height.</param>
/// <param name="fixStart">if set to <c>true</c> [fix start].</param>
/// <param name="fixEnd">if set to <c>true</c> [fix end].</param>
/// <param name="numberOfLinks">The number of links.</param>
/// <param name="linkDensity">The link density.</param>
/// <returns></returns>
public static Path CreateChain(World world, Vector2 start, Vector2 end, float linkWidth, float linkHeight, bool fixStart, bool fixEnd, int numberOfLinks, float linkDensity)
{
// Chain start / end
Path path = new Path();
path.Add(start);
path.Add(end);
// A single chainlink
PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(linkWidth, linkHeight));
// Use PathManager to create all the chainlinks based on the chainlink created before.
List<Body> chainLinks = PathManager.EvenlyDistibuteShapesAlongPath(world, path, shape, BodyType.Dynamic, numberOfLinks, linkDensity);
if (fixStart)
{
// Fix the first chainlink to the world
JointFactory.CreateFixedRevoluteJoint(world, chainLinks[0], new Vector2(0, -(linkHeight / 2)), chainLinks[0].Position);
}
if (fixEnd)
{
// Fix the last chainlink to the world
JointFactory.CreateFixedRevoluteJoint(world, chainLinks[chainLinks.Count - 1], new Vector2(0, (linkHeight / 2)), chainLinks[chainLinks.Count - 1].Position);
}
// Attach all the chainlinks together with a revolute joint
PathManager.AttachBodiesWithRevoluteJoint(world, chainLinks, new Vector2(0, -linkHeight), new Vector2(0, linkHeight),
false, false);
return (path);
}
示例2: Robot
public Robot(Texture2D tex, Vector2 pos, World world)
{
this.tex = tex;
this.pos = pos;
robotBody = BodyFactory.CreateRectangle(world, 100f / 64f, 100f / 64f, 1f, pos / 64);
robotBody.BodyType = BodyType.Dynamic;
robotBody.FixedRotation = true;
robotBody.CollisionCategories = Category.Cat3;
robotBody.CollidesWith = Category.All ^ Category.Cat4;
robotBody.BodyId = 4;
robotBody.OnCollision += new OnCollisionEventHandler(OnCollision);
// path
{
pos = pos / 64;
path = new Path();
path.Add(pos);
path.Add(new Vector2(pos.X + 6.5f, pos.Y));
path.Add(new Vector2(pos.X + 6.5f, pos.Y + 0.1f));
path.Add(new Vector2(pos.X, pos.Y + 0.1f));
path.Closed = true;
}
}
示例3: LoadContent
public override void LoadContent()
{
base.LoadContent();
World.Gravity = new Vector2(0, 9.82f);
_border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport);
/* Bridge */
//We make a path using 2 points.
Path bridgePath = new Path();
bridgePath.Add(new Vector2(-15, 5));
bridgePath.Add(new Vector2(15, 5));
bridgePath.Closed = false;
Vertices box = PolygonTools.CreateRectangle(0.125f, 0.5f);
PolygonShape shape = new PolygonShape(box, 20);
_bridgeBodies = PathManager.EvenlyDistributeShapesAlongPath(World, bridgePath, shape,
BodyType.Dynamic, 29);
_bridgeBox =
new Sprite(ScreenManager.Assets.TextureFromShape(shape, MaterialType.Dots, Color.SandyBrown, 1f));
//Attach the first and last fixtures to the world
JointFactory.CreateFixedRevoluteJoint(World, _bridgeBodies[0], new Vector2(0f, -0.5f),
_bridgeBodies[0].Position);
JointFactory.CreateFixedRevoluteJoint(World, _bridgeBodies[_bridgeBodies.Count - 1], new Vector2(0, 0.5f),
_bridgeBodies[_bridgeBodies.Count - 1].Position);
PathManager.AttachBodiesWithRevoluteJoint(World, _bridgeBodies, new Vector2(0f, -0.5f),
new Vector2(0f, 0.5f),
false, true);
/* Soft body */
//We make a rectangular path.
Path rectanglePath = new Path();
rectanglePath.Add(new Vector2(-6, -11));
rectanglePath.Add(new Vector2(-6, 1));
rectanglePath.Add(new Vector2(6, 1));
rectanglePath.Add(new Vector2(6, -11));
rectanglePath.Closed = true;
//Creating two shapes. A circle to form the circle and a rectangle to stabilize the soft body.
List<Shape> shapes = new List<Shape>(2);
shapes.Add(new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f, new Vector2(-0.1f, 0f), 0f), 1f));
shapes.Add(new CircleShape(0.5f, 1f));
//We distribute the shapes in the rectangular path.
_softBodies = PathManager.EvenlyDistributeShapesAlongPath(World, rectanglePath, shapes,
BodyType.Dynamic, 30);
_softBodyBox =
new Sprite(ScreenManager.Assets.TextureFromShape(shapes[0], MaterialType.Blank, Color.Silver * 0.8f, 1f));
_softBodyBox.Origin += new Vector2(ConvertUnits.ToDisplayUnits(0.1f), 0f);
_softBodyCircle =
new Sprite(ScreenManager.Assets.TextureFromShape(shapes[1], MaterialType.Waves, Color.Silver, 1f));
//Attach the bodies together with revolute joints. The rectangular form will converge to a circular form.
PathManager.AttachBodiesWithRevoluteJoint(World, _softBodies, new Vector2(0f, -0.5f), new Vector2(0f, 0.5f),
true, true);
}
示例4: LoadContent
public override void LoadContent()
{
base.LoadContent();
World.Gravity = new Vector2(0, 9.82f);
_border = new Border(World, Lines, Framework.GraphicsDevice);
// Bridge
// We make a path using 2 points.
Path bridgePath = new Path();
bridgePath.Add(new Vector2(-15, 5));
bridgePath.Add(new Vector2(15, 5));
bridgePath.Closed = false;
Vertices box = PolygonTools.CreateRectangle(0.125f, 0.5f);
PolygonShape shape = new PolygonShape(box, 20);
_bridgeBodies = PathManager.EvenlyDistributeShapesAlongPath(World, bridgePath, shape, BodyType.Dynamic, 29);
// Attach the first and last fixtures to the world
Body anchor = new Body(World, Vector2.Zero);
anchor.BodyType = BodyType.Static;
World.AddJoint(new RevoluteJoint(_bridgeBodies[0], anchor, _bridgeBodies[0].Position - new Vector2(0.5f, 0f), true));
World.AddJoint(new RevoluteJoint(_bridgeBodies[_bridgeBodies.Count - 1], anchor, _bridgeBodies[_bridgeBodies.Count - 1].Position + new Vector2(0.5f, 0f), true));
PathManager.AttachBodiesWithRevoluteJoint(World, _bridgeBodies, new Vector2(0f, -0.5f), new Vector2(0f, 0.5f), false, true);
// Soft body
// We make a rectangular path.
Path rectanglePath = new Path();
rectanglePath.Add(new Vector2(-6, -11));
rectanglePath.Add(new Vector2(-6, 1));
rectanglePath.Add(new Vector2(6, 1));
rectanglePath.Add(new Vector2(6, -11));
rectanglePath.Closed = true;
// Creating two shapes. A circle to form the circle and a rectangle to stabilize the soft body.
Shape[] shapes = new Shape[2];
shapes[0] = new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f, new Vector2(-0.1f, 0f), 0f), 1f);
shapes[1] = new CircleShape(0.5f, 1f);
// We distribute the shapes in the rectangular path.
_softBodies = PathManager.EvenlyDistributeShapesAlongPath(World, rectanglePath, shapes, BodyType.Dynamic, 30);
// Attach the bodies together with revolute joints. The rectangular form will converge to a circular form.
PathManager.AttachBodiesWithRevoluteJoint(World, _softBodies, new Vector2(0f, -0.5f), new Vector2(0f, 0.5f), true, true);
// GFX
_bridgeBox = new Sprite(ContentWrapper.TextureFromShape(shape, ContentWrapper.Orange, ContentWrapper.Brown));
_softBodyBox = new Sprite(ContentWrapper.TextureFromShape(shapes[0], ContentWrapper.Green, ContentWrapper.Black));
_softBodyBox.Origin += new Vector2(ConvertUnits.ToDisplayUnits(0.1f), 0f);
_softBodyCircle = new Sprite(ContentWrapper.TextureFromShape(shapes[1], ContentWrapper.Lime, ContentWrapper.Grey));
}
示例5: PathTest
private PathTest()
{
//Single body that moves around path
_movingBody = BodyFactory.CreateBody(World);
_movingBody.Position = new Vector2(-25, 25);
_movingBody.BodyType = BodyType.Dynamic;
_movingBody.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f), 1));
//Static shape made up of bodies
_path = new Path();
_path.Add(new Vector2(0, 20));
_path.Add(new Vector2(5, 15));
_path.Add(new Vector2(20, 18));
_path.Add(new Vector2(15, 1));
_path.Add(new Vector2(-5, 14));
_path.Closed = true;
CircleShape shape = new CircleShape(0.25f, 1);
PathManager.EvenlyDistributeShapesAlongPath(World, _path, shape, BodyType.Static, 100);
//Smaller shape that is movable. Created from small rectangles and circles.
Vector2 xform = new Vector2(0.5f, 0.5f);
_path.Scale(ref xform);
xform = new Vector2(5, 5);
_path.Translate(ref xform);
List<Shape> shapes = new List<Shape>(2);
shapes.Add(new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f, new Vector2(-0.1f, 0), 0), 1));
shapes.Add(new CircleShape(0.5f, 1));
List<Body> bodies = PathManager.EvenlyDistributeShapesAlongPath(World, _path, shapes, BodyType.Dynamic, 20);
//Attach the bodies together with revolute joints
PathManager.AttachBodiesWithRevoluteJoint(World, bodies, new Vector2(0, 0.5f), new Vector2(0, -0.5f), true,
true);
xform = new Vector2(-25, 0);
_path.Translate(ref xform);
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Static;
//Static shape made up of edges
PathManager.ConvertPathToEdges(_path, body, 25);
body.Position -= new Vector2(0, 10);
xform = new Vector2(0, 15);
_path.Translate(ref xform);
PathManager.ConvertPathToPolygon(_path, body, 1, 50);
}
示例6: Whip
public Whip(Texture2D tex, Vector2 start, Vector2 end, World world )
{
this.tex = tex;
this.world = world;
this.start = start / 64;
this.end = end / 64;
Path path = new Path();
path.Add(this.start);
path.Add(this.end);
//A single chainlink
PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(0.125f, 0.125f),20);
// ChainLink shape = new ChainLink(100);
//Use PathFactory to create all the chainlinks based on the chainlink created before.
chainLinks = PathManager.EvenlyDistributeShapesAlongPath(world, path, shape, BodyType.Dynamic,30);
foreach (Body chainLink in chainLinks)
{
foreach (Fixture f in chainLink.FixtureList)
{
f.Friction = 0.2f;
f.CollisionCategories = Category.Cat3;
Category whipMask = Category.All ^ Category.Cat2;
f.CollidesWith = whipMask;
f.Body.BodyId = 8;
f.OnCollision += new OnCollisionEventHandler(OnCollision);
}
}
//Fix the first chainlink to the world
// FixedRevoluteJoint fixedJoint = new FixedRevoluteJoint(chainLinks[0], Vector2.Zero, chainLinks[0].Position);
// Game1.world.AddJoint(fixedJoint);
//Attach all the chainlinks together with a revolute joint. This is the spacing between links
joints = PathManager.AttachBodiesWithRevoluteJoint(world, chainLinks,
new Vector2(0, -0.1f),
new Vector2(0, 0.1f),
false, false);
//The chain is breakable
for (int i = 0; i < joints.Count; i++)
{
RevoluteJoint r = joints[i];
r.Breakpoint = 5000f;
}
}
示例7: Bady
/// <summary>
/// Creates a bady
/// </summary>
/// <param name="tex"></param>
/// <param name="pos">Physcis units</param>
/// <param name="pathLenght"></param>
/// <param name="direction">true for an x - axis movement</param>
/// <param name="rotation">angle in degrees</param>
/// <param name="content"></param>
public Bady(Texture2D tex, Vector2 pos, int pathLenght, bool direction, float rotation ,ContentManager content,World world)
{
this.tex = tex;
this.pos = pos;
this.world = world;
Lasers = new List<Laser>();
laserTex = content.Load<Texture2D>("orangeLaser");
this.direction = direction;
// create the path the AI follows
if (this.direction)
{
path = new Path();
path.Add(pos);
path.Add(new Vector2(pos.X + pathLenght, pos.Y));
path.Add(new Vector2(pos.X + pathLenght, pos.Y + 0.1f));
path.Add(new Vector2(pos.X, pos.Y + 0.1f));
path.Closed = true;
}
else
{
path = new Path();
path.Add(this.pos);
path.Add(new Vector2(pos.X, pos.Y + pathLenght));
path.Add(new Vector2(pos.X - 0.1f, pos.Y + pathLenght));
path.Add(new Vector2(pos.X - 0.1f, pos.Y / 64));
path.Closed = true;
}
//Badybody
{
badyBody = BodyFactory.CreateRectangle(world, tex.Width / 64.0f, tex.Height / 64.0f, 1f, pos);
badyBody.BodyType = BodyType.Dynamic;
badyBody.Mass = 10f;
badyBody.CollisionCategories = Category.Cat4;
badyBody.CollidesWith = Category.All ^ Category.Cat2;
badyBody.Rotation = AngleToRads(rotation);
badyBody.FixedRotation = true;
badyBody.OnCollision += new OnCollisionEventHandler(OnCollision);
badyBody.BodyId = 9;
}
}
示例8: ChainTest
private ChainTest()
{
//Ground
FixtureFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
//Chain start / end
Path path = new Path();
path.Add(new Vector2(0, 25));
path.Add(new Vector2(40, 25));
//A single chainlink
PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(0.125f, 0.6f), 20);
//Use PathFactory to create all the chainlinks based on the chainlink created before.
List<Body> chainLinks = PathManager.EvenlyDistributeShapesAlongPath(World, path, shape, BodyType.Dynamic, 30);
foreach (Body chainLink in chainLinks)
{
foreach (Fixture f in chainLink.FixtureList)
{
f.Friction = 0.2f;
}
}
//Fix the first chainlink to the world
FixedRevoluteJoint fixedJoint = new FixedRevoluteJoint(chainLinks[0], Vector2.Zero, chainLinks[0].Position);
World.AddJoint(fixedJoint);
//Attach all the chainlinks together with a revolute joint
List<RevoluteJoint> joints = PathManager.AttachBodiesWithRevoluteJoint(World, chainLinks,
new Vector2(0, -0.6f),
new Vector2(0, 0.6f),
false, false);
//The chain is breakable
for (int i = 0; i < joints.Count; i++)
{
RevoluteJoint r = joints[i];
r.Breakpoint = 10000f;
}
}
示例9: LoadStaticObstacles
private void LoadStaticObstacles()
{
box = PolygonTools.CreateRectangle(1f, 10f);
shape = new PolygonShape(box, 30);
_bridgeBox = new Sprite(ScreenManager.Assets.TextureFromShape(shape, MaterialType.Dots, Color.SandyBrown, 1f));
Path bridgePathL = new Path();
bridgePathL.Add(new Vector2(-400, -50));
bridgePathL.Add(new Vector2(0, 0));
bridgePathL.Closed = false;
_bridgeBodiesL = PathManager.EvenlyDistributeShapesAlongPath(World, bridgePathL, shape,
BodyType.Dynamic, 30);
//Attach the first and last fixtures to the world
JointFactory.CreateFixedRevoluteJoint(World, _bridgeBodiesL[0], new Vector2(0f, -0.5f),
_bridgeBodiesL[0].Position);
JointFactory.CreateFixedRevoluteJoint(World, _bridgeBodiesL[_bridgeBodiesL.Count - 1], new Vector2(0, 0.5f),
_bridgeBodiesL[_bridgeBodiesL.Count - 1].Position);
PathManager.AttachBodiesWithRevoluteJoint(World, _bridgeBodiesL, new Vector2(0f, -0.5f),
new Vector2(0f, 0.5f),
false, true);
Path bridgePathR = new Path();
bridgePathR.Add(new Vector2(350, -50));
bridgePathR.Add(new Vector2(0, 0));
bridgePathR.Closed = false;
_bridgeBodiesR = PathManager.EvenlyDistributeShapesAlongPath(World, bridgePathR, shape,
BodyType.Dynamic, 30);
//Attach the first and last fixtures to the world
JointFactory.CreateFixedRevoluteJoint(World, _bridgeBodiesR[0], new Vector2(0f, -0.5f),
_bridgeBodiesR[0].Position);
JointFactory.CreateFixedRevoluteJoint(World, _bridgeBodiesR[_bridgeBodiesR.Count - 1], new Vector2(0, 0.5f),
_bridgeBodiesR[_bridgeBodiesR.Count - 1].Position);
PathManager.AttachBodiesWithRevoluteJoint(World, _bridgeBodiesR, new Vector2(0f, -0.5f),
new Vector2(0f, 0.5f),
false, true);
}
示例10: Speedwalk
public Speedwalk(World world, SpeedwalkData speedwalkData)
{
bodies = new List<Body>(50);
speed = Math.Abs(speedwalkData.Speed);
leftToRight = speedwalkData.LeftToRight;
radius = speedwalkData.Radius;
from = speedwalkData.From;
to = speedwalkData.To;
speedwalkPath = new SpeedwalkPath(from, to, radius, bodies.Capacity);
for (int i = 0; i < bodies.Capacity; i++)
{
Body body = BodyFactory.CreateCircle(world, speedwalkPath.delta / 2, 1f);
body.Position = speedwalkPath.Pts[i];
body.BodyType = BodyType.Kinematic;
body.LinearVelocity = Vector2.Zero;
bodies.Add(body);
}
path = new Path();
foreach (Vector2 pt in speedwalkPath.Pts)
{
path.Add(pt);
}
path.Closed = true;
dShift = leftToRight ? -speed / 30 : speed / 30;
}
示例11: Update
public override void Update(GameTime gameTime)
{
effect.Projection = GetProjectionMatrix();
effect.View = GetViewMatrix();
if (!isComplete && (MouseInput.isLeftClicked() || (points.Count > 0 && Vector2.Distance(points[points.Count - 1], MouseInput.Position) > 5)))
{
points.Add(MouseInput.Position);
}
if (MouseInput.isRightClicked())
{
isComplete = false;
points.Clear();
}
if (KeyboardInput.isKeyPressed(Keys.Enter))
{
isComplete = true;
// points.Add(points[0]);
Vector2[] sourceVerticies;
int[] sourceIndicies;
Triangulator.Triangulator.Triangulate(points.ToArray(), Triangulator.WindingOrder.Clockwise, out sourceVerticies, out sourceIndicies);
verticies = new VertexPositionColorTexture[sourceVerticies.Length];
for (int index = 0; index < sourceVerticies.Length; index++)
{
Color mRandomColor = new Color(
(Globals.Random.Next(50, 230)),
(Globals.Random.Next(50, 230)),
(Globals.Random.Next(50, 230)));
verticies[index] = new VertexPositionColorTexture(new Vector3(sourceVerticies[index], 0f), Color.White, sourceVerticies[index] / 10);
}
indices = new short[sourceIndicies.Length];
for (int index = 0; index < sourceIndicies.Length; index++)
{
indices[index] = (short)sourceIndicies[index];
}
//RepairTextureWrapSeam(verticies.ToList<VertexPositionColorTexture>(), indices.ToList<short>());
//sourceVerticies.(points[0]);
//sourceVerticies.Reverse();
int numOfPoly = indices.Length / 3;
for (int index = 0; index < numOfPoly; index++)
{
List<short> currentIndie = indices.ToList<short>().GetRange(index * 3, 3);
List<Vector2> currentVerts = new List<Vector2>();
currentIndie.ForEach(i => currentVerts.Add(sourceVerticies[i]));
//= sourceVerticies.ToList<Vector2>().GetRange(index * 3, 3);
currentVerts.Reverse();
hull = new PolygonHull(WorldPosition, currentVerts.ToList<Vector2>());
hull.Hull.Position.Y -= Globals.ScreenHeight;
//hull.Hull.Opacity = 0.5f;
//hull = new BasicHull(WorldPosition,new Vector2(50, 50));
Scene.ComponentManager.GetComponent<LightingComponent>().Light.Hulls.Add(hull.Hull);
//currentVerts.Reverse();
/*
* List<Vector2> physicsVerts = new List<Vector2>();
currentVerts.ToList<Vector2>().ForEach(s => physicsVerts.Add(ConvertUnits.ToSimUnits(s)));
Body b = BodyFactory.CreatePolygon(PhysicsComponent.World, new FarseerPhysics.Common.Vertices(physicsVerts), 1);
*/
List<Vector2> physicsVerts = new List<Vector2>();
currentVerts.ToList<Vector2>().ForEach(s => physicsVerts.Add(ConvertUnits.ToSimUnits(s)));
Path path = new Path(physicsVerts);
path.Closed = true;
path.Add(physicsVerts[0]);
Body body = BodyFactory.CreateBody(PhysicsComponent.World);
body.BodyType = BodyType.Static;
PathManager.ConvertPathToPolygon(path, body, 1.0f, currentVerts.Count);
}
outlineVerticies = new List<VertexPositionColor[]>();
if (points.Count > 3)
{
for (int i = 0; i < points.Count - 2; i++)
{
MakeZone(points[i], points[i + 1], points[i + 2]);
}
MakeZone(points[points.Count - 2], points[points.Count - 1], points[0]);
MakeZone(points[points.Count - 1], points[0], points[1]);
}
}
//.........这里部分代码省略.........
示例12: SetupPhysics
protected override void SetupPhysics(World world)
{
#if EDITOR
#else
this._pathBodies = new List<Body>();
float width = ConvertUnits.ToSimUnits(this._texture.Width * 0.5f);
float height = ConvertUnits.ToSimUnits(this._texture.Height * 0.5f);
Vector2 startPos = ConvertUnits.ToSimUnits(this._position);
Vector2 endPos = ConvertUnits.ToSimUnits(this._endPosition);
Path _ropePath = new Path();
_ropePath.Add(startPos);
_ropePath.Add(endPos);
PolygonShape rotationPointShape = new PolygonShape(PolygonTools.CreateCircle(height, 8), 25);
PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(width, height), ConvertUnits.ToSimUnits(1.0f));
PolygonShape sensorShape = new PolygonShape(PolygonTools.CreateCircle(height * 1.5f, 6), 1.0f);
List<Shape> shapes = new List<Shape>(2);
shapes.Add(new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f, new Vector2(-0.1f, 0f), 0f), 1f));
shapes.Add(new CircleShape(0.5f, 1f));
_pathBodies = PathManager.EvenlyDistributeShapesAlongPath(world, _ropePath, shapes,
BodyType.Dynamic, _chainCount);
JointFactory.CreateFixedRevoluteJoint(world, _pathBodies[0], Vector2.Zero, startPos);
PathManager.AttachBodiesWithRevoluteJoint(world, _pathBodies, new Vector2(0f, -0.5f), new Vector2(0f, 0.5f),
false, true);
for (int i = 1; i < _pathBodies.Count; i++)
{
_pathBodies[i].FixtureList[0].CollidesWith = Category.All & ~Category.Cat10 & ~Category.Cat12;
_pathBodies[i].FixtureList[1].CollidesWith = Category.All & ~Category.Cat10 & ~Category.Cat12;
Fixture fix = FixtureFactory.AttachCircle(height * 2, 0.0f, _pathBodies[i]);
fix.IsSensor = true;
fix.OnCollision += Body_OnCollision;
fix.OnSeparation += Body_OnSeparation;
}
//Body prevBody = new Body(world); ;
//for (int i = 0; i < _chainCount; ++i)
//{
// Body body = new Body(world);
// body.BodyType = BodyType.Dynamic;
// body.Position = startPos + new Vector2(0, height * i);
// if (i == 0)
// {
// Fixture fixture = body.CreateFixture(rotationPointShape);
// fixture.Friction = 0.2f;
// body.AngularDamping = 0.4f;
// FixedRevoluteJoint fixedJoint = JointFactory.CreateFixedRevoluteJoint(world, body, Vector2.Zero, startPos);
// }
// else
// {
// Fixture fixture = body.CreateFixture(shape);
// fixture.Friction = 0.2f;
// Fixture sensorFix = FixtureFactory.AttachCircle(height * 2, 0.0f, body);
// sensorFix.IsSensor = true;
// fixture.CollidesWith = Category.All & ~Category.Cat10 & ~Category.Cat12;
// RopeJoint rj = new RopeJoint(prevBody, body, new Vector2(0.0f, height), new Vector2(0.0f, -height * 0.5f));
// rj.CollideConnected = false;
// world.AddJoint(rj);
// body.FixtureList[1].Body.OnCollision += Body_OnCollision;
// body.FixtureList[1].Body.OnSeparation += Body_OnSeparation;
// }
// prevBody = body;
// _pathBodies.Add(body);
//}
#endif
}
示例13: AddCrates
private void AddCrates()
{
// Define a path that gives the placements of the crates
var cratesPath = new Path();
cratesPath.Add(new Vector2(160, 1000));
cratesPath.Add(new Vector2(3500, 1000));
// Split the path into 30 positions - this is where the crates go
var positions = cratesPath
.SubdivideEvenly(30)
.Select(v3 => new Vector2(v3.X, v3.Y));
foreach (var position in positions)
{
var crate = new Crate(this) { Position = position };
_crates.Add(crate);
_allGameOjbects.Add(crate);
}
}
示例14: AddBallAndChain
private void AddBallAndChain(Body body)
{
// The chain will be divided into several segments along the following path
var chainPath = new Path();
chainPath.Add(ConvertUnits.ToSimUnits(332, 332));
chainPath.Add(ConvertUnits.ToSimUnits(332, 452));
// Creates the shape for the chain segments
var chainLinkShape = new PolygonShape(PolygonTools.CreateRectangle(ConvertUnits.ToSimUnits(1), ConvertUnits.ToSimUnits(2)), 0.5f);
// Creates the bodies for the chain segments
_chainBodies = PathManager.EvenlyDistributeShapesAlongPath(World, chainPath,
new[] {chainLinkShape}, BodyType.Dynamic, 30);
// Connects the chain segments
for (var i = 0; i < _chainBodies.Count - 1; i++)
{
var joint = new RevoluteJoint(_chainBodies[i], _chainBodies[i + 1], Vector2.Zero, Vector2.Zero);
World.AddJoint(joint);
}
// Connects the start of the chain to the ufo
var chainStartJoint = new RevoluteJoint(body, _chainBodies.First(), ConvertUnits.ToSimUnits(0, 25), Vector2.Zero);
World.AddJoint(chainStartJoint);
// Creates the ball at the end of the chain
_chainEndBall = BodyFactory.CreateCircle(World, ConvertUnits.ToSimUnits(10), 3f, bodyType: BodyType.Dynamic);
_chainEndBall.Position = ConvertUnits.ToSimUnits(332, 452);
_chainEndBall.OnCollision += ChainBallOnCollision;
// Adds the ball to the chain
var chainEndJoint = new RevoluteJoint(_chainBodies.Last(), _chainEndBall, Vector2.Zero, Vector2.Zero);
World.AddJoint(chainEndJoint);
// Adds a rope join that ensures that the chain won't stretch
var ropeJoint = new RopeJoint(body, _chainEndBall, ConvertUnits.ToSimUnits(0, 25), Vector2.Zero)
{
MaxLength = chainPath.GetLength()
};
World.AddJoint(ropeJoint);
}