Class Bullet

java.lang.Object
core.GameObject
entities.bullets.Bullet

public class Bullet extends GameObject
Represents a bullet in the game. Bullets have a velocity, power, an owner (who fired it), and a hitbox for collision detection.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static javafx.scene.image.Image
    Sprite image used to render the bullet.
    private static final double
    Diameter of the bullet.
    The type of character who owns/fired the bullet.
    private int
    Power (damage) of the bullet.
    private double
    Horizontal velocity of the bullet.
    private double
    Vertical velocity of the bullet.

    Fields inherited from class core.GameObject

    x, y
  • Constructor Summary

    Constructors
    Constructor
    Description
    Bullet(double x, double y, double vx, double vy, int power, CharacterType owner)
    Constructs a new Bullet.
  • Method Summary

    Modifier and Type
    Method
    Description
    javafx.scene.image.Image
    Returns the sprite image for the bullet.
    javafx.geometry.Rectangle2D
    Returns the hitbox of the bullet for collision detection.
    Returns the owner of the bullet.
    int
    Returns the damage power of the bullet.
    double
    Returns the horizontal velocity of the bullet.
    double
    Returns the vertical velocity of the bullet.
    void
    render(javafx.scene.canvas.GraphicsContext gc)
    Renders the bullet on the screen.
    void
    Sets the owner of the bullet.
    void
    setPower(int power)
    Sets the damage power of the bullet.
    void
    setVx(double vx)
    Sets the horizontal velocity of the bullet.
    void
    setVy(double vy)
    Sets the vertical velocity of the bullet.
    void
    update(double dt)
    Updates the position of the bullet based on its velocity.

    Methods inherited from class core.GameObject

    getX, getY, setX, setY

    Methods inherited from class java.lang.Object

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

    • vx

      private double vx
      Horizontal velocity of the bullet.
    • vy

      private double vy
      Vertical velocity of the bullet.
    • owner

      private CharacterType owner
      The type of character who owns/fired the bullet.
    • power

      private int power
      Power (damage) of the bullet.
    • DIAMETER

      private static final double DIAMETER
      Diameter of the bullet.
      See Also:
    • BULLET_SPRITE

      private static javafx.scene.image.Image BULLET_SPRITE
      Sprite image used to render the bullet.
  • Constructor Details

    • Bullet

      public Bullet(double x, double y, double vx, double vy, int power, CharacterType owner)
      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:
      update in class GameObject
      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:
      render in class GameObject
      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

      public CharacterType getOwner()
      Returns the owner of the bullet.
      Returns:
      CharacterType representing the bullet's owner.
    • setOwner

      public void setOwner(CharacterType owner)
      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.