Class Laser
java.lang.Object
core.GameObject
entities.bullets.Laser
Represents a laser beam in the game.
The laser has a direction, length, damage, and limited lifetime.
It is rendered as a thick line and has a rectangular hitbox for collision detection.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhether the laser is still active/alive.private intDamage dealt by the laser.private doubleDirection vector of the laser (normalized).private doubleDirection vector of the laser (normalized).private doubleLength of the laser in pixels.private doubleTime remaining before the laser disappears (in seconds).Fields inherited from class core.GameObject
x, y -
Constructor Summary
ConstructorsConstructorDescriptionLaser(double x, double y, double dirX, double dirY, int damage) Constructs a new Laser. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the damage/power of the laser.javafx.geometry.Rectangle2DReturns the rectangular hitbox of the laser for collision detection.booleanisAlive()Checks if the laser is still active.voidrender(javafx.scene.canvas.GraphicsContext gc) Renders the laser as a red line on the screen.voidupdate(double dt) Updates the laser's lifetime.Methods inherited from class core.GameObject
getX, getY, setX, setY
-
Field Details
-
dirX
private double dirXDirection vector of the laser (normalized). -
dirY
private double dirYDirection vector of the laser (normalized). -
length
private double lengthLength of the laser in pixels. -
damage
private int damageDamage dealt by the laser. -
alive
private boolean aliveWhether the laser is still active/alive. -
lifetime
private double lifetimeTime remaining before the laser disappears (in seconds).
-
-
Constructor Details
-
Laser
public Laser(double x, double y, double dirX, double dirY, int damage) Constructs a new Laser.- Parameters:
x- Starting X position of the laser.y- Starting Y position of the laser.dirX- X component of the laser's direction vector.dirY- Y component of the laser's direction vector.damage- Damage dealt by the laser.
-
-
Method Details
-
update
public void update(double dt) Updates the laser's lifetime. Marks it as inactive when lifetime expires.- Specified by:
updatein classGameObject- Parameters:
dt- Time elapsed since last update (seconds).
-
isAlive
public boolean isAlive()Checks if the laser is still active.- Returns:
- true if the laser is alive/active, false otherwise.
-
render
public void render(javafx.scene.canvas.GraphicsContext gc) Renders the laser as a red line on the screen.- Specified by:
renderin classGameObject- Parameters:
gc- GraphicsContext used for drawing.
-
getHitbox
public javafx.geometry.Rectangle2D getHitbox()Returns the rectangular hitbox of the laser for collision detection.- Returns:
- Rectangle2D representing the laser's hitbox.
-
getDamage
public int getDamage()Returns the damage/power of the laser.- Returns:
- Damage value.
-