Class Door

java.lang.Object
rooms.Door

public class Door extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private static final double
     
    private static final double
     
    private boolean
     
    private static final javafx.scene.image.Image
     
    private javafx.geometry.Rectangle2D
     
    private static final javafx.scene.image.Image
     
    private static final double
     
    private double
     
    private double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Door(double x, double y)
    Constructs a door at the specified position.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    intersects(javafx.geometry.Rectangle2D hitbox)
    Checks if the given hitbox intersects with this door.
    boolean
    Checks if the door is currently locked.
    void
    render(javafx.scene.canvas.GraphicsContext gc)
    Renders the door using the appropriate sprite based on its locked state.
    void
    setLocked(boolean locked)
    Sets the locked state of the door.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 door
      y - 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