public TBuilderMethodResult CoheseWithNeighbors(Proximity proximity)
        {
            var behaviour = new CoheseWithNeighbors(proximity);

            Accept(behaviour);
            return(GetBuilderMethodResult());
        }
        public TBuilderMethodResult SeparateFromNeighbors(Proximity proximity)
        {
            var behaviour = new SeparateFromNeighbors(proximity);

            Accept(behaviour);
            return(GetBuilderMethodResult());
        }
        public TBuilderMethodResult AlignVelocityWithNeighbors(Proximity proximity)
        {
            var behaviour = new AlignVelocityWithNeighbors(proximity);

            Accept(behaviour);
            return(GetBuilderMethodResult());
        }
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            _linear   = FixVec2.Zero;
            _position = owner.Get <Position>().Value;

            Proximity.FindNeighbors(owner, _proximityCallback);

            var maxVelocity = owner.Get <MaxVelocity>().Value;

            if (_linear.MagnitudeSqr == 0)
            {
                return(SteeringVelocity.Zero);
            }

            _linear.Normalize();
            _linear.Scale(ref maxVelocity);

            return(new SteeringVelocity(_linear));
        }
Beispiel #5
0
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            _averageVelocity = FixVec2.Zero;

            var neighborCount = Proximity.FindNeighbors(owner, _proximityCallback);

            if (neighborCount > 0)
            {
                var maxVelocity = owner.Get <MaxVelocity>().Value;

                _averageVelocity /= neighborCount;

                if (_averageVelocity.MagnitudeSqr == 0)
                {
                    return(SteeringVelocity.Zero);
                }

                _averageVelocity.Normalize();
                _averageVelocity.Scale(ref maxVelocity);
            }

            return(new SteeringVelocity(_averageVelocity));
        }
Beispiel #6
0
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            _centroid = FixVec2.Zero;

            var neighborCount = Proximity.FindNeighbors(owner, _proximityCallback);

            if (neighborCount > 0)
            {
                _centroid /= neighborCount;
                _centroid -= owner.Get <Position>().Value;

                if (_centroid.MagnitudeSqr == 0)
                {
                    return(SteeringVelocity.Zero);
                }

                _centroid.Normalize();

                var maxVelocity = owner.Get <MaxVelocity>().Value;
                _centroid.Scale(ref maxVelocity);
            }

            return(new SteeringVelocity(_centroid));
        }
 public SeparateFromNeighbors(Proximity proximity) : base(proximity)
 {
     _proximityCallback = ProximityCallback;
 }
Beispiel #8
0
 public AlignVelocityWithNeighbors(Proximity proximity) : base(proximity)
 {
     _proximityCallback = ProximityCallback;
 }
Beispiel #9
0
 public CoheseWithNeighbors(Proximity proximity) : base(proximity)
 {
     _proximityCallback = ProximityCallback;
 }