update level introspection

This commit is contained in:
Peter Tillemans 2024-05-21 09:08:01 +02:00
parent 82caa7b341
commit bdd12beff5

View file

@ -2,6 +2,7 @@
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (ice-9 pretty-print) #:use-module (ice-9 pretty-print)
#:use-module (ice-9 textual-ports) #:use-module (ice-9 textual-ports)
#:use-module (chickadee math vector)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-9) #:use-module (srfi srfi-9)
#:use-module (srfi srfi-64) #:use-module (srfi srfi-64)
@ -78,6 +79,33 @@
(define (level-tile-at level x y ) (define (level-tile-at level x y )
(level-tile-at-row-col level (coord->cell y) (coord->cell x))) (level-tile-at-row-col level (coord->cell y) (coord->cell x)))
(define (gen-coords a b)
(for ((row (iota a)))
(for ((col (iota b)))
(list row col))
)
)
(define (level-find-tile level tile)
(let loop ((row 0))
(if (= row (level-height level))
#f
(let loop2 ((col 0))
(if (= col (level-width level))
(loop (+ row 1))
(if (eq? (level-tile-at-row-col level row col) 'player)
(vec2 (* col cell-size) (* row cell-size))
(loop2 (+ col 1))))))))
(define (level-find-player level)
(let loop ((row 0))
(if (= row (level-height level))
#f
(let loop2 ((col 0))
(if (= col (level-width level))
(loop (+ row 1))
(if (eq? (level-tile-at-row-col level row col) 'player)
(vec2 (* col cell-size) (* row cell-size))
(loop2 (+ col 1))))))))
(test-begin "level") (test-begin "level")
@ -115,15 +143,15 @@
'goal) 'goal)
(test-equal (test-equal
(level-find-player (level-parse "WWWWW\nWP GW\nWWWWW\n") 1 3) (level-find-player (level-parse "WWWWW\nWP GW\nWWWWW\n"))
(vec2 16 16)) (vec2 16 16))
(test-equal (test-equal
(level-find-goal (level-parse "WWWWW\nWP GW\nWWWWW\n") 1 3) (level-find-goal (level-parse "WWWWW\nWP GW\nWWWWW\n"))
(vec2 48 16)) (vec2 48 16))
(test-equal (test-equal
(level-find-goal (level-parse "WWWWW\nWE EW\nWWWWW\n") 1 3) (level-find-others (level-parse "WWWWW\nWE EW\nWWWWW\n"))
(list (vec 16 16) (vec2 48 16))) (list (vec 16 16) (vec2 48 16)))
(test-end "level") (test-end "level")