The distance is the score in the game. The same set of enemies will spawn after every 500 mts but with increased health every time they spawn in the next set.
The enemies spawn at player.x+some number, random(some number, some number)
now when do they spawn
1st set of enemies spawn when the score 0 to 500
every X seconds (score is a global variable, which is set to player.x)
2nd set of enemies spawn when the score is between 250 -750 mts
every X seconds
3rd set of enemies spawn when the score is between 500-1000 mts, every X seconds
4th set of enemies spawn when the score is between 750-1250 mts, every X