java.lang.Object
net.regsirius06.engine.point.Point
net.regsirius06.engine.point.entities.Player

public class Player extends Point
The Player class represents a player in a 2D space, extending the Point class. It includes a direction in which the player is facing, in addition to the x and y coordinates inherited from the Point class. This class allows the player to move in a specified direction and adjust their direction based on steps and angles.
  • Field Summary

    Fields inherited from class net.regsirius06.engine.point.Point

    x, y
  • Constructor Summary

    Constructors
    Constructor
    Description
    Player(double x, double y, double direction)
    Constructs a new Player at the specified x, y coordinates, and facing a given direction.
    Player(@NotNull Point spawnPoint, double direction)
    Constructs a new Player at the specified Point spawn location and facing a given direction.
    Player(Point spawnPoint)
    Constructs a new Player at the specified Point spawn location with a random direction.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    add(double step, double angle)
    Moves the player by a specified step in the direction the player is facing.
    final double
    Returns the direction the player is facing, measured in radians.

    Methods inherited from class net.regsirius06.engine.point.Point

    angleTo, angleTo, distanceTo, distanceTo, equals, getPoint, getX, getY, hashCode, isPointInside, isPointInside, movePoint, movePoint

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Player

      public Player(double x, double y, double direction)
      Constructs a new Player at the specified x, y coordinates, and facing a given direction.
      Parameters:
      x - the x coordinate of the player's position
      y - the y coordinate of the player's position
      direction - the direction the player is facing, measured in radians
    • Player

      public Player(@NotNull @NotNull Point spawnPoint, double direction)
      Constructs a new Player at the specified Point spawn location and facing a given direction.
      Parameters:
      spawnPoint - the Point that represents the player's initial position
      direction - the direction the player is facing, measured in radians
    • Player

      public Player(Point spawnPoint)
      Constructs a new Player at the specified Point spawn location with a random direction. The direction is chosen randomly within the range of -Math.PI to Math.PI.
      Parameters:
      spawnPoint - the Point that represents the player's initial position
  • Method Details

    • getDirection

      public final double getDirection()
      Returns the direction the player is facing, measured in radians. A direction of 0 represents the positive x-axis, and the angle increases counterclockwise.
      Returns:
      the direction the player is facing, in radians
    • add

      public final void add(double step, double angle)
      Moves the player by a specified step in the direction the player is facing. The direction is adjusted by the given angle (in radians), and the player's position is updated accordingly. The direction is kept within the range [-2 * Math.PI, 2 * Math.PI] by normalizing it.
      Parameters:
      step - the distance to move the player
      angle - the angle (in radians) by which to adjust the player's facing direction