Class MysteryBox

java.lang.Object
entities.items.Item
entities.items.MysteryBox
All Implemented Interfaces:
Collectible

public class MysteryBox extends Item
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

    Fields
    Modifier and Type
    Field
    Description
    private static final javafx.scene.image.Image
    Mystery box sprite.
    private static final javafx.scene.image.Image
    Coin icon sprite for displaying cost.
    private int
    Cost of the mystery box in coins.
    private static final double
    Height of the mystery box sprite.
    private Room
    The room this mystery box belongs to.
    private static final double
    Width of the mystery box sprite.
  • Constructor Summary

    Constructors
    Constructor
    Description
    MysteryBox(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 Type
    Method
    Description
    void
    collect(Player player)
    Collects the mystery box, randomly spawning a new item in the room.
    void
    render(javafx.scene.canvas.GraphicsContext gc)
    Renders the mystery box and its cost (if any) at its current position.
    void
    update(double dt, Player player)
    Updates the box state.

    Methods inherited from class entities.items.Item

    getHeight, getHitbox, getRoom, getWidth, getX, getY, isCollected, setCollected, setHeight, setRoom, setWidth, setX, setY

    Methods inherited from class java.lang.Object

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

    • WIDTH

      private static final double WIDTH
      Width of the mystery box sprite.
      See Also:
    • HEIGHT

      private static final double HEIGHT
      Height of the mystery box sprite.
      See Also:
    • COIN_SPRITE

      private static final javafx.scene.image.Image COIN_SPRITE
      Coin icon sprite for displaying cost.
    • BOX_SPRITE

      private static final javafx.scene.image.Image BOX_SPRITE
      Mystery box sprite.
    • cost

      private int cost
      Cost of the mystery box in coins.
    • room

      private Room room
      The room this mystery box belongs to.
  • Constructor Details

    • MysteryBox

      public MysteryBox(double x, double y, Room room, int cost)
      Constructs a new MysteryBox at the specified position, with a cost and associated room.
      Parameters:
      x - X coordinate of the box center
      y - Y coordinate of the box center
      room - Room in which the box is located
      cost - Coin cost to collect the box
  • Method Details

    • collect

      public void collect(Player player)
      Collects the mystery box, randomly spawning a new item in the room.
      Specified by:
      collect in interface Collectible
      Specified by:
      collect in class Item
      Parameters:
      player - The player who collects the mystery box
    • update

      public void update(double dt, Player player)
      Updates the box state. If the player intersects and has sufficient coins, collects the box and deducts coins from the player.
      Specified by:
      update in interface Collectible
      Overrides:
      update in class Item
      Parameters:
      dt - Delta time since last update
      player - 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:
      render in interface Collectible
      Specified by:
      render in class Item
      Parameters:
      gc - GraphicsContext used for rendering