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))
15 (show-mob (make-asteroid))
17 ;; (define draw-asteroid
18 ;; (let ((asteroid (load-texture "Asteroid.png")))
21 ;; (translate (assoc-ref a 'x) (assoc-ref a 'y))
22 ;; (rotate (assoc-ref a 'angle))
23 ;; (draw-texture asteroid))))
25 ;; (define (move-asteroid a)
26 ;; (let ((x (assoc-ref a 'x)) (y (assoc-ref a 'y))
27 ;; (angle (assoc-ref a 'angle))
28 ;; (vx (assoc-ref a 'vx)) (vy (assoc-ref a 'vy)))
31 ;; (cond ((> x max-x) (set! vx -1))
32 ;; ((< x min-x) (set! vx 1)))
33 ;; (cond ((> y max-y) (set! vy -1))
34 ;; ((< y min-y) (set! vy 1)))
36 ;; (assoc-multiple-set! a 'x x 'y y 'angle (+ angle 1) 'vx vx 'vy vy)))
39 ;; (let ((ship1 (load-texture "Ship1.png"))
40 ;; (ship2 (load-texture "Ship2.png")))
43 ;; (translate (assoc-ref s 'x) (assoc-ref s 'y))
44 ;; (rotate (assoc-ref s 'angle))
45 ;; (let ((ship (if (assoc-ref s 'moving) ship2 ship1)))
46 ;; (draw-texture ship)))))
48 ;; (define (move-ship ship)
50 ;; (x (assoc-ref s 'x)) (y (assoc-ref s 'y))
51 ;; (angle (assoc-ref s 'angle))
52 ;; (moving (assoc-ref s 'moving)))
53 ;; (cond ((key? 'left) (set! angle (+ angle 5)))
54 ;; ((key? 'right) (set! angle (- angle 5))))
56 ;; (let ((r (degrees-to-radians (- angle))))
57 ;; (set! x (+ x (* 4 (sin r))))
58 ;; (set! y (+ y (* 4 (cos r)))))
59 ;; (cond ((> x max-x) (set! x min-x))
60 ;; ((< x min-x) (set! x max-x)))
61 ;; (cond ((> y max-y) (set! y min-y))
62 ;; ((< y min-y) (set! y max-y)))
67 ;; (assoc-multiple-set! s 'x x 'y y 'angle angle 'moving moving)))
69 ;; (define (ship-shot s)
70 ;; (cond ((key-pressed? 'space)
71 ;; `((x . ,(assoc-ref s 'x)) (y . ,(assoc-ref s 'y)) (angle . ,(assoc-ref s 'angle))))
75 ;; (define (draw-shot sh)
77 ;; (translate (assoc-ref sh 'x) (assoc-ref sh 'y))
78 ;; (rotate (assoc-ref sh 'angle))
81 ;; (define (move-shots shots)
82 ;; (cond ((null? shots) '())
84 ;; (let* ((sh (car shots))
85 ;; (x (assoc-ref sh 'x)) (y (assoc-ref sh 'y))
86 ;; (angle (assoc-ref sh 'angle))
87 ;; (r (degrees-to-radians (- angle))))
88 ;; (set! x (+ x (* 10 (sin r))))
89 ;; (set! y (+ y (* 10 (cos r))))
90 ;; (cond ((and (<= x max-x)
94 ;; (cons `((x . ,x) (y . ,y) (angle . ,angle))
95 ;; (move-shots (cdr shots))))
97 ;; (move-shots (cdr shots))))))))
99 ;; (define (make-asteroids n)
101 ;; (let ((n2 (- (random (* n 2)) n)))
102 ;; (cond ((and (< n2 r) (>= n2 0)) r)
103 ;; ((and (> n2 (- r)) (< n2 0)) (- r))
106 ;; (cond ((= n 0) '())
108 ;; (cons `((x . ,(xy max-x 20)) (y . ,(xy max-y 20)) (angle . 0) (vx . 1) (vy . 1) (size . 95))
109 ;; (make-asteroids (- n 1))))))
111 ;; (define (killed-ship? s a)
112 ;; (cond ((null? a) #f)
114 ;; (or (< (distance-between-points (list (assoc-ref s 'x) (assoc-ref s 'y))
115 ;; (list (assoc-ref (car a) 'x) (assoc-ref (car a) 'y)))
116 ;; (assoc-ref (car a) 'size))
117 ;; (killed-ship? s (cdr a))))))
119 ;; (define (kill-asteroids s a)
124 ;; (let ((a1 (car a)))
125 ;; (cond ((< (distance-between-points (list (assoc-ref s1 'x) (assoc-ref s1 'y))
126 ;; (list (assoc-ref a1 'x) (assoc-ref a1 'y)))
127 ;; (assoc-ref a1 'size))
128 ;; (values (cdr a) #t))
130 ;; (receive (an k) (f1 s1 (cdr a))
131 ;; (values (cons a1 an) k))))))))
136 ;; (let ((s1 (car s)))
137 ;; (receive (an k) (f1 s1 a)
139 ;; (kill-asteroids (cdr s) an))
141 ;; (receive (sn an) (kill-asteroids (cdr s) an)
142 ;; (values (cons s1 sn) an)))))))))
145 ;; (let ((asteroids #f) (ship #f) (shots #f))
146 ;; (define (new-game n)
147 ;; (set! asteroids (make-asteroids n))
148 ;; (set! ship '((x . 0) (y . 0) (angle . 0) (moving . #f)))
154 ;; (cond ((killed-ship? ship asteroids)
156 ;; (receive (s a) (kill-asteroids shots asteroids)
158 ;; (set! asteroids a))
159 ;; (set! asteroids (map move-asteroid asteroids))
160 ;; (set! ship (move-ship (alist-copy ship)))
161 ;; (let ((shot (ship-shot ship)))
163 ;; (set! shots (cons shot shots)))))
164 ;; (set! shots (move-shots shots))
165 ;; (for-each draw-asteroid asteroids)
166 ;; (for-each draw-shot shots)
167 ;; (draw-ship ship)))