コード例 #1
0
        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;
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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;
        }
コード例 #4
0
 public override void Enter(Agent a)
 {
     a.col = Color.Red;
 }
コード例 #5
0
 public override void Enter(Agent a)
 {
     a.col = Color.Yellow;
 }
コード例 #6
0
 public override Vector2 Execute(Agent a, GameTime gameTime, Vector2 Target)
 {
     return this.steering.Wander(a, gameTime);
 }
コード例 #7
0
        public virtual void Exit(Agent a)
        {

        }
コード例 #8
0
 void RemoveAgent(Agent a)
 {
     this.agents.Remove(a);
 }
コード例 #9
0
        public virtual void Enter(Agent a)
        {

        }
コード例 #10
0
        private bool CheckForOverlap(Agent a)
        {
            foreach(Agent agent in this.agents)
            {
                if (a.Intersects(agent))
                    return true;
            }

            return false;
        }
コード例 #11
0
 void AddAgent(Agent a)
 {
     this.agents.Add(a);
 }
コード例 #12
0
        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();
        }
コード例 #13
0
        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);
        }
コード例 #14
0
 public void ChangeAgentState(Agent a, State newState)
 {
     a.state.Exit(a);
     a.state = newState;
     a.state.Enter(a);
 }
コード例 #15
0
 public override Vector2 Execute(Agent a, GameTime gameTime, Vector2 Target)
 {
     return this.steering.Seek(a, this.input.mouseDirection);
 }
コード例 #16
0
 public virtual Vector2 Execute(Agent a, GameTime gameTime, Vector2 Target)
 {
     return new Vector2(0, 0);
 }
コード例 #17
0
        public override void Exit(Agent a)
        {

        }
コード例 #18
0
 public override void Enter(Agent a)
 {
     a.col = Color.Blue;
 }