MODIFIED: implemented terrain based on TerrainGrid. There are modifications in the logic, which are different from the original terrainGrid.