API Reference › Map — tilemap › Map.tile
method

Map.tile

Map.tile(x, y) -> int

Reads the tile character at cell (x, y) and returns it as a character code, so you can compare it against literals like '#' or '.'. Use it for collision checks (is the cell ahead a wall?), rendering the map, or querying your own custom tile codes. Cells outside the map you set with Map.size answer '#', so the border of the world acts as a wall automatically and you never need special edge-of-map handling. Coordinates are cell indices, not pixels.

Parameters

xthe cell column to read (0-based)
ythe cell row to read (0-based)

Example

program WallCollision {
  property Position { column: int = 0, row: int = 0 }
  model Player { Position }

  const TILE_SIZE: int = 16

  handler BuildLevel phase Start {
    Map.size(width: 8, height: 4)
    Map.row(y: 0, cells: "########")
    Map.row(y: 1, cells: "#..##..#")
    Map.row(y: 2, cells: "#......#")
    Map.row(y: 3, cells: "########")
    spawn Player { Position { column: 1, row: 2 } }
  }

  handler MovePlayer phase Update {
    for (Position) in query [Position, {Player}] {
      let next_column = Position.column + 1
      if Map.tile(x: next_column, y: Position.row) != '#' {
        Position.column = next_column
      }
    }
  }

  handler DrawWorld phase Render {
    Screen.clear(Color.MidnightBlue)
    for (Position) in query [Position, {Player}] {
      Screen.fill_rectangle(
        x: Position.column * TILE_SIZE,
        y: Position.row * TILE_SIZE,
        width: TILE_SIZE,
        height: TILE_SIZE,
        color: Color.LimeGreen)
    }
    Screen.show()
  }
}
← All symbols