Class Door
java.lang.Object
rooms.Door
Represents a door in a room.
A door can be locked or unlocked and can detect if a player intersects it. It also renders a locked or unlocked sprite depending on its state.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final doubleprivate static final doubleprivate booleanprivate static final javafx.scene.image.Imageprivate javafx.geometry.Rectangle2Dprivate static final javafx.scene.image.Imageprivate static final doubleprivate doubleprivate double -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanintersects(javafx.geometry.Rectangle2D hitbox) Checks if the given hitbox intersects with this door.booleanisLocked()Checks if the door is currently locked.voidrender(javafx.scene.canvas.GraphicsContext gc) Renders the door using the appropriate sprite based on its locked state.voidsetLocked(boolean locked) Sets the locked state of the door.
-
Field Details
-
region
private javafx.geometry.Rectangle2D region -
locked
private boolean locked -
LOCKEDDOOR_SPRITE
private static final javafx.scene.image.Image LOCKEDDOOR_SPRITE -
UNLOCKEDDOOR_SPRITE
private static final javafx.scene.image.Image UNLOCKEDDOOR_SPRITE -
WIDTH
private static final double WIDTH- See Also:
-
HEIGHT
private static final double HEIGHT- See Also:
-
IMAGE_HEIGHT
private static final double IMAGE_HEIGHT- See Also:
-
x
private double x -
y
private double y
-
-
Constructor Details
-
Door
public Door(double x, double y) Constructs a door at the specified position.- Parameters:
x- top-left x-coordinate of the doory- top-left y-coordinate of the door
-
-
Method Details
-
intersects
public boolean intersects(javafx.geometry.Rectangle2D hitbox) Checks if the given hitbox intersects with this door.- Parameters:
hitbox- the hitbox to check- Returns:
- true if the hitbox intersects the door, false otherwise
-
setLocked
public void setLocked(boolean locked) Sets the locked state of the door.- Parameters:
locked- true to lock the door, false to unlock
-
isLocked
public boolean isLocked()Checks if the door is currently locked.- Returns:
- true if the door is locked, false otherwise
-
render
public void render(javafx.scene.canvas.GraphicsContext gc) Renders the door using the appropriate sprite based on its locked state.- Parameters:
gc- the GraphicsContext to draw on
-