 ### Sonic Game Engine

To understand how to create a Sonic Game Engine you must first understand the physics of sonic the hedgehog and how he moves along a curves using basic collision detection by angles using sin and cos.

A collision circle object is used to detect objects and terrain which is used only for an x and y position at end, sonic will be drawn over the object at angles rounded to the nearest 45 degree increment.

Sin and Cos is used to locate precise X and Y positions by angle for object detection. Cos represents horizontal positions in X to current angle. Sin represents vertical positions in Y to current angle.

At object angle 0 a variable angle can be used to locate a position by sin and cos angle. This can only work by the use of code degtorad which converts degrees to radians for game maker.  Just change the angle to change the position to a circular path.

for example

//==========================
if place_meeting( x + cos( degtorad( angle )) * 10 , y - sin( degtorad( angle )) * 10 , land_object )
{ do codes here }
The chart below is a point of reference on which direction to apply sin and cos which includes corner positions.

for example

// Bottom Right Corner
//==========================
if place_meeting( x + cos( degtorad( angle )) * 10 + sin( degtorad(angle)) * 10  ,
y - sin( degtorad( angle )) * 10 + cos( degtorad(angle)) * 10 , land_object )
{ do codes here }

Sonic moves horizontally by the calculation of sin and cos according to the current angle to the ground multiplied by the x_speed which determines the next X , Y position

for example

// X Movement
x += cos( degtorad(angle)) * x_speed
y - = sin( degtorad(angle)) * x_speed
This is a list of major collision positions during a calculation of sonic falling to the ground.
A basic collision detection keeps the circle out of the walls.

P1 and P2 detect weather these two position detect the ground. If they do detect the ground together they perform a calculation to change the angle variable to the angle of the ground. This angle is change by first creating 2 positions inside of the circle. If there is no collision between these two points the position is change down 1 pixel position. These two positions will eventually collide with land at two different positions. The new angle is then gained by a point_direction between these two new positions.

This new angle is then used for all angled collision detection like the slope position which will keep sonic to the ground and out of the ground according to the direction of sin and cos angle.

When P1 and P2 do not collide together the angle calculation is not performed and the angle is change to angle 0 and x_speed and y_speed are exchanged if the angle was not = to 0.