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 Summary

    Fields
    Modifier and Type
    Field
    Description
    unique internal name for Collider
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract boolean
    checks the collission with another collider instance.
    returns the internal unique name
    double
    returns the corresponding game objects X coordinate (center) plus this colliders offset in X (probably zero).
    double
    returns the corresponding game objects Y coordinate (center) plus this colliders offset in Y (probably zero).
    void
    setter for GameController
    void
    setObject(GameObject gameObject)
    setter for corresponding GameObject
    setOffsets(double dx, double dy)
    setter for offset values to be used relative to GameObject center. default is zero.
    void
    setter for Playground instance this collider belongs to
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • id

      public String id
      unique internal name for Collider
  • 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)