There are a couple of ways to do this with a Tile-based game like Sonic:
a) Check the player sprite against the surrounding tiles
b) Check the player sprite against a collision map
Have a look through the code archives, there are a number of useful articles and code snippets.
a) Check the player sprite against the surrounding tiles
b) Check the player sprite against a collision map
Have a look through the code archives, there are a number of useful articles and code snippets.