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

    Class GameMap

    Represents the game map.

    Discretized in Nx * Ny tiles, which can be separated by walls (walls) also the tiles keep object lists for spatial sorting the canvas is passed to the constructor to provide the size of the canvas

    Index

    Constructors

    • Creates a new GameMap.

      Parameters

      • canvas: Canvas

        The canvas object.

      • Nx: number | null = null

        Number of tiles in X direction.

      • Ny: number | null = null

        Number of tiles in Y direction.

      Returns GameMap

    Properties

    canvas: Canvas

    The canvas object.

    dx: number = 130

    Tile width in world coordinates (pixels). Default is 130.

    dy: number

    Tile height in world coordinates (pixels). Always equal to dx (square tiles).

    Nx: number

    Number of horizontal tiles. Calculated based on settings and canvas aspect ratio.

    Ny: number

    Number of vertical tiles.

    tiles: Tile[] = []

    Flat array of all tiles in the map, indexed as i * Ny + j.

    Methods

    • Spatial sorting: clear tile object lists.

      Returns void

    • Draws the map.

      Parameters

      • context: CanvasRenderingContext2D

        The context.

      Returns void

    • Finds a spawn point that maximizes the distance to the nearest point in the avoid list. Uses BFS flood fill for distance calculation (Dijkstra map).

      Parameters

      • avoidPoints: Coord[]

        List of coordinates to avoid (e.g. existing bases).

      Returns Coord

      The best spawn point.

    • Gets a tile by its grid index.

      Parameters

      • i: number

        X index.

      • j: number

        Y index.

      Returns Tile | null

      The tile or null if out of bounds.

    • Gets a tile by its world position.

      Parameters

      • x: number

        X coordinate.

      • y: number

        Y coordinate.

      Returns Tile | null

      The tile or null.

    • Update sizes of map and tiles, for window.onresize.

      Returns void

    • Returns a random free spawn point.

      Parameters

      • tries: number = 0

        Recursion counter.

      Returns Coord

      coordinates.