CTFTNKS Project Documentation - v1.3.0
    Preparing search index...

    Class Tile

    Class for tiles of a GameMap. Contains position, wall list, neighbor list, object list.

    Implements

    Index

    Constructors

    Properties

    dx: number

    Width.

    dy: number

    Height.

    i: number

    X index.

    id: number

    Unique tile ID.

    j: number

    Y index.

    map: GameMap

    The map.

    neighbors: (Tile | null)[] = ...

    List of neighboring tiles [top, left, bottom, right].

    objs: GameObject[] = []

    Objects currently in this tile.

    walls: boolean[] = ...

    List of Walls [top, left, bottom, right].

    x: number

    X coordinate in pixels.

    y: number

    Y coordinate in pixels.

    Methods

    • Adds or removes a wall.

      Parameters

      • direction: number

        0: top, 1: left, 2: bottom, 3: right.

      • remove: boolean = false

        Whether to remove the wall.

      • neighbor: boolean = true

        Whether to update the neighbor as well.

      Returns void

    • Return the coordinates of the corners of the tile and whether they're part of some wall.

      Returns { w: boolean; x: number; y: number }[]

      List of corners with {x, y, w}.

    • Draw the tile walls.

      Parameters

      • context: CanvasRenderingContext2D

        The context.

      Returns void

    • Is there any walls between the tile and a point at x,y?

      Parameters

      • x: number

        X coordinate.

      • y: number

        Y coordinate.

      Returns boolean[]

      List of walls encountered.

    • Recursively find the shortest path to any tile in map where condition is met.

      Parameters

      • condition: (tile: Tile) => boolean

        Function returning boolean.

      • path: Tile[] = []

        Current path.

      • minPathLength: number | null = null

        Optimization: abort if path is longer than this.

      • maxPathLength: number | null = null

        Max allowed path length.

      Returns Tile[] | null

      The path or null if not found.

    • Random walk along the map.

      Parameters

      • distance: number

        Steps to walk.

      Returns Tile

      The final tile.

    • Find any object that matches the condition and return a path of coordinates to it.

      Parameters

      • condition: (obj: GameObject) => boolean

        Match condition.

      • maxPathLength: number | null = null

        Max path length.

      Returns Coord[] | null

      Path to object or null.