Class Room

java.lang.Object
rooms.Room
Direct Known Subclasses:
CombatRoom, NormalRoom, StoreRoom, TreasureRoom

public abstract class Room extends Object
Abstract base class for all types of rooms in the game.

Handles entities such as enemies, bullets, items, lasers, and the player. Provides update and render methods for the room and its entities.

  • Field Details

    • FLOOR_SPRITE

      private static javafx.scene.image.Image FLOOR_SPRITE
      Shared floor sprite for all rooms
    • active

      public boolean active
      Whether this room is currently active
    • player

      private Player player
    • x

      protected double x
    • y

      protected double y
    • width

      protected double width
    • height

      protected double height
    • topDoor

      protected Door topDoor
    • enemies

      private List<Enemy> enemies
    • bullets

      private List<Bullet> bullets
    • items

      private List<Item> items
    • pendingItems

      private List<Item> pendingItems
    • characters

      private List<Character> characters
    • lasers

      private List<Laser> lasers
  • Constructor Details

    • Room

      public Room(double x, double y, double width, double height, Player player)
      Constructs a room with specified size and player reference.
      Parameters:
      x - top-left x-coordinate
      y - top-left y-coordinate
      width - width of the room
      height - height of the room
      player - the player object inside the room
  • Method Details

    • addEnemy

      public void addEnemy(Enemy e)
      Adds an enemy to the room and to the characters list.
      Parameters:
      e - enemy to add
    • spawnBullet

      public void spawnBullet(Bullet b)
      Spawns a bullet in the room.
      Parameters:
      b - bullet to spawn
    • spawnItems

      public void spawnItems(Item i)
      Schedules an item to be added to the room.
      Parameters:
      i - item to spawn
    • spawnLaser

      public void spawnLaser(Laser l)
      Spawns a laser in the room.
      Parameters:
      l - laser to spawn
    • getWidth

      public double getWidth()
      Returns:
      width of the room
    • getHeight

      public double getHeight()
      Returns:
      height of the room
    • getEnemies

      public List<Enemy> getEnemies()
      Returns:
      list of enemies in the room
    • getBullets

      public List<Bullet> getBullets()
      Returns:
      list of bullets in the room
    • getItems

      public List<Item> getItems()
      Returns:
      list of items in the room
    • getLasers

      public List<Laser> getLasers()
      Returns:
      list of lasers in the room
    • getCharacters

      public List<Character> getCharacters()
      Returns:
      list of all characters (player + enemies) in the room
    • getFloorSprite

      public javafx.scene.image.Image getFloorSprite()
      Returns:
      shared floor sprite
    • addDoor

      public void addDoor(Door door)
      Adds a door to the room.
      Parameters:
      door - the door to add
    • getDoorAtPlayer

      public Door getDoorAtPlayer(javafx.geometry.Rectangle2D playerHitbox)
      Checks if the player intersects the door.
      Parameters:
      playerHitbox - the player's hitbox
      Returns:
      the door if intersecting, otherwise null
    • updateEntities

      public void updateEntities(double dt)
      Updates all entities in the room: enemies, bullets, items, lasers.
      Parameters:
      dt - delta time in seconds
    • renderEntities

      public void renderEntities(javafx.scene.canvas.GraphicsContext gc)
      Renders bullets, enemies, items, and lasers in the room
    • setActive

      public void setActive(boolean active)
    • isActive

      public boolean isActive()
    • drawFog

      protected void drawFog(javafx.scene.canvas.GraphicsContext gc, javafx.scene.paint.Color edgeColor, double strength)
      Draws fog/smoke effect over the room.
      Parameters:
      gc - GraphicsContext
      edgeColor - color of the outer edge
      strength - opacity of the fog
    • render

      public void render(javafx.scene.canvas.GraphicsContext gc)
      Base render method for the room.
      Parameters:
      gc - GraphicsContext
    • update

      public void update(double dt)
      Updates the room and its entities.
      Parameters:
      dt - delta time in seconds