Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public abstract class LevelEntity
- Object
- LevelEntity
Known subtypesBlockEntity, 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.
Fields
public int x | Left edge, fixed point. |
public int y | Top edge, fixed point. |
public int w | Width, fixed point. |
public int h | Height, fixed point. |
Constructors
protected LevelEntity(String id, String type, int x, int y, int w, int h) | Creates an entity. |
Methods
public String getId() | The entity’s id. |
public String getType() | The entity’s kind. |
public boolean isActive() | Whether the entity still takes part. |
public void deactivate() | Removes the entity at the end of the tick. |
public int getPhase() | A small number the view reads to pick a frame: open or closed, lit or not, how cracked. |
public int getTouchMargin() | How far outside its rectangle the entity still counts as touched. |
public void onAdded(PlatformWorld world) | Called once when the entity is added to a world, before the first step: the place to write solid cells. |
public void step(PlatformWorld world) | Advances one tick. |
public void onTouch(PlatformWorld world, Actor c) | Called each tick a living actor overlaps the entity. |
public long hashState(long h) | Mixes the entity’s play-relevant state into a hash. |
Inherited methods
Field details
x
public int xy
public int yw
public int wh
public int hConstructor details
LevelEntity
protected LevelEntity(String id, String type, int x, int y, int w, int h)Parameters
idString- a name, unique in its world
typeString- the kind, which the view maps to art (
"coin","spring") xint- left, fixed point
yint- top, fixed point
wint- width, fixed point
hint- height, fixed point
Method details
getId
public String getId()Returns
getType
public String getType()Returns
isActive
public boolean isActive()Returns
deactivate
public void deactivate()getPhase
public int getPhase()Returns
getTouchMargin
public int getTouchMargin()Returns
onAdded
public void onAdded(PlatformWorld world)Parameters
worldPlatformWorld- the world
step
public void step(PlatformWorld world)Parameters
worldPlatformWorld- the world
onTouch
public void onTouch(PlatformWorld world, Actor c)Parameters
worldPlatformWorld- the world
cActor- the actor
hashState
public long hashState(long h)Parameters
hlong- the running hash