Exemplo n.º 1
0
        public NavNode WanderTarget() //returns a random NavNode that is next to currentNode. Prefers nodes in direction enemy is heading
        {
            System.Random r = new System.Random();
            float         x;
            float         y;

            x  = currentNode.Location.X + (float)(-100 + r.NextDouble() * (200));
            r  = new System.Random();
            y  = currentNode.Location.Y + (float)(-100 + r.NextDouble() * (200));
            x += this.Direction.X * 75;
            y += this.Direction.Y * 75;
            NavNode passNode = navMesh.nodeClosestToPointNextToNode(x, y, currentNode);

            return(passNode);
        }
Exemplo n.º 2
0
 public void AddNode(NavNode nn) //Adds a node to nearest nodes if it is close enough
 {
     if (this.Location.X < nn.Location.X + 51 && this.Location.X > nn.Location.X - 51)
     {
         if (this.Location.Y < nn.Location.Y + 51 && this.Location.Y > nn.Location.Y - 51)
         {
             if (this.Location.Y != nn.Location.Y || this.Location.X != nn.Location.X)
             {
                 nearestNodes.Add(nn);
             }
         }
     }
     if (nearestNodes.Count >= 8) // if the node has 8 near nodes than there no walls near by
     {
         nearWall = false;
     }
 }
Exemplo n.º 3
0
        public NavNode nodeClosestToPoint(float x, float y) //returns NavNode closest to given location
        {
            float   shortestDist = 200;
            NavNode passNode     = new NavNode(0, 0);

            foreach (NavNode n in Mesh)
            {
                float xDif        = x - n.Location.X;
                float yDif        = y - n.Location.Y;
                float currentDist = (float)Math.Sqrt((xDif * xDif) + (yDif * yDif));
                if (currentDist < shortestDist)
                {
                    passNode     = n;
                    shortestDist = currentDist;
                }
            }
            return(passNode);
        }
Exemplo n.º 4
0
        public NavNode nodeClosestToPointNextToNode(float x, float y, NavNode originNode) //returns NavNode next to input Node that is closest to point
        {
            float   shortestDist = 10000;
            NavNode passNode     = new NavNode(0, 0);

            foreach (NavNode n in originNode.nearestNodes)
            {
                if (!n.nearWall)
                {
                    float xDif        = x - n.Location.X;
                    float yDif        = y - n.Location.Y;
                    float currentDist = (float)Math.Sqrt((xDif * xDif) + (yDif * yDif));
                    if (currentDist < shortestDist)
                    {
                        passNode     = n;
                        shortestDist = currentDist;
                    }
                }
            }
            return(passNode);
        }