Class PhysicsMovementComponent

java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.physics.components.PhysicsMovementComponent
All Implemented Interfaces:
MovementController

public class PhysicsMovementComponent extends Component implements MovementController
Movement controller for a physics-based entity.
  • Field Summary

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

    enabled, entity
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initialising the PhysicsMovementComponent by default.
    PhysicsMovementComponent(com.badlogic.gdx.math.Vector2 speed)
    Creates an entity that have a base speed.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Checks the direction of the entity and changes to appropriate animation and direction
    void
    changeSpeed(float factor)
     
    void
    Called when the entity is created and registered.
    void
    Changes the direction to face east and trigger that respective animation on the condition that the previous recorded direction is not east.
    void
    Changes the direction to face north and trigger that respective animation on the condition that the previous recorded direction is not north.
    void
    Changes the direction to face south and trigger that respective animation on the condition that the previous recorded direction is not south.
    void
    Changes the direction to face west and trigger that respective animation on the condition that the previous recorded direction is not west.
    boolean
     
    com.badlogic.gdx.math.Vector2
     
    void
    setMoving(boolean movementEnabled)
    Enable/disable movement for the controller.
    void
    setTarget(com.badlogic.gdx.math.Vector2 target)
    Set a target to move towards.
    void
    Called once per frame of the game, and should be used for most component logic.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PhysicsMovementComponent

      public PhysicsMovementComponent()
      Initialising the PhysicsMovementComponent by default.
    • PhysicsMovementComponent

      public PhysicsMovementComponent(com.badlogic.gdx.math.Vector2 speed)
      Creates an entity that have a base speed.
      Parameters:
      speed - the moving speed
  • Method Details

    • faceWest

      public void faceWest()
      Changes the direction to face west and trigger that respective animation on the condition that the previous recorded direction is not west.
    • faceEast

      public void faceEast()
      Changes the direction to face east and trigger that respective animation on the condition that the previous recorded direction is not east.
    • faceNorth

      public void faceNorth()
      Changes the direction to face north and trigger that respective animation on the condition that the previous recorded direction is not north.
    • faceSouth

      public void faceSouth()
      Changes the direction to face south and trigger that respective animation on the condition that the previous recorded direction is not south.
    • changeAnimation

      public void changeAnimation()
      Checks the direction of the entity and changes to appropriate animation and direction
    • create

      public void create()
      Description copied from class: Component
      Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished.
      Overrides:
      create in class Component
    • update

      public void update()
      Description copied from class: Component
      Called once per frame of the game, and should be used for most component logic. Not called if component is disabled.
      Overrides:
      update in class Component
    • setMoving

      public void setMoving(boolean movementEnabled)
      Enable/disable movement for the controller. Disabling will immediately set velocity to 0.
      Specified by:
      setMoving in interface MovementController
      Parameters:
      movementEnabled - true to enable movement, false otherwise
    • changeSpeed

      public void changeSpeed(float factor)
    • getMoving

      public boolean getMoving()
      Specified by:
      getMoving in interface MovementController
      Returns:
      True when movement enabled, false when disabled
    • getTarget

      public com.badlogic.gdx.math.Vector2 getTarget()
      Specified by:
      getTarget in interface MovementController
      Returns:
      Target position in the world
    • setTarget

      public void setTarget(com.badlogic.gdx.math.Vector2 target)
      Set a target to move towards. The entity will be steered towards it in a straight line, not using pathfinding or avoiding other entities.
      Specified by:
      setTarget in interface MovementController
      Parameters:
      target - target position