Effect of habitat destruction on cooperation in public goods games