Class MovementController<T extends IMobileEntity>
java.lang.Object
de.gurkenlabs.litiengine.physics.MovementController<T>
- All Implemented Interfaces:
IEntityController,IUpdateable,IMovementController
- Direct Known Subclasses:
GamepadEntityController,KeyboardEntityController,MousePathController
public class MovementController<T extends IMobileEntity>
extends Object
implements IMovementController
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidApply the force to the entity.voidattach()voiddetach()Gets the active forces.floatgetDx()Gets the delta x for each horizontal movement.floatgetDy()Sets the delta y for each vertical movement.Gets the force with the specified identifier.doubleGets the angle of movement.doubleGet the current velocity.voidHandles the movement of the entity.protected booleanChecks if the movement is allowed based on the movement predicates.protected voidmoveEntity(double deltaX, double deltaY) voidonMovementCheck(Predicate<IMobileEntity> predicate) Checks given conditions before moving.voidsetDx(float dx) Gets the delta x for each horizontal movement.voidsetDy(float dy) Sets the delta y for each vertical movement.voidsetVelocity(double velocity) Sets the current velocity.voidupdate()This method is called by the game loop on all objects that are attached to the loop.
-
Constructor Details
-
MovementController
-
-
Method Details
-
attach
public void attach()- Specified by:
attachin interfaceIEntityController
-
detach
public void detach()- Specified by:
detachin interfaceIEntityController
-
apply
Description copied from interface:IMovementControllerApply the force to the entity.- Specified by:
applyin interfaceIMovementController- Parameters:
force- the force being applied to the entity
-
getActiveForces
Description copied from interface:IMovementControllerGets the active forces.- Specified by:
getActiveForcesin interfaceIMovementController- Returns:
- the active forces
-
getEntity
- Specified by:
getEntityin interfaceIEntityController
-
getDx
public float getDx()Description copied from interface:IMovementControllerGets the delta x for each horizontal movement.- Specified by:
getDxin interfaceIMovementController- Returns:
- the dx
-
setDx
public void setDx(float dx) Description copied from interface:IMovementControllerGets the delta x for each horizontal movement.- Specified by:
setDxin interfaceIMovementController- Parameters:
dx- the new dx
-
getDy
public float getDy()Description copied from interface:IMovementControllerSets the delta y for each vertical movement.- Specified by:
getDyin interfaceIMovementController- Returns:
- the dy
-
setDy
public void setDy(float dy) Description copied from interface:IMovementControllerSets the delta y for each vertical movement.- Specified by:
setDyin interfaceIMovementController- Parameters:
dy- the new dy
-
onMovementCheck
Description copied from interface:IMovementControllerChecks given conditions before moving.- Specified by:
onMovementCheckin interfaceIMovementController- Parameters:
predicate- the conditions that need to apply before moving. If they don't apply, the entity won't be moved.
-
update
public void update()Description copied from interface:IUpdateableThis method is called by the game loop on all objects that are attached to the loop. It's called on every tick of the loop and the frequency can be configured using theClientConfiguration.- Specified by:
updatein interfaceIUpdateable- See Also:
-
handleMovement
public void handleMovement()Handles the movement of the entity. This method calculates the new velocity and direction of the entity based on the current forces and movement predicates. It also updates the entity's position accordingly. -
getForce
Description copied from interface:IMovementControllerGets the force with the specified identifier.- Specified by:
getForcein interfaceIMovementController- Parameters:
identifier- the identifier of the force to retrieve- Returns:
- the force with the specified identifier
-
getMoveAngle
public double getMoveAngle()Description copied from interface:IMovementControllerGets the angle of movement.- Specified by:
getMoveAnglein interfaceIMovementController- Returns:
- the angle of movement
-
setVelocity
public void setVelocity(double velocity) Description copied from interface:IMovementControllerSets the current velocity.- Specified by:
setVelocityin interfaceIMovementController- Parameters:
velocity- The velocity to set.
-
getVelocity
public double getVelocity()Description copied from interface:IMovementControllerGet the current velocity.- Specified by:
getVelocityin interfaceIMovementController- Returns:
- The current velocity.
-
moveEntity
protected void moveEntity(double deltaX, double deltaY) -
isMovementAllowed
protected boolean isMovementAllowed()Checks if the movement is allowed based on the movement predicates.- Returns:
- true if all movement predicates allow movement, false otherwise
-