-
Notifications
You must be signed in to change notification settings - Fork 0
/
scmrl.scm
75 lines (54 loc) · 1.85 KB
/
scmrl.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(use Terminal)
(use Dungeon)
(use Fov)
(use Dijkstra)
(use srfi-25) ;to delete
(begin
(createScreen!)
(define w 70)
(define h 40)
(define d (createDungeon w h 14 30 10))
(define explored (make-array (shape 0 w 0 h) #\space))
(define xPlayer)
(define yPlayer)
(let ((coord (getFloorRandomCoord d w h)))
(set! xPlayer (first coord))
(set! yPlayer (second coord)))
(define xEnd)
(define yEnd)
(let ((coord (getFloorRandomCoord d w h)))
(set! xEnd (first coord))
(set! yEnd (second coord)))
(define dm)
(pushMsg! "Welcome adventurer!")
(pushMsg! (format #f "Target: ~a, ~a" xEnd yEnd))
(let loop ((running #t))
(when running
(let ((fov (calculateFov d w h xPlayer yPlayer 5)))
(for-each (lambda (x)
(for-each (lambda (y)
(when (array-ref fov x y)
(array-set! explored x y (array-ref d x y))))
(iota h)))
(iota w))
(drawMap! explored fov xPlayer yPlayer w h))
(drawPlayer!)
;(set! dm (createDijkstraMap d w h xPlayer yPlayer))
;(let ((path (calculatePath dm w h xEnd yEnd)))
;(drawPath! d path xPlayer yPlayer))
(pushMsg! (format #f "Position (~a, ~a)" xPlayer yPlayer))
(let ((key (getKey)))
(cond ((eq? key #\w)
(when (eq? (array-ref d xPlayer (- yPlayer 1)) #\.) (set! yPlayer (- yPlayer 1))))
((eq? key #\a)
(when (eq? (array-ref d (- xPlayer 1) yPlayer) #\.) (set! xPlayer (- xPlayer 1))))
((eq? key #\s)
(when (eq? (array-ref d xPlayer (+ yPlayer 1)) #\.) (set! yPlayer (+ yPlayer 1))))
((eq? key #\d)
(when (eq? (array-ref d (+ xPlayer 1) yPlayer) #\.) (set! xPlayer (+ xPlayer 1))))
((eq? key #\q)
(when (equal? (askMsg "Type 'quit' to quit: ") "quit")
(set! running #f)))))
(loop running)))
(destroyScreen! "Thanks for playing")
)