Package role

Class BarrierModel

All Implemented Interfaces:
Configuration, Cloneable, Comparable<EntityModel>
Direct Known Subclasses:
ScreenBoundary

public class BarrierModel extends EntityModel
The barrier model represents an impenetrable line barrier that triggers collisions on impact. The barrier Model is an inactive entity. In other words, it does not get the callbacks that dynamic entities receive for updating its parameters. Entities colliding with a barrier can be made to rebound by overriding the onBlocked() abstract method in the controller. Barriers can have no velocity and cannot move once created. They are ideal for overlays of static scenery or drawings (do not roll).
Author:
Krish Pillai
See Also:
  • GameController.onBlocked(event.BlockedEvent[])
  • BlockedEvent
  • Constructor Details

    • BarrierModel

      public BarrierModel(int x1, int y1, int x2, int y2)
      Constructs a barrier with end points (x1, y1) and (x2, y2)
      Parameters:
      x1 - x coordinate of end point #1
      y1 - y coordinate of end point #1
      x2 - x coordinate of end point #2
      y2 - y coordinate of end point #2
    • BarrierModel

      public BarrierModel(Line line)
      Constructs a barrier defined by the line argument.
      Parameters:
      line - the line defining the barrier
    • BarrierModel

      public BarrierModel(int x1, int y1, int x2, int y2, int layer)
      Constructs a barrier with end points (x1, y1) and (x2, y2) situated on layer (Z-axis) specified
      Parameters:
      x1 - x coordinate of end #1
      y1 - y coordinate of end #1
      x2 - x coordinate of end #2
      y2 - y coordinate of end #2
      layer - the z-axis subject to hidden-line removal
  • Method Details

    • getLine

      public Line getLine()
      Returns the line defining this barrier.
      Returns:
      line the barrier
    • setActive

      public void setActive(boolean state)
      Description copied from class: EntityModel
      Sets the state of the entity. Active entities take part in the EntityModel.updateParameters(long) call. Inactive (passive) models do not get this call-back invoked.
      Overrides:
      setActive in class EntityModel
      Parameters:
      state - State of the entity
    • getCollisionBounds

      public Dimension getCollisionBounds()
      Description copied from class: EntityModel
      Return the current collision bounds for this entity. The entity location (x,y) is not available through this call. Use EntityModel.getCollisionRange() to get the absolute screen area containing the entity.
      Overrides:
      getCollisionBounds in class EntityModel
      Returns:
      dim The dimensions (width and height) of the hit-box
      See Also:
    • getBearingDegrees

      public double getBearingDegrees()
      Returns the angle made by the barrier to the horizontal in degrees. 0 to 90 CW, 0 to -90 CCW. 0 degrees is horizontal 90 degrees is vertical
      Overrides:
      getBearingDegrees in class EntityModel
      Returns:
      bearing the direction in which the entity is headed
    • getCollisionRange

      public Rectangle getCollisionRange()
      Description copied from class: EntityModel
      Returns a rectangle defining the absolute area of the screen location of the entity. The rectangle contains the top left corner of the area rect occupied by the entity, and the dimensions of the collision bounds defined for the entity. The rectangle is centered about the location (body-center) of the entity.
      • rect.x = top left corner x coordinate
      • rect.y = top left corner y coordinate
      • rect.width = width of the hit box
      • rect.height = height of the hit box
      Overrides:
      getCollisionRange in class EntityModel
      Returns:
      range The collision range of the entity
    • setShowBounds

      public final void setShowBounds(boolean showBounds)
      Description copied from class: EntityModel
      Sets the state of the collision bounds display. Setting this to true will display a hit-box around the entity. This feature is useful for debugging purposes.
      Overrides:
      setShowBounds in class EntityModel
      Parameters:
      showBounds - true to turn on the hit-box rendering
    • updateParameters

      public void updateParameters(long elapsedTime)
    • setCoefficientOfRestitution

      public void setCoefficientOfRestitution(float coefficientOfRestitution)
      Description copied from class: EntityModel
      COR normally ranges from 0 to 1 where 1 would be a perfectly elastic collision. A perfectly inelastic collision has a coefficient of 0.
      Overrides:
      setCoefficientOfRestitution in class EntityModel
      Parameters:
      coefficientOfRestitution - COR
    • toString

      public String toString()
      Description copied from class: EntityModel
      String representation of the entity showing unique ID, location and collision bounds.
      Overrides:
      toString in class EntityModel
      Returns:
      a string representation of the entity
    • isActive

      public boolean isActive()
      Description copied from class: EntityModel
      Returns the state of the entity. Active entities take part in the EntityModel.updateParameters(long) call. Passive models do not get this call-back invoked.
      Overrides:
      isActive in class EntityModel
      Returns:
      state Active state of the entity
    • getAngleWithHorizontal

      public double getAngleWithHorizontal()
      Returns the angle that the barrier makes with the horizontal. Top left corner is (0,0) in the graphics systems used by Swing. Since Y axis increases from top to bottom, zero-degrees is 3 O'Clock, 90 degrees is 6:00 O'Clock, +-180 degrees is 9 O'Clock and 12 O'Clock is -90 degrees.
      Returns:
      angle line makes with horizontal
    • intersects

      public boolean intersects(Rectangle rectangle)
      Return true if the rectangle supplied is intersected by the barrier.
      Parameters:
      rectangle - the region to be checked against
      Returns:
      true if barrier intersects the rectangle