Пример #1
0
        /// <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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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;
        }
Пример #4
0
 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;
 }
Пример #5
0
 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;
 }
Пример #6
0
        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;
        }
Пример #7
0
        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;
        }