Note: This is NOT an updated version of my old engine; instead this is a made-from-scratch new version that I put together last night, which allows for much neater stuffs, and also comes open sourced!
If you remember my old engine; this is essentially the same thing, except with a revamped movement/platforming engine. It works on 2 rather simple concepts:
1) The gravity:
This is for those who would rather hear how it works, then dig through the code; What it does is on every frame of gameplay, it cycles through each source of gravity ("gravity well", and adds a velocity vector to the player's movement based on the formula:
Velocity = Power / (distance ^ 2)
Hence, the X & Y velocities applied to the player each frame for every single gravity object are:
XVel = Cos(Angle between player & well) * (Well Power) / ((Distance between Player & Well) ^ 2)
YVel = Sin(Angle between player & well) * (Well Power) / ((Distance between Player & Well) ^ 2)
In a simple setup where these velocities are integrated into standard positional movement, this then provides accurate gravitation. In the code, you'll notice alot of these numbers have VERY high values; this is due to TGF not being able to save floats, and thus is neccesary.
2) The platform movement:
This is new to this version- it allows for the player to walk along the edges of essentially any oddly shaped obtuse object with a gravity well on it, even if its not in the center.
First, as soon as you touch down onto ground (it detects the player hitting ground via a posteriori detection; it checks your next movement due to your current velocity, and if this would overlap a backdrop, it keeps you in the same position as the last frame, but counts you as "touching ground" it will keep track of the greatest source of gravity nearby; each run through the gravity well cycles, it records which one gave the highest 'weighted power'. This one is then treated as the center of gravity for the object you are on.
Nextly, when moving "left or right" around an object, it follows a simple algorithm;
1) Check the position equal to the next positional movement at a 90 degree angle to the gravity well; the tangent with the surface.
2) If this position is overlapping a backdrop, move the angle upwards by 1 degree, and repeat until it is not overlapping a backdrop, then skip to 4)
3) If this position is NOT overlapping a backdrop, move the angle downwards by 1 degree, until it is overlapping a backdrop, then move it upwards by 1 degree and go to 4
4) Use this angle as the position for the next movement; move the player
Hence, at every frame of movement, the player will be set to to 1 pixel away from the ground along the surface, and will follow it as long as the surface doesn't diverge from the center of gravity by more then 90 degrees.
*3)*
(This is a feature I Have not made, but intended to)
Linear projection;
I got lazy, and only set the groundworks for this, but couldn't get the math quite right; I wanted to implement a system where given 2 points that form the endpoints of a line (seen as "Left Checker" and "Right Checker" in the editor), it could then place a gravity well projected and restricted into this line from the players position. The point of this, is that then on long surfaces, such as the vertical strip or the Sin wave you see in the editor, the gravity well would follow beneath the player, always counting the center of gravity as immediately on the surface. This is very useful, as it allows the player to effectively gravitate towards the surface with proper effect, and jump with the restrictions of gravity constant at any point on the surface. Simply creating a long horizontal strip with 1 gravity well in the center would result in that jumping from either edge would have dramatically higher jumping then jumping from the middle. If the well was projected onto this line, its always constant.
Likewise, this would allow for more spunky effects, such as platforms set at odd angles, sin waves and other wierd transformation types of platforms and the like. Unfortunately, my brains were too addled to do this on anything more then a simple vertical/horizontal scale, which is retardedly easy.
So be a dear and looky through, see if you can discern from my poorly commented coding how it works.
Review This Download
http://claniraq.googlepages.com/SMGEngine.zip (699 kb )
|