map.scm 2.58 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
                          ((#\L) 'lamp)
23 24 25
                          ((#\#) 'wall)
                          ((#\:) 'grass)
                          ((#\;) 'teleporter)
Hugo Hörnquist's avatar
Hugo Hörnquist committed
26
                          ((#\*) 'window)
Filip Polbratt's avatar
Filip Polbratt committed
27
                          ((#\%) 'entrance))))
28 29 30 31 32 33
    (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))))
34

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

55
#;
56

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