Esempio n. 1
0
        void MoveToTargetNode() //Använder en counter för att gå ett antal pixlar i spökets givna riktning för att sedan byta nod.
        {
            Node n = getNode();

            if (counter == 20)
            {
                if (pathStack == null || pathStack.Count() == 0) // Om vi inte har någon stack skapar vi en ny med en ny väg till målet.
                {
                    FindPath();
                }

                rec.X = targetNode.Y * 20;
                rec.Y = targetNode.X * 20;

                if (pathStack != null && pathStack.Count() != 0)
                {
                    targetNode = (Node)pathStack.Pop();
                }

                targetDirection = new Vector2(targetNode.X, targetNode.Y) - new Vector2(n.X, n.Y);

                if (targetDirection != Vector2.Zero)
                {
                    targetDirection.Normalize();
                }
                counter = 0;
            }
            else
            {
                rec.X += (int)targetDirection.Y;
                rec.Y += (int)targetDirection.X;
                counter++;
            }
        }
Esempio n. 2
0
        public void FindPath() //Initierar en bredden först sökning som returnerar en stack. Hittar en riktning från noden i stacken. Normaliserar värdet sedan värdet och sätyter det till spökets riktning.
        {
            if (target == null)
            {
                return;
            }

            Node n = getNode();
            Node m = target.getNode();

            pathStack = pathFinder.FindPath(n, target.getNode());
            //pathStack = pathFinder.FindPath(n, Map.nodeArray[2, 14]);

            if (pathStack == null || pathStack.Count() == 0)
            {
                return;
            }
            targetNode      = (Node)pathStack.Pop();
            targetDirection = new Vector2(targetNode.X, targetNode.Y) - new Vector2(n.X, n.Y);

            if (targetDirection != Vector2.Zero)
            {
                targetDirection.Normalize();
            }
            else
            {
                targetDirection = Vector2.Zero;
            }
        }
Esempio n. 3
0
        //Initierar en bredden först sökning som returnerar en stack. Hittar en riktning från noden i stacken. Normaliserar värdet sedan värdet och sätyter det till spökets riktning.
        public void FindPath()
        {
            if (target == null)
                return;

            Node n = getNode();
            Node m = target.getNode();
            pathStack = pathFinder.FindPath(n, target.getNode());
            //pathStack = pathFinder.FindPath(n, Map.nodeArray[2, 14]);

            if (pathStack == null || pathStack.Count() == 0)
                return;
            targetNode = (Node)pathStack.Pop();
            targetDirection = new Vector2(targetNode.X, targetNode.Y) - new Vector2(n.X, n.Y);

            if (targetDirection != Vector2.Zero)
                targetDirection.Normalize();
            else
                targetDirection = Vector2.Zero;
        }