コード例 #1
0
        public override void Start()
        {
            //Set up our obstacle course
            ActorFactory.Instance.LoadLevel("maze");

            //Create the bounding box that will limit the pathfinding search area
            BoundingBox2D bounds = new BoundingBox2D(new Vector2(-20, -20), new Vector2(20, 20));

            //Create our pathfinding graph. In our 2D worlds, this is a relatively fast
            // operation -- you shouldn't be doing it every frame, but recalculating every
            // so often if your world has changed is not inappropriate.
            SpatialGraphManager.Instance.CreateGraph(
                0.75f, //The size of the entity you want to pathfind (so the generator
                       //  can know how small a space can be and still have it fit.)
                ref bounds //The search area
            );

            //Create a MazeFinder (class definition below), and put him in the bottom
            //  left corner of the maze
            _mf = new MazeFinder();
            _mf.Position = new Vector2(-11.5f, -8.0f);
            World.Instance.Add(_mf, 2);

            //Send him to the upper right, watch him scurry
            _mf.GoTo(Vector2.Zero);

            // Register this object as the mouse listener
            InputManager.Instance.RegisterMouseListener(this);

            //Demo housekeeping below this point.
            #region Demo housekeeping
            String description = "This little dude is pathfinding through the area.";
            description += "\n\nClick the mouse to give him a new target.";
            description += "\n\nPress [B] to see the pathfinding graph.";
            TextActor t = new TextActor("Console", description);
            t.TextAlignment = TextActor.Alignment.Center;
            t.Position = new Vector2(0.0f, -5.0f);
            World.Instance.Add(t, 2);
            TextActor fileLoc = new TextActor("ConsoleSmall", "DemoScreenPathfinding.cs");
            fileLoc.Position = World.Instance.Camera.ScreenToWorld(5, 755);
            fileLoc.Color = new Color(.3f, .3f, .3f);
            World.Instance.Add(fileLoc, 2);
            _objects.Add(fileLoc);
            _objects.Add(t);
            _objects.Add(_mf);

            Actor[] walls = TagCollection.Instance.GetObjectsTagged("maze_wall");
            foreach(Actor a in walls)
                _objects.Add(a);
            #endregion
        }
コード例 #2
0
 public override void Stop()
 {
     SpatialGraphManager.Instance.DrawGraph = false;
     _mf = null;
     base.Stop();
 }