Class Jumper

All Implemented Interfaces:
Hittable

public class Jumper extends Enemy
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 Details

    • targetX

      private double targetX
      Target X coordinate for the current jump.
    • targetY

      private double targetY
      Target Y coordinate for the current jump.
    • jumping

      private volatile boolean jumping
      Flag indicating whether the Jumper is currently jumping. Volatile ensures every thread see the change
    • jumpRadius

      private double jumpRadius
      Maximum jump distance from current position.
    • JUMPER_SPRITE

      private static final javafx.scene.image.Image JUMPER_SPRITE
      Sprite used to render the Jumper.
  • Constructor Details

    • Jumper

      public Jumper(double x, double y, Room room, int hp, int power, double diameter)
      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

      private void smoothMove(double durationSeconds) throws InterruptedException
      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

      public void update(double dt)
      Updates the Jumper each frame. Handles damage flash animation.
      Specified by:
      update in class Enemy
      Parameters:
      dt - Delta time since last update (seconds).
    • render

      public void render(javafx.scene.canvas.GraphicsContext gc)
      Renders the Jumper, including its sprite and damage flash.
      Specified by:
      render in class Enemy
      Parameters:
      gc - GraphicsContext used for rendering.