public void LoadContent(ContentManager content, World world, Vector2 position, Vector2 size) { body = BodyFactory.CreateRectangle(world, size.X, size.Y, 1f); body.FixedRotation = true; body.FixtureList[0].UserData = 9000; body.Position = ConvertUnits.ToSimUnits(position); body.BodyType = BodyType.Dynamic; CircleShape circle1 = new CircleShape(size.X / 4, 1f); CircleShape circle2 = new CircleShape(size.Y / 6, 1f); CircleShape circle3 = new CircleShape(size.Y / 6, 1f); circle1.Position = new Vector2(0, -size.Y / 3); circle2.Position = new Vector2(-1.5f * size.X / 5, -size.Y / 10); circle3.Position = new Vector2(-0.4f * size.X / 5, -size.Y / 10); head = body.CreateFixture(circle1); hands[0] = body.CreateFixture(circle2); hands[1] = body.CreateFixture(circle3); head.UserData = (int)10000; hands[0].UserData = (int)11000; hands[1].UserData = (int)11000; image.LoadContent(content, "Graphics/tezka", Color.White, position); image.ScaleToMeters(size); image.position = ConvertUnits.ToDisplayUnits(body.Position); }
//Contributed by Matthew Bettcher /// <summary> /// Convert a path into a set of edges and attaches them to the specified body. /// Note: use only for static edges. /// </summary> /// <param name="path">The path.</param> /// <param name="body">The body.</param> /// <param name="subdivisions">The subdivisions.</param> public static void ConvertPathToEdges(Path path, Body body, int subdivisions) { List<Vector2> verts = path.GetVertices(subdivisions); for (int i = 1; i < verts.Count; i++) { body.CreateFixture(new PolygonShape(PolygonTools.CreateEdge(verts[i], verts[i - 1]), 0)); } if (path.Closed) { body.CreateFixture(new PolygonShape(PolygonTools.CreateEdge(verts[verts.Count - 1], verts[0]), 0)); } }
private static void CreateBounds(float width, float height) { var body = new Body(world); body.BodyType = BodyType.Static; var bottom = new PolygonShape(PolygonTools.CreateRectangle(width / 2, 0.1f, new Vector2(width / 2, height), 0), 5); var top = new PolygonShape(PolygonTools.CreateRectangle(width / 2, 0.1f, new Vector2(width / 2, 0), 0), 5); var left = new PolygonShape(PolygonTools.CreateRectangle(0.1f, height / 2, new Vector2(0, height / 2), 0), 5); var right = new PolygonShape(PolygonTools.CreateRectangle(0.1f, height / 2, new Vector2(width, height / 2), 0), 5); body.CreateFixture(bottom); body.CreateFixture(top); body.CreateFixture(left); body.CreateFixture(right); }
public Zombie(Rectangle pos, Map m) : base(m) { Body BodyDec = new Body(m.PhysicalWorld); BodyDec.BodyType = BodyType.Dynamic; Fixture = BodyDec.CreateFixture(new CircleShape(15f, 2.5f)); //Fixture.Restitution = 0f; walkAnim = new Animation(); walkNormalAnim = new AnimationNormal(); walkAnim.Load("ZombieAnim", Vector2.One * 64, 6, 200); walkNormalAnim.Load("ZombieAnim_normal", Vector2.One * 64, 6, 200, (LightingEngine)Renderer.GetRenderEffect("LightingEngine")); walkAnim.Center = Vector2.One * 32; walkNormalAnim.Center = Vector2.One * 32; Position = pos; hp = 100; def = 1; damage = 2; lucky = 1; SetName("zombie"); sounds = new Dictionary<string, ISound>(); //sounds.Add("Sounds/Mobs/zombie_walk", GeneralManager.Sounds["Sounds/Mobs/zombie_walk"].CreateInstance()); //sounds.Add("zombie_moan", GeneralManager.Sounds["Sounds/Mobs/zombie_moan"].CreateInstance()); //pfinder = new PathFinderFast(m.GetChunk().GetCostArray()); }
public Ship(World world, SpawnData spawn, int id) { Ball = null; Id = id; IsThrusting = false; IsReversing = false; IsBoosting = false; IsLeftTurning = false; IsRightTurning = false; IsShooting = false; IsBlocked = false; IsBlockedFrame = false; Color = spawn.Color; var body = new Body(world); body.Rotation = FMath.Atan2(-spawn.Position.Y, -spawn.Position.X); body.Position = spawn.Position; var shape = new CircleShape(radius, 1f); body.BodyType = BodyType.Dynamic; body.FixedRotation = true; Fixture = body.CreateFixture(shape); Fixture.Restitution = restitution; var bodyGravity = new Body(world); bodyGravity.Position = spawn.Position; var shapeGravity = new CircleShape(radiusGravity, 1f); bodyGravity.FixedRotation = true; FixtureGravity = bodyGravity.CreateFixture(shapeGravity); FixtureGravity.IsSensor = true; }
public Missile( ISoundManager soundManager, World world, Collection<IDoodad> doodads, int numberOfBounces, Team team, Vector2 position, float rotation, DoodadFactory doodadFactory) { this.soundManager = soundManager; this.doodadFactory = doodadFactory; this.world = world; this.doodads = doodads; this.numberOfBounces = numberOfBounces; this.body = BodyFactory.CreateBody(world, position, this); this.body.BodyType = BodyType.Dynamic; this.body.FixedRotation = true; CircleShape shape = new CircleShape(5 / Constants.PixelsPerMeter, 0.1f); Fixture fixture = body.CreateFixture(shape); fixture.Restitution = 1; fixture.Friction = 0; fixture.CollisionCategories = PhysicsConstants.MissileCategory; fixture.CollidesWith = PhysicsConstants.EnemyCategory | PhysicsConstants.PlayerCategory | PhysicsConstants.ObstacleCategory | PhysicsConstants.MissileCategory | PhysicsConstants.SensorCategory; obstacleCollisionCtr = 0; Vector2 force = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) * 3; this.body.ApplyForce(force); }
protected Bullet(Ship parent, Vector2 offset, Vector2 speed, string texture) : base(parent, texture, parent.Size) { Sprite.Origin = new Vector2f(Sprite.Texture.Size.X / 2f, 0); #region Body Initialize Body = new Body(State.World); Body.BodyType = BodyType.Dynamic; Body.IsBullet = true; var shape = new CircleShape((0.15f / 4) * parent.Size, 0); Body.CreateFixture(shape); Body.Position = parent.Body.Position + parent.Body.GetWorldVector(offset); Body.Rotation = parent.Body.Rotation; Body.OnCollision += (a, b, contact) => { if (!Collision(a, b, contact)) return false; Dead = true; return false; }; Body.LinearVelocity = Parent.Body.LinearVelocity + Parent.Body.GetWorldVector(speed); Body.UserData = this; #endregion }
public Asteroid(State state, Vector2 position, int? typeOverride = null, bool isStatic = false) : base(state) { var type = typeOverride.HasValue ? typeOverride.Value : Program.Random.Next(Radiuses.Count); var radius = Radiuses[type]; _sprite = new Sprite(Assets.LoadTexture(string.Format("asteroid{0}.png", type))).Center(); var c = (byte)Program.Random.Next(180, 255); _sprite.Color = new Color(c, c, c); #region Body Initialize Body = new Body(State.World); Body.BodyType = BodyType.Dynamic; Body.LinearDamping = 0.5f; Body.AngularDamping = 0.5f; var shape = new FarseerPhysics.Collision.Shapes.CircleShape(radius, 20 * radius); Body.CreateFixture(shape); Body.UserData = this; if (isStatic) Body.BodyType = BodyType.Static; Body.Position = position; Body.Rotation = (float)(Program.Random.NextDouble() * (Math.PI * 2)); #endregion }
public Key(Rectangle pos, Map map) : base(map) { Body BodyDec = new Body(map.PhysicalWorld); BodyDec.BodyType = BodyType.Static; PolygonShape S = new PolygonShape(1f); S.SetAsBox(pos.Width / 2, pos.Height / 2); Fixture = BodyDec.CreateFixture(S); Fixture.Restitution = 1f; Fixture.Friction = 10f; this.Position = pos; SetName("Key"); LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine"); light = new PointLight() { IsEnabled = true, Color = new Vector4(0.95f, .7f, .05f, 1f), Power = power, LightDecay = 350, Position = new Vector3(Position.X, Position.Y, 20), Direction = new Vector3(0,0, 0) }; LE.AddLight(light); }
private void onGridSizeChanged(object sender, SizeChangedEventArgs e) { Debug.WriteLine("width: " + LayoutRoot.ActualWidth + " height: " + LayoutRoot.ActualHeight); if (ball == null) { float width = (float)LayoutRoot.ActualWidth; float height = (float)LayoutRoot.ActualHeight; ballBody = BodyFactory.CreateBody(world, new Vector2(ConvertUnits.ToSimUnits(width / 2f), ConvertUnits.ToSimUnits(height / 2f))); ballBody.BodyType = BodyType.Dynamic; ballBody.LinearDamping = 1f; CircleShape circleShape = new CircleShape(ConvertUnits.ToSimUnits(8f), 1f); Fixture fixture = ballBody.CreateFixture(circleShape); fixture.OnCollision += OnBalCollision; ball = new Ball(canvas, 8, new System.Windows.Point(width / 2f, height / 2f)); } if (level == null) { level = new Level(currentLevel, canvas); Body wallBody; System.Windows.Point position; foreach (Wall wall in level.getWalls()) { position = wall.getPosition(); wallBody = BodyFactory.CreateRectangle( world, ConvertUnits.ToSimUnits(wall.getWidth()), ConvertUnits.ToSimUnits(wall.getHeight()), 0.001f, new Vector2(ConvertUnits.ToSimUnits(position.X + wall.getWidth() / 2f), ConvertUnits.ToSimUnits(position.Y + wall.getHeight() / 2f)) ); wallBody.Restitution = 0.25f; } ballBody.Position = new Vector2(ConvertUnits.ToSimUnits(level.getStart().X), ConvertUnits.ToSimUnits(level.getStart().Y)); ball.setPosition(new System.Windows.Point(ConvertUnits.ToDisplayUnits(ballBody.Position.X), ConvertUnits.ToDisplayUnits(ballBody.Position.Y))); } }
public Chest(Rectangle r,Map m) : base(m) { Body BodyDec = new Body(m.PhysicalWorld); BodyDec.BodyType = BodyType.Static; PolygonShape S = new PolygonShape(1f); S.SetAsBox(r.Width / 2, r.Height / 2); Fixture = BodyDec.CreateFixture(S); Fixture.Restitution = 1f; Fixture.Friction = 10f; Position = r; SetName("Chest"); items = new List<Item>(); ChestWindow = new Window(GeneralManager.GetPartialRect(0.4f, 0.2f, 0.2f, 0.6f)); ChestWindow.BgTex = GeneralManager.Textures["GUI/InGameGUI/ChestMenuBg"]; ChestWindow.Visible = false; CloseButton = new Button(new Rectangle(ChestWindow.Position.Width - 32, 8, 24, 24), "", GeneralManager.Textures["GUI/InGameGUI/CloseButton"], Color.Gray, Color.White, null); CloseButton.Action = CloseChestWindow; ChestWindow.AddGUI(CloseButton ); list = new ListBox(new Rectangle(16,16,ChestWindow.Position.Width - 24,ChestWindow.Position.Height - 32)); ChestWindow.AddGUI(list); Map.Parent.AddGUI(ChestWindow); }
private RopeTest() { Body ground; { ground = new Body(World); EdgeShape shape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f)); ground.CreateFixture(shape); } { Body prevBody = ground; PolygonShape largeShape = new PolygonShape(PolygonTools.CreateRectangle(1.5f, 1.5f), 100); PolygonShape smallShape = new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.125f), 20); const int N = 10; const float y = 15; for (int i = 0; i < N; ++i) { Body body = BodyFactory.CreateBody(World); body.BodyType = BodyType.Dynamic; body.Position = new Vector2(0.5f + 1.0f * i, y); if (i == N - 1) { Fixture fixture = body.CreateFixture(largeShape); fixture.Friction = 0.2f; fixture.CollisionCategories = Category.Cat2; fixture.CollidesWith = Category.All & ~Category.Cat2; body.Position = new Vector2(1.0f * i, y); body.AngularDamping = 0.4f; } else { Fixture fixture = body.CreateFixture(smallShape); fixture.Friction = 0.2f; fixture.CollisionCategories = Category.Cat1; fixture.CollidesWith = Category.All & ~Category.Cat2; } Vector2 anchor = new Vector2(i, y); RevoluteJoint jd = new RevoluteJoint(prevBody, body, prevBody.GetLocalPoint(ref anchor), body.GetLocalPoint(ref anchor)); jd.CollideConnected = false; World.AddJoint(jd); prevBody = body; } _rj = new RopeJoint(ground, prevBody, new Vector2(0, y), Vector2.Zero); //FPE: The two following lines are actually not needed as FPE sets the MaxLength to a default value const float extraLength = 0.01f; _rj.MaxLength = N - 1.0f + extraLength; World.AddJoint(_rj); } }
public Goalie(World world, GoalieData spawn) { var body = new Body(world); var angle = spawn.End - spawn.Begin; body.Rotation = FMath.Atan2(angle.Y, angle.X); segment.A = spawn.Begin; segment.B = spawn.End; var normal = new Vector2(-angle.Y, angle.X); normal.Normalize(); delta = normal * .5f; segmentOut.A = spawn.Begin + delta; segmentOut.B = spawn.End + delta; segmentIn.A = spawn.Begin - delta; segmentIn.B = spawn.End - delta; body.Position = spawn.Begin; var verts = new Vertices(); verts.Add(new Vector2(left, bottom)); verts.Add(new Vector2(right, bottom)); verts.Add(new Vector2(right, top)); verts.Add(new Vector2(left, top)); var shape = new PolygonShape(verts, 1f); body.FixedRotation = true; body.BodyType = BodyType.Dynamic; Fixture = body.CreateFixture(shape); }
private WheelJointTest() { Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f)); { PolygonShape shape = new PolygonShape(1); shape.Vertices = PolygonTools.CreateRectangle(0.5f, 2.0f); Body body = new Body(World); body.BodyType = BodyType.Dynamic; body.Position = new Vector2(0.0f, 7.0f); body.CreateFixture(shape); Vector2 axis = new Vector2(-1000.0f, -2.0f); axis.Normalize(); WheelJoint jd = new WheelJoint(ground, body, new Vector2(0, 8.5f), axis); jd.MotorSpeed = 1.0f; jd.MaxMotorTorque = 1000.0f; jd.MotorEnabled = true; jd.SpringFrequencyHz = 1.0f; jd.SpringDampingRatio = 0.2f; World.AddJoint(jd); PolygonShape shape2 = new PolygonShape(1); shape2.Vertices = PolygonTools.CreateRectangle(0.5f, 2.0f); Body body2 = BodyFactory.CreatePolygon(World, shape2.Vertices, 0.5f); body2.BodyType = BodyType.Dynamic; body2.Position = new Vector2(10.0f, 7.0f); } }
public NetworkCollisionRemnant(Vector2 position, float size, float angleOfStartForce, int ownerId, Color color, World world, Player creator) : base(position, size, color, null, creator) { OwnerId = ownerId; body = BodyFactory.CreateBody(world); body.BodyType = BodyType.Dynamic; body.Position = ConvertUnits.ToSimUnits(position); body.FixedRotation = true; body.LinearDamping = 0.8f; //Create the vertices that will create the collision shape Vertices verts = new Vertices(); verts.Add(new Vector2(-ConvertUnits.ToSimUnits(size / 2f), ConvertUnits.ToSimUnits(size / 2f))); verts.Add(new Vector2(-ConvertUnits.ToSimUnits(size / 2f), -ConvertUnits.ToSimUnits(size / 2f))); verts.Add(new Vector2(ConvertUnits.ToSimUnits(size / 2f), -ConvertUnits.ToSimUnits(size / 2f))); verts.Add(new Vector2(ConvertUnits.ToSimUnits(size / 2f), ConvertUnits.ToSimUnits(size / 2f))); //Create the shape and attach it to the body PolygonShape s = new PolygonShape(verts, 0); body.CreateFixture(s); body.FixtureList[0].IsSensor = true; body.UserData = this; body.CollidesWith = Category.Cat2; body.CollisionCategories = Category.Cat2; //body.OnSeparation += body_OnSeparation; body.ApplyLinearImpulse(new Vector2((float)Math.Cos(angleOfStartForce),(float)Math.Sin(angleOfStartForce)) * 10f); }
public override Body CreateBody(World world) { var unitHull = (Vector2[])ResourceDictionary.GetResource("UnitHull"); var scaledVertices = new List<Vector2>(); foreach (var vertex in unitHull) { scaledVertices.Add(new Vector2(vertex.X * _resource.Width, vertex.Y * _resource.Height)); } var vertices = new Vertices(scaledVertices); var body = new Body(world); body.BodyType = BodyType.Static; var location = ((ILocatable)_actor).Location; body.Position = new Vector2(location.X, location.Y); var shape = new PolygonShape(vertices, 1f); var fixture = body.CreateFixture(shape, 0f); fixture.UserData = new CollisionData { Actor = _actor }; fixture.CollisionGroup = _resource.CollisionGroup; fixture.OnCollision += OnCollision; _body = body; return body; }
public override Body CreateBody(World world) { var unithull = new Vertices((Vector2[])this.ResourceDictionary.GetResource(_resource.CollisionHullKey)); var scaledVertices = new List<Vector2>(); foreach (var vertex in unithull) { scaledVertices.Add(new Vector2(vertex.X * _resource.Width, vertex.Y * _resource.Height)); } var vertices = new Vertices(scaledVertices); var body = new Body(world); body.BodyType = BodyType.Dynamic; body.IgnoreGravity = true; body.LinearDamping = 0.0f; body.FixedRotation = true; body.Mass = 0; var location = ((ILocatable)_actor).Location; body.Position = new Vector2(location.X, location.Y); var shape = new PolygonShape(vertices, 1f); var fixture = body.CreateFixture(shape, 0f); fixture.CollisionGroup = _resource.CollisionGroup; fixture.UserData = new CollisionData { Actor = _actor }; fixture.OnCollision += OnCollision; _body = body; return body; }
public RedAlarmLamp(Rectangle r, Map m) : base(m) { Body BodyDec = new Body(m.PhysicalWorld); BodyDec.BodyType = BodyType.Static; PolygonShape S = new PolygonShape(1f); S.SetAsBox(r.Width / 2, r.Height / 2); Fixture = BodyDec.CreateFixture(S); Fixture.Restitution = 1f; Fixture.Friction = 10f; Position = r; SetName("RedAlarmLamp"); AlertLight = new SpotLight() { IsEnabled = true, Color = new Vector4(0.9f, .1f, .1f, 1f), Power = .6f, LightDecay = 600, Position = new Vector3(r.X, r.Y, 20), SpotAngle = 1.5f, SpotDecayExponent = 3, Direction = new Vector3(0.244402379f, 0.969673932f, 0) }; LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine"); LE.AddLight(AlertLight); }
void SetupPhysics() { if(body == null) { body = GetComponent<FSBodyComponent>().PhysicsBody; body.CreateFixture(CreateDiamond(Height, Width, Density)); } }
private static void CreateBullets(Body ship) { Func<Vector2, Body> createBullet = pos => { var body = new Body(world); body.BodyType = BodyType.Dynamic; body.IsBullet = true; var shape = new FarseerCircleShape(0.15f / 4, 1); body.CreateFixture(shape); body.Position = ship.Position + ship.GetWorldVector(pos); body.Rotation = ship.Rotation; body.ApplyForce(body.GetWorldVector(new Vector2(0.0f, -15f))); body.OnCollision += (a, b, contact) => { world.RemoveBody(body); return false; }; return body; }; createBullet(new Vector2(-0.575f, -0.20f)); createBullet(new Vector2(0.575f, -0.20f)); }
public FarseerObject(FarseerWorld world, Shape shape, BodyType BodyType = BodyType.Dynamic) { body = new Body(world.World); body.BodyType = BodyType; body.CreateFixture(shape); body.Enabled = false; }
public CoolRibbonObject(World world, Texture2D tex) { points = new List<Vector2>(); points.Add(new Vector2(4, -1)); points.Add(new Vector2(4, 22)); points.Add(new Vector2(30, 22)); points.Add(new Vector2(30, -1)); stops = new float[4]; for(int i = 0; i < points.Count-1; i++) { stops[i] = Vector2.Distance(points[i],points[i+1]); } body = BodyFactory.CreateBody(world); body.BodyType = BodyType.Static; body.Position = new Vector2(0,0); body.UserData = this; hinges = new List<Hinge>(); AddBox(world, tex); ChainShape chain = new ChainShape(new Vertices(points)); fixture = body.CreateFixture(chain); }
public static Fixture AttachRectangle(float width, float height, float density, Vector2 offset, Body body, object userData = null) { Vertices rectangleVertices = PolygonTools.CreateRectangle(width / 2, height / 2); rectangleVertices.Translate(ref offset); PolygonShape rectangleShape = new PolygonShape(rectangleVertices, density); return body.CreateFixture(rectangleShape, userData); }
public static Fixture AttachPolygon(Vertices vertices, float density, Body body, object userData = null) { if (vertices.Count <= 1) throw new ArgumentOutOfRangeException("vertices", "Too few points to be a polygon"); PolygonShape polygon = new PolygonShape(vertices, density); return body.CreateFixture(polygon, userData); }
//Contributed by Matthew Bettcher /// <summary> /// Convert a path into a set of edges and attaches them to the specified body. /// Note: use only for static edges. /// </summary> /// <param name="path">The path.</param> /// <param name="body">The body.</param> /// <param name="subdivisions">The subdivisions.</param> public static void ConvertPathToEdges(Path path, Body body, int subdivisions) { Vertices verts = path.GetVertices(subdivisions); if (path.Closed) { LoopShape loop = new LoopShape(verts); body.CreateFixture(loop); } else { for (int i = 1; i < verts.Count; i++) { body.CreateFixture(new EdgeShape(verts[i], verts[i - 1])); } } }
public static Fixture AttachCircle(float radius, float density, Body body, object userData) { if (radius <= 0) throw new ArgumentOutOfRangeException("radius", "Radius must be more than 0 meters"); CircleShape circleShape = new CircleShape(radius, density); return body.CreateFixture(circleShape, userData); }
void SetupPhysics() { if(body == null) { body = GetComponent<FSBodyComponent>().PhysicsBody; body.CreateFixture(CreateEqlTriangle(SideLength, Density)); } }
public FarseerObject(FarseerWorld world, Vertices vertices, float density = 1, BodyType BodyType = BodyType.Dynamic) { Shape shape = new PolygonShape(vertices, density); body = new Body(world.World); body.BodyType = BodyType; body.CreateFixture(shape); body.Enabled = false; }
public Missile(Ship parent, Vector2 offset, Vector2 speed, string texture) : base(parent, texture, parent.Size) { #region Body Initialize Body = new Body(State.World); Body.BodyType = BodyType.Dynamic; Body.IsBullet = true; Body.LinearDamping = 1; Body.AngularDamping = 1; var size = parent.Size; var shape = new PolygonShape(PolygonTools.CreateRectangle(0.05f * size, 0.2f * size, new Vector2(0) * size, 0), 1); Body.CreateFixture(shape); Body.Position = parent.Body.Position + parent.Body.GetWorldVector(offset); Body.Rotation = parent.Body.Rotation; Body.OnCollision += (a, b, contact) => { if (b.Body.UserData == Parent) return false; if (b.Body.UserData is Projectile) // TODO: damage return false; var entityB = b.Body.UserData as Entity; if (entityB != null) Hit(entityB); Dead = true; return false; }; Body.LinearVelocity = Parent.Body.LinearVelocity + Parent.Body.GetWorldVector(speed); Body.UserData = this; #endregion var start = Body.Position; var point = start + Util.RadarLengthDir(Body.Rotation - (Util.Pi2 / 4), 50); var min = 100f; Entity entity = null; // TODO: use multiple rays parent.State.World.RayCast((f, p, n, fr) => { if (f.Body == parent.Body || f.Body.UserData is Bullet) return -1; if (fr > min) return 1; min = fr; entity = (Entity)f.Body.UserData; return fr; }, start, point); if (entity is Ship) _target = entity; }
public DynamicBody(GameWorld World, Shape Shape, Vector2 Position, string TexName) : base(World) { Body BodyDec; BodyDec = new Body(World.PhysicalWorld); BodyDec.BodyType = BodyType.Dynamic; BodyFixture = BodyDec.CreateFixture(Shape); BodyFixture.Body.Position = Position; Texture = GeneralManager.Textures[TexName]; }
public Body(Vector2?position = null, Dyn.BodyType bodyType = Dyn.BodyType.Dynamic) : base() { Shape = Body.RectShape(10, 20); BodyType = bodyType; var pos = position ?? Vector2.Zero; Xna.Vector2 xpos = Util.ConvertVector2(pos); PBody = new Dyn.Body(DummyWorld, position: xpos, userdata: this); Fixture = PBody.CreateFixture(Shape, userData: this); PBody.BodyType = BodyType; }
public void CreateBoxCollider(int width, int height) { var w = FarseerPhysics.ConvertUnits.ToSimUnits(width); var h = FarseerPhysics.ConvertUnits.ToSimUnits(height); FarseerPhysics.Common.Vertices rectangleVertices = FarseerPhysics.Common.PolygonTools.CreateRectangle(w / 2, h / 2); FarseerPhysics.Collision.Shapes.PolygonShape rectangleShape = new FarseerPhysics.Collision.Shapes.PolygonShape(rectangleVertices, 1.0f); var fixture = _body.CreateFixture(rectangleShape); //fixture.IsSensor = true; fixture.OnCollision += HandleCollision; fixture.Friction = 0f; fixture.Body.Mass = 10f; fixture.Body.FixedRotation = true; }