Class Coin
java.lang.Object
entities.items.Item
entities.items.Coin
- All Implemented Interfaces:
Collectible
A collectible coin item.
When collected by the player, adds one coin to the player's inventory and plays a sound effect.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static javafx.scene.image.ImageCoin sprite image.private static final doubleHeight of the coin sprite.private static final doubleWidth of the coin sprite. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCollects the coin, giving the player 1 coin and playing a sound effect.static javafx.scene.image.ImageReturns the coin sprite image.voidrender(javafx.scene.canvas.GraphicsContext gc) Renders the coin at its current position.
-
Field Details
-
WIDTH
private static final double WIDTHWidth of the coin sprite.- See Also:
-
HEIGHT
private static final double HEIGHTHeight of the coin sprite.- See Also:
-
COIN_SPRITE
private static javafx.scene.image.Image COIN_SPRITECoin sprite image.
-
-
Constructor Details
-
Coin
public Coin(double x, double y) Constructs a new Coin at the specified position.- Parameters:
x- X coordinate of the coin centery- Y coordinate of the coin center
-
-
Method Details
-
collect
Collects the coin, giving the player 1 coin and playing a sound effect.- Specified by:
collectin interfaceCollectible- Specified by:
collectin classItem- Parameters:
player- The player who collects the coin
-
getCoinSprite
public static javafx.scene.image.Image getCoinSprite()Returns the coin sprite image. Loads it if it has not been loaded yet.- Returns:
- Image representing the coin
-
render
public void render(javafx.scene.canvas.GraphicsContext gc) Renders the coin at its current position.- Specified by:
renderin interfaceCollectible- Specified by:
renderin classItem- Parameters:
gc- GraphicsContext used for rendering
-