public override Vector2?CalculateResultingVector()
        {
            if (ownEntity.velocity == Vector2.Zero)
            {
                return(Vector2.Zero);
            }
            SetFeelers();
            CheckFeelers();

            if (!(feeler1hit || feeler2hit || feeler3hit))
            {
                resultingVector = Vector2.Zero;
                lastDirection   = 0;
                return(resultingVector);
            }

            int strength = 10;

            if (feeler2hit)
            {
                strength = 20;
            }
            if (feeler1hit && feeler2hit && feeler3hit)
            {
                strength = 30;
            }

            Vector2 vector = Vector2.Normalize(ownEntity.velocity);



            if (feeler1hit && !feeler3hit)
            {
                vector         = BehaviourUtil.RotateVector(vector, Math.PI / 2);
                lastDirection += 1;
            }
            else if (!feeler1hit && feeler3hit)
            {
                vector         = BehaviourUtil.RotateVector(vector, -Math.PI / 2);
                lastDirection -= 1;
            }
            else
            {
                if (lastDirection > 0)
                {
                    vector         = BehaviourUtil.RotateVector(vector, Math.PI / 2);
                    lastDirection += 1;
                }
                else
                {
                    vector         = BehaviourUtil.RotateVector(vector, -Math.PI / 2);
                    lastDirection -= 1;
                }
            }

            vector         *= strength;
            resultingVector = vector;
            return(vector);
        }
 public override void Render(GameTime gameTime, SpriteBatch _spriteBatch, Vector2 position)
 {
     if (Settings.RenderSeeking)
     {
         CalculateResultingVector();
         BehaviourUtil.RenderVector(_spriteBatch, Currentvector, position, 20, Color.Red);
     }
 }
Exemple #3
0
 public override void Render(GameTime gameTime, SpriteBatch _spriteBatch, Vector2 Position)
 {
     if (Settings.RenderGroupPressure)
     {
         CalculateResultingVector();
         BehaviourUtil.RenderVector(_spriteBatch, CurrentVector, Position, 1, Color.White);
     }
 }
Exemple #4
0
 public override void Render(GameTime gameTime, SpriteBatch _spriteBatch, Vector2 Position)
 {
     if (Settings.RenderWander)
     {
         CalculateResultingVector();
         //BehaviourUtil.RenderCircle(_spriteBatch, wanderVector + ownEntity.Position, 10, Color.Yellow);
         BehaviourUtil.RenderVector(_spriteBatch, CurrentVector, Position, 20, Color.Navy);
     }
 }
 public void renderPoint(SpriteBatch _spriteBatch, Vector2 position, bool isred)
 {
     if (isred)
     {
         BehaviourUtil.RenderPoint(_spriteBatch, position, Color.Red);
     }
     else
     {
         BehaviourUtil.RenderPoint(_spriteBatch, position, Color.Green);
     }
 }
        public override Vector2?CalculateResultingVector()
        {
            var entities = Game1.GetMovingEntitiesInRange(Range, ownEntity);

            currentVector = new Vector2();
            //get vector for every entity
            foreach (BaseEntity entity in entities)
            {
                currentVector += 20 * BehaviourUtil.CalculateSeekVector(ownEntity.Position, entity.Position);
            }
            return(currentVector);
        }
        public override void Render(GameTime gameTime, SpriteBatch _spriteBatch, Vector2 Position)
        {
            CalculateResultingVector();
            BehaviourUtil.RenderVector(_spriteBatch, resultingVector, Position, 1, Color.Red);

            for (int i = 0; i < feelerArray1.Length; i++)
            {
                renderPoint(_spriteBatch, feelerArray1[i] + Position, feeler1hit);
                renderPoint(_spriteBatch, feelerArray2[i] + Position, feeler2hit);
                renderPoint(_spriteBatch, feelerArray3[i] + Position, feeler3hit);
            }
        }
Exemple #8
0
 public override void Render(GameTime gameTime, SpriteBatch _spriteBatch, Vector2 Position)
 {
     if (Settings.RenderDistancing)
     {
         CalculateResultingVector();
         BehaviourUtil.RenderVector(_spriteBatch, currentVector, Position, 20, Color.Blue);
         foreach (Vector2 target in targets)
         {
             BehaviourUtil.RenderPoint(_spriteBatch, Vector2.Subtract(Position, target), Color.Yellow);
         }
     }
 }
        private void SetFeelers()
        {
            Vector2 feeler2 = Vector2.Normalize(ownEntity.velocity);
            Vector2 feeler1 = BehaviourUtil.RotateVector(feeler2, -Math.PI / 6);
            Vector2 feeler3 = BehaviourUtil.RotateVector(feeler2, Math.PI / 6);

            feelerArray1 = new Vector2[5];
            feelerArray2 = new Vector2[5];
            feelerArray3 = new Vector2[5];

            for (int i = 0; i < feelerArray1.Length; i++)
            {
                feelerArray1[i] = feeler1 * (i + 2) * 20;
                feelerArray2[i] = feeler2 * (i + 2) * 20;
                feelerArray3[i] = feeler3 * (i + 2) * 20;
            }
        }
Exemple #10
0
        public override Vector2?CalculateResultingVector()
        {
            var entities = Game1.GetMovingEntitiesInRange(Settings.DistancingRange, ownEntity);

            currentVector = new Vector2();
            targets       = new List <Vector2>();

            foreach (BaseEntity entity in entities)
            {
                if (ownEntity.GetType() == entity.GetType())
                {
                    Vector2 target = Vector2.Subtract(ownEntity.Position, entity.GetClosestCoords(ownEntity.Position));
                    target  = Vector2.Normalize(target);
                    target *= (float)Settings.DistancingRange / 2;
                    targets.Add(target);
                    currentVector += BehaviourUtil.CalculateSeekVector(ownEntity.Position, Vector2.Add(target, entity.Position));
                }
            }
            return(currentVector);
        }
 public override Vector2?CalculateResultingVector()
 {
     if (Waypoints != null && Target != null)
     {
         if (currentWaypoint < Waypoints.Length - 1)
         {
             if (UpdateAstar && Vector2.DistanceSquared(Target.Position, Target.GetClosestCoords(Waypoints[Waypoints.Length - 1])) > Game1.Grid.RegionSize * Game1.Grid.RegionSize)
             {
                 GenerateWaypoints();
             }
             UpdateWaypoint();
             if (Waypoints != null)
             {
                 return(Currentvector = BehaviourUtil.CalculateSeekVector(ownEntity.Position, Game1.GetClosestCoords(ownEntity.Position, Waypoints[currentWaypoint])));
             }
             return(null);
         }
         return(Currentvector = BehaviourUtil.CalculateSeekVector(ownEntity.Position, Game1.GetClosestCoords(ownEntity.Position, Target.Position)));
     }
     return(null);
 }
 public override Vector2?CalculateResultingVector()
 {
     Currentvector = BehaviourUtil.CalculateSeekVector(ownEntity.Position, Target.GetClosestCoords(ownEntity.Position)) * -1;
     return(Currentvector);
 }