Пример #1
0
		public AIMap(int width, int height, float horizontalSpan, float verticalSpan)
        {

            this.HorizontalSpan = horizontalSpan;
            this.VerticalSpan = verticalSpan;
            this.width = width;
            this.height = height;

            Vector3 startEdge = new Vector3();
            startEdge.X = this.HorizontalSpan * -0.5f; // graphicsDevice.Viewport.Width * 0.5f;
            startEdge.Y = this.VerticalSpan * -0.5f;// graphicsDevice.Viewport.Height * 0.5f;
            
            float horizontalStep = (float)(this.HorizontalSpan / width);
            float verticalStep = (float)(this.VerticalSpan / height);

            nodes = new AINode[width, height];
            for (int iWidth = 0; iWidth < width; iWidth++)
            {
                for (int iHeight = 0; iHeight < height; iHeight++)
                {
                    AINode newNode = new AINode();
                    newNode.Parent = this;
                    newNode.Type = 1;// +iWidth;// / (iHeight + 1);
                    newNode.X = iWidth;
                    newNode.Y = iHeight;
                    newNode.Position = new Vector3(
                        startEdge.X + horizontalStep * (float)iWidth,
                        startEdge.Y + verticalStep * (float)iHeight,
                        0);
                    nodes[iWidth, iHeight] = newNode;
                }
            } // next iWidth

		}
Пример #2
0
        /// <summary>
        /// Every time an actor changes its position, it remembers all map's nodes
        /// he is in.
        /// </summary>
        public void UpdateLocationData()
        {
            // 1. remove itself from all previous AINodes
            for (int index = 0; index < nodesIamIn.Count; index++)
            {
                // remove myself from AINode I was registered previously
                nodesIamIn[index].Actors.Remove(this);
            }

            nodesIamIn.Clear();

            // 2. add itself to all 
            // - get distance from the center of a map,
            // - extract x and y components,
            // - for each component calculate row and col

            Vector3 vDistanceFromMapCenter = this.position - map.Position;

            float xComponent = (vDistanceFromMapCenter.X / (map.HorizontalSpan / ((float)map.Width )));
            float yComponent = (vDistanceFromMapCenter.Y / (map.VerticalSpan / ((float)map.Height )));

            xComponent = (map.Width  * 0.5f) + xComponent + 0.5f ;
            yComponent = (map.Height * 0.5f) + yComponent +0.5f;

            debugX = (int)xComponent;
            debugY = (int)yComponent;

            int indexX = (int)xComponent;
            int indexY = (int)yComponent;

            AINode desiredNode = map.Node(indexX, indexY);

            // am I out of map?
            desiredNode.Actors.Add(this);
            nodesIamIn.Add(desiredNode);

        }
Пример #3
0
 public AIEdge(AINode startNode, AINode endNode)
 {
     this.startNode = startNode;
     this.endNode   = endNode;
 }