Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Raycaster

Index

Constructors

constructor

Properties

Private currentDir

currentDir: Vec2D

Direction of the ray that's currently being worked on (x,y) = (cos, sin)

IMPORTANT: This vector needs to be set from outside BEFORE calling this.ray(..). Otherwise it'll shoot the ray in the wrong direction.

Private currentRange

currentRange: number

Raycasting range: how far do we want to cast the ray in total?

IMPORTANT: The raycasting range needs to be updated each time we cast a ray aswell

Private rayBuffer

rayBuffer: Step[]

Buffer that's used to store the steps in a ray cast. The idea is to not have to re allocate a whole new array every time a ray is cast.

Static Private Readonly DEFAULT_RANGE

DEFAULT_RANGE: 8 = 8

How far we cast rays by default. See this.currentRange.

Accessors

dir

  • set dir(dir: Vec2D): void

range

  • set range(range: number): void

Methods

Private calculateCurrentStep

  • calculateCurrentStep(currentStep: Step): Step

inspect

  • inspect(step: Step, shiftX: number, shiftY: number, distance: number, offset: number): Step
  • Determine mapelement we've reached with this step, what the cell offset is, and what distance it currently is from the player

    Parameters

    • step: Step

      Gets us to the MapElement we want to inspect and save

    • shiftX: number

      Delta needed to subtract from step position x

    • shiftY: number

      Delta needed to subtract from step position y

    • distance: number

      Distance traveled so far in the ray (by all the steps)

    • offset: number

      Current offset from the gridline

    Returns Step

ray

  • Casts a ray based off of origin parameters and this.map

    Parameters

    • origin: Step

      Starting step from where the ray is cast

    Returns Step[]

    An array of steps up to the point where a wall is hit

step

  • step(ySlope: number, xSlope: number, pos: Vec2D, isInverted: boolean): Step
  • Calculate step for the next MapElement to be reached

    Parameters

    • ySlope: number

      y component of the ray slope

    • xSlope: number

      x component of the ray slope

    • pos: Vec2D

      From where the ray originates

    • isInverted: boolean

    Returns Step

    Next step that has reached the next MapElement

Generated using TypeDoc