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 class PushBlock

  1. Object
  2. LevelEntity
  3. BlockEntity
  4. PushBlock

A crate a player pushes one tile at a time by walking into it, the piece puzzle platformers are built from. It is solid while it rests, so it can be stood on and climbed; it falls when nothing holds it up, and it holds down a pressure plate (Switch) as a player standing on it would.

A push takes pushTicks of walking against it, so brushing past never moves it, and a crate only moves into empty cells. Movement is in whole tiles, which keeps a puzzle exactly solvable and a replay exact.

Fields

public int pushTicksTicks of pushing before the crate moves.
public int moveTicksTicks one tile of movement takes.

Constructors

public PushBlock(String id, int x, int y, int size)Creates a crate one tile in size.

Methods

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 boolean isMoving()Whether the crate is sliding or falling.
public int getPhase()A small number the view reads to pick a frame: open or closed, lit or not, how cracked.
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 fields

From LevelEntity

x, y, w, h

Inherited methods

Field details

pushTicks

public int pushTicks
Ticks of pushing before the crate moves.

moveTicks

public int moveTicks
Ticks one tile of movement takes.

Constructor details

PushBlock

public PushBlock(String id, int x, int y, int size)
Creates a crate one tile in size.

Parameters

id String
the id
x int
left, fixed point, on a tile edge
y int
top, fixed point, on a tile edge
size int
the tile size, fixed point

Method details

onAdded

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. The default does nothing.

Parameters

world PlatformWorld
the world

isMoving

public boolean isMoving()
Whether the crate is sliding or falling.

Returns

true mid-move

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

step

public void step(PlatformWorld world)
Advances one tick. The default does nothing.

Parameters

world PlatformWorld
the world

onTouch

public void onTouch(PlatformWorld world, Actor c)
Called each tick a living actor overlaps the entity.

Parameters

world PlatformWorld
the world
c Actor
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 long
the running hash

Returns

the updated hash