java.lang.Object
net.regsirius06.engine.core.graphics.labyrinth.default2D.LabyrinthGraphics2D
All Implemented Interfaces:
Drawable2D

public class LabyrinthGraphics2D extends Object implements Drawable2D
The LabyrinthGraphics2D class provides the logic for rendering a 2D labyrinth with ray casting effects, simulating what the player sees, including light sources, reflections, and walls.

This class visualizes the labyrinth and displays the player's perspective on the surrounding environment, taking into account factors such as lighting, intersections with objects, and reflections.

It implements the Drawable2D interface, which allows the labyrinth to be drawn on a 2D canvas.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Movement step for rays during raycasting.
    static final double
    Rotation step for rays (not used in current implementation).
  • Constructor Summary

    Constructors
    Constructor
    Description
    LabyrinthGraphics2D(int width, int height, Labyrinth2D labyrinth, Player player)
    Constructor that initializes the LabyrinthGraphics2D instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static double
    claimAngle(double angle)
    Claims an angle by normalizing it to the range [0, 2ПЂ).
    final void
    Draws the 2D visualization of the labyrinth and what the player sees.
    final Set<Wall>
    Returns the set of visible light sources.
    protected void
    Visualizes the labyrinth, including walls and light sources.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • moveStep

      public static final double moveStep
      Movement step for rays during raycasting.
      See Also:
    • rotationStep

      public static final double rotationStep
      Rotation step for rays (not used in current implementation).
      See Also:
  • Constructor Details

    • LabyrinthGraphics2D

      public LabyrinthGraphics2D(int width, int height, Labyrinth2D labyrinth, Player player)
      Constructor that initializes the LabyrinthGraphics2D instance.
      Parameters:
      width - The width of the canvas for rendering.
      height - The height of the canvas for rendering.
      labyrinth - The labyrinth instance representing the environment.
      player - The player instance determining the position and direction.
  • Method Details

    • getVisibleLightSources

      public final Set<Wall> getVisibleLightSources()
      Returns the set of visible light sources.
      Returns:
      A set of light sources that are visible to the player.
    • draw

      public final void draw(Graphics2D g2d)
      Draws the 2D visualization of the labyrinth and what the player sees.
      Specified by:
      draw in interface Drawable2D
      Parameters:
      g2d - The Graphics2D object used for drawing the scene.
    • visualize

      protected void visualize(Graphics2D g2d)
      Visualizes the labyrinth, including walls and light sources.
      Parameters:
      g2d - The Graphics2D object used for rendering the scene.
    • claimAngle

      protected static double claimAngle(double angle)
      Claims an angle by normalizing it to the range [0, 2ПЂ).
      Parameters:
      angle - The angle to normalize.
      Returns:
      The normalized angle in radians.