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)))
dungeon crawler in Scheme
Which Scheme?
>>2
Portable Scheme, obviously.
>>2
Right, just as >>3 said, since the premise here is using the same core in multiple engines, obviously it has to be portable across all Scheme dialects that end up used in such engines. Of course, they're hypothetical right now, but we could at least start out writing code targeting a smaller Scheme standard and let the host engine developers argue about whether to support extra features.
Also, just speaking for myself here, I wouldn't be averse to using a custom dialect of some kind, maybe even a novel Lisp that departs quite radically from the LISP-1/Scheme tradition for the sake of (for example) easier host integration, simpler GC, better/simpler optimization rules, or (most critical for game development) more reliable live debugging and hot code reloading. I could even acquiesce to building the whole game in SBCL, like Kandria.
So why Scheme? Just because we are here, surrounded by people who love Scheme.
I like the idea of making something actually useful and nontrivial in pure R*RS Scheme. Of course, there will be times when we must depart from it and use implementation-specific features, but the core ought to be entirely portable.
It always help me to visualize things early in the development process. Let's see what we have so far:
(require srfi/43)
(define terrain-width 12)
(define terrain-height 12)
(define (print-terrain)
(vector-for-each (lambda (i n)
(cond ((zero? (remainder (+ i 1) terrain-width)) (newline))
((eq? n 'floor) (display ".")))) terrain))
(print-terrain)
...........
...........
...........
...........
...........
...........
...........
...........
...........
...........
...........
...........
Nice.