/// <summary> /// Removes an entity from the physics world. /// </summary> /// <param name="entity">The entity to remove</param> public void RemoveEntity(WorldEntity entity) { if (!entities.ContainsKey(entity.Body)) { return; } if (entity.Joint != null) { world.RemoveJoint(entity.Joint); } if (entity.Body != null) { world.RemoveBody(entity.Body); } entities.Remove(entity.Body); }
private void CreateHandFixture(Hand hand) { Vector2 handPos = new Vector2(hand.Position.X, hand.Position.Y); Body handBody = BodyFactory.CreateCircle(world, handSize, 1f, handPos / MeterInPixels); handBody.BodyType = BodyType.Dynamic; // Check what hands should be colliding with if (handCollisionsEnabled) { handBody.OnCollision += HandCollisionCheckDelegate; } else { handBody.OnCollision += HandCollisionFalseDelegate; } FixedMouseJoint handJoint = new FixedMouseJoint(handBody, handBody.Position); handJoint.MaxForce = 10000f; world.AddJoint(handJoint); WorldEntity handEntity = new WorldEntity(handBody, handJoint, WorldEntity.EntityType.Hand); handBodies.Add(hand, handEntity); entities.Add(handBody, handEntity); }
public Hand GetHandForHandEntity(WorldEntity ent) { if (ent.Type != WorldEntity.EntityType.Hand) return null; foreach (Hand hand in handBodies.Keys) { if (handBodies[hand] == ent) return hand; } return null; }
public WorldEntity CreatePlane(Vector2 position) { Vector2 planeSize = ClientPlane.PlaneSize * ClientPlane.PlaneScale / MeterInPixels; Body planeBody = BodyFactory.CreateRectangle(world, planeSize.X, planeSize.Y, 1f, position); WorldEntity entity = new WorldEntity(planeBody, WorldEntity.EntityType.Plane); entities.Add(planeBody, entity); return entity; }
public WorldEntity CreateBucket(Vector2 size, Vector2 position) { Body body = BodyFactory.CreateRectangle(world, size.X, size.Y, 0.1f, position); WorldEntity entity = new WorldEntity(body, WorldEntity.EntityType.Bucket); entities.Add(body, entity); return entity; }
public WorldEntity CreateBoundary(int width, Vector2 position) { Body roofBody = BodyFactory.CreateRectangle(world, width / MeterInPixels, 1 / MeterInPixels, 1f, position / MeterInPixels); roofBody.IsStatic = true; roofBody.Restitution = 0.3f; roofBody.Friction = 1f; WorldEntity entity = new WorldEntity(roofBody, WorldEntity.EntityType.Landscape); entities.Add(roofBody, entity); return entity; }
public WorldEntity CreateBalloon(Vector2 position, Vector2 velocity) { float circleRadius = ClientBalloon.BalloonWidth / (2f * MeterInPixels); Body balloonBody = BodyFactory.CreateCircle(world, circleRadius, 1f, PixelToWorld(position)); balloonBody.BodyType = BodyType.Dynamic; balloonBody.Restitution = 0.3f; balloonBody.Friction = 0.5f; balloonBody.LinearDamping = 1.0f; balloonBody.ApplyLinearImpulse(velocity * balloonBody.Mass); balloonBody.OnCollision += new OnCollisionEventHandler(onBalloonCollision); WorldEntity entity = new WorldEntity(balloonBody, WorldEntity.EntityType.Balloon); entities.Add(balloonBody, entity); return entity; }