example/bundle.js
// ROOM-CORNER-OVERLAP       can't excavate: touches a room corner tile
ROOM-CORNER-OVERLAP       can't excavate: touches a room corner tile
ROOM - CORNER - OVERLAP can ' t excavate : touches a room corner tile
excavate(startPosition, direction, stepLength, tunnelWidth) {
    this.direction = direction
    this.tunnelWidth = tunnelWidth
    const radius = (this.tunnelWidth - 1) / 2
    if (this.direction === 'EAST') {
      Object.assign(this, { x: startPosition.x+1, y: startPosition.y-radius, width: 0, height: this.tunnelWidth })
    } else if (this.direction === 'WEST') {
      Object.assign(this, { x: startPosition.x, y: startPosition.y-radius, width: 0, height: this.tunnelWidth })
    } else if (this.direction === 'NORTH') {
      Object.assign(this, { x: startPosition.x-radius, y: startPosition.y, width: this.tunnelWidth, height: 0 })
    } else {
      Object.assign(this, { x: startPosition.x-radius, y: startPosition.y+1, width: this.tunnelWidth, height: 0 })
    }
    const minRoomSpacing = 1
    const minAnteroomSpacing = 0
    const minTunnelSpacing = 0
    let step = 0
    const ignore = this.parentTunnel
    while (step < stepLength) {
      const survey = expandAABB(this, this.direction, 1)
      if (!this.level.contains(survey)) {
        return 'DUNGEON-OVERLAP'
      }
      const entity = this.level.overlaps(survey, minRoomSpacing, minAnteroomSpacing, minTunnelSpacing, ignore)
      if (entity) {
        if (entity.prefab) {
          return 'PREFAB-OVERLAP'
        }
        if (entity.type === 'room') {
          if (this._atRoomCorner(entity)) {
            return 'ROOM-CORNER-OVERLAP'
          }
          if ((this.width > 0) && (this.height > 0)) {
            var doorPosition = this._getDoorPosition(entity, this.direction)
            if (doorPosition) {
              const overlappingDoors = this.level.objects.filter(o => (o.type === 'door') && overlaps(doorPosition, o))
              if (overlappingDoors.length === 0) {
                const d = new Door(doorPosition)
                d.direction = this.direction
                this.level.addEntity(d)
              }
            }
          }
        }
        return entity.type.toUpperCase()
      }
      Object.assign(this, survey)
      step++
    }
    return 'CLOSED'
  }
excavate ( startPosition , direction , stepLength , tunnelWidth ) { this . direction = direction this . tunnelWidth = tunnelWidth const radius = ( this . tunnelWidth - 1 ) / 2 if ( this . direction === 'EAST' ) { Object . assign ( this , { x : startPosition . x + 1 , y : startPosition . y - radius , width : 0 , height : this . tunnelWidth } ) } else if ( this . direction === 'WEST' ) { Object . assign ( this , { x : startPosition . x , y : startPosition . y - radius , width : 0 , height : this . tunnelWidth } ) } else if ( this . direction === 'NORTH' ) { Object . assign ( this , { x : startPosition . x - radius , y : startPosition . y , width : this . tunnelWidth , height : 0 } ) } else { Object . assign ( this , { x : startPosition . x - radius , y : startPosition . y + 1 , width : this . tunnelWidth , height : 0 } ) } const minRoomSpacing = 1 const minAnteroomSpacing = 0 const minTunnelSpacing = 0 let step = 0 const ignore = this . parentTunnel while ( step < stepLength ) { const survey = expandAABB ( this , this . direction , 1 ) if ( ! this . level . contains ( survey ) ) { return 'DUNGEON-OVERLAP' } const entity = this . level . overlaps ( survey , minRoomSpacing , minAnteroomSpacing , minTunnelSpacing , ignore ) if ( entity ) { if ( entity . prefab ) { return 'PREFAB-OVERLAP' } if ( entity . type === 'room' ) { if ( this . _atRoomCorner ( entity ) ) { return 'ROOM-CORNER-OVERLAP' } if ( ( this . width > 0 ) && ( this . height > 0 ) ) { var doorPosition = this . _getDoorPosition ( entity , this . direction ) if ( doorPosition ) { const overlappingDoors = this . level . objects . filter ( o => ( o . type === 'door' ) && overlaps ( doorPosition , o ) ) if ( overlappingDoors . length === 0 ) { const d = new Door ( doorPosition ) d . direction = this . direction this . level . addEntity ( d ) } } } } return entity . type . toUpperCase ( ) } Object . assign ( this , survey ) step ++ } return 'CLOSED' }
ROOM-CORNER-OVERLAP       can't excavate: touches a room corner tile
ROOM - CORNER - OVERLAP can ' t excavate : touches a room corner tile
// tunnels can't overlap with room corners // only create a door if the tunnel was excavated at all // prohibit door placement when adjacent to any existing door