Package com.csse3200.game.components
Class AutonomousBoxComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.AutonomousBoxComponent
Component for a box that moves autonomously along a specified path at a specified speed.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor to remove gradle warnings about missing constructor in this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Initialises the box's physics referencefloat
Retrieves the bottom boundary of the autonomous box's vertical pathint
Retrieves the current horizontal movement direction of the box A value of 1 indicates movement to the right, and -1 indicates movement to the leftint
Retrieves the current vertical movement direction of the box A value of 1 indicates upward movement, and -1 indicates downward movementfloat
getLeftX()
Retrieves the left boundary of the autonomous box's horizontal pathRetrieves the PhysicsComponent after creationfloat
Retrieves the right boundary of the autonomous box's horizontal pathfloat
getSpeed()
Gets the movement speed of the autonomous boxfloat
getTopY()
Retrieves the top boundary of the autonomous box's vertical pathvoid
setBounds
(float minMoveX, float maxMoveX, float minMoveY, float maxMoveY) Sets the horizontal movement bounds for the box.void
setSpeed
(float speed) Sets the movement speedvoid
update()
Updates the box's position every frame based on its movement bounds and speed.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
-
Constructor Details
-
AutonomousBoxComponent
public AutonomousBoxComponent()Default constructor to remove gradle warnings about missing constructor in this class.
-
-
Method Details
-
create
public void create()Initialises the box's physics reference -
update
public void update()Updates the box's position every frame based on its movement bounds and speed.This box moves horizontally and/or vertically. When it reaches a boundary, the direction is reversed.
This method is called automatically once per frame. -
getPhysics
Retrieves the PhysicsComponent after creation- Returns:
- the physics component
-
setBounds
public void setBounds(float minMoveX, float maxMoveX, float minMoveY, float maxMoveY) Sets the horizontal movement bounds for the box.- Parameters:
minMoveX
- the left boundarymaxMoveX
- the right boundary
-
setSpeed
public void setSpeed(float speed) Sets the movement speed- Parameters:
speed
- the speed in units per second
-
getLeftX
public float getLeftX()Retrieves the left boundary of the autonomous box's horizontal path- Returns:
- the left X coordinate
-
getRightX
public float getRightX()Retrieves the right boundary of the autonomous box's horizontal path- Returns:
- the right X coordinate
-
getTopY
public float getTopY()Retrieves the top boundary of the autonomous box's vertical path- Returns:
- the top Y coordinate
-
getBottomY
public float getBottomY()Retrieves the bottom boundary of the autonomous box's vertical path- Returns:
- the bottom Y coordinate
-
getDirectionX
public int getDirectionX()Retrieves the current horizontal movement direction of the box A value of 1 indicates movement to the right, and -1 indicates movement to the left- Returns:
- the current horizontal direction
-
getDirectionY
public int getDirectionY()Retrieves the current vertical movement direction of the box A value of 1 indicates upward movement, and -1 indicates downward movement- Returns:
- the current vertical direction
-
getSpeed
public float getSpeed()Gets the movement speed of the autonomous box- Returns:
- the box's speed
-