Package collider

Class Collider

java.lang.Object
collider.Collider
Direct Known Subclasses:
CircleCollider, RectCollider

public abstract class Collider extends Object
abstract base class for all Colliders to detect collisions between GameObjects
  • Field Details

    • id

      public String id
      unique internal name for Collider
    • gameobject

      protected GameObject gameobject
      GameObject it belongs to
    • playground

      protected Playground playground
      PlayGround instance it belongs to
    • controller

      protected ObjectController controller
      the ObjectController to the corresponding GameObject (can be null)
    • dx

      protected double dx
    • dy

      double dy
  • Constructor Details

    • Collider

      public Collider(String id, GameObject o)
      Parameters:
      id - unique name for Collider (internally)
      o - GameObject instance it belongs to
  • Method Details

    • setOffsets

      public Collider setOffsets(double dx, double dy)
      setter for offset values to be used relative to GameObject center. default is zero.
      Parameters:
      dx - offset in X direction (default 0)
      dy - offset in Y direction (default 0)
      Returns:
      this instance of Collider
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getX

      public double getX()
      returns the corresponding game objects X coordinate (center) plus this colliders offset in X (probably zero).
      Returns:
      X value
    • getY

      public double getY()
      returns the corresponding game objects Y coordinate (center) plus this colliders offset in Y (probably zero).
      Returns:
      Y value
    • getId

      public String getId()
      returns the internal unique name
      Returns:
      the String with the name
    • setObject

      public void setObject(GameObject gameObject)
      setter for corresponding GameObject
      Parameters:
      gameObject - to be saved in attribute
    • setController

      public void setController(ObjectController controller)
      setter for GameController
      Parameters:
      controller - to be saved in attribute
    • setPlayground

      public void setPlayground(Playground playground)
      setter for Playground instance this collider belongs to
      Parameters:
      playground - instance to be stored in attribute
    • collidesWith

      public abstract boolean collidesWith(Collider other)
      checks the collission with another collider instance.
      Parameters:
      other - the instance to compare to
      Returns:
      true if the colliders collide (touch or overlap)