Class PushBlock


public class PushBlock extends BlockEntity

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.

  • 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: the id
      • x: left, fixed point, on a tile edge
      • y: top, fixed point, on a tile edge
      • size: the tile size, fixed point
  • Method Details

    • onAdded

      public void onAdded(PlatformWorld world)
      Description copied from class: LevelEntity

      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
      Overrides:
      onAdded in class LevelEntity
    • isMoving

      public boolean isMoving()

      Whether the crate is sliding or falling.

      Returns

      true mid-move

    • getPhase

      public int getPhase()
      Description copied from class: LevelEntity

      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

      Overrides:
      getPhase in class LevelEntity
    • step

      public void step(PlatformWorld world)
      Description copied from class: LevelEntity

      Advances one tick. The default does nothing.

      Parameters
      • world: the world
      Overrides:
      step in class LevelEntity
    • onTouch

      public void onTouch(PlatformWorld world, Actor c)
      Description copied from class: LevelEntity

      Called each tick a living actor overlaps the entity.

      Parameters
      • world: the world
      • c: the actor
      Overrides:
      onTouch in class LevelEntity
    • hashState

      public long hashState(long h)
      Description copied from class: LevelEntity

      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

      Overrides:
      hashState in class BlockEntity