public abstract class MobileObject extends SpaceObject
A MobileObject is a SpaceObject that can simulate continuous movement through its SpaceState's space. If a MobileObject has had Cell2D's standard collision mechanics enabled for it, this movement will be blocked by any solid surfaces of SpaceObjects in the MobileObject's path.
A MobileObject may have a collision Hitbox that represents it for purposes of colliding with solid surfaces. The collision Hitbox's rectangular bounding box, rather than its exact shape, is what represents the MobileObject in Cell2D's standard collision mechanics, and thus standard collision only handles interactions between rectangular shapes. A MobileObject with no collision Hitbox cannot collide with solid surfaces, even if collision is enabled for it.
A MobileObject may have a pressing angle that causes it to press against and collide with solid surfaces in the angle's direction during movement, as long as it is touching them and not moving away from them. The pressing angle is specified as relative (to the MobileObject's flipped status and angle of rotation) or absolute.
A MobileObject may have one or more MobileObject followers, and if it does, it is called its followers' leader. When a MobileObject moves, all of its followers automatically move to maintain their relative positions to it. A MobileObject cannot collide with its leader, super-leaders, followers, or sub-followers.
A MobileObject has a velocity, as well as a vector called a step that acts as a short-term adjustment to its velocity, both in fracunits per time unit, and both of which are initially (0, 0). Every frame, between the periods in which its SpaceState's SpaceThinkers perform their beforeMovementActions() and their frameActions(), a MobileObject assigned to an active SpaceState moves by the sum of its velocity and step multiplied by its time factor, then resets its step to (0, 0). A MobileObject's movement priority (0 by default) determines when it will move relative to other MobileObjects. MobileObjects with higher movement priorities move before those with lower ones. Also, if two solid MobileObjects would otherwise collide with each other, the one with the higher movement priority will push the other one along with it.
Every time a MobileObject moves, it records the SpaceObjects whose solid surfaces it collided with and the Directions of the surfaces relative to it when it collided with them, as well as its total displacement over the course of the movement, not counting pushes from moving solid surfaces or manual manipulation of its position. These records are reset when the MobileObject moves again, or when it is removed from the SpaceState whose space the records reflect.
Constructor and Description |
---|
MobileObject()
Constructs a MobileObject with no locator Hitbox.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addFollower(MobileObject follower)
Adds the specified MobileObject as this MobileObject's follower if it
does not have a leader already, and if doing so would not create a loop
of followers in which MobileObjects directly or indirectly follow
themselves.
|
void |
changePosition(CellVector change,
boolean bringFollowers)
Changes this MobileObject's position by the specified amount.
|
void |
changePosition(long changeX,
long changeY,
boolean bringFollowers)
Changes the coordinates of this MobileObject's position by the specified
amounts.
|
void |
changeStep(CellVector change)
Changes this MobileObject's step by the specified amount.
|
void |
changeStep(long changeX,
long changeY)
Changes this MobileObject's step by the specified amount.
|
void |
changeStepX(long changeX)
Changes the x-component of this MobileObject's step by the specified
amount.
|
void |
changeStepY(long changeY)
Changes the y-component of this MobileObject's step by the specified
amount.
|
void |
changeX(long changeX,
boolean bringFollowers)
Changes the x-coordinate of this MobileObject's position by the specified
amount.
|
void |
changeY(long changeY,
boolean bringFollowers)
Changes the y-coordinate of this MobileObject's position by the specified
amount.
|
void |
clearFollowers()
Removes all of this MobileObject's followers from it.
|
CollisionResponse |
collide(SpaceObject object,
Direction direction)
This MobileObject's response to colliding with a solid surface of the
specified SpaceObject in the specified Direction.
|
boolean |
collided()
Returns whether this MobileObject collided with any solid surfaces during
its last movement.
|
boolean |
collided(Direction direction)
Returns whether this MobileObject collided with any solid surfaces in the
specified Direction during its last movement.
|
void |
doMovement(CellVector change)
Moves this MobileObject and its followers and sub-followers by the
specified amount, colliding with solid surfaces if they have collision
enabled.
|
void |
doMovement(long changeX,
long changeY)
Moves this MobileObject and its followers and sub-followers by the
specified amount, colliding with solid surfaces if they have collision
enabled.
|
java.lang.Double |
getAbsPressingAngle()
Returns this MobileObject's absolute pressing angle, or null if it has
none.
|
java.util.Set<Direction> |
getCollisionDirections()
Returns an unmodifiable Set view of the Directions in which this
MobileObject collided with solid surfaces during its last movement.
|
Hitbox |
getCollisionHitbox()
Returns this MobileObject's collision Hitbox, or null if it has none.
|
java.util.Map<SpaceObject,java.util.Set<Direction>> |
getCollisions()
Returns a Map of the SpaceObjects whose solid surfaces this MobileObject
collided with during its last movement to the Sets of the Directions in
which it collided with them.
|
CellVector |
getDisplacement()
Returns this MobileObject's displacement during its last movement.
|
long |
getDisplacementLength()
Returns the length of this MobileObject's displacement during its last
movement.
|
long |
getDisplacementX()
Returns the x-component of this MobileObject's displacement during its
last movement.
|
long |
getDisplacementY()
Returns the y-component of this MobileObject's displacement during its
last movement.
|
java.util.Set<MobileObject> |
getFollowers()
Returns an unmodifiable Set view of this MobileObject's followers.
|
MobileObject |
getLeader()
Returns this MobileObject's leader, or null if it has none.
|
int |
getMovementPriority()
Returns this MobileObject's movement priority.
|
int |
getNewMovementPriority()
Returns the movement priority that this MobileObject is about to have,
but does not yet have due to its SpaceState's MobileObject list being
iterated over.
|
int |
getNumFollowers()
Returns the number of followers that this MobileObject currently has.
|
java.lang.Double |
getRelPressingAngle()
Returns this MobileObject's relative pressing angle, or null if it has
none.
|
long |
getSpeed()
Returns this MobileObject's speed, the magnitude of its velocity.
|
CellVector |
getStep()
Returns this MobileObject's step.
|
long |
getStepLength()
Returns the length of this MobileObject's step.
|
long |
getStepX()
Returns the x-component of this MobileObject's step.
|
long |
getStepY()
Returns the y-component of this MobileObject's step.
|
CellVector |
getVelocity()
Returns this MobileObject's velocity.
|
long |
getVelocityX()
Returns the x-component of this MobileObject's velocity.
|
long |
getVelocityY()
Returns the y-component of this MobileObject's velocity.
|
boolean |
hasCollision()
Returns whether this MobileObject has Cell2D's standard collision
mechanics enabled.
|
boolean |
isPressingIn(Direction direction)
Returns whether this MobileObject's absolute pressing angle, if it has
one, has a component in the specified Direction.
|
void |
moveToward(CellVector point,
long speed)
Sets this MobileObject's velocity to send it moving toward the specified
point at the specified speed.
|
void |
moveToward(long x,
long y,
long speed)
Sets this MobileObject's velocity to send it moving toward the specified
point at the specified speed.
|
boolean |
removeFollower(MobileObject follower)
Removes the specified MobileObject as this MobileObject's follower if
this MobileObject is its leader.
|
void |
setCollision(boolean hasCollision)
Sets whether this MobileObject has Cell2D's standard collision mechanics
enabled.
|
boolean |
setCollisionHitbox(Hitbox collisionHitbox)
Sets this MobileObject's collision Hitbox to the specified Hitbox.
|
void |
setGameState(SpaceState state,
boolean bringFollowers)
Sets the SpaceState to which this MobileObject is currently assigned.
|
void |
setLeader(MobileObject leader)
Sets this MobileObject's leader to the specified one.
|
void |
setMovementPriority(int movementPriority)
Sets this MobileObject's movement priority to the specified value.
|
void |
setPosition(CellVector position,
boolean bringFollowers)
Sets this MobileObject's position to the specified value.
|
void |
setPosition(long x,
long y,
boolean bringFollowers)
Sets this MobileObject's position to the specified value.
|
void |
setRelPressingAngle(double angle)
Sets this MobileObject's relative pressing angle to the specified value.
|
void |
setRelPressingAngle(java.lang.Double angle)
Sets this MobileObject's relative pressing angle to the specified value,
or to none if the specified value is null.
|
void |
setSpeed(long speed)
Sets this MobileObject's speed, the magnitude of its velocity, to the
specified value.
|
void |
setStep(CellVector step)
Sets this MobileObject's step to the specified value.
|
void |
setStep(long stepX,
long stepY)
Sets this MobileObject's step to the specified value.
|
void |
setStepLength(long length)
Sets the length of this MobileObject's step to the specified value.
|
void |
setStepX(long stepX)
Sets the x-component of this MobileObject's step to the specified value.
|
void |
setStepY(long stepY)
Sets the y-component of this MobileObject's step to the specified value.
|
void |
setVelocity(CellVector velocity)
Sets this MobileObject's velocity to the specified value.
|
void |
setVelocity(long velocityX,
long velocityY)
Sets this MobileObject's velocity to the specified value.
|
void |
setVelocityX(long velocityX)
Sets the x-component of this MobileObject's velocity to the specified
value.
|
void |
setVelocityY(long velocityY)
Sets the y-component of this MobileObject's velocity to the specified
value.
|
void |
setX(long x,
boolean bringFollowers)
Sets the x-coordinate of this MobileObject's position to the specified
value.
|
void |
setY(long y,
boolean bringFollowers)
Sets the y-coordinate of this MobileObject's position to the specified
value.
|
<O extends SpaceObject> |
solidBoundingBoxesMeet(java.lang.Class<O> cls)
Returns all of the solid SpaceObjects of the specified class in this
MobileObject's SpaceState whose solid Hitboxes' rectangular bounding
boxes touch or intersect this MobileObject's collision Hitbox's
rectangular bounding box.
|
addAnimInstance, addAnimInstance, angleTo, boundingBoxesMeet, changeAngle, changePosition, changePosition, changeX, changeY, clearAnimInstances, distanceTo, draw, flipX, flipY, getAlpha, getAngle, getAngleX, getAngleY, getAnimation, getAnimation, getAnimInstance, getAnimInstance, getAppearance, getBottomEdge, getCenter, getCenterOffset, getCenterOffsetX, getCenterOffsetY, getCenterX, getCenterY, getDrawPriority, getEffectiveTimeFactor, getFilter, getGame, getGameState, getHeight, getLeftEdge, getLocatorHitbox, getNewGameState, getNumAnimInstances, getOverlapHitbox, getPosition, getRightEdge, getSolidHitbox, getTimeFactor, getTopEdge, getWidth, getX, getXFlip, getXSign, getY, getYFlip, getYSign, intersectingSolidObject, intersectingSolidObjects, isIntersectingSolidObject, isOverlappingObject, isSolid, isVisible, isVisible, nearestObject, nearestObjectWithinCircle, nearestObjectWithinCircle, nearestObjectWithinRadius, nearestObjectWithinRectangle, nearestOverlappingObject, objectIsWithinRadius, objectsWithinRadius, objectWithinRadius, overlap, overlappingObject, overlappingObjects, overlaps, removeAnimInstance, setAlpha, setAngle, setAnimation, setAnimation, setAnimInstance, setAnimInstance, setAppearance, setCenterOffset, setCenterOffset, setCenterOffsetX, setCenterOffsetY, setDrawPriority, setFilter, setGameState, setLocatorHitbox, setOverlapHitbox, setPosition, setPosition, setSolid, setSolidHitbox, setSurfaceSolid, setTimeFactor, setX, setXFlip, setY, setYFlip, surfaceIsSolid
public MobileObject()
public final int getMovementPriority()
public final int getNewMovementPriority()
public final void setMovementPriority(int movementPriority)
movementPriority
- The new movement prioritypublic final boolean hasCollision()
public final void setCollision(boolean hasCollision)
hasCollision
- Whether this MobileObject should have collision
enabledpublic final Hitbox getCollisionHitbox()
public final boolean setCollisionHitbox(Hitbox collisionHitbox)
collisionHitbox
- The new collision Hitboxpublic final <O extends SpaceObject> java.util.List<O> solidBoundingBoxesMeet(java.lang.Class<O> cls)
O
- The subclass of SpaceObject to search forcls
- The Class object that represents the SpaceObject subclasspublic final java.lang.Double getRelPressingAngle()
public final void setRelPressingAngle(java.lang.Double angle)
angle
- The new relative pressing anglepublic final void setRelPressingAngle(double angle)
angle
- The new relative pressing anglepublic final java.lang.Double getAbsPressingAngle()
public final boolean isPressingIn(Direction direction)
direction
- The Direction to checkpublic final MobileObject getLeader()
public final void setLeader(MobileObject leader)
leader
- This MobileObject's new leaderpublic final java.util.Set<MobileObject> getFollowers()
public final int getNumFollowers()
public final boolean addFollower(MobileObject follower)
follower
- The new followerpublic final boolean removeFollower(MobileObject follower)
follower
- The follower to be removedpublic final void clearFollowers()
public final void setGameState(SpaceState state, boolean bringFollowers)
state
- The SpaceState to which this MobileObject should be assignedbringFollowers
- If true, all of this MobileObject's followers and
sub-followers will be assigned to the same SpaceState (false by default)public final void setPosition(CellVector position, boolean bringFollowers)
position
- The new positionbringFollowers
- If true, all of this MobileObject's followers and
sub-followers will change their positions by the same amount as this
MobileObject (false by default)public final void setPosition(long x, long y, boolean bringFollowers)
x
- The x-coordinate of the new positiony
- The y-coordinate of the new positionbringFollowers
- If true, all of this MobileObject's followers and
sub-followers will change their positions by the same amount as this
MobileObject (false by default)public final void setX(long x, boolean bringFollowers)
x
- The x-coordinate of the new positionbringFollowers
- If true, all of this MobileObject's followers and
sub-followers will change their positions by the same amount as this
MobileObject (false by default)public final void setY(long y, boolean bringFollowers)
y
- The y-coordinate of the new positionbringFollowers
- If true, all of this MobileObject's followers and
sub-followers will change their positions by the same amount as this
MobileObject (false by default)public final void changePosition(CellVector change, boolean bringFollowers)
change
- The amount to change the position bybringFollowers
- If true, all of this MobileObject's followers and
sub-followers will change their positions by the same amount as this
MobileObject (false by default)public final void changePosition(long changeX, long changeY, boolean bringFollowers)
changeX
- The amount to change the position's x-coordinate bychangeY
- The amount to change the position's y-coordinate bybringFollowers
- If true, all of this MobileObject's followers and
sub-followers will change their positions by the same amount as this
MobileObject (false by default)public final void changeX(long changeX, boolean bringFollowers)
changeX
- The amount to change the position's x-coordinate bybringFollowers
- If true, all of this MobileObject's followers and
sub-followers will change their positions by the same amount as this
MobileObject (false by default)public final void changeY(long changeY, boolean bringFollowers)
changeY
- The amount to change the position's y-coordinate bybringFollowers
- If true, all of this MobileObject's followers and
sub-followers will change their positions by the same amount as this
MobileObject (false by default)public final void doMovement(CellVector change)
change
- The amount by which this MobileObject should movepublic final void doMovement(long changeX, long changeY)
changeX
- The amount by which this MobileObject should move along
the x-axischangeY
- The amount by which this MobileObject should move along
the y-axispublic CollisionResponse collide(SpaceObject object, Direction direction)
object
- The SpaceObject whose surface this MobileObject collided
withdirection
- The Direction in which this MobileObject collided with
the surfacepublic final java.util.Map<SpaceObject,java.util.Set<Direction>> getCollisions()
public final java.util.Set<Direction> getCollisionDirections()
public final boolean collided()
public final boolean collided(Direction direction)
direction
- The Direction to checkpublic final CellVector getVelocity()
public final long getVelocityX()
public final long getVelocityY()
public final long getSpeed()
public final void setVelocity(CellVector velocity)
velocity
- The new velocitypublic final void setVelocity(long velocityX, long velocityY)
velocityX
- The new x-component of the velocityvelocityY
- The new y-component of the velocitypublic final void setVelocityX(long velocityX)
velocityX
- The new x-component of the velocitypublic final void setVelocityY(long velocityY)
velocityY
- The new y-component of the velocitypublic final void setSpeed(long speed)
speed
- The new speedpublic final void moveToward(CellVector point, long speed)
point
- The point that this MobileObject should move towardspeed
- The speed that this MobileObject should move atpublic final void moveToward(long x, long y, long speed)
x
- The x-coordinate of the point that this MobileObject should
move towardy
- The y-coordinate of the point that this MobileObject should
move towardspeed
- The speed that this MobileObject should move atpublic final CellVector getStep()
public final long getStepX()
public final long getStepY()
public final long getStepLength()
public final void setStep(CellVector step)
step
- The new steppublic final void setStep(long stepX, long stepY)
stepX
- The x-component of the new stepstepY
- The y-component of the new steppublic final void setStepX(long stepX)
stepX
- The new x-component of the steppublic final void setStepY(long stepY)
stepY
- The new y-component of the steppublic final void setStepLength(long length)
length
- The new step lengthpublic final void changeStep(CellVector change)
change
- The amount to change the step bypublic final void changeStep(long changeX, long changeY)
changeX
- The amount to change the step's x-component bychangeY
- The amount to change the step's y-component bypublic final void changeStepX(long changeX)
changeX
- The amount to change the step's x-component bypublic final void changeStepY(long changeY)
changeY
- The amount to change the step's y-component bypublic final CellVector getDisplacement()
public final long getDisplacementX()
public final long getDisplacementY()
public final long getDisplacementLength()