Class PhysicsMovementComponent
java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.physics.components.PhysicsMovementComponent
- All Implemented Interfaces:
MovementController
- Direct Known Subclasses:
ProjectileMovementComponent
Movement controller for a physics-based entity.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Called when the entity is created and registered.protected com.badlogic.gdx.math.Vector2
boolean
com.badlogic.gdx.math.Vector2
getSpeed()
com.badlogic.gdx.math.Vector2
void
Reset Entity to Original Speedvoid
setMoving
(boolean movementEnabled) Enable/disable movement for the controller.void
setNewSpeed
(com.badlogic.gdx.math.Vector2 speed) set new speed which can differ to default speedvoid
setOriginalSpeed
(com.badlogic.gdx.math.Vector2 speed) Sets the fault speed of the entityvoid
setTarget
(com.badlogic.gdx.math.Vector2 target) Set a target to move towards.protected void
setToVelocity
(com.badlogic.gdx.physics.box2d.Body body, com.badlogic.gdx.math.Vector2 desiredVelocity) void
update()
Called once per frame of the game, and should be used for most component logic.Methods inherited from class com.deco2800.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
-
Field Details
-
physicsComponent
-
-
Constructor Details
-
PhysicsMovementComponent
public PhysicsMovementComponent()
-
-
Method Details
-
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. -
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. -
setMoving
public void setMoving(boolean movementEnabled) Enable/disable movement for the controller. Disabling will immediately set velocity to 0.- Specified by:
setMoving
in interfaceMovementController
- Parameters:
movementEnabled
- true to enable movement, false otherwise
-
getMoving
public boolean getMoving()- Specified by:
getMoving
in interfaceMovementController
- Returns:
- True when movement enabled, false when disabled
-
getTarget
public com.badlogic.gdx.math.Vector2 getTarget()- Specified by:
getTarget
in interfaceMovementController
- 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 interfaceMovementController
- Parameters:
target
- target position
-
setToVelocity
protected void setToVelocity(com.badlogic.gdx.physics.box2d.Body body, com.badlogic.gdx.math.Vector2 desiredVelocity) -
getDirection
protected com.badlogic.gdx.math.Vector2 getDirection() -
getSpeed
public com.badlogic.gdx.math.Vector2 getSpeed()- Returns:
- the current speed of the entity
-
setOriginalSpeed
public void setOriginalSpeed(com.badlogic.gdx.math.Vector2 speed) Sets the fault speed of the entity- Parameters:
speed
- vector of speed in x,y
-
setNewSpeed
public void setNewSpeed(com.badlogic.gdx.math.Vector2 speed) set new speed which can differ to default speed- Parameters:
speed
- vector of speed in x,y
-
resetSpeed
public void resetSpeed()Reset Entity to Original Speed
-