Class Collision


  • public class Collision
    extends java.lang.Object
    • Field Detail

      • NONE

        public static final int NONE
        Indicates the basic type of collision NONE = no collision
        See Also:
        Constant Field Values
      • MOVING

        public static final int MOVING
        Indicates the basic type of collision MOVING = moving element colliding with another moving element
        See Also:
        Constant Field Values
      • STATIONARY

        public static final int STATIONARY
        Indicates the basic type of collision STATIONARY = moving element colliding with a stationary (non-moveable) element
        See Also:
        Constant Field Values
      • myMovingElement

        protected MoverIfc myMovingElement
        The element that was moving and detected the collision
      • myCollisionElement

        protected SpatialElement myCollisionElement
        The moving element that will collide with myMovingElement
      • myTimeOfCollision

        protected double myTimeOfCollision
        The projected time of the collision
      • myCollisionPosition

        protected CoordinateIfc myCollisionPosition
        The position associated with the collision
      • myCollisionType

        protected int myCollisionType
        Holds the basic type of collision
      • myCollisionHandler

        protected CollisionHandlerIfc myCollisionHandler
        Used to handle the collision
    • Constructor Detail

      • Collision

        public Collision​(MoverIfc myMovingElement)
        Creates a Collision which represents a collsition in space
    • Method Detail

      • clear

        public void clear()
        Clears the collision for reuse
      • hasCollided

        public final boolean hasCollided()
        Indicates whether or not the elements have collided
        Returns:
        true if collided
      • getCollisionType

        public final int getCollisionType()
        Used to indicate the type of collision using one of the class constants
        Returns:
        Returns the collisionType.
      • getCollisionPosition

        public final CoordinateIfc getCollisionPosition()
        The position associated with the collision
        Returns:
        Returns the collisionPosition.
      • getCollisionElement

        public final SpatialElement getCollisionElement()
        The element that will collide with the movingElement
        Returns:
        Returns the collisionElement.
      • getMovingElement

        public final MoverIfc getMovingElement()
        The element that was moving and detected the collision
        Returns:
        Returns the movingElement.
      • getTimeOfCollision

        public final double getTimeOfCollision()
        The projected time of the collision
        Returns:
        Returns the timeOfCollision.
      • getCollisionHandler

        public final CollisionHandlerIfc getCollisionHandler()
        Gets the collision handler for this collision. It may be null indicating no collision handling actions
        Returns:
        Returns the collisionHandler.
      • setCollision

        public void setCollision​(SpatialElement element,
                                 double timeOfCollision,
                                 CoordinateIfc collisionPosition,
                                 int collisionType)
        Sets the characteristics of the collision
        Parameters:
        element -
        timeOfCollision -
        collisionPosition -
        collisionType - The type of collision (moving to moving, moving to stationary)
      • setCollisionHandler

        public final void setCollisionHandler​(CollisionHandlerIfc collisionHandler)
        Sets the collision handler for this collision. It may be null indicating no collision handling
        Parameters:
        collisionHandler - The collisionHandler to set.
      • setMovingElement

        protected final void setMovingElement​(MoverIfc movingElement)
        Parameters:
        movingElement - The movingElement to set.