Options
All
  • Public
  • Public/Protected
  • All
Menu

Map class contains the map elements and the skybox. Has the ability to do raycasting on itself.

Consult the Map Wiki: https://github.zhaw.ch/raycasters/docs/wiki/Map

Hierarchy

  • Map2D

Index

Constructors

constructor

  • new Map2D(size?: number): Map2D
  • Parameters

    • Optional size: number

      Size refers to the height and width of the map (it's square)

    Returns Map2D

Properties

Private ceilingGradient

ceilingGradient: ColorGradient

Gradient for the ceiling

Private floorGradient

floorGradient: ColorGradient

Gradient for the floor

Private fog

fog: Fog

Fog instance to set fogging properties. Remember that each map can have different fogging distances and colors.

Private map

map: MapElement[]

An array describing the map (whether a cell has a wall or not): wall = 1, floor = 0

Note that the world is basically 2D, but saved as 1D in the array.

Private mapName

mapName: string

Map data according to wiki, see https://github.zhaw.ch/raycasters/docs/wiki/Map

Private mapSize

mapSize: number

Mapsize (side length)

Private raycaster

raycaster: Raycaster

To shoot rays and find out where they hit on (this) map.

Private skyBox

skyBox: Image2D

Skybox image

Private wallTextures

wallTextures: Map<string, Image2D>

Map of wall textures. Example entry: '2' -> Image2D("brick_wall.png")

Static Private Readonly SKYBOX_HEIGHT

SKYBOX_HEIGHT: 1440 = 1440

Static Private Readonly SKYBOX_WIDTH

SKYBOX_WIDTH: 3512 = 3512

Accessors

getCeilingGradient

getElementCount

  • get getElementCount(): number
  • Get all map element counts (square of side with of the map)

    Returns number

getElements

getFloorGradient

getFog

  • get getFog(): Fog

getMapName

  • get getMapName(): string

getSize

  • get getSize(): number

getSkyBox

Methods

getElementByPosition

  • Queries the element of a map at clamped coordinate (x,y), could be wall, floor, etc..

    Parameters

    • pos: Vec2D

      Position at which we want to get the map element

    Returns MapElement

    The ELEMENT of map at (x,y) ONLY if it's inside the map, othertype MapElementType.NONE (!)

initialize

  • initialize(): void

parseMapData

  • parseMapData(filename: string, readFromFile?: any): void

rayCast

  • rayCast(origin: Vec2D, angle: number, range: number): Step[]
  • Cast a ray from an origin point in a certain direction with a range cutoff.

    Parameters

    • origin: Vec2D

      Origin position. The player's standing position.

    • angle: number

      Ray shooting angle in radians. The player's direction.

    • range: number

      Maximum drawing distance. 1 unit = 1 MapElement.

    Returns Step[]

    Array of steps composing the ray casted.

Private readMap

  • readMap(filename: string, readFromFile?: any): string
  • Asynchronous method to read the map file.

    Parameters

    • filename: string

      Name of map file

    • Optional readFromFile: any

      callback for testing

    Returns string

    map data file (see wiki for syntax)

setElement

  • Overwrite mapelement at position in this map.

    Parameters

    Returns void

toString

  • toString(): string
  • Probably best used for debugging on the console.

    Returns string

    String representation of the map.

Generated using TypeDoc