Class AutonomousBoxComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.AutonomousBoxComponent

public class AutonomousBoxComponent extends Component
Component for a box that moves autonomously along a specified path at a specified speed.
  • Field Summary

    Fields inherited from class com.csse3200.game.components.Component

    enabled, entity
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor to remove gradle warnings about missing constructor in this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Initialises the box's physics reference
    float
    Retrieves the bottom boundary of the autonomous box's vertical path
    int
    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
    int
    Retrieves the current vertical movement direction of the box A value of 1 indicates upward movement, and -1 indicates downward movement
    float
    Retrieves the left boundary of the autonomous box's horizontal path
    Retrieves the PhysicsComponent after creation
    float
    Retrieves the right boundary of the autonomous box's horizontal path
    float
    Gets the movement speed of the autonomous box
    float
    Retrieves the top boundary of the autonomous box's vertical path
    void
    setBounds(float minMoveX, float maxMoveX, float minMoveY, float maxMoveY)
    Sets the horizontal movement bounds for the box.
    void
    setSpeed(float speed)
    Sets the movement speed
    void
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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
      Overrides:
      create in class Component
    • 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.

      Overrides:
      update in class Component
    • getPhysics

      public PhysicsComponent 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 boundary
      maxMoveX - 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