Class Jumper
java.lang.Object
core.GameObject
core.Character
entities.enemies.Enemy
entities.enemies.Jumper
- All Implemented Interfaces:
Hittable
Represents a Jumper enemy.
The Jumper randomly jumps within a radius around its current position,
and shoots four bullets in four directions after each jump.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final javafx.scene.image.ImageSprite used to render the Jumper.private booleanFlag indicating whether the Jumper is currently jumping.private doubleMaximum jump distance from current position.private doubleTarget X coordinate for the current jump.private doubleTarget Y coordinate for the current jump.Fields inherited from class core.GameObject
x, y -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidMain AI loop running in a separate thread.private voidPicks a random target position within the jump radius.voidrender(javafx.scene.canvas.GraphicsContext gc) Renders the Jumper, including its sprite and damage flash.private voidShoots bullets in four cardinal directions (up, down, left, right).private voidsmoothMove(double durationSeconds) Smoothly moves the Jumper toward the target position over a specified duration.voidupdate(double dt) Updates the Jumper each frame.Methods inherited from class entities.enemies.Enemy
getDamageFlash, getRoom, isAlive, isDead, onDead, onHit, setDamageFlash, setRoomMethods inherited from class core.Character
getDiameter, getHitbox, getHp, getMaxHp, getPower, setAlive, setDiameter, setHp, setMaxHp, setPowerMethods inherited from class core.GameObject
getX, getY, setX, setYMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface core.Hittable
getDiameter, getHitbox
-
Field Details
-
targetX
private double targetXTarget X coordinate for the current jump. -
targetY
private double targetYTarget Y coordinate for the current jump. -
jumping
private volatile boolean jumpingFlag indicating whether the Jumper is currently jumping. Volatile ensures every thread see the change -
jumpRadius
private double jumpRadiusMaximum jump distance from current position. -
JUMPER_SPRITE
private static final javafx.scene.image.Image JUMPER_SPRITESprite used to render the Jumper.
-
-
Constructor Details
-
Jumper
Constructs a new Jumper enemy.- Parameters:
x- Initial X position.y- Initial Y position.room- Room where the enemy resides.hp- Health points of the Jumper.power- Attack power of the Jumper.diameter- Diameter for hitbox and rendering.
-
-
Method Details
-
loopBehavior
private void loopBehavior()Main AI loop running in a separate thread. Handles waiting, jumping, and shooting behavior. -
pickRandomTarget
private void pickRandomTarget()Picks a random target position within the jump radius. Ensures the target remains inside room bounds. -
smoothMove
Smoothly moves the Jumper toward the target position over a specified duration.- Parameters:
durationSeconds- Duration of the movement in seconds.- Throws:
InterruptedException- If the thread is interrupted.
-
shoot4Directions
private void shoot4Directions()Shoots bullets in four cardinal directions (up, down, left, right). -
update
-
render
-