public class MovementController<T extends IMobileEntity> extends java.lang.Object implements IMovementController
Constructor and Description |
---|
MovementController(T mobileEntity) |
Modifier and Type | Method and Description |
---|---|
void |
apply(Force force)
Apply the force to the entity.
|
void |
attach() |
void |
decelerateVelocityX(double dec) |
void |
decelerateVelocityY(double dec) |
void |
detach() |
java.util.List<Force> |
getActiveForces()
Gets the active forces.
|
float |
getDx()
Gets the delta x for each horizontal movement.
|
float |
getDy()
Sets the delta y for each vertical movement.
|
T |
getEntity() |
Force |
getForce(java.lang.String identifier) |
protected double |
getStopThreshold() |
double |
getVelocityX() |
double |
getVelocityY() |
void |
handleMovement() |
boolean |
isMovedX() |
boolean |
isMovedY() |
protected boolean |
isMovementAllowed() |
protected void |
moveEntity(double deltaX,
double deltaY) |
void |
onMoved(java.util.function.Consumer<java.awt.geom.Point2D> cons)
Calls given logic after the entity has been moved.
|
void |
onMovementCheck(java.util.function.Predicate<IMobileEntity> predicate)
Checks given conditions before moving.
|
void |
setDx(float dx)
Gets the delta x for each horizontal movement.
|
void |
setDy(float dy)
Sets the delta y for each vertical movement.
|
void |
setMovedX(boolean movedX) |
void |
setMovedY(boolean movedY) |
protected void |
setVelocityX(double velocityX) |
protected void |
setVelocityY(double velocityY) |
void |
update()
This method is called by the game loop on all objects that need to update
their attributes.
|
public MovementController(T mobileEntity)
public void attach()
attach
in interface IEntityController
public void detach()
detach
in interface IEntityController
public void apply(Force force)
IMovementController
apply
in interface IMovementController
force
- the force being applied to the entitypublic java.util.List<Force> getActiveForces()
IMovementController
getActiveForces
in interface IMovementController
public T getEntity()
getEntity
in interface IEntityController
public float getDx()
IMovementController
getDx
in interface IMovementController
public void setDx(float dx)
IMovementController
setDx
in interface IMovementController
dx
- the new dxpublic float getDy()
IMovementController
getDy
in interface IMovementController
public void setDy(float dy)
IMovementController
setDy
in interface IMovementController
dy
- the new dypublic void onMovementCheck(java.util.function.Predicate<IMobileEntity> predicate)
IMovementController
onMovementCheck
in interface IMovementController
predicate
- the conditions that need to apply before moving. If they don't apply, the entity won't be moved.public void update()
IUpdateable
update
in interface IUpdateable
public void onMoved(java.util.function.Consumer<java.awt.geom.Point2D> cons)
IMovementController
onMoved
in interface IMovementController
cons
- the logic that will be called after the entity has been moved.public void handleMovement()
public boolean isMovedX()
public void setMovedX(boolean movedX)
public boolean isMovedY()
public void setMovedY(boolean movedY)
public double getVelocityX()
public Force getForce(java.lang.String identifier)
getForce
in interface IMovementController
protected void setVelocityX(double velocityX)
protected void setVelocityY(double velocityY)
public void decelerateVelocityX(double dec)
public void decelerateVelocityY(double dec)
public double getVelocityY()
protected double getStopThreshold()
protected void moveEntity(double deltaX, double deltaY)
protected boolean isMovementAllowed()