- All Superinterfaces:
Anchorable
,Bounded
,com.github.hanyaeger.core.scenes.DimensionsProvider
,DirectionProvider
,GameNode
,MotionModifier
,Placeable
,SpeedProvider
- All Known Subinterfaces:
BufferedMovable
,Newtonian
,SceneBorderCrossingWatcher
,SceneBorderTouchingWatcher
- All Known Implementing Classes:
DynamicCircleEntity
,DynamicCompositeEntity
,DynamicEllipseEntity
,DynamicRectangleEntity
,DynamicSpriteEntity
,DynamicTextEntity
Movable
is implemented, an YaegerEntity
is able to move around the YaegerScene
on each Game World Update.
This behaviour required a delegate object, a MotionApplier
that performs all the actual computations
of the new location, based on the speed
and direction
.
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
addToMotion
(double speed, double direction) Add a given motion to the current motion.default void
addToMotion
(double speed, Direction direction) Add a given motion to the current motion.default void
changeDirection
(double rotation) Change the direction by adding a rotation in degrees.default double
Get the direction in which theYaegerEntity
is moving, in degrees.Return theMotionApplier
that should be used.default double
getSpeed()
Return the current speed as adouble
.default double
getSpeedInDirection
(double direction) Since a motion can be described as a vector, such a vector can be decomposed in two perpendicular components, of which one is parallel to the given direction.default double
getSpeedInDirection
(Direction direction) default void
incrementSpeed
(double increment) Alter the speed through addition.default void
invertSpeedInDirection
(double direction) Since a motion can be described as a vector, such a vector can be decomposed in two perpendicular components, of which one is parallel to the given direction.default void
invertSpeedInDirection
(Direction direction) default void
maximizeMotionInDirection
(double direction, double speed) Since the motion can be described as a vector, such a vector can be decomposed in two perpendicular components.default void
maximizeMotionInDirection
(Direction direction, double speed) default void
multiplySpeed
(double multiplication) Alter the speed through multiplication.default void
nullifySpeedInDirection
(double direction) Since the motion can be described as a vector, such a vector can be decomposed in two perpendicular components, of which one is parallel to the given direction.default void
nullifySpeedInDirection
(Direction direction) default void
setDirection
(double newDirection) Set theDirection
.default void
setDirection
(Direction newDirection) default void
setMotion
(double speed, double direction) Set the motion with which thisYaegerEntity
is travelling.default void
Set the motion with which thisYaegerEntity
is travelling.void
setMotionApplier
(MotionApplier motionApplier) Set theMotionApplier
that will be used.default void
setSpeed
(double newSpeed) Set the speed.default Updatable
Return theUpdatable
to be called on each Game World Update.Methods inherited from interface com.github.hanyaeger.core.entities.Anchorable
getAnchorPoint, setAnchorPoint
Methods inherited from interface com.github.hanyaeger.core.entities.Bounded
getBoundingBox, getHeight, getWidth
Methods inherited from interface com.github.hanyaeger.core.entities.Placeable
getAnchorLocation, setAnchorLocation, setAnchorLocationX, setAnchorLocationY, transferCoordinatesToNode
-
Method Details
-
setMotionApplier
Set theMotionApplier
that will be used.- Parameters:
motionApplier
- an instance ofMotionApplier
-
getMotionApplier
MotionApplier getMotionApplier()Return theMotionApplier
that should be used.- Returns:
- an instance of
MotionApplier
-
setMotion
Description copied from interface:MotionModifier
Set the motion with which thisYaegerEntity
is travelling.- Specified by:
setMotion
in interfaceMotionModifier
- Parameters:
speed
- the speed as adouble
direction
- the direction as aDirection
-
setMotion
default void setMotion(double speed, double direction) Description copied from interface:MotionModifier
Set the motion with which thisYaegerEntity
is travelling.- Specified by:
setMotion
in interfaceMotionModifier
- Parameters:
speed
- the speed as adouble
direction
- the direction in degrees as adouble
-
addToMotion
Description copied from interface:MotionModifier
Add a given motion to the current motion. Since motions are essentially vectors, defined by speed and direction, this method results in the addition of those vectors.- Specified by:
addToMotion
in interfaceMotionModifier
- Parameters:
speed
- the speed as adouble
direction
- the direction as aDirection
-
addToMotion
default void addToMotion(double speed, double direction) Description copied from interface:MotionModifier
Add a given motion to the current motion. Since motions are essentially vectors, defined by speed and direction, this method results in the addition of those vectors.- Specified by:
addToMotion
in interfaceMotionModifier
- Parameters:
speed
- the speed as adouble
direction
- the direction as adouble
-
getSpeedInDirection
- Specified by:
getSpeedInDirection
in interfaceMotionModifier
- Parameters:
direction
- theDirection
in which the speed should be calculated- Returns:
- the speed of the decomposed vector in the specified direction
- See Also:
-
getSpeedInDirection
default double getSpeedInDirection(double direction) Description copied from interface:MotionModifier
Since a motion can be described as a vector, such a vector can be decomposed in two perpendicular components, of which one is parallel to the given direction. Calling this method returns the magnitude of that vector, which represents the speed in the given direction.- Specified by:
getSpeedInDirection
in interfaceMotionModifier
- Parameters:
direction
- theDirection
in which the speed should be nullified- Returns:
- the speed of the decomposed vector in the specified direction
-
maximizeMotionInDirection
- Specified by:
maximizeMotionInDirection
in interfaceMotionModifier
- Parameters:
direction
- theDirection
in which the speed of the vector describing the motion, should be maximizedspeed
- the speed as ainvalid reference
double
- See Also:
-
maximizeMotionInDirection
default void maximizeMotionInDirection(double direction, double speed) Description copied from interface:MotionModifier
Since the motion can be described as a vector, such a vector can be decomposed in two perpendicular components. Calling this method maximize the vector for the component in the givenDirection
to the given speed.In the image above, let v be the vector associated with the current motion and r be the vector that represents the direction and speed that should be maximized, then the resulting vector s represents the maximized motion.
A typical use case would be when an entity has to accelerate to a maximum value into a specific direction, while gravity (or any other force) should be preserved.
- Specified by:
maximizeMotionInDirection
in interfaceMotionModifier
- Parameters:
direction
- the direction as adouble
in which the speed of the vector describing the motion, should be maximizedspeed
- the speed as ainvalid reference
double
-
nullifySpeedInDirection
- Specified by:
nullifySpeedInDirection
in interfaceMotionModifier
- Parameters:
direction
- theDirection
in which the speed should be nullified- See Also:
-
nullifySpeedInDirection
default void nullifySpeedInDirection(double direction) Description copied from interface:MotionModifier
Since the motion can be described as a vector, such a vector can be decomposed in two perpendicular components, of which one is parallel to the given direction. Calling this method nullifies that vector, leaving the other as the new motion.In the image above, let v denote the vector associated with the current motion and b be the vector in the direction that has to be nullified, then the resulting vector p represents the new motion.
Note that for this method only the direction of b has to be given. The length of b is automatically derived.
A typical use case would be an entity that jumps with a parabolic motion. At one point it collides with the ground, which should cancel the vertical downward motion. The vertical motion, however, should not be cancelled. In this case, one should call this method with the parameter
Direction.DOWN
.- Specified by:
nullifySpeedInDirection
in interfaceMotionModifier
- Parameters:
direction
- the direction in which the speed should be nullified, as adouble
-
invertSpeedInDirection
- Specified by:
invertSpeedInDirection
in interfaceMotionModifier
- Parameters:
direction
- theDirection
in which the speed should be inverted- See Also:
-
invertSpeedInDirection
default void invertSpeedInDirection(double direction) Description copied from interface:MotionModifier
Since a motion can be described as a vector, such a vector can be decomposed in two perpendicular components, of which one is parallel to the given direction. Calling this method inverts the vector parallel to the direction and computes a new motion, based on that vector.In the image above, let v denote the vector associated with the current motion and b be the vector in the direction that should be inverted. Then b` represents the inverse of b and v` the resulting vector of the new motion.
Note that for this method only the direction of b has to be given. The length of b is automatically derived.
A typical use case would be an entity that bounces on a plane. At one point it collides with the ground, which should invert the downward (vertical) component of its motion. The horizontal motion, however, should remain the same.
- Specified by:
invertSpeedInDirection
in interfaceMotionModifier
- Parameters:
direction
- the direction in which the speed should be inverted, as adouble
-
multiplySpeed
default void multiplySpeed(double multiplication) Description copied from interface:MotionModifier
Alter the speed through multiplication. Using this method will increase or decrease the current speed. It will multiply the current speed by the provided value.If it is required to set the speed to a specific value, use the method
MotionModifier.setSpeed(double)
}.- Specified by:
multiplySpeed
in interfaceMotionModifier
- Parameters:
multiplication
- a value greater than 1 will mean an increment in speed. A value between 0 and 1 will mean a decrement in speed
-
setSpeed
default void setSpeed(double newSpeed) Description copied from interface:MotionModifier
Set the speed.- Specified by:
setSpeed
in interfaceMotionModifier
- Parameters:
newSpeed
- the speed as adouble
-
getSpeed
default double getSpeed()Description copied from interface:SpeedProvider
Return the current speed as adouble
.- Specified by:
getSpeed
in interfaceSpeedProvider
- Returns:
- The speed as a
double
-
setDirection
default void setDirection(double newDirection) Description copied from interface:MotionModifier
Set theDirection
. This value is in degrees, where- 0 means up
- 90 means to the right
- 180 means down
- 270 to the left
If one of the values above is set, it is more convenient to use the method
MotionModifier.setDirection(Direction)
, which accepts aDirection
as its parameter.- Specified by:
setDirection
in interfaceMotionModifier
- Parameters:
newDirection
- the direction in degrees as adouble
-
setDirection
Description copied from interface:MotionModifier
Set theDirection
, which is in essence a value in degrees, but by using this method, one can use the enumerationDirection
. If a more specific value is required, use the methodMotionModifier.setDirection(double)
.- Specified by:
setDirection
in interfaceMotionModifier
- Parameters:
newDirection
- aDirection
-
getDirection
default double getDirection()Description copied from interface:DirectionProvider
Get the direction in which theYaegerEntity
is moving, in degrees. If theYaegerEntity
is not moving, and therefore has no direction, this method will returnNaN
.- Specified by:
getDirection
in interfaceDirectionProvider
- Returns:
- The direction in degrees as a
double
orNaN
-
incrementSpeed
default void incrementSpeed(double increment) Description copied from interface:MotionModifier
Alter the speed through addition. Using this method will increase or decrease the current speed. It will add the provided value to the current speed. Use a negative value to decrease the speed.- Specified by:
incrementSpeed
in interfaceMotionModifier
- Parameters:
increment
- a value greater than 1 will mean an increment in speed. A value between 0 and 1 will mean a decrement in speed
-
changeDirection
default void changeDirection(double rotation) Description copied from interface:MotionModifier
Change the direction by adding a rotation in degrees. A positive value will be added and will result in a clockwise rotation. A negative value will be subtracted and will result in a counterclockwise rotation.- Specified by:
changeDirection
in interfaceMotionModifier
- Parameters:
rotation
- the rotation as a double
-
updateLocation
Return theUpdatable
to be called on each Game World Update.- Returns:
- an
Updatable
to be called
-