map.scm 2.54 KB
Newer Older
1
(define-module (map)
2 3
  :use-module (ice-9 rdelim)
  :export ())
4

5 6 7 8 9 10 11 12
(define-public (read-map port)
  (let loop ((board '()))
    (let ((p (read-line port 'split)))
      (let ((line (car p))
            (delim (cdr p)))
        (if (eof-object? delim)
            (reverse board)
            (loop (cons line board)))))))
13

14 15 16
(define-public (parse-map spec)
  (let ((arr (make-array #f (length spec) (string-length (car spec))))
        (spawn '(1 1)))
17 18 19
    (array-index-map! arr
                      (lambda (i j)
                        (case (string-ref (list-ref spec i) j)
20
                          ((#\P #\p) (set! spawn (list j i)) 'space)
21
                          ((#\space) 'space)
22 23 24
                          ((#\#) 'wall)
                          ((#\:) 'grass)
                          ((#\;) 'teleporter)
Hugo Hörnquist's avatar
Hugo Hörnquist committed
25
                          ((#\*) 'window)
Filip Polbratt's avatar
Filip Polbratt committed
26
                          ((#\%) 'entrance))))
27 28 29 30 31 32
    (list spawn arr)))

(define-public board-spawn car)
(define-public board-data cadr)
(define-public (board-height board) (car (array-dimensions (board-data board))))
(define-public (board-width board) (cadr (array-dimensions (board-data board))))
33

34
#;
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
(define game-map
  (parse-map
   '(
     "  #    #######****#**#**#"
     "###%####:::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::#   #::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::#   #::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::#   #::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "  #  ###**#*#**#**#**#**#"
     "  ## #####################")))
53

54
#;
55

56 57
(define game-map
  (parse-map
58 59
   '(
     "  ######                 "
Filip Polbratt's avatar
Filip Polbratt committed
60
     "  #  % #                 "
61
     "  #  ####################"
Filip Polbratt's avatar
Filip Polbratt committed
62 63
     "  #    %                #"
     "  #    #############%#%##"
64
     "  #    #          #  #  #"
Filip Polbratt's avatar
Filip Polbratt committed
65
     "  #    %          #  #  #"
66
     "  #    #######****#**#**#"
Hugo Hörnquist's avatar
Hugo Hörnquist committed
67 68 69 70 71 72 73 74 75 76 77 78
     "###%####:::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::#   #::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::#   #::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::#   #::::::::::::::::::"
     "::*   *::::::::::::::::::"
     "::*   *::::::::::::::::::"
79
     "  #  ###**#*#**#**#**#**#"
Filip Polbratt's avatar
Filip Polbratt committed
80
     "  #  % #  # #  #  #  #  #"
81
     "  #  ###  # #  #  #  #  #"
Filip Polbratt's avatar
Filip Polbratt committed
82 83
     "  #  ####%#%##%##%#%##%##"
     "  #  %                   "
84
     "  ## #####################")))
85 86 87