T
- The type of CellGame that uses the SpaceStates that this
ThinkerObject can be assigned topublic abstract class ThinkerObject<T extends CellGame> extends SpaceObject<T>
A ThinkerObject is a SpaceObject that acts like a SpaceThinker, possessing SpaceThinkerStates, timers, and various actions in response to events. A ThinkerObject can also simulate continuous movement through its SpaceState's space. If a ThinkerObject has had Cell2D's standard collision mechanics enabled for it, this movement will be blocked by any solid surfaces of SpaceObjects in the ThinkerObject's path.
A ThinkerObject 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 ThinkerObject in Cell2D's standard collision mechanics, and thus standard collision only handles interactions between rectangular shapes. A ThinkerObject with no collision Hitbox cannot collide with solid surfaces, even if collision is enabled for it.
A ThinkerObject 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 ThinkerObject's flipped status and angle of rotation) or absolute.
A ThinkerObject may have one or more ThinkerObject followers, and if it does, it is called those followers' leader. When a ThinkerObject moves, all of its followers automatically move to maintain their relative positions to it. A ThinkerObject cannot collide with its leader, super-leaders, followers, or sub-followers.
A ThinkerObject has a velocity, as well as a vector called a step that acts as a short-term adjustment to its velocity, both in pixels per time unit. Every frame, between its frameActions() and afterMovementActions(), a ThinkerObject 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 ThinkerObject's movement priority determines when it will move relative to other ThinkerObjects. ThinkerObjects with higher movement priorities move before those with lower ones. Also, if two solid ThinkerObjects would otherwise collide with each other, the one with the higher movement priority will push the other one along with it.
Every time a ThinkerObject 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 ThinkerObject moves again, or when it is removed from the SpaceState whose space the records reflect.
Constructor and Description |
---|
ThinkerObject(Hitbox<T> locatorHitbox)
Creates a new ThinkerObject with the specified locator Hitbox.
|
ThinkerObject(Hitbox<T> locatorHitbox,
SpaceObject<T> creator)
Creates a new ThinkerObject with the specified locator Hitbox that acts
as if it was created by the specified SpaceObject, initially copying its
creator's time factor, flipped status, and angle of rotation.
|
Modifier and Type | Method and Description |
---|---|
void |
addedActions(T game,
SpaceState<T> state)
Actions for this ThinkerObject to take immediately after being added to a
new SpaceState.
|
boolean |
addFollower(ThinkerObject follower)
Adds the specified ThinkerObject as this ThinkerObject's follower if it
does not have a leader already.
|
void |
afterMovementActions(T game,
SpaceState<T> state)
Actions for this ThinkerObject to take once every frame, after its
SpaceState moves its assigned ThinkerObjects.
|
void |
changePosition(CellVector change,
boolean bringFollowers)
Changes this ThinkerObject's position by the specified amount.
|
void |
changePosition(long changeX,
long changeY,
boolean bringFollowers)
Changes the coordinates of this ThinkerObject's position by the specified
amounts.
|
void |
changeStep(CellVector change)
Changes this ThinkerObject's step by the specified amount.
|
void |
changeStep(long changeX,
long changeY)
Changes this ThinkerObject's step by the specified amount.
|
void |
changeStepX(long changeX)
Changes the x-component of this ThinkerObject's step by the specified
amount.
|
void |
changeStepY(long changeY)
Changes the y-component of this ThinkerObject's step by the specified
amount.
|
void |
changeX(long changeX,
boolean bringFollowers)
Changes the x-coordinate of this ThinkerObject's position by the
specified amount.
|
void |
changeY(long changeY,
boolean bringFollowers)
Changes the y-coordinate of this ThinkerObject's position by the
specified amount.
|
void |
clearFollowers()
Removes all of this ThinkerObject's followers from it.
|
CollisionResponse |
collide(SpaceObject<T> object,
Direction direction)
This ThinkerObject's response to colliding with a solid surface of the
specified SpaceObject in the specified Direction.
|
boolean |
collided()
Returns whether this ThinkerObject collided with any solid surfaces
during its last movement.
|
boolean |
collided(Direction direction)
Returns whether this ThinkerObject collided with any solid surfaces in
the specified Direction during its last movement.
|
void |
doMovement(CellVector change)
Moves this ThinkerObject 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 ThinkerObject and its followers and sub-followers by the
specified amount, colliding with solid surfaces if they have collision
enabled.
|
void |
frameActions(T game,
SpaceState<T> state)
Actions for this ThinkerObject to take once every frame, after
SpaceThinkers take their timeUnitActions() but before its SpaceState
takes its own frameActions().
|
java.lang.Double |
getAbsPressingAngle()
Returns this ThinkerObject's absolute pressing angle, or null if it has
none.
|
int |
getActionPriority()
Returns this ThinkerObject's action priority.
|
java.util.Set<Direction> |
getCollisionDirections()
Returns the Set of the Directions in which this ThinkerObject collided
with solid surfaces during its last movement.
|
Hitbox<T> |
getCollisionHitbox()
Returns this ThinkerObject's collision Hitbox, or null if it has none.
|
java.util.Map<SpaceObject<T>,java.util.Set<Direction>> |
getCollisions()
Returns a Map of the SpaceObjects whose solid surfaces this ThinkerObject
collided with during its last movement to the Sets of the Directions in
which it collided with them.
|
CellVector |
getDisplacement()
Returns this ThinkerObject's displacement during its last movement.
|
long |
getDisplacementLength()
Returns the length of this ThinkerObject's displacement during its last
movement.
|
long |
getDisplacementX()
Returns the x-component of this ThinkerObject's displacement during its
last movement.
|
long |
getDisplacementY()
Returns the y-component of this ThinkerObject's displacement during its
last movement.
|
java.util.Set<ThinkerObject> |
getFollowers()
Returns the Set of this ThinkerObject's followers.
|
ThinkerObject |
getLeader()
Returns this ThinkerObject's leader, or null if it has none.
|
int |
getMovementPriority()
Returns this ThinkerObject's movement priority.
|
int |
getNewActionPriority()
Returns the action priority that this ThinkerObject is about to have, but
does not yet have due to its SpaceState's SpaceThinker list being
iterated over.
|
int |
getNewMovementPriority()
Returns the movement priority that this ThinkerObject is about to have,
but does not yet have due to its SpaceState's ThinkerObject list being
iterated over.
|
int |
getNumFollowers()
Returns the number of followers that this ThinkerObject currently has.
|
java.lang.Double |
getRelPressingAngle()
Returns this ThinkerObject's relative pressing angle, or null if it has
none.
|
long |
getSpeed()
Returns this ThinkerObject's speed, the magnitude of its velocity.
|
CellVector |
getStep()
Returns this ThinkerObject's step.
|
long |
getStepLength()
Returns the length of this ThinkerObject's step.
|
long |
getStepX()
Returns the x-component of this ThinkerObject's step.
|
long |
getStepY()
Returns the y-component of this ThinkerObject's step.
|
SpaceThinkerState |
getThinkerState()
Returns this ThinkerObject's current SpaceThinkerState.
|
int |
getThinkerStateDuration()
Returns the remaining duration in time units of this ThinkerObject's
current SpaceThinkerState.
|
int |
getTimerValue(TimedEvent<SpaceState<T>> timedEvent)
Returns the current value of this ThinkerObject's timer for the specified
TimedEvent.
|
CellVector |
getVelocity()
Returns this ThinkerObject's velocity.
|
long |
getVelocityX()
Returns the x-component of this ThinkerObject's velocity.
|
long |
getVelocityY()
Returns the y-component of this ThinkerObject's velocity.
|
boolean |
hasCollision()
Returns whether this ThinkerObject has Cell2D's standard collision
mechanics enabled.
|
boolean |
isPressingIn(Direction direction)
Returns whether this ThinkerObject's absolute pressing angle, if it has
one, has a component in the specified Direction.
|
void |
moveToward(CellVector point,
long speed)
Sets this ThinkerObject's velocity to send it moving toward the specified
point at the specified speed.
|
void |
moveToward(long x,
long y,
long speed)
Sets this ThinkerObject's velocity to send it moving toward the specified
point at the specified speed.
|
void |
removedActions(T game,
SpaceState<T> state)
Actions for this ThinkerObject to take immediately before being removed
from its SpaceState.
|
boolean |
removeFollower(ThinkerObject follower)
Removes the specified ThinkerObject as this ThinkerObject's follower if
this ThinkerObject is its leader.
|
void |
setActionPriority(int actionPriority)
Sets this ThinkerObject's action priority to the specified value.
|
void |
setCollision(boolean hasCollision)
Sets whether this ThinkerObject has Cell2D's standard collision mechanics
enabled.
|
boolean |
setCollisionHitbox(Hitbox<T> collisionHitbox)
Sets this ThinkerObject's collision Hitbox to the specified Hitbox.
|
void |
setGameState(SpaceState<T> state,
boolean bringFollowers)
Sets the SpaceState to which this ThinkerObject is currently assigned.
|
void |
setLeader(ThinkerObject leader)
Sets this ThinkerObject's leader to the specified ThinkerObject.
|
void |
setMovementPriority(int movementPriority)
Sets this ThinkerObject's movement priority to the specified value.
|
void |
setPosition(CellVector position,
boolean bringFollowers)
Sets this ThinkerObject's position to the specified value.
|
void |
setPosition(long x,
long y,
boolean bringFollowers)
Sets this ThinkerObject's position to the specified value.
|
void |
setRelPressingAngle(double angle)
Sets this ThinkerObject's relative pressing angle to the specified value.
|
void |
setRelPressingAngle(java.lang.Double angle)
Sets this ThinkerObject's relative pressing angle to the specified value,
or to none if the specified value is null.
|
void |
setSpeed(long speed)
Sets this ThinkerObject's speed, the magnitude of its velocity, to the
specified value.
|
void |
setStep(CellVector step)
Sets this ThinkerObject's step to the specified value.
|
void |
setStep(long stepX,
long stepY)
Sets this ThinkerObject's step to the specified value.
|
void |
setStepLength(long length)
Sets the length of this ThinkerObject's step to the specified value.
|
void |
setStepX(long stepX)
Sets the x-component of this ThinkerObject's step to the specified value.
|
void |
setStepY(long stepY)
Sets the y-component of this ThinkerObject's step to the specified value.
|
void |
setThinkerState(SpaceThinkerState thinkerState)
Sets this ThinkerObject's current SpaceThinkerState to the specified one.
|
void |
setThinkerStateDuration(int duration)
Sets the remaining duration in time units of this ThinkerObject's current
SpaceThinkerState to the specified value.
|
void |
setTimerValue(TimedEvent<SpaceState<T>> timedEvent,
int value)
Sets the value of this ThinkerObject's timer for the specified TimedEvent
to the specified value.
|
void |
setVelocity(CellVector velocity)
Sets this ThinkerObject's velocity to the specified value.
|
void |
setVelocity(long velocityX,
long velocityY)
Sets this ThinkerObject's velocity to the specified value.
|
void |
setVelocityX(long velocityX)
Sets the x-component of this ThinkerObject's velocity to the specified
value.
|
void |
setVelocityY(long velocityY)
Sets the y-component of this ThinkerObject's velocity to the specified
value.
|
void |
setX(long x,
boolean bringFollowers)
Sets the x-coordinate of this ThinkerObject's position to the specified
value.
|
void |
setY(long y,
boolean bringFollowers)
Sets the y-coordinate of this ThinkerObject's position to the specified
value.
|
<O extends SpaceObject<T>> |
solidBoundingBoxesMeet(java.lang.Class<O> cls)
Returns all of the solid SpaceObjects of the specified class in this
ThinkerObject's SpaceState whose solid Hitboxes' rectangular bounding
boxes touch or intersect this ThinkerObject's collision Hitbox's
rectangular bounding box.
|
void |
timeUnitActions(T game,
SpaceState<T> state)
Actions for this ThinkerObject to take once every time unit, after
AnimationInstances update their indices but before SpaceThinkers take
their frameActions().
|
angleTo, boundingBoxesMeet, changeAngle, changePosition, changePosition, changeX, changeY, clearAnimInstances, distanceTo, draw, flipX, flipY, getAlpha, getAngle, getAngleX, getAngleY, getAnimation, getAnimation, getAnimInstance, getAppearance, getBottomEdge, getCenter, getCenterOffset, getCenterOffsetX, getCenterOffsetY, getCenterX, getCenterY, getDrawPriority, getEffectiveTimeFactor, getFilter, getGameState, getLeftEdge, getLocatorHitbox, getNewGameState, getOverlapHitbox, getPosition, getRightEdge, getSolidHitbox, getTimeFactor, getTopEdge, 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, 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 ThinkerObject(Hitbox<T> locatorHitbox)
locatorHitbox
- This ThinkerObject's locator Hitboxpublic ThinkerObject(Hitbox<T> locatorHitbox, SpaceObject<T> creator)
locatorHitbox
- This ThinkerObject's locator Hitboxcreator
- This ThinkerObject's creatorpublic final int getActionPriority()
public final int getNewActionPriority()
public final void setActionPriority(int actionPriority)
actionPriority
- The new action prioritypublic final SpaceThinkerState getThinkerState()
public final void setThinkerState(SpaceThinkerState thinkerState)
thinkerState
- The new SpaceThinkerStatepublic final int getThinkerStateDuration()
public final void setThinkerStateDuration(int duration)
duration
- The new duration in time units of this ThinkerObject's
current SpaceThinkerStatepublic final int getTimerValue(TimedEvent<SpaceState<T>> timedEvent)
timedEvent
- The TimedEvent whose timer value should be returnedpublic final void setTimerValue(TimedEvent<SpaceState<T>> timedEvent, int value)
timedEvent
- The TimedEvent whose timer value should be setvalue
- The new value of the specified TimedEvent's timerpublic void timeUnitActions(T game, SpaceState<T> state)
game
- This ThinkerObject's CellGamestate
- This ThinkerObject's SpaceStatepublic void frameActions(T game, SpaceState<T> state)
game
- This ThinkerObject's CellGamestate
- This ThinkerObject's SpaceStatepublic void afterMovementActions(T game, SpaceState<T> state)
game
- This ThinkerObject's CellGamestate
- This ThinkerObject's SpaceStatepublic void addedActions(T game, SpaceState<T> state)
game
- This ThinkerObject's CellGamestate
- This ThinkerObject's SpaceStatepublic void removedActions(T game, SpaceState<T> state)
game
- This ThinkerObject's CellGamestate
- This ThinkerObject's SpaceStatepublic 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 ThinkerObject should have collision
enabledpublic final Hitbox<T> getCollisionHitbox()
public final boolean setCollisionHitbox(Hitbox<T> collisionHitbox)
collisionHitbox
- The new collision Hitboxpublic final <O extends SpaceObject<T>> 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 ThinkerObject getLeader()
public final void setLeader(ThinkerObject leader)
leader
- The new leaderpublic final java.util.Set<ThinkerObject> getFollowers()
public final int getNumFollowers()
public final boolean addFollower(ThinkerObject follower)
follower
- The new followerpublic final boolean removeFollower(ThinkerObject follower)
follower
- The follower to be removedpublic final void clearFollowers()
public final void setGameState(SpaceState<T> state, boolean bringFollowers)
state
- The SpaceState to which this ThinkerObject should be
assignedbringFollowers
- If true, all of this ThinkerObject'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 ThinkerObject's followers and
sub-followers will change their positions by the same amount as this
ThinkerObject (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 ThinkerObject's followers and
sub-followers will change their positions by the same amount as this
ThinkerObject (false by default)public final void setX(long x, boolean bringFollowers)
x
- The x-coordinate of the new positionbringFollowers
- If true, all of this ThinkerObject's followers and
sub-followers will change their positions by the same amount as this
ThinkerObject (false by default)public final void setY(long y, boolean bringFollowers)
y
- The y-coordinate of the new positionbringFollowers
- If true, all of this ThinkerObject's followers and
sub-followers will change their positions by the same amount as this
ThinkerObject (false by default)public final void changePosition(CellVector change, boolean bringFollowers)
change
- The amount to change the position bybringFollowers
- If true, all of this ThinkerObject's followers and
sub-followers will change their positions by the same amount as this
ThinkerObject (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 ThinkerObject's followers and
sub-followers will change their positions by the same amount as this
ThinkerObject (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 ThinkerObject's followers and
sub-followers will change their positions by the same amount as this
ThinkerObject (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 ThinkerObject's followers and
sub-followers will change their positions by the same amount as this
ThinkerObject (false by default)public final void doMovement(CellVector change)
change
- The amount by which this ThinkerObject should movepublic final void doMovement(long changeX, long changeY)
changeX
- The amount by which this ThinkerObject should move along
the x-axischangeY
- The amount by which this ThinkerObject should move along
the y-axispublic CollisionResponse collide(SpaceObject<T> object, Direction direction)
object
- The SpaceObject whose surface this ThinkerObject collided
withdirection
- The Direction in which this ThinkerObject collided with
the surfacepublic final java.util.Map<SpaceObject<T>,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 ThinkerObject should move towardspeed
- The speed that this ThinkerObject should move atpublic final void moveToward(long x, long y, long speed)
x
- The x-coordinate of the point that this ThinkerObject should
move towardy
- The y-coordinate of the point that this ThinkerObject should
move towardspeed
- The speed that this ThinkerObject 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()