TravelerSkeleton

TravelerSkeleton

A Class that uses MoverPoints to move based on a given velocity. All other 'Traveler' Classes extend this class or use this class. This 'skeleton' class does not implement any actual movement, it holds all the methods that manipulate points.


Constructor

new TravelerSkeleton(x, y, width, height)

Parameters:
Name Type Description
x Number

The initial x position of the TravelerSkeleton.

y Number

The initial y position of the TravelerSkeleton.

width Number

the width of the TravelerSkeleton

height Number

the height of the TravelerSkeleton

Members

_lastPos

Would hold the last known position of the TravlerSkeleton

_lastVeloc

Would hold the last known velocity of the TravelerSkeleton

_pos :MoverPoint

Holds the position of the TravelerSkeleton

Type:

_rect :Rectangle

Type:

_veloc :MoverPoint

Holds the velocity of the TravelerSkeleton

Type:

avoidDistance :Number

Default is 20.

Type:
  • Number

avoidee :MoverSkeleton

avoidSpace :Number

Default is 20.

Type:
  • Number

bird

bypassAvoidDistance :Boolean

Type:
  • Boolean

circleDistance :Number

Used with the .circle method. Default is 10

Type:
  • Number

dX :Number

For denoting horizontal direction

Type:
  • Number

dY :Number

For denoting vertical direction

Type:
  • Number

easeProximity :Number

Default is 2

Type:
  • Number

followDistance :Number

Type:
  • Number

forceHolder :MoverPoint

Type:

height

mass :Number

Default is 2

Type:
  • Number

maxForce :Number

Default is 12

Type:
  • Number

maxSpeed :Number

Default is 5

Type:
  • Number

path :Array

Type:
  • Array

personalSpace :Number

Default is 20.

Type:
  • Number

separationDistance :Number

Default is 10

Type:
  • Number

spreadDistance :Number

Used with the separate method. Default is 10

Type:
  • Number

visionDistance :Number

Default is 20

Type:
  • Number

wanderAngle :Number

Default is 10

Type:
  • Number

wanderOffset

wanderProximity :Number

Default is 10

Type:
  • Number

wanderRadius :Number

Default is 20

Type:
  • Number

wanderRange :Number

Default is 20

Type:
  • Number

width :Number

Type:
  • Number

x :Number

Holding the x position

Type:
  • Number

y :Number

Holding the y position

Type:
  • Number

Methods

addEventListener(type, listenerString, object)

Parameters:
Name Type Description
type
listenerString
object

align(withThese, priority)

Parameters:
Name Type Description
withThese Array

Array of other Travelers

priority Number

almostCloseTo(mp) → {Boolean}

Returns true if almost close to the MoverPoint

Parameters:
Name Type Description
mp MoverPoint
Returns:
Type
Boolean

avoid(moverSkeleton) → {Boolean}

Avoid the given Mover

Parameters:
Name Type Description
moverSkeleton MoverSkeleton
Returns:
Type
Boolean

avoidThese(these) → {Boolean}

Avoid the given Array of Movers.

Parameters:
Name Type Description
these Array

An Array of the Movers to avoid.

Returns:
Type
Boolean

canSeeThis(mp) → {Boolean}

Returns true if the MoverPoint is within visionDistance at the current velocity

Parameters:
Name Type Description
mp MoverPoint
Returns:
Type
Boolean

chase(target)

Chase the target given.

Parameters:
Name Type Description
target Mover | Traveler

circle(mp)

Circle around the given MoverPoint position. Uses circleDistance

Parameters:
Name Type Description
mp MoverPoint

The MoverPoint to circle around.

cohesion(withThese, cohesionPriority)

Parameters:
Name Type Description
withThese Array

Array of other Travelers

cohesionPriority Number

dispatchEvent(event)

Parameters:
Name Type Description
event

easeAwayFrom(mp)

Ease away from the MoverPoint given.

Parameters:
Name Type Description
mp MoverPoint

easeTo(mp)

Ease to the given MoverPoint. Uses easeProximity.

Parameters:
Name Type Description
mp MoverPoint

evade(target)

Evade the given target

Parameters:
Name Type Description
target Mover | Traveler

flee(mp)

Flee the given MoverPoint

Parameters:
Name Type Description
mp MoverPoint

the MoverPoint to flee

flock(withThese, separatePriority, alignPriority, cohesionPriority)

separate, align, and cohesion together.

Parameters:
Name Type Description
withThese Array

Array of other Travelers

separatePriority Number
alignPriority Number
cohesionPriority Number

followPath(path, loopPath)

