This post originally had a semi-accurate way of checking the distance from a jump, but this method will work perfectly, even though the calculations take more time.

This post will assume you know how speeds affect positions (explained in below posts).

As a starting point, we need to see what is needed in this calculation. What we will need is a starting y position, an x speed, and an ending y position. The starting y position will be the theoretical position of the top of the block you are currently standing on, and the ending y position will be the theoretical top of the section of the blocks you will be landing on.

For an example, I will use the data below:

The theoretical top of the block mario is standing on is located at 370.00. To find this, take the block's floored multiple of 16 and subtract 11 from that.

The ending theoretical top we will be landing on is 322.00.

Also, I will be jumping at 37 speed in this demonstration.

Using a formula I have come up with earlier, we can find the y speed from a jump with a given x speed.

**ceil(-2.5 * floor(abs(xspeed) / 8) - 77)**

Since I'm jumping at 37 speed, filling that into the formula will give us -87 as our y speed.

Along with this, we need to know a little bit about how y speeds work over time. After a jump occurs, a certain y speed is stored (which we just figured out, in this case, is -87). Now, if the B button is held, this stored value will increase by 3 every frame. To calculate the max amount of x distance from a jump, we need to know how long the player is in the air, and doing this will just increase our number every frame, adding up the amount of frames that have passed, until the number is greater than the new block's theoretical position. To do this, we will need a continuous loop to change the player's y speed accordingly. Even though the player is at a specific position, this jump distance will be true for any given position, as long as the same theoretical y block top positions are the same distance apart.

It is recommended to use a programming language, excel, or something else that allows you to do loops until something specific occurs. A variable "delta" will be the amount of y speed in which our player's y position (in subpixels) will increase every frame. Also note that this delta will retain at a constant 67 when falling if B is being held.

delta = -87 (for this example)

loop (until y position (theoretical top(1)) > theoretical top(2) from the highest point of a jump) (add delta to position, and then add 3 to delta)

If you do all of this, you will end up with 49 frames that the jump covers over, and that is 49 frames we are in the air without losing speed. With this, all you must do is multiply the x speed (in this case 37) by 49 frames, and that will give us a subpixel amount of distance of 1813. This can be converted to an x distance of 113.50 as an actual game distance, and dividing the amount of subpixels by 256 will let us see that the player jumps over an equivalent distance of ~7.082 tiles with these two given y theoretical positions.

## No comments:

## Post a Comment