public Vector2 Flee(Agent a, Vector2 Target)
        {
            float PanicDistance = 200;
            if ((a.Location - Target).Length() > PanicDistance)
            {
                return a.steeringForce;
            }

            Vector2 DesiredVel = (Vector2.Normalize(a.Location - Target) * a.maxSpeed);

            return (DesiredVel - a.velocity) * 6;
        }
        public Vector2 Seek(Agent a, Vector2 Target)
        {
            if(a.Location.X > Target.X - 5 && a.Location.X < Target.X + 5 &&
                a.Location.Y > Target.Y + 5 && a.Location.Y < Target.Y - 5)
            {
                return a.steeringForce;
            }

            Vector2 DesiredVelocity = (Vector2.Normalize(Target - a.Location) * a.maxSpeed);

            return (DesiredVelocity - a.velocity) * 4;
        }
        public Vector2 Wander(Agent a, GameTime gameTime)
        {
            int rando = Utility.rand.Next(0, 5);

            if (rando == 1 || rando == 3 || rando == 5)
            {
                if (a.timeSinceStateLastWanderChange < gameTime.TotalGameTime.TotalSeconds - 1)
                {
                    Vector2 NewSteer = new Vector2(Utility.rand.Next(-500, 500), Utility.rand.Next(-500, 500));
                    return NewSteer;
                }
            }

            return a.steeringForce;
        }
 public override void Enter(Agent a)
 {
     a.col = Color.Red;
 }
 public override void Enter(Agent a)
 {
     a.col = Color.Yellow;
 }
 public override Vector2 Execute(Agent a, GameTime gameTime, Vector2 Target)
 {
     return this.steering.Wander(a, gameTime);
 }
Esempio n. 7
0
        public virtual void Exit(Agent a)
        {

        }
 void RemoveAgent(Agent a)
 {
     this.agents.Remove(a);
 }
Esempio n. 9
0
        public virtual void Enter(Agent a)
        {

        }
        private bool CheckForOverlap(Agent a)
        {
            foreach(Agent agent in this.agents)
            {
                if (a.Intersects(agent))
                    return true;
            }

            return false;
        }
 void AddAgent(Agent a)
 {
     this.agents.Add(a);
 }
        void PositionAgent(Agent a)
        {
            a.Location = new Vector2(rand.Next(this.Game.GraphicsDevice.Viewport.Bounds.Left + 10, this.Game.GraphicsDevice.Viewport.Bounds.Right - 10),
                rand.Next(this.Game.GraphicsDevice.Viewport.Bounds.Top + 10, this.Game.GraphicsDevice.Viewport.Bounds.Bottom - 10));

            a.SetTranformAndRect();
        }
        void SpawnAgent()
        {
            Agent a = new Agent(this.Game);
            a.Initialize();

            this.PositionAgent(a);

            while(CheckForOverlap(a))
            {
                this.PositionAgent(a);
            }
            
            a.state = this.stateContainer.wander;
            a.state.Enter(a);
            this.AddAgent(a);
        }
 public void ChangeAgentState(Agent a, State newState)
 {
     a.state.Exit(a);
     a.state = newState;
     a.state.Enter(a);
 }
Esempio n. 15
0
 public override Vector2 Execute(Agent a, GameTime gameTime, Vector2 Target)
 {
     return this.steering.Seek(a, this.input.mouseDirection);
 }
Esempio n. 16
0
 public virtual Vector2 Execute(Agent a, GameTime gameTime, Vector2 Target)
 {
     return new Vector2(0, 0);
 }
Esempio n. 17
0
        public override void Exit(Agent a)
        {

        }
 public override void Enter(Agent a)
 {
     a.col = Color.Blue;
 }