Sure, here's a basic example of a 3D Sonic game called Sonic Galaxy implemented as a single HTML file using JavaScript. Please note that this is a simplified version and does not incorporate all the features of a full-fledged game.
This code sets up a canvas element for the game display and uses basic keyboard controls to move the Sonic character on the canvas. The Sonic character is represented as a blue square. You can customize the game visuals, controls, and add additional features as per your requirements.