Esempio n. 1
0
 public bool findPath(ref int flags, ref Vector2 velocity, ref Vector2 target, GameObject player, Rigidbody2D body)
 {
     PathFinder.Dir k = player.GetComponent <UpdatePathFind>().path.getTileDir(body.position);
     rotation.rotToPl   = false;
     rotation.playerPos = player.transform.position;
     if (k == PathFinder.Dir.NoDir)
     {
         if (player.GetComponent <UpdatePathFind>().path.getTileDir(new Vector2(body.position.x - 1, body.position.y)) != PathFinder.Dir.NoDir)
         {
             flags  = (int)behavior.findPath;
             target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x - 1, body.position.y));
         }
         else if (player.GetComponent <UpdatePathFind>().path.getTileDir(new Vector2(body.position.x + 1, body.position.y)) != PathFinder.Dir.NoDir)
         {
             flags  = (int)behavior.findPath;
             target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x + 1, body.position.y));
         }
         else if (player.GetComponent <UpdatePathFind>().path.getTileDir(new Vector2(body.position.x, body.position.y - 1)) != PathFinder.Dir.NoDir)
         {
             flags  = (int)behavior.findPath;
             target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x, body.position.y - 1));
         }
         else if (player.GetComponent <UpdatePathFind>().path.getTileDir(new Vector2(body.position.x, body.position.y + 1)) != PathFinder.Dir.NoDir)
         {
             flags  = (int)behavior.findPath;
             target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x, body.position.y + 1));
         }
         else
         {
             return(false);
         }
     }
     else if (k == PathFinder.Dir.Right)
     {
         flags  = (int)behavior.findPath;
         target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x + 1, body.position.y));
     }
     else if (k == PathFinder.Dir.Left)
     {
         flags  = (int)behavior.findPath;
         target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x - 1, body.position.y));
     }
     else if (k == PathFinder.Dir.Up)
     {
         flags  = (int)behavior.findPath;
         target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x, body.position.y + 1));
     }
     else if (k == PathFinder.Dir.Down)
     {
         flags  = (int)behavior.findPath;
         target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x, body.position.y - 1));
     }
     else
     {
         return(false);
     }
     return(true);
 }
Esempio n. 2
0
    void findPath() //gen
    {
        PathFinder.Dir k = player.GetComponent <UpdatePathFind>().path.getTileDir(body.position);

        if (k == PathFinder.Dir.NoDir /*|| k == BreadthFirstSearch.states.wall || k == BreadthFirstSearch.states.unVisited*/)
        {
            flags     = 0;
            velocity *= 0;
        }
        else if (k == PathFinder.Dir.Right)
        {
            flags  = (int)behavior.findPath;
            target = new Vector2(body.position.x + 1, body.position.y);
        }
        else if (k == PathFinder.Dir.Left)
        {
            flags  = (int)behavior.findPath;
            target = new Vector2(body.position.x - 1, body.position.y);
        }
        else if (k == PathFinder.Dir.Up)
        {
            flags  = (int)behavior.findPath;
            target = new Vector2(body.position.x, body.position.y + 1);
        }
        else if (k == PathFinder.Dir.Down)
        {
            flags  = (int)behavior.findPath;
            target = new Vector2(body.position.x, body.position.y - 1);
        }
        else
        {
            flags     = 0;
            velocity *= 0;
        }
        //minne menen
    }
Esempio n. 3
0
 public void reversedFindPath(ref int flags, ref Vector2 velocity, ref Vector2 target, GameObject player, Rigidbody2D body) // älä käytä, riks pox
 {
     int[]          ind = player.GetComponent <UpdatePathFind>().path.calculateIndex(body.position);
     PathFinder.Dir k   = player.GetComponent <UpdatePathFind>().path.getTileDir(body.position);
     rotation.rotToPl   = true;
     rotation.playerPos = player.transform.position;
     if (k == PathFinder.Dir.NoDir)
     {
         flags     = 0;
         velocity *= 0;
     }
     else if (k == PathFinder.Dir.Right)
     {
         flags = (int)behavior.findPath;
         ind[0]--;
         PathFinder.Dir temp = player.GetComponent <UpdatePathFind>().path.getTileDir(ind);
         if (temp != PathFinder.Dir.NoDir || temp != PathFinder.Dir.NoWayOut)
         {
             target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x - 1, body.position.y));
         }
         else
         {
             flags     = 0;
             velocity *= 0;
         }
     }
     else if (k == PathFinder.Dir.Left)
     {
         flags = (int)behavior.findPath;
         ind[0]++;
         PathFinder.Dir temp = player.GetComponent <UpdatePathFind>().path.getTileDir(ind);
         if (temp != PathFinder.Dir.NoDir || temp != PathFinder.Dir.NoWayOut)
         {
             target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x + 1, body.position.y));
         }
         else
         {
             flags     = 0;
             velocity *= 0;
         }
     }
     else if (k == PathFinder.Dir.Up)
     {
         flags = (int)behavior.findPath;
         ind[1]++;
         PathFinder.Dir temp = player.GetComponent <UpdatePathFind>().path.getTileDir(ind);
         if (temp != PathFinder.Dir.NoDir || temp != PathFinder.Dir.NoWayOut)
         {
             target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x, body.position.y - 1));
         }
         else
         {
             flags     = 0;
             velocity *= 0;
         }
     }
     else if (k == PathFinder.Dir.Down)
     {
         flags = (int)behavior.findPath;
         ind[1]--;
         PathFinder.Dir temp = player.GetComponent <UpdatePathFind>().path.getTileDir(ind);
         if (temp != PathFinder.Dir.NoDir || temp != PathFinder.Dir.NoWayOut)
         {
             target = player.GetComponent <UpdatePathFind>().path.getTileTrans(new Vector2(body.position.x, body.position.y + 1));
         }
         else
         {
             flags     = 0;
             velocity *= 0;
         }
     }
     else
     {
         flags     = 0;
         velocity *= 0;
     }
 }