Class Item
java.lang.Object
entities.items.Item
- All Implemented Interfaces:
Collectible
- Direct Known Subclasses:
Coin,HealthPot,MaxHealthUpgrade,MysteryBox,StrengthPot,TreasureBox
Abstract base class for all collectible items in the game.
Handles position, size, collection state, and collision detection with the player.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanFlag indicating whether the item has been collected.private doubleHeight of the item for hitbox and rendering.private RoomRoom in which the item exists.private doubleWidth of the item for hitbox and rendering.private doubleX coordinate of the item center.private doubleY coordinate of the item center. -
Constructor Summary
ConstructorsConstructorDescriptionItem(double x, double y, double width, double height) Constructs a new Item. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidCollects the item, applying its effect to the player.doubleReturns the height of the item.javafx.geometry.Rectangle2DReturns the hitbox of the item.getRoom()Returns the room the item belongs to.doublegetWidth()Returns the width of the item.doublegetX()Returns the X coordinate of the item.doublegetY()Returns the Y coordinate of the item.booleanReturns true if the item has been collected.abstract voidrender(javafx.scene.canvas.GraphicsContext gc) Renders the item.voidsetCollected(boolean collected) Sets the collected state of the item.voidsetHeight(double height) Sets the height of the item.voidSets the room the item belongs to.voidsetWidth(double width) Sets the width of the item.voidsetX(double x) Sets the X coordinate of the item.voidsetY(double y) Sets the Y coordinate of the item.voidUpdates the item state.
-
Field Details
-
x
private double xX coordinate of the item center. -
y
private double yY coordinate of the item center. -
width
private double widthWidth of the item for hitbox and rendering. -
height
private double heightHeight of the item for hitbox and rendering. -
collected
private boolean collectedFlag indicating whether the item has been collected. -
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
Updates the item state. Checks for collision with the player and collects the item if intersecting.- Specified by:
updatein interfaceCollectible- 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:
getHitboxin interfaceCollectible- Returns:
- Rectangle2D representing the item's hitbox.
-
render
public abstract void render(javafx.scene.canvas.GraphicsContext gc) Renders the item.- Specified by:
renderin interfaceCollectible- Parameters:
gc- GraphicsContext used for rendering.
-
collect
Collects the item, applying its effect to the player.- Specified by:
collectin interfaceCollectible- 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
-
setRoom
-