Chunk

Individual chunk for space partitioning.

Constructor

new Chunk(space, x, y)

Create a new chunk.
Parameters:
NameTypeDescription
spaceSpaceParent space
xnumberIndex of chunk along x-axis
ynumberIndex of chunk along y-axis

Members

persistent

Check if the chunk, or any of its actors, are persistent.

persistent

Set the chunk itself to be persistent.

space

Get the parent space.

x

Get the index along the x-axis.

y

Get the index along the y-axis

Methods

addActor(actor)

Add an actor to the chunk.
Parameters:
NameTypeDescription
actorActorActor to add

addOverlapping(actor)

Add an actor that is overlapping the chunk.
Parameters:
NameTypeDescription
actorActorActor to add as overlapping

checkCollision(actor, pos) → {Object}

Check collision for an actor with other actors.
Parameters:
NameTypeDescription
actorActorActor to check collision for
posVec2Position to attempt to move to
Returns:
Object containing collision result data
Type: 
Object

drawActors(ctx)

Draw all actors in the chunk.
Parameters:
NameTypeDescription
ctxCanvasRenderingContext2DCanvas context to draw on

drawDebug(ctx)

Draw all debugging information for the chunk and its actors.
Parameters:
NameTypeDescription
ctxCanvasRenderingContext2DCanvas context to draw on

drawUnits(ctx)

Draw all units within the chunk.
Parameters:
NameTypeDescription
ctxCanvasRenderingContext2DCanvas context to draw on

getNearbyActors(ignore, pos, radius) → {Array.<Actor>}

Get all actors near a specified position and within a radius.
Parameters:
NameTypeDescription
ignoreActorActor to ignore
posVec2Point to find actors around
radiusnumberRadius to find actors within
Returns:
Array of actors near point within at radius
Type: 
Array.<Actor>

getNextID()

Find and set the next actor ID to use.

getUnit(x, y) → {ChunkUnit|null}

Get a specific unit in the chunk.
Parameters:
NameTypeDescription
xnumberRelative index along the x-axis
ynumberRelative index along the y-axis
Returns:
Chunk unit at specified position, or null if there is none.
Type: 
ChunkUnit | null

getUnitAt(x, y) → {ChunkUnit|null}

Get a chunk unit at a specific position in the space.
Parameters:
NameTypeDescription
xnumberGlobal position along the x-axis
ynumberGlobal position along the y-axis
Returns:
Chunk unit at specified position, or null if there is none.
Type: 
ChunkUnit | null

makeUnits()

Generate units within the chunk.

removeOverlapping(actor)

Remove an actor from overlapping with the chunk.
Parameters:
NameTypeDescription
actorActorActor to remove as overlapping

setUnit(x, y, unit)

Set a unit at a specific index.
Parameters:
NameTypeDescription
xnumberRelative index along the x-axis
ynumberRelative index along the y-axis
unitChunkUnit | nullUnit to set at indices, or null to remove.

update(elapsed)

Update the chunk and its actors.
Parameters:
NameTypeDescription
elapsednumberTime since last update cycle in seconds