Esempio n. 1
0
        /// <summary>
        /// Builds the chain of Bodies with joints and add this chain into World.
        /// </summary>
        /// <param name="position">Direction and position of first chain member.</param>
        /// <param name="boxLength">Chain member (rectangle) length</param>
        /// <param name="boxWidth">Chain member (rectangle) height</param>
        /// <param name="boxMass">Chain member mass</param>
        /// <param name="spacing">Distance between chain members</param>
        /// <param name="length">The chain length</param>
        /// <param name="modelId">Id of the parent Model entity</param>
        /// <returns>The list of Bodies created</returns>
        public static IList <BaseModelBody> BuildChain(Vector2D position, Scalar boxLength, Scalar boxWidth, Scalar boxMass, Scalar spacing, Scalar length, Guid modelId)
        {
            var         bodies = new List <BaseModelBody>();
            ChainMember last   = null;

            for (Scalar x = 0; x < length; x += boxLength + spacing, position.X += boxLength + spacing)
            {
                var current = ChainMember.Create(CreateRectangle(boxWidth, boxLength, boxMass, new ALVector2D(0, position)), modelId);
                Will.Instance.AddBody(current);

                if (last != null)
                {
                    var anchor = (current.State.Position.Linear + last.State.Position.Linear) * .5f;

                    var joint = new HingeJoint(last, current, anchor, new Lifespan())
                    {
                        DistanceTolerance = 50, Softness = 0.005f
                    };

                    last.EndJoint = current.BegJoint = joint;

                    Will.Instance.AddJoint(joint);
                }

                bodies.Add(current);

                last = current;
            }
            return(bodies);
        }
Esempio n. 2
0
    public FoodChain()
    {
        type = ChainMember.nul;
        List <FoodChain> all = new List <FoodChain>();

        all.Add(new FoodChain(ChainMember.shrub));
        all.Add(new FoodChain(ChainMember.algae));
        all.Add(new FoodChain(ChainMember.grass));
        all.Add(new FoodChain(ChainMember.rabbit));
        all.Add(new FoodChain(ChainMember.fish));
        all.Add(new FoodChain(ChainMember.mouse));
        all.Add(new FoodChain(ChainMember.cat));
        all.Add(new FoodChain(ChainMember.eagle));
        all[0].Predator.Add(all[3]);
        all[1].Predator.Add(all[4]);
        all[2].Predator.Add(all[3]);
        all[2].Predator.Add(all[5]);
        all[3].Prey.Add(all[0]);
        all[3].Prey.Add(all[2]);
        all[3].Predator.Add(all[7]);
        all[4].Prey.Add(all[1]);
        all[4].Predator.Add(all[6]);
        all[5].Prey.Add(all[2]);
        all[5].Predator.Add(all[6]);
        all[5].Predator.Add(all[7]);
        all[6].Prey.Add(all[4]);
        all[6].Prey.Add(all[5]);
        all[6].Predator.Add(all[7]);
        all[7].Prey.Add(all[3]);
        all[7].Prey.Add(all[5]);
        all[7].Prey.Add(all[6]);
        Predator.Add(all[0]);
        Predator.Add(all[1]);
        Predator.Add(all[2]);
    }
Esempio n. 3
0
 public bool Query(ChainMember t, List <FoodChain> predator, List <FoodChain> prey)
 {
     if (type == t)
     {
         predator = Predator;
         prey     = Prey;
         return(true);
     }
     for (int i = 0; i < Predator.Count; i++)
     {
         if (Predator[i].Query(t, predator, prey))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 4
0
 FoodChain(ChainMember m)
 {
     type = m;
 }