Package role
Class BarrierModel
java.lang.Object
role.EntityModel
role.BarrierModel
- All Implemented Interfaces:
Configuration,Cloneable,Comparable<EntityModel>
- Direct Known Subclasses:
ScreenBoundary
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface common.Configuration
Configuration.Direction -
Field Summary
Fields inherited from interface common.Configuration
AUDIO_DIR, DEFAULT_FRAME_RATE, DRAWABLE_DIR, GAMELOGGER, setViewCallChain -
Constructor Summary
ConstructorsConstructorDescriptionBarrierModel(int x1, int y1, int x2, int y2) Constructs a barrier with end points (x1, y1) and (x2, y2)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) specifiedBarrierModel(Line line) Constructs a barrier defined by the line argument. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the angle that the barrier makes with the horizontal.doubleReturns the angle made by the barrier to the horizontal in degrees.Return the current collision bounds for this entity.Returns a rectangle defining the absolute area of the screen location of the entity.getLine()Returns the line defining this barrier.booleanintersects(Rectangle rectangle) Return true if the rectangle supplied is intersected by the barrier.booleanisActive()Returns the state of the entity.voidsetActive(boolean state) Sets the state of the entity.voidsetCoefficientOfRestitution(float coefficientOfRestitution) COR normally ranges from 0 to 1 where 1 would be a perfectly elastic collision.final voidsetShowBounds(boolean showBounds) Sets the state of the collision bounds display.toString()String representation of the entity showing unique ID, location and collision bounds.voidupdateParameters(long elapsedTime) Methods inherited from class role.EntityModel
clone, collidesWith, compareTo, dispose, equals, getBearingRadians, getCoefficientOfRestitution, getHitboxHeight, getHitboxWidth, getID, getLayer, getMass, getName, getScaleX, getScaleY, getSpeed, getTimeToLive, getX, getXAcceleration, getXLocation, getXVelocity, getY, getYAcceleration, getYLocation, getYVelocity, hashCode, isAnimated, isDisposed, isGhost, isShowBounds, isVisible, isWrappedMode, poachState, resetCollisionBounds, resetEntityState, setAnimation, setCollisionBounds, setCollisionBounds, setGhost, setLayer, setLocation, setMass, setName, setScale, setScale, setTimeToLive, setVelocityDegrees, setVelocityRadians, setVisible, setWrappedMode, setXAcceleration, setXLocation, setXVelocity, setYAcceleration, setYLocation, setYVelocity
-
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 #1y1- y coordinate of end point #1x2- x coordinate of end point #2y2- y coordinate of end point #2
-
BarrierModel
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 #1y1- y coordinate of end #1x2- x coordinate of end #2y2- y coordinate of end #2layer- the z-axis subject to hidden-line removal
-
-
Method Details
-
getLine
Returns the line defining this barrier.- Returns:
- line the barrier
-
setActive
public void setActive(boolean state) Description copied from class:EntityModelSets the state of the entity. Active entities take part in theEntityModel.updateParameters(long)call. Inactive (passive) models do not get this call-back invoked.- Overrides:
setActivein classEntityModel- Parameters:
state- State of the entity
-
getCollisionBounds
Description copied from class:EntityModelReturn the current collision bounds for this entity. The entity location (x,y) is not available through this call. UseEntityModel.getCollisionRange()to get the absolute screen area containing the entity.- Overrides:
getCollisionBoundsin classEntityModel- 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:
getBearingDegreesin classEntityModel- Returns:
- bearing the direction in which the entity is headed
-
getCollisionRange
Description copied from class:EntityModelReturns 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:
getCollisionRangein classEntityModel- Returns:
- range The collision range of the entity
-
setShowBounds
public final void setShowBounds(boolean showBounds) Description copied from class:EntityModelSets 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:
setShowBoundsin classEntityModel- 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:EntityModelCOR normally ranges from 0 to 1 where 1 would be a perfectly elastic collision. A perfectly inelastic collision has a coefficient of 0.- Overrides:
setCoefficientOfRestitutionin classEntityModel- Parameters:
coefficientOfRestitution- COR
-
toString
Description copied from class:EntityModelString representation of the entity showing unique ID, location and collision bounds.- Overrides:
toStringin classEntityModel- Returns:
- a string representation of the entity
-
isActive
public boolean isActive()Description copied from class:EntityModelReturns the state of the entity. Active entities take part in theEntityModel.updateParameters(long)call. Passive models do not get this call-back invoked.- Overrides:
isActivein classEntityModel- 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
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
-