[ prog / sol / mona ]

prog


Roguelike dungeon generator

1 2024-02-27 05:08

Someone in another thread suggested writing the core of a dungeon crawler in Scheme, and then being able to use it in multiple engines for different styles of gameplay. That second part sounds like an entire shitload of work, but that shouldn't stop us from getting started, so I went ahead and scaffolded some basic code.

(define terrain-width 128)
(define terrain-height 128)

(define (xy->index x y)
  (+ x (* y terrain-width)))

(define (index->x index)
  (remainder index terrain-width))

(define (index->y index)
  (floor (/ index terrain-width)))

(define (terrain-edge? x y)
  (or (<= x 0)
      (<= y 0)
      (>= (+ x 1) terrain-width)
      (>= (+ y 1) terrain-height)))

(define terrain
  (let ((num-cells (* terrain-width terrain-height)))
    ; TODO: Actual dungeon generation algorithm
    (make-vector num-cells 'floor)))
8


VIP:

do not edit these