Follow the path of given MoverPoints; easeTo each MoverPoint.

Parameters:
Name Type Description
path Array

An Array of MoverPoints that make up the path.

loopPath Boolean

getAlignmentForce(withThese)

Parameters:
Name Type Description
withThese Array

getCohesionForce(withThese)

Parameters:
Name Type Description
withThese

getHeight() → {Number}

Returns the height of the TravelerSkeleton

Returns:
Type
Number

getHideSpot(currentPosition, radius, from) → {MoverPoint}

Returns the MoverPoint position that is out of the given radius of from. Uses personalSpace. This method is used internally by the hide method.

Parameters:
Name Type Description
currentPosition MoverPoint

the current MoverPoint position to calculate the hide spot from.

radius Number

The radius to use during calculations.

from Mover | Traveler

The Mover to hide from.

Returns:
Type
MoverPoint

getHorizontalDirection() → {Number}

Returns the horizontal direction the TravelerSkeleton is moving typically 0 1 or -1.

Returns:
Type
Number

getMaxForceSquared() → {Number}

Returns maxForce * maxForce;

Returns:
Type
Number

getMiddle() → {MoverPoint}

Returns the middle position MoverPoint of the TravelerSkeleton

Returns:
Type
MoverPoint

getPathIndex() → {Number}

Returns the _pathIndex

Returns:
Type
Number

getPosition() → {MoverPoint}

Returns the MoverPoint position of the TravelerSkeleton

Returns:
Type
MoverPoint

getRectangle(wOffset, hOffset) → {Rectangle}

Returns the rectangle bounds of the TravelerSkeleton

Parameters:
Name Type Description
wOffset Number

offset the width result by this amount

hOffset Number

offset the height result by this amount

Returns:
Type
Rectangle

getSeparationForce(fromThese)

Parameters:
Name Type Description
fromThese Array

getSteerForce(target, ease, easeDistance) → {MoverPoint}

Returns the force needed to steer towards the target given. Uses maxForce and maxSpeed.

Parameters:
Name Type Description
target Mover | Traveler
ease Boolean

If present ease the steer, otherwise just directly steer

easeDistance Number

the amount of distance before easing should happen.

Returns:
Type
MoverPoint

getVelocity() → {MoverPoint}

Returns the current velocity (._veloc) MoverPoint

Returns:
Type
MoverPoint

getVerticalDirection() → {Number}

Returns the vertical direction the TravelerSkeleton is moving typically 0 1 or -1.

Returns:
Type
Number

getWidth() → {Number}

Returns the width of the TravelerSkeleton

Returns:
Type
Number

getX() → {Number}

Returns the x position of the TravelerSkeleton

Returns:
Type
Number

getY() → {Number}

Returns the y position of the TravelerSkeleton

Returns:
Type
Number

hide(behindThese, from)

Hide behind the given Array of Movers, from the given Mover.

Parameters:
Name Type Description
behindThese Array

An Array of Movers/Travelers to hide behind.

from Mover | Traveler

The Mover/Traveler to hide from.

removeEventListener(type, listenerString, object)

Parameters:
Name Type Description
type
listenerString
object

seek(mp)

Seek the given MoverPoint position.

Parameters:
Name Type Description
mp MoverPoint

The MoverPoint to seek.

separate(withThese, separatePriority)

Separate from the other TravelerSkeletons in the withThese Array.

Parameters:
Name Type Description
withThese Array

an Array of TravelerSkeletons to separate from.

separatePriority Number

A higher number will produce more separation.

separateFromThis(mover)

Separate from the Mover given.

Parameters:
Name Type Description
mover Mover | Traveler

setPathIndex(toThis)

Sets the pathIndex

Parameters:
Name Type Description
toThis Number

setPosition(toThis)

Sets the MoverPoint position of the TravelerSkeleton

Parameters:
Name Type Description
toThis MoverPoint

setVelocity(toThis)

Sets the current velocity MoverPoint

Parameters:
Name Type Description
toThis MoverPoint

setX(toThis, notDX)

Sets the x position of the TravelerSkeleton

Parameters:
Name Type Description
toThis Number

the number to set the x position to.

notDX Number

if present, the direction values of the TravelerSkeleton will not be updated.

setY(toThis, notDY)

Sets the y position of the TravelerSkeleton

Parameters:
Name Type Description
toThis Number
notDY Number

if present the y direction value will not be updated.

update()

Updates _lastPos _lastVeloc _unGrounded _npRight _npLeft and _unCeiling Gets overriden in other classes to do other additional things.

wander()

Wander aimlessly.