Class Item

java.lang.Object
entities.items.Item
All Implemented Interfaces:
Collectible
Direct Known Subclasses:
Coin, HealthPot, MaxHealthUpgrade, MysteryBox, StrengthPot, TreasureBox

public abstract class Item extends Object implements Collectible
Abstract base class for all collectible items in the game. Handles position, size, collection state, and collision detection with the player.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    Flag indicating whether the item has been collected.
    private double
    Height of the item for hitbox and rendering.
    private Room
    Room in which the item exists.
    private double
    Width of the item for hitbox and rendering.
    private double
    X coordinate of the item center.
    private double
    Y coordinate of the item center.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Item(double x, double y, double width, double height)
    Constructs a new Item.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    collect(Player player)
    Collects the item, applying its effect to the player.
    double
    Returns the height of the item.
    javafx.geometry.Rectangle2D
    Returns the hitbox of the item.
    Returns the room the item belongs to.
    double
    Returns the width of the item.
    double
    Returns the X coordinate of the item.
    double
    Returns the Y coordinate of the item.
    boolean
    Returns true if the item has been collected.
    abstract void
    render(javafx.scene.canvas.GraphicsContext gc)
    Renders the item.
    void
    setCollected(boolean collected)
    Sets the collected state of the item.
    void
    setHeight(double height)
    Sets the height of the item.
    void
    setRoom(Room room)
    Sets the room the item belongs to.
    void
    setWidth(double width)
    Sets the width of the item.
    void
    setX(double x)
    Sets the X coordinate of the item.
    void
    setY(double y)
    Sets the Y coordinate of the item.
    void
    update(double dt, Player player)
    Updates the item state.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • x

      private double x
      X coordinate of the item center.
    • y

      private double y
      Y coordinate of the item center.
    • width

      private double width
      Width of the item for hitbox and rendering.
    • height

      private double height
      Height of the item for hitbox and rendering.
    • collected

      private boolean collected
      Flag indicating whether the item has been collected.
    • room

      private Room room
      Room in which the item exists.
  • Constructor Details

    • Item

      public Item(double x, double y, double width, double height)
      Constructs a new Item.
      Parameters:
      x - Initial X position.
      y - Initial Y position.
      width - Width of the item.
      height - Height of the item.
  • Method Details

    • update

      public void update(double dt, Player player)
      Updates the item state. Checks for collision with the player and collects the item if intersecting.
      Specified by:
      update in interface Collectible
      Parameters:
      dt - Delta time since last update (seconds).
      player - Player object to check collision against.
    • getHitbox

      public javafx.geometry.Rectangle2D getHitbox()
      Returns the hitbox of the item.
      Specified by:
      getHitbox in interface Collectible
      Returns:
      Rectangle2D representing the item's hitbox.
    • render

      public abstract void render(javafx.scene.canvas.GraphicsContext gc)
      Renders the item.
      Specified by:
      render in interface Collectible
      Parameters:
      gc - GraphicsContext used for rendering.
    • collect

      public abstract void collect(Player player)
      Collects the item, applying its effect to the player.
      Specified by:
      collect in interface Collectible
      Parameters:
      player - Player who collected the item.
    • getX

      public double getX()
      Returns the X coordinate of the item.
      Returns:
      X coordinate
    • setX

      public void setX(double x)
      Sets the X coordinate of the item.
      Parameters:
      x - New X coordinate
    • getY

      public double getY()
      Returns the Y coordinate of the item.
      Returns:
      Y coordinate
    • setY

      public void setY(double y)
      Sets the Y coordinate of the item.
      Parameters:
      y - New Y coordinate
    • getWidth

      public double getWidth()
      Returns the width of the item.
      Returns:
      Width
    • setWidth

      public void setWidth(double width)
      Sets the width of the item.
      Parameters:
      width - New width
    • getHeight

      public double getHeight()
      Returns the height of the item.
      Returns:
      Height
    • setHeight

      public void setHeight(double height)
      Sets the height of the item.
      Parameters:
      height - New height
    • isCollected

      public boolean isCollected()
      Returns true if the item has been collected.
      Returns:
      true if collected, false otherwise
    • setCollected

      public void setCollected(boolean collected)
      Sets the collected state of the item.
      Parameters:
      collected - New collected state
    • getRoom

      public Room getRoom()
      Returns the room the item belongs to.
      Returns:
      Room object
    • setRoom

      public void setRoom(Room room)
      Sets the room the item belongs to.
      Parameters:
      room - Room object