Class Bullet
java.lang.Object
core.GameObject
entities.bullets.Bullet
Represents a bullet in the game.
Bullets have a velocity, power, an owner (who fired it), and a hitbox for collision detection.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static javafx.scene.image.ImageSprite image used to render the bullet.private static final doubleDiameter of the bullet.private CharacterTypeThe type of character who owns/fired the bullet.private intPower (damage) of the bullet.private doubleHorizontal velocity of the bullet.private doubleVertical velocity of the bullet.Fields inherited from class core.GameObject
x, y -
Constructor Summary
ConstructorsConstructorDescriptionBullet(double x, double y, double vx, double vy, int power, CharacterType owner) Constructs a new Bullet. -
Method Summary
Modifier and TypeMethodDescriptionjavafx.scene.image.ImageReturns the sprite image for the bullet.javafx.geometry.Rectangle2DReturns the hitbox of the bullet for collision detection.getOwner()Returns the owner of the bullet.intgetPower()Returns the damage power of the bullet.doublegetVx()Returns the horizontal velocity of the bullet.doublegetVy()Returns the vertical velocity of the bullet.voidrender(javafx.scene.canvas.GraphicsContext gc) Renders the bullet on the screen.voidsetOwner(CharacterType owner) Sets the owner of the bullet.voidsetPower(int power) Sets the damage power of the bullet.voidsetVx(double vx) Sets the horizontal velocity of the bullet.voidsetVy(double vy) Sets the vertical velocity of the bullet.voidupdate(double dt) Updates the position of the bullet based on its velocity.Methods inherited from class core.GameObject
getX, getY, setX, setY
-
Field Details
-
vx
private double vxHorizontal velocity of the bullet. -
vy
private double vyVertical velocity of the bullet. -
owner
The type of character who owns/fired the bullet. -
power
private int powerPower (damage) of the bullet. -
DIAMETER
private static final double DIAMETERDiameter of the bullet.- See Also:
-
BULLET_SPRITE
private static javafx.scene.image.Image BULLET_SPRITESprite image used to render the bullet.
-
-
Constructor Details
-
Bullet
Constructs a new Bullet.- Parameters:
x- Initial X position.y- Initial Y position.vx- Horizontal velocity.vy- Vertical velocity.power- Damage power of the bullet.owner- Owner of the bullet (who fired it).
-
-
Method Details
-
update
public void update(double dt) Updates the position of the bullet based on its velocity.- Specified by:
updatein classGameObject- Parameters:
dt- Time elapsed since the last update (seconds).
-
render
public void render(javafx.scene.canvas.GraphicsContext gc) Renders the bullet on the screen.- Specified by:
renderin classGameObject- Parameters:
gc- GraphicsContext used for drawing.
-
getBulletSprite
public javafx.scene.image.Image getBulletSprite()Returns the sprite image for the bullet. Loads the image lazily on first call.- Returns:
- Image of the bullet.
-
getHitBox
public javafx.geometry.Rectangle2D getHitBox()Returns the hitbox of the bullet for collision detection.- Returns:
- Rectangle2D representing the bullet's hitbox.
-
getOwner
Returns the owner of the bullet.- Returns:
- CharacterType representing the bullet's owner.
-
setOwner
Sets the owner of the bullet.- Parameters:
owner- CharacterType to set as the bullet's owner.
-
getVy
public double getVy()Returns the vertical velocity of the bullet.- Returns:
- Vertical velocity.
-
setVy
public void setVy(double vy) Sets the vertical velocity of the bullet.- Parameters:
vy- Vertical velocity to set.
-
getVx
public double getVx()Returns the horizontal velocity of the bullet.- Returns:
- Horizontal velocity.
-
setVx
public void setVx(double vx) Sets the horizontal velocity of the bullet.- Parameters:
vx- Horizontal velocity to set.
-
getPower
public int getPower()Returns the damage power of the bullet.- Returns:
- Power of the bullet.
-
setPower
public void setPower(int power) Sets the damage power of the bullet. Values below 0 are clamped to 0.- Parameters:
power- Power to set.
-