Package collider

Class RectCollider

java.lang.Object
collider.Collider
collider.RectCollider

public class RectCollider extends Collider
a Collider for Rectangles, usually used for RectObject instances.
See Also:
  • Constructor Details

    • RectCollider

      public RectCollider(String id, GameObject o, double w, double h)
      initializes this RectCollider. calls superclass constructor of Collider(String, GameObject) with params String id and GameObject o.
      Parameters:
      id - String unique name for this RectCollider
      o - GameObject instance this RectCollider belongs to (cannot be null)
      w - width in pixels for the collider dimensions (> 0)
      h - height in pixels for the collider dimensions (>0)
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Collider
    • checkCollisionRectRect

      public boolean checkCollisionRectRect(Collider other)
      checks collision with other Collider, which needs to be a RectCollider, too.
      Parameters:
      other - RectCollider (is casted) to calculate collision with
      Returns:
      true if collission is detected
    • checkCollisionRectCirc

      public boolean checkCollisionRectCirc(Collider other)
      checks collision with other Collider, which needs to be a CircleCollider
      Parameters:
      other - CircleCollider (is casted) to calculate collision with
      Returns:
      true if collission is detected
    • collidesWith

      public boolean collidesWith(Collider other)
      Description copied from class: Collider
      checks the collission with another collider instance.
      Specified by:
      collidesWith in class Collider
      Parameters:
      other - the instance to compare to
      Returns:
      true if the colliders collide (touch or overlap)