1 (set-game-properties! #:title "Gacela Asteroids")
3 (define max-x (/ (assoc-ref (get-game-properties) 'width) 2))
4 (define min-x (- max-x))
5 (define max-y (/ (assoc-ref (get-game-properties) 'height) 2))
6 (define min-y (- max-y))
9 (image (load-texture "Asteroid.png"))
10 (x 0) (y 0) (angle 0) (dir 0))
11 (let ((r (degrees-to-radians (- dir))))
12 (set! x (+ x (sin r)))
13 (set! y (+ y (cos r))))
14 (set! angle (+ angle 1))
16 (cond ((or (> x max-x) (< x min-x))
17 (set! dir (* -1 dir))))
18 (cond ((or (> y max-y) (< y min-y))
19 (set! dir (- 180 dir))))
25 ;; (define (killed-ship? s a)
26 ;; (cond ((null? a) #f)
28 ;; (or (< (distance-between-points (list (assoc-ref s 'x) (assoc-ref s 'y))
29 ;; (list (assoc-ref (car a) 'x) (assoc-ref (car a) 'y)))
30 ;; (assoc-ref (car a) 'size))
31 ;; (killed-ship? s (cdr a))))))
33 (define-macro (killed-ship?)
39 (ship1 (load-texture "Ship1.png"))
40 (ship2 (load-texture "Ship2.png"))
43 (cond ((key? 'left) (set! angle (+ angle 5)))
44 ((key? 'right) (set! angle (- angle 5))))
46 (let ((r (degrees-to-radians (- angle))))
47 (set! x (+ x (* 4 (sin r))))
48 (set! y (+ y (* 4 (cos r)))))
49 (cond ((> x max-x) (set! x min-x))
50 ((< x min-x) (set! x max-x)))
51 (cond ((> y max-y) (set! y min-y))
52 ((< y min-y) (set! y max-y)))
56 (cond ((key-pressed? 'space)
57 (show-mob (make-shot #:x x #:y y #:angle angle))))
61 (draw-texture (if moving ship2 ship1)))
63 (define-mob (shot (x 0) (y 0) (angle 0))
64 (let ((r (degrees-to-radians (- angle))))
65 (set! x (+ x (* 10 (sin r))))
66 (set! y (+ y (* 10 (cos r))))
67 (cond ((or (> x max-x)
78 (define (init-asteroids n)
80 (let ((x (- (random (* max-x 2)) max-x))
81 (y (- (random (* max-y 2)) max-y)))
82 (cond ((< (distance-between-points (list x y) '(0 0)) 120)
85 (let ((angle (random 360)) (dir (- (random 360) 180)))
86 (show-mob (make-asteroid #:x x #:y y #:angle angle #:dir dir)))
87 (init-asteroids (- n 1))))))))
91 (show-mob (make-ship))
93 (let ((font (load-font "../tetris/lazy.ttf" #:size 20)))
95 (render-text (format #f "Mobs: ~a" (length (get-active-mobs))) font)))
98 ;; (define (new-game n)
99 ;; (set! asteroids (make-asteroids n))
100 ;; (set! ship '((x . 0) (y . 0) (angle . 0) (moving . #f)))
105 ;; (define (killed-ship? s a)
106 ;; (cond ((null? a) #f)
108 ;; (or (< (distance-between-points (list (assoc-ref s 'x) (assoc-ref s 'y))
109 ;; (list (assoc-ref (car a) 'x) (assoc-ref (car a) 'y)))
110 ;; (assoc-ref (car a) 'size))
111 ;; (killed-ship? s (cdr a))))))
113 ;; (define (kill-asteroids s a)
118 ;; (let ((a1 (car a)))
119 ;; (cond ((< (distance-between-points (list (assoc-ref s1 'x) (assoc-ref s1 'y))
120 ;; (list (assoc-ref a1 'x) (assoc-ref a1 'y)))
121 ;; (assoc-ref a1 'size))
122 ;; (values (cdr a) #t))
124 ;; (receive (an k) (f1 s1 (cdr a))
125 ;; (values (cons a1 an) k))))))))
130 ;; (let ((s1 (car s)))
131 ;; (receive (an k) (f1 s1 a)
133 ;; (kill-asteroids (cdr s) an))
135 ;; (receive (sn an) (kill-asteroids (cdr s) an)
136 ;; (values (cons s1 sn) an)))))))))
139 ;; (let ((asteroids #f) (ship #f) (shots #f))
142 ;; (cond ((killed-ship? ship asteroids)
144 ;; (receive (s a) (kill-asteroids shots asteroids)
146 ;; (set! asteroids a))
147 ;; (set! asteroids (map move-asteroid asteroids))
148 ;; (set! ship (move-ship (alist-copy ship)))
149 ;; (let ((shot (ship-shot ship)))
151 ;; (set! shots (cons shot shots)))))
152 ;; (set! shots (move-shots shots))
153 ;; (for-each draw-asteroid asteroids)
154 ;; (for-each draw-shot shots)
155 ;; (draw-ship ship)))