Class MysteryBox
java.lang.Object
entities.items.Item
entities.items.MysteryBox
- All Implemented Interfaces:
Collectible
A collectible mystery box item.
When collected, it randomly spawns another item in the room,
and can be purchased by the player for a cost (Sometimes cost 0 coin).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final javafx.scene.image.ImageMystery box sprite.private static final javafx.scene.image.ImageCoin icon sprite for displaying cost.private intCost of the mystery box in coins.private static final doubleHeight of the mystery box sprite.private RoomThe room this mystery box belongs to.private static final doubleWidth of the mystery box sprite. -
Constructor Summary
ConstructorsConstructorDescriptionMysteryBox(double x, double y, Room room, int cost) Constructs a new MysteryBox at the specified position, with a cost and associated room. -
Method Summary
Modifier and TypeMethodDescriptionvoidCollects the mystery box, randomly spawning a new item in the room.voidrender(javafx.scene.canvas.GraphicsContext gc) Renders the mystery box and its cost (if any) at its current position.voidUpdates the box state.
-
Field Details
-
WIDTH
private static final double WIDTHWidth of the mystery box sprite.- See Also:
-
HEIGHT
private static final double HEIGHTHeight of the mystery box sprite.- See Also:
-
COIN_SPRITE
private static final javafx.scene.image.Image COIN_SPRITECoin icon sprite for displaying cost. -
BOX_SPRITE
private static final javafx.scene.image.Image BOX_SPRITEMystery box sprite. -
cost
private int costCost of the mystery box in coins. -
room
The room this mystery box belongs to.
-
-
Constructor Details
-
MysteryBox
Constructs a new MysteryBox at the specified position, with a cost and associated room.- Parameters:
x- X coordinate of the box centery- Y coordinate of the box centerroom- Room in which the box is locatedcost- Coin cost to collect the box
-
-
Method Details
-
collect
Collects the mystery box, randomly spawning a new item in the room.- Specified by:
collectin interfaceCollectible- Specified by:
collectin classItem- Parameters:
player- The player who collects the mystery box
-
update
Updates the box state. If the player intersects and has sufficient coins, collects the box and deducts coins from the player.- Specified by:
updatein interfaceCollectible- Overrides:
updatein classItem- Parameters:
dt- Delta time since last updateplayer- The player interacting with the box
-
render
public void render(javafx.scene.canvas.GraphicsContext gc) Renders the mystery box and its cost (if any) at its current position.- Specified by:
renderin interfaceCollectible- Specified by:
renderin classItem- Parameters:
gc- GraphicsContext used for rendering
-