Class Player
java.lang.Object
net.regsirius06.engine.point.Point
net.regsirius06.engine.point.entities.Player
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
-
Constructor Summary
ConstructorsConstructorDescriptionPlayer(double x, double y, double direction) Constructs a newPlayerat the specifiedx,ycoordinates, and facing a given direction.Constructs a newPlayerat the specifiedPointspawn location and facing a given direction.Constructs a newPlayerat the specifiedPointspawn location with a random direction. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidadd(double step, double angle) Moves the player by a specified step in the direction the player is facing.final doubleReturns 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
-
Constructor Details
-
Player
public Player(double x, double y, double direction) Constructs a newPlayerat the specifiedx,ycoordinates, and facing a given direction.- Parameters:
x- thexcoordinate of the player's positiony- theycoordinate of the player's positiondirection- the direction the player is facing, measured in radians
-
Player
Constructs a newPlayerat the specifiedPointspawn location and facing a given direction.- Parameters:
spawnPoint- thePointthat represents the player's initial positiondirection- the direction the player is facing, measured in radians
-
Player
Constructs a newPlayerat the specifiedPointspawn location with a random direction. The direction is chosen randomly within the range of-Math.PItoMath.PI.- Parameters:
spawnPoint- thePointthat 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 of0represents the positivex-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 givenangle(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 playerangle- the angle (in radians) by which to adjust the player's facing direction
-