- 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 voidaddToMotion(double speed, double direction) Add a given motion to the current motion.default voidaddToMotion(double speed, Direction direction) Add a given motion to the current motion.default voidchangeDirection(double rotation) Change the direction by adding a rotation in degrees.default doubleGet the direction in which theYaegerEntityis moving, in degrees.Return theMotionApplierthat should be used.default doublegetSpeed()Return the current speed as adouble.default doublegetSpeedInDirection(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 doublegetSpeedInDirection(Direction direction) default voidincrementSpeed(double increment) Alter the speed through addition.default voidinvertSpeedInDirection(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 voidinvertSpeedInDirection(Direction direction) default voidmaximizeMotionInDirection(double direction, double speed) Since the motion can be described as a vector, such a vector can be decomposed in two perpendicular components.default voidmaximizeMotionInDirection(Direction direction, double speed) default voidmultiplySpeed(double multiplication) Alter the speed through multiplication.default voidnullifySpeedInDirection(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 voidnullifySpeedInDirection(Direction direction) default voidsetDirection(double newDirection) Set theDirection.default voidsetDirection(Direction newDirection) default voidsetMotion(double speed, double direction) Set the motion with which thisYaegerEntityis travelling.default voidSet the motion with which thisYaegerEntityis travelling.voidsetMotionApplier(MotionApplier motionApplier) Set theMotionApplierthat will be used.default voidsetSpeed(double newSpeed) Set the speed.default UpdatableReturn theUpdatableto be called on each Game World Update.Methods inherited from interface com.github.hanyaeger.core.entities.Anchorable
getAnchorPoint, setAnchorPointMethods inherited from interface com.github.hanyaeger.core.entities.Bounded
getBoundingBox, getHeight, getWidthMethods inherited from interface com.github.hanyaeger.core.entities.Placeable
getAnchorLocation, setAnchorLocation, setAnchorLocationX, setAnchorLocationY, transferCoordinatesToNode
-
Method Details
-
setMotionApplier
Set theMotionApplierthat will be used.- Parameters:
motionApplier- an instance ofMotionApplier
-
getMotionApplier
MotionApplier getMotionApplier()Return theMotionApplierthat should be used.- Returns:
- an instance of
MotionApplier
-
setMotion
Description copied from interface:MotionModifierSet the motion with which thisYaegerEntityis travelling.- Specified by:
setMotionin interfaceMotionModifier- Parameters:
speed- the speed as adoubledirection- the direction as aDirection
-
setMotion
default void setMotion(double speed, double direction) Description copied from interface:MotionModifierSet the motion with which thisYaegerEntityis travelling.- Specified by:
setMotionin interfaceMotionModifier- Parameters:
speed- the speed as adoubledirection- the direction in degrees as adouble
-
addToMotion
Description copied from interface:MotionModifierAdd 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:
addToMotionin interfaceMotionModifier- Parameters:
speed- the speed as adoubledirection- the direction as aDirection
-
addToMotion
default void addToMotion(double speed, double direction) Description copied from interface:MotionModifierAdd 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:
addToMotionin interfaceMotionModifier- Parameters:
speed- the speed as adoubledirection- the direction as adouble
-
getSpeedInDirection
- Specified by:
getSpeedInDirectionin interfaceMotionModifier- Parameters:
direction- theDirectionin 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:MotionModifierSince 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:
getSpeedInDirectionin interfaceMotionModifier- Parameters:
direction- theDirectionin which the speed should be nullified- Returns:
- the speed of the decomposed vector in the specified direction
-
maximizeMotionInDirection
- Specified by:
maximizeMotionInDirectionin interfaceMotionModifier- Parameters:
direction- theDirectionin which the speed of the vector describing the motion, should be maximizedspeed- the speed as ato which the vector should be maximizedinvalid reference
double- See Also:
-
maximizeMotionInDirection
default void maximizeMotionInDirection(double direction, double speed) Description copied from interface:MotionModifierSince 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 givenDirectionto 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:
maximizeMotionInDirectionin interfaceMotionModifier- Parameters:
direction- the direction as adoublein which the speed of the vector describing the motion, should be maximizedspeed- the speed as ato which the vector should be maximizedinvalid reference
double
-
nullifySpeedInDirection
- Specified by:
nullifySpeedInDirectionin interfaceMotionModifier- Parameters:
direction- theDirectionin which the speed should be nullified- See Also:
-
nullifySpeedInDirection
default void nullifySpeedInDirection(double direction) Description copied from interface:MotionModifierSince 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:
nullifySpeedInDirectionin interfaceMotionModifier- Parameters:
direction- the direction in which the speed should be nullified, as adouble
-
invertSpeedInDirection
- Specified by:
invertSpeedInDirectionin interfaceMotionModifier- Parameters:
direction- theDirectionin which the speed should be inverted- See Also:
-
invertSpeedInDirection
default void invertSpeedInDirection(double direction) Description copied from interface:MotionModifierSince 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:
invertSpeedInDirectionin interfaceMotionModifier- Parameters:
direction- the direction in which the speed should be inverted, as adouble
-
multiplySpeed
default void multiplySpeed(double multiplication) Description copied from interface:MotionModifierAlter 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:
multiplySpeedin 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:MotionModifierSet the speed.- Specified by:
setSpeedin interfaceMotionModifier- Parameters:
newSpeed- the speed as adouble
-
getSpeed
default double getSpeed()Description copied from interface:SpeedProviderReturn the current speed as adouble.- Specified by:
getSpeedin interfaceSpeedProvider- Returns:
- The speed as a
double
-
setDirection
default void setDirection(double newDirection) Description copied from interface:MotionModifierSet 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 aDirectionas its parameter.- Specified by:
setDirectionin interfaceMotionModifier- Parameters:
newDirection- the direction in degrees as adouble
-
setDirection
Description copied from interface:MotionModifierSet 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:
setDirectionin interfaceMotionModifier- Parameters:
newDirection- aDirection
-
getDirection
default double getDirection()Description copied from interface:DirectionProviderGet the direction in which theYaegerEntityis moving, in degrees. If theYaegerEntityis not moving, and therefore has no direction, this method will returnNaN.- Specified by:
getDirectionin interfaceDirectionProvider- Returns:
- The direction in degrees as a
doubleorNaN
-
incrementSpeed
default void incrementSpeed(double increment) Description copied from interface:MotionModifierAlter 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:
incrementSpeedin 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:MotionModifierChange 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:
changeDirectionin interfaceMotionModifier- Parameters:
rotation- the rotation as a double
-
updateLocation
Return theUpdatableto be called on each Game World Update.- Returns:
- an
Updatableto be called
-