private int g(Node n, Node startNode) {
    // g = the movement cost to move from the starting point to a n, following the path generated to get there.
    int g = 0;

    Node parent;
    do {
      // Add 10 if next point is orthogonal, 14 for diagonal. see comment above.
      parent = n.parent;
      if ((n.x == parent.x) || (n.y == parent.y)) {
        g += 10; // we're now only considering every third pixel

      } else {
        g += 14;
      // n becomes equal to the the next point (it's parent)
      }
      n = parent;
    } while (n != startNode);
    return g;
  }