Skip to content

Instantly share code, notes, and snippets.

@MathyFurret
Last active April 18, 2019 20:50
Show Gist options
  • Save MathyFurret/c261b9c359786dd633aaacf5693d2e5d to your computer and use it in GitHub Desktop.
Save MathyFurret/c261b9c359786dd633aaacf5693d2e5d to your computer and use it in GitHub Desktop.
Phineas & Ferb Ride Again research
public class PhysicsTests {
public static final int Y_ACCELERATION = -16;
public static final int GROUNDED_Y_VELOCITY = -328;
public static final int JUMPING_Y_VELOCITY = 328;
public static final int GROUND_UPPER_HITBOX = 40951;
public static final int GROUND_LOWER_HITBOX = 1654;
/**
* Calculates the number of frames it will take from right before Phineas is in freefall to
* the frame Phineas lands on solid ground.
*
* @param startingGround Y position of the starting ground.
* @param endingGround Y position of the ending ground.
* @param jumping Whether Phineas jumps prior to falling off the starting ground. If false
* he will simply walk off the platform.
* @return The number of frames that pass between Phineas falling off the starting ground
* and landing on the ending ground.
*/
public static int verticalOverflowTime(int startingGround, int endingGround, boolean jumping) {
final int MIN_FRAMES = 10 * 60; // to ensure we are actually using vertical underflow
int frameCounter = 0;
int yVelocity = jumping ? JUMPING_Y_VELOCITY : GROUNDED_Y_VELOCITY; // might rarely underflow
int yPosition = startingGround; // will definitely underflow
while (true) {
yVelocity += Y_ACCELERATION;
yPosition += yVelocity;
if (frameCounter == 0 && !jumping) yVelocity = 0;
// upper ground hit detection (happens on frame prior to update)
if (frameCounter >= MIN_FRAMES && yVelocity < 0
&& yPosition > endingGround && yPosition - endingGround <= GROUND_UPPER_HITBOX)
break;
frameCounter++;
// lower ground hit detection (happens on frame after update)
if (frameCounter >= MIN_FRAMES && endingGround > yPosition
&& endingGround - yPosition <= GROUND_LOWER_HITBOX)
break;
}
return frameCounter;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment