public class Physics
extends java.lang.Object
PlatformPhysics.)| Modifier and Type | Field and Description |
|---|---|
double |
accelerationValue
Constant amount of acceleration, used by
accelerateAtAngle(double). |
(package private) Vector2 |
accelerationVector
Acceleration (rate of chance of velocity) of object.
|
double |
decelerationValue
Rate of speed reduction to apply when object is not accelerating.
|
double |
maximumSpeed
Maximum speed possible for object.
|
(package private) Vector2 |
positionVector
Position of object.
|
(package private) Vector2 |
velocityVector
Velocity (rate of change of position) of object.
|
| Constructor and Description |
|---|
Physics(double accValue,
double maxSpeed,
double decValue)
Initialize values used by physics simulation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
accelerateAtAngle(double angleDegrees)
Accelerate this object in the direction angleDegrees
by the amount specified by
accelerationValue. |
void |
bounceAgainst(double surfaceAngleDegrees)
Change angle of motion assuming a collision with a flat surface
inclined at an angle of surfaceAngleDegrees.
|
double |
getMotionAngle()
Calculate the angle of motion (in degrees)
as measured from the x-axis (the vector (1,0)).
|
double |
getSpeed()
Calculate speed of object.
|
void |
setMotionAngle(double angleDegrees)
Set the angle of motion of this object.
|
void |
setSpeed(double speed)
Set speed of object.
|
void |
update(double dt)
Update the position of this object
according to velocity and acceleration.
|
Vector2 positionVector
Vector2 velocityVector
Vector2 accelerationVector
public double accelerationValue
accelerateAtAngle(double).public double maximumSpeed
public double decelerationValue
public Physics(double accValue,
double maxSpeed,
double decValue)
accValue - acceleration valuemaxSpeed - maximum speeddecValue - deceleration valuepublic double getSpeed()
public void setSpeed(double speed)
speed - speed of objectpublic double getMotionAngle()
public void setMotionAngle(double angleDegrees)
angleDegrees - angle of motion of objectpublic void bounceAgainst(double surfaceAngleDegrees)
surfaceAngleDegrees - inclination of surface this object has collided withpublic void accelerateAtAngle(double angleDegrees)
accelerationValue.angleDegrees - direction of accelerationpublic void update(double dt)
dt - elapsed time (seconds) since previous iteration of game loop
(typically approximately 1/60 second)