Class Enemy

All Implemented Interfaces:
Hittable
Direct Known Subclasses:
Boss, Chaser, Jumper

public abstract class Enemy extends Character implements Hittable
Abstract base class for all enemy types. Handles health, damage reactions, damage flash, and room reference. Every enemy must implement update and render methods (Some enemies do not use update() but will create its own thread.)
  • Field Details

    • room

      protected Room room
      Reference to the room where the enemy exists.
    • damageFlash

      private double damageFlash
      Visual flash effect when the enemy takes damage (0 = none, 1 = full).
  • Constructor Details

    • Enemy

      public Enemy(double x, double y, int hp, int power, Room room, double diameter)
      Constructs an Enemy.
      Parameters:
      x - Initial X position.
      y - Initial Y position.
      hp - Health points.
      power - Attack power.
      room - Room where the enemy is located.
      diameter - Diameter for hitbox and rendering.
  • Method Details

    • isDead

      public boolean isDead()
      Checks whether the enemy is dead.
      Overrides:
      isDead in class Character
      Returns:
      true if dead, false otherwise.
    • onHit

      public void onHit(int damage)
      Called when the enemy takes damage. Updates HP and triggers damage flash effect.
      Specified by:
      onHit in interface Hittable
      Parameters:
      damage - Amount of damage to apply.
    • getDamageFlash

      public double getDamageFlash()
      Returns the current damage flash value.
      Returns:
      Damage flash (0–1).
    • setDamageFlash

      public void setDamageFlash(double damageFlash)
      Sets the damage flash value.
      Parameters:
      damageFlash - Value to set (0–1).
    • isAlive

      public boolean isAlive()
      Checks if the enemy is alive.
      Specified by:
      isAlive in interface Hittable
      Overrides:
      isAlive in class Character
      Returns:
      true if alive, false otherwise.
    • onDead

      public void onDead()
      Called when the enemy dies. Default behavior is to spawn a coin at the enemy's location.
      Specified by:
      onDead in interface Hittable
    • getRoom

      public Room getRoom()
      Returns the room this enemy belongs to.
      Returns:
      Room object.
    • setRoom

      public void setRoom(Room room)
      Sets the room this enemy belongs to.
      Parameters:
      room - Room object.
    • update

      public abstract void update(double dt)
      Updates the enemy state each frame.
      Specified by:
      update in class GameObject
      Parameters:
      dt - Delta time since last update (seconds).
    • render

      public abstract void render(javafx.scene.canvas.GraphicsContext gc)
      Renders the enemy on the screen.
      Specified by:
      render in class GameObject
      Parameters:
      gc - GraphicsContext used for rendering.