Example #1
0
        private void LoadLevel1()
        {
            List <Actor> obstacles     = new List <Actor>();
            Color        obstacleColor = new Color(255, 200, 96);

            for (int i = 0; i < 4; i++)
            {
                obstacles.Add(new Actor("Common/arrow", obstacleColor));
            }

            obstacles[0].Position = new Vector2(250, -200);
            obstacles[1].Position = new Vector2(530, -200);
            obstacles[2].Position = new Vector2(250, -400);
            obstacles[3].Position = new Vector2(530, -400);

            Actor leader = new Actor("Common/arrow", new Color(64, 255, 64));

            leader.Speed     = 1.0f;
            leader.Direction = Actor.GetRandomDirection();
            leader.Position  = new Vector2(0, -100); // Actor.GetRandomPosition(1280, 720);
            //leader.BehaviorList.Add(new BehaviorConstant(0.1f, new Vector2(1, 0))); // Direction pointing right
            leader.BehaviorList.Add(new BehaviorInput(0.5f));
            leader.BehaviorList.Add(new BehaviorWander(0.05f, 60)); // if we have 60 fps, this changes the wander direction every second

            Behavior seek = new BehaviorSeek(0.05f, leader);

            for (int i = 0; i < 10; i++)
            {
                Actor drone = new Actor("Common/arrow", Color.White);
                drone.Speed     = 0.9f;
                drone.Direction = Actor.GetRandomDirection();
                drone.Position  = new Vector2(0, -200);
                drone.BehaviorList.Add(seek);
                drone.BehaviorList.Add(new BehaviorWander(0.03f, 15));      // flocking result, better: avoid behavior

                // drone must avoid each of the multiple obstacles
                foreach (var obstacle in obstacles)
                {
                    drone.BehaviorList.Add(new BehaviorAvoid(0.2f, obstacle, 60));
                }
            }

            // leader shall also avoid the obstacles
            foreach (var obstacle in obstacles)
            {
                leader.BehaviorList.Add(new BehaviorAvoid(0.2f, obstacle, 60));
            }
        }
Example #2
0
    //----------------------------------------------------------------------
    //----------------------------------------------------------------------
    void Awake()
    {
        Agent sAgent = GetComponent <Agent>();

        BehaviorWallAvoidance sWallAvoid = new BehaviorWallAvoidance(sAgent, 1.0f);

        //sWallAvoid.SetEnabled(true);
        sAgent.AddBehavior(sWallAvoid);

        BehaviorObstacleAvoidance sObsAvoid = new BehaviorObstacleAvoidance(sAgent, 1.0f);

        sObsAvoid.SetEnabled(true);
        sAgent.AddBehavior(sObsAvoid);

        m_sSeek = new BehaviorSeek(sAgent, 0.9f, Vector3.zero);
        m_sSeek.SetEnabled(true);
        sAgent.AddBehavior(m_sSeek);
    }
Example #3
0
 //----------------------------------------------------------------------
 //----------------------------------------------------------------------
 public BehaviorPersue(Agent sAgent, float fWeighting, GameObject oTarget) : base(sAgent, fWeighting)
 {
     m_oTarget = oTarget;
     m_sSeek   = new BehaviorSeek(sAgent, 0.0f, Vector2.zero);
 }
Example #4
0
 //----------------------------------------------------------------------
 //----------------------------------------------------------------------
 public BehaviorFollowPath(Agent sAgent, float fWeighting, GameObject[] oWayPoints) : base(sAgent, fWeighting)
 {
     m_oWayPoints = oWayPoints;
     m_sSeek      = new BehaviorSeek(sAgent, 0.0f, Vector3.zero);
 }