/// <summary> /// Moves the digger up, down, left, or right, /// clearing a path if it was not already clear. /// </summary> /// <param name="dir">An action specifying the direction /// to move in</param> /// <returns>The new location of the digger</returns> protected Vector2 Move(DiggerAction dir) { // Calculate the new location of the digger Vector2 end = transform.position; switch (dir) { case DiggerAction.Up: end += Vector2.up; break; case DiggerAction.Down: end += Vector2.down; break; case DiggerAction.Left: end += Vector2.left; break; case DiggerAction.Right: end += Vector2.right; break; default: throw new System.Exception(dir + " is not a valid directional action."); } // Don't allow the digger to move outside the // maximum size of the area if (end.x < 0 || end.x >= LevelManager.instance.width || end.y < 0 || end.y >= LevelManager.instance.height) { return(transform.position); } // Trigger the coroutine to move the agent isMoving = true; StartCoroutine(SmoothMovement(end)); // Clear out the tile if it was a block if (LevelManager.instance.GetTileAt((int)end.x, (int)end.y) == LevelManager.CELL_BLOCK) { LevelManager.instance.SetTileAt((int)end.x, (int)end.y, LevelManager.CELL_OPEN); } return(end); }
public Step(DiggerAction action, State state) { Action = action; State = state; }