Class Tile

java.lang.Object
com.codename1.gaming.platformer.Tile

public final class Tile extends Object

The collision kinds a TileGrid cell can hold, and the actors a level file writes them with.

A level's tiles are rows of text, one character per cell, which a person or a language model can read and write directly:

Char Kind Collision
. or space EMPTY none
# SOLID blocks from every side
= ONE_WAY stands on its top, passes from below and the sides; drop through with down + jump
/ SLOPE_UP 45 degree floor rising to the right
\ SLOPE_DOWN 45 degree floor falling to the right
a b SLOPE_UP_LOW, SLOPE_UP_HIGH a 22.5 degree rise, two tiles wide
c d SLOPE_DOWN_HIGH, SLOPE_DOWN_LOW a 22.5 degree fall, two tiles wide
H LADDER climbable; the top rung of a ladder can be stood on
^ HAZARD hurts on touch, no collision
~ WATER a swim volume, no collision
r f aliases for / and \ for writers that escape backslashes badly
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final byte
    Nothing.
    static final byte
    A damaging cell such as spikes.
    static final byte
    A climbable ladder.
    static final byte
    A platform that is solid from above only.
    static final byte
    A 45 degree slope falling left to right.
    static final byte
    The high half of a 22.5 degree fall.
    static final byte
    The low half of a 22.5 degree fall.
    static final byte
    A 45 degree slope rising left to right.
    static final byte
    The high half of a 22.5 degree rise.
    static final byte
    The low half of a 22.5 degree rise.
    static final byte
    A full block.
    static final byte
    Water an actor swims in.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    fromChar(char c)
    Maps a level-file character to its kind.
    static boolean
    isSlope(int kind)
    Whether a kind is one of the slopes.
    static int
    slopeDepth(int kind, int lx, int ts)
    The floor height of a slope at a point across the tile, measured down from the tile's top edge.
    static char
    toChar(int kind)
    The canonical level-file character for a kind.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EMPTY

      public static final byte EMPTY
      Nothing.
      See Also:
    • SOLID

      public static final byte SOLID
      A full block.
      See Also:
    • ONE_WAY

      public static final byte ONE_WAY
      A platform that is solid from above only.
      See Also:
    • SLOPE_UP

      public static final byte SLOPE_UP
      A 45 degree slope rising left to right.
      See Also:
    • SLOPE_DOWN

      public static final byte SLOPE_DOWN
      A 45 degree slope falling left to right.
      See Also:
    • SLOPE_UP_LOW

      public static final byte SLOPE_UP_LOW
      The low half of a 22.5 degree rise.
      See Also:
    • SLOPE_UP_HIGH

      public static final byte SLOPE_UP_HIGH
      The high half of a 22.5 degree rise.
      See Also:
    • SLOPE_DOWN_HIGH

      public static final byte SLOPE_DOWN_HIGH
      The high half of a 22.5 degree fall.
      See Also:
    • SLOPE_DOWN_LOW

      public static final byte SLOPE_DOWN_LOW
      The low half of a 22.5 degree fall.
      See Also:
    • LADDER

      public static final byte LADDER
      A climbable ladder.
      See Also:
    • HAZARD

      public static final byte HAZARD
      A damaging cell such as spikes.
      See Also:
    • WATER

      public static final byte WATER
      Water an actor swims in.
      See Also:
  • Method Details

    • fromChar

      public static int fromChar(char c)

      Maps a level-file character to its kind.

      Parameters
      • c: the character
      Returns

      the kind, or -1 for an actor that is not a tile

    • toChar

      public static char toChar(int kind)

      The canonical level-file character for a kind.

      Parameters
      • kind: a tile kind
      Returns

      its character

    • isSlope

      public static boolean isSlope(int kind)

      Whether a kind is one of the slopes.

      Parameters
      • kind: a tile kind
      Returns

      true for the six slope kinds

    • slopeDepth

      public static int slopeDepth(int kind, int lx, int ts)

      The floor height of a slope at a point across the tile, measured down from the tile's top edge.

      Parameters
      • kind: a slope kind
      • lx: the distance from the tile's left edge, fixed point, in [0, ts]
      • ts: the tile size, fixed point
      Returns

      the distance from the tile's top down to the floor, fixed point