new Entity(x, y, width, height)
The base in-game object, it supports a location and velocity.
Entities are boxes, consisting of an x,y coordinate along with a width and height.
Entities have basic collision detection and resolution.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The top-left x coordinate |
y |
number | The top-left y coordinate |
width |
number | The width on the x-axis |
height |
number | The height on the y-axis |
Members
height :number
Height of the Entity, extending downward from Splat.Entity#y.
Type:
- number
(readonly) lastX :number
The value of Splat.Entity#x in the previous frame.
Type:
- number
(readonly) lastY :number
The value of Splat.Entity#y in the previous frame.
Type:
- number
vx :number
Velocity along the x-axis in pixels/millisecond.
Type:
- number
vy :number
Velocity along the y-axis in pixels/millisecond.
Type:
- number
width :number
Width of the Entity, extending to the right of Splat.Entity#x.
Type:
- number
x :number
Leftmost position along the x-axis.
Type:
- number
y :number
Topmost position along the y-axis.
Type:
- number
Methods
collides(other) → {boolean}
Test if this Entity is currently colliding with another.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for collision with |
Returns:
- Type
- boolean
didOverlapHoriz(other) → {boolean}
Test if this Entity horizontally overlapped another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for overlap with |
Returns:
- Type
- boolean
didOverlapVert(other) → {boolean}
Test if this Entity vertically overlapped another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for overlap with |
Returns:
- Type
- boolean
getCollisions(entities) → {Array}
Return a list of all Entities that collide with this Entity.
Parameters:
Name | Type | Description |
---|---|---|
entities |
Array | A list of Entities to check for collisions. |
Returns:
A list of entities that collide with this Entity.
- Type
- Array
move(elapsedMillis)
Simulate movement since the previous frame, changing Splat.Entity#x and Splat.Entity#y as necessary.
Parameters:
Name | Type | Description |
---|---|---|
elapsedMillis |
number | The number of milliseconds since the previous frame. |
moved() → {boolean}
Test if this Entity has changed position since the previous frame.
Returns:
- Type
- boolean
overlapsHoriz(other) → {boolean}
Test if this Entity horizontally overlaps another.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for overlap with |
Returns:
- Type
- boolean
overlapsVert(other) → {boolean}
Test if this Entity vertically overlaps another.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for overlap with |
Returns:
- Type
- boolean
resolveBottomCollisionWith(other)
Adjust the Entity's position so its bottom edge does not penetrate the other Entity's top edge.
Splat.Entity#vy is also zeroed.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity |
resolveCollisionWith(other)
Adjust the Entity's position so it does not penetrate the other Entity.
Splat.Entity#vx will be zeroed if Splat.Entity#x was adjusted, and Splat.Entity#vy will be zeroed if Splat.Entity#y was adjusted.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity |
resolveLeftCollisionWith(other)
Adjust the Entity's position so its left edge does not penetrate the other Entity's right edge.
Splat.Entity#vx is also zeroed.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity |
resolveRightCollisionWith(other)
Adjust the Entity's position so its right edge does not penetrate the other Entity's left edge.
Splat.Entity#vx is also zeroed.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity |
resolveTopCollisionWith(other)
Adjust the Entity's position so its top edge does not penetrate the other Entity's bottom edge.
Splat.Entity#vy is also zeroed.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity |
solveCollisions(entities) → {Array}
Detect and resolve collisions between this Entity and a list of other Entities
Parameters:
Name | Type | Description |
---|---|---|
entities |
Array | A list of Entities to solve against. |
Returns:
A list of entities that were involved in collisions.
- Type
- Array
wasAbove(other) → {boolean}
Test if this Entity was above another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for above-ness with |
Returns:
- Type
- boolean
wasBelow(other) → {boolean}
Test if this Entity was below another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for below-ness with |
Returns:
- Type
- boolean
wasLeft(other) → {boolean}
Test if this Entity was to the left of another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for left-ness with |
Returns:
- Type
- boolean
wasRight(other) → {boolean}
Test if this Entity was to the right of another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for right-ness with |
Returns:
- Type
- boolean