Assets/Scripts/Digger.cs
/// <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>
Moves the digger up, down, left, or right,
clearing a path if it was not already clear.
Moves the digger up down left or right clearing a path if it was not already clear .
protected Vector2 Move (DiggerAction dir)
    {
        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.");
        }
        if(end.x < 0 || end.x >= LevelManager.instance.width
            || end.y < 0 || end.y >= LevelManager.instance.height)
        {
            return transform.position;
        }
        isMoving = true;
        StartCoroutine(SmoothMovement(end));
        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;
    }
protected Vector2 Move ( DiggerAction dir ) { 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 + " " ) ; } if ( end . x < 0 || end . x >= LevelManager . instance . width || end . y < 0 || end . y >= LevelManager . instance . height ) { return transform . position ; } isMoving = true ; StartCoroutine ( SmoothMovement ( end ) ) ; 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 ; }
Moves the digger up, down, left, or right,
clearing a path if it was not already clear.
Moves the digger up down left or right clearing a path if it was not already clear .
// Calculate the new location of the digger // Don't allow the digger to move outside the // maximum size of the area // Trigger the coroutine to move the agent // Clear out the tile if it was a block
The new location of the digger
The new location of the digger
dir
DiggerAction
An action specifying the direction
to move in
An action specifying the direction to move in