public class PlatformPhysics extends Physics
Physics
class,
useful in games with a side-view perspective and platform games in particular.
In this context, Physics.accelerationValue
, Physics.maximumSpeed
,
and Physics.decelerationValue
refer to horizontal movement;
this class includes additional variables to quantify jump strength,
the force of gravity (which constantly accelerates an object downwards),
and terminal velocity (maximum vertical speed).Modifier and Type | Field and Description |
---|---|
double |
gravity
constant downwards acceleration
|
double |
jumpSpeed
initial vertical velocity when jumping
|
double |
terminalVelocity
maximum vertical speed
|
accelerationValue, accelerationVector, decelerationValue, maximumSpeed, positionVector, velocityVector
Constructor and Description |
---|
PlatformPhysics(double accValue,
double maxHorizontalSpeed,
double decValue,
double jumpSpeed,
double gravity,
double terminalVelocity)
Initialize values used by physics simulation.
|
Modifier and Type | Method and Description |
---|---|
void |
jump()
Simulate jumping, using value stored in
jumpSpeed . |
void |
update(double dt)
Update the position of this object
according to velocity, acceleration, and gravity.
|
accelerateAtAngle, bounceAgainst, getMotionAngle, getSpeed, setMotionAngle, setSpeed
public double jumpSpeed
public double gravity
public double terminalVelocity
public PlatformPhysics(double accValue, double maxHorizontalSpeed, double decValue, double jumpSpeed, double gravity, double terminalVelocity)
accValue
- walk/run acceleration valuemaxHorizontalSpeed
- maximum horizontal speeddecValue
- walk/run deceleration valuejumpSpeed
- initial vertical velocity when jumpinggravity
- force of gravity; constant downwards accelerationterminalVelocity
- maximum vertical speedpublic void jump()
jumpSpeed
.public void update(double dt)
Physics.maximumSpeed
and vertical speed is bounded by terminalVelocity
.