示例#1
0
        // Use this for initialization
        void Start()
        {
            boardScript    = GetComponent <BoardManager>();
            playerScript   = GetComponent <PlayerManager>();
            obstacleScript = GetComponent <ObstacleManager>();
            playerScript.obstacleScript = obstacleScript;
            obstacleScript.setupManager(playerScript);

            initBoard();
        }
 public int Movement(int index)
 {
     if (Input.GetKeyDown("up") && !upLock)
     {
         if (ObstacleManager.CheckObstacleTile((int)transform.position.x, (int)transform.position.y + 1) && restMove != 1)
         {
             meetObsracle = true;
         }
         target.y = Mathf.Round(transform.position.y) + 1;
         target.x = Mathf.Round(transform.position.x);
         if (tileCheck((int)target.x, (int)target.y) && (!ObstacleManager.CheckObstacleTile((int)transform.position.x, (int)transform.position.y + 1) || (ObstacleManager.CheckObstacleTile((int)transform.position.x, (int)transform.position.y + 1) && restMove == 1)))
         {
             transform.position = target;
             verticalMoves++;
             //Once the player goes up a floor, vertical moves now keep track of total moves made.
             //Allows changing direction on the new floor without messing up how many squares you moved on the previous floor
             verticalMoves  += Mathf.Abs(horizontalMoves);
             horizontalMoves = 0;
             downLock        = true;
         }
         else
         {
             target = transform.position;
         }
     }
     if (Input.GetKeyDown("down") && !downLock)
     {
         if (ObstacleManager.CheckObstacleTile((int)transform.position.x, (int)transform.position.y - 1) && restMove != 1)
         {
             meetObsracle = true;
         }
         target.y = Mathf.Round(transform.position.y) - 1;
         target.x = Mathf.Round(transform.position.x);
         if (tileCheck((int)target.x, (int)target.y) && (!ObstacleManager.CheckObstacleTile((int)transform.position.x, (int)transform.position.y - 1) || (ObstacleManager.CheckObstacleTile((int)transform.position.x, (int)transform.position.y - 1) && restMove == 1)))
         {
             transform.position = target;
             verticalMoves++;
             //Once the player goes down a floor, vertical moves now keep track of total moves made.
             //Allows changing direction on the new floor without messing up how many squares you moved on the previous floor
             verticalMoves  += Mathf.Abs(horizontalMoves);
             horizontalMoves = 0;
             upLock          = true;
         }
         else
         {
             target = transform.position;
         }
     }
     if (Input.GetKeyDown("right"))
     {
         if (ObstacleManager.CheckObstacleTile((int)transform.position.x + 1, (int)transform.position.y) && restMove != 1)
         {
             meetObsracle = true;
         }
         target.x = Mathf.Round(transform.position.x) + 1;
         target.y = Mathf.Round(transform.position.y);
         if (tileCheck((int)target.x, (int)target.y) && (!ObstacleManager.CheckObstacleTile((int)transform.position.x + 1, (int)transform.position.y) || (ObstacleManager.CheckObstacleTile((int)transform.position.x + 1, (int)transform.position.y) && restMove == 1)))
         {
             transform.position = target;
             horizontalMoves++;
         }
         else
         {
             target = transform.position;
         }
     }
     if (Input.GetKeyDown("left"))
     {
         if (ObstacleManager.CheckObstacleTile((int)transform.position.x - 1, (int)transform.position.y + 1) && restMove != 1)
         {
             meetObsracle = true;
         }
         target.x = Mathf.Round(transform.position.x) - 1;
         target.y = Mathf.Round(transform.position.y);
         if (tileCheck((int)target.x, (int)target.y) && (!ObstacleManager.CheckObstacleTile((int)transform.position.x - 1, (int)transform.position.y) || (ObstacleManager.CheckObstacleTile((int)transform.position.x - 1, (int)transform.position.y) && restMove == 1)))
         {
             transform.position = target;
             horizontalMoves--;
         }
         else
         {
             target = transform.position;
         }
     }
     return((Mathf.Abs(horizontalMoves)) + (Mathf.Abs(verticalMoves)));
 }