Module hanyaeger

Interface Movable

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

public interface Movable extends Placeable, MotionModifier
When the Interface 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 Details

    • setMotionApplier

      void setMotionApplier(MotionApplier motionApplier)
      Set the MotionApplier that will be used.
      Parameters:
      motionApplier - an instance of MotionApplier
    • getMotionApplier

      MotionApplier getMotionApplier()
      Return the MotionApplier that should be used.
      Returns:
      an instance of MotionApplier
    • setMotion

      default void setMotion(double speed, Direction direction)
      Description copied from interface: MotionModifier
      Set the motion with which this YaegerEntity is travelling.
      Specified by:
      setMotion in interface MotionModifier
      Parameters:
      speed - the speed as a double
      direction - the direction as a Direction
    • setMotion

      default void setMotion(double speed, double direction)
      Description copied from interface: MotionModifier
      Set the motion with which this YaegerEntity is travelling.
      Specified by:
      setMotion in interface MotionModifier
      Parameters:
      speed - the speed as a double
      direction - the direction in degrees as a double
    • addToMotion

      default void addToMotion(double speed, Direction 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 interface MotionModifier
      Parameters:
      speed - the speed as a double
      direction - the direction as a Direction
    • 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 interface MotionModifier
      Parameters:
      speed - the speed as a double
      direction - the direction as a double
    • getSpeedInDirection

      default double getSpeedInDirection(Direction direction)
      Specified by:
      getSpeedInDirection in interface MotionModifier
      Parameters:
      direction - the Direction 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 interface MotionModifier
      Parameters:
      direction - the Direction in which the speed should be nullified
      Returns:
      the speed of the decomposed vector in the specified direction
    • maximizeMotionInDirection

      default void maximizeMotionInDirection(Direction direction, double speed)
      Specified by:
      maximizeMotionInDirection in interface MotionModifier
      Parameters:
      direction - the Direction in which the speed of the vector describing the motion, should be maximized
      speed - the speed as a
      invalid reference
      double
      to which the vector should be maximized
      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 given Direction to the given speed.

      Vector representation of maximizing the motion in a given direction

      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 interface MotionModifier
      Parameters:
      direction - the direction as a double in which the speed of the vector describing the motion, should be maximized
      speed - the speed as a
      invalid reference
      double
      to which the vector should be maximized
    • nullifySpeedInDirection

      default void nullifySpeedInDirection(Direction direction)
      Specified by:
      nullifySpeedInDirection in interface MotionModifier
      Parameters:
      direction - the Direction 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.

      Vector representation of negating the motion in a given direction

      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 interface MotionModifier
      Parameters:
      direction - the direction in which the speed should be nullified, as a double
    • invertSpeedInDirection

      default void invertSpeedInDirection(Direction direction)
      Specified by:
      invertSpeedInDirection in interface MotionModifier
      Parameters:
      direction - the Direction 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.

      Vector representation of inverting the motion in a given direction

      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 interface MotionModifier
      Parameters:
      direction - the direction in which the speed should be inverted, as a double
    • 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 interface MotionModifier
      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 interface MotionModifier
      Parameters:
      newSpeed - the speed as a double
    • getSpeed

      default double getSpeed()
      Description copied from interface: SpeedProvider
      Return the current speed as a double.
      Specified by:
      getSpeed in interface SpeedProvider
      Returns:
      The speed as a double
    • setDirection

      default void setDirection(double newDirection)
      Description copied from interface: MotionModifier
      Set the Direction. 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 a Direction as its parameter.

      Specified by:
      setDirection in interface MotionModifier
      Parameters:
      newDirection - the direction in degrees as a double
    • setDirection

      default void setDirection(Direction newDirection)
      Description copied from interface: MotionModifier
      Set the Direction, which is in essence a value in degrees, but by using this method, one can use the enumeration Direction. If a more specific value is required, use the method MotionModifier.setDirection(double).
      Specified by:
      setDirection in interface MotionModifier
      Parameters:
      newDirection - a Direction
    • getDirection

      default double getDirection()
      Description copied from interface: DirectionProvider
      Get the direction in which the YaegerEntity is moving, in degrees. If the YaegerEntity is not moving, and therefore has no direction, this method will return NaN.
      Specified by:
      getDirection in interface DirectionProvider
      Returns:
      The direction in degrees as a double or NaN
    • 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 interface MotionModifier
      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 interface MotionModifier
      Parameters:
      rotation - the rotation as a double
    • updateLocation

      default Updatable updateLocation()
      Return the Updatable to be called on each Game World Update.
      Returns:
      an Updatable to be called