Class Force

java.lang.Object
de.gurkenlabs.litiengine.physics.Force
Direct Known Subclasses:
GravityForce, StickyForce

public class Force extends Object
Represents a force in the physics engine. A force has a location, strength, size, and various properties that determine its behavior.
  • Constructor Details

    • Force

      public Force(Point2D location, float strength, float size)
      Instantiates a new force.
      Parameters:
      location - The location where the force is originating from
      strength - The strength/intensity of this force instance
      size - The size of this force (used to determine if/when an entity has reached the force)
  • Method Details

    • cancelOnCollision

      public boolean cancelOnCollision()
      Checks if the force should be canceled on collision.
      Returns:
      true if the force should be canceled on collision, false otherwise
    • cancelOnReached

      public boolean cancelOnReached()
      Checks if the force should be canceled when the target is reached.
      Returns:
      true if the force should be canceled when the target is reached, false otherwise
    • end

      public void end()
      Ends the force, marking it as ended.
    • getLocation

      public Point2D getLocation()
      Gets the location.
      Returns:
      the location
    • getStrength

      public float getStrength()
      Gets the strength in pixels per second.
      Returns:
      the strength in pixels per seconds
    • getIdentifier

      public String getIdentifier()
      Gets the identifier for the force.
      Returns:
      the identifier of the force
    • hasEnded

      public boolean hasEnded()
      Checks if the force has ended.
      Returns:
      true if the force has ended, false otherwise
    • hasReached

      public boolean hasReached(ICollisionEntity entity)
      Checks if the force has reached the specified entity.
      Parameters:
      entity - the entity to check against
      Returns:
      true if the force has reached the entity, false otherwise
    • setCancelOnCollision

      public void setCancelOnCollision(boolean cancelOnCollision)
      Sets whether the force should be canceled on collision.
      Parameters:
      cancelOnCollision - true if the force should be canceled on collision, false otherwise
    • setCancelOnReached

      public void setCancelOnReached(boolean cancelOnReached)
      Sets whether the force should be canceled when the target is reached.
      Parameters:
      cancelOnReached - true if the force should be canceled when the target is reached, false otherwise
    • setLocation

      public void setLocation(Point2D location)
      Sets the location of the force.
      Parameters:
      location - the new location of the force
    • setStrength

      public void setStrength(float strength)
      Sets the strength of the force in pixels per second.
      Parameters:
      strength - the new strength of the force
    • setIdentifier

      public void setIdentifier(String identifier)
      Sets the identifier for the force.
      Parameters:
      identifier - the new identifier for the force
    • toString

      public String toString()
      Returns a string representation of the Force object. The string includes the identifier (if available), strength in pixels per second, and location.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the Force object