Class LevelEntity
- Direct Known Subclasses:
BlockEntity, Checkpoint, Pickup, Projectile, Spring, Switch
Something in a level that is not an actor: a coin, a spring, a door, a projectile, a crumbling block.
An entity is a rectangle with a getType() name that the view maps to art.
Each tick the world calls step, and calls onTouch for every living
actor that overlaps it. An entity that must block movement (a door, a
gate, a crumbling block) writes Tile#SOLID cells into the grid rather than
colliding itself, so the controller stays one fast tile scan.
Subclasses must be deterministic, like abilities, and fold any state that
changes play into hashState.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLevelEntity(String id, String type, int x, int y, int w, int h) Creates an entity. -
Method Summary
Modifier and TypeMethodDescriptionvoidRemoves the entity at the end of the tick.getId()The entity's id.intgetPhase()A small number the view reads to pick a frame: open or closed, lit or not, how cracked.intHow far outside its rectangle the entity still counts as touched.getType()The entity's kind.longhashState(long h) Mixes the entity's play-relevant state into a hash.booleanisActive()Whether the entity still takes part.voidonAdded(PlatformWorld world) Called once when the entity is added to a world, before the first step: the place to write solid cells.voidonTouch(PlatformWorld world, Actor c) Called each tick a living actor overlaps the entity.voidstep(PlatformWorld world) Advances one tick.
-
Field Details
-
x
public int xLeft edge, fixed point. -
y
public int yTop edge, fixed point. -
w
public int wWidth, fixed point. -
h
public int hHeight, fixed point.
-
-
Constructor Details
-
LevelEntity
-
-
Method Details
-
getId
The entity's id.
Returns
the id
-
getType
The entity's kind.
Returns
the type name
-
isActive
public boolean isActive()Whether the entity still takes part. Inactive entities are skipped and not drawn; the world drops them at the end of the tick.
Returns
true while active
-
deactivate
public void deactivate()Removes the entity at the end of the tick. -
getPhase
public int getPhase()A small number the view reads to pick a frame: open or closed, lit or not, how cracked. The default is 0.
Returns
the visual phase
-
getTouchMargin
public int getTouchMargin()How far outside its rectangle the entity still counts as touched. An entity that writes solid cells (a door) needs a margin, since an actor can never overlap a solid cell. The default is 0.
Returns
the margin, fixed point
-
onAdded
Called once when the entity is added to a world, before the first step: the place to write solid cells. The default does nothing.
Parameters
world: the world
-
step
Advances one tick. The default does nothing.
Parameters
world: the world
-
onTouch
Called each tick a living actor overlaps the entity.
Parameters
world: the worldc: the actor
-
hashState
public long hashState(long h) Mixes the entity's play-relevant state into a hash. The default mixes the position and whether it is active.
Parameters
h: the running hash
Returns
the updated hash
-