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"))
14 (set! angle (+ angle 1))
16 (cond ((> x max-x) (set! vx -1))
17 ((< x min-x) (set! vx 1)))
18 (cond ((> y max-y) (set! vy -1))
19 ((< y min-y) (set! vy 1)))
26 (ship1 (load-texture "Ship1.png"))
27 (ship2 (load-texture "Ship2.png"))
30 (cond ((key? 'left) (set! angle (+ angle 5)))
31 ((key? 'right) (set! angle (- angle 5))))
33 (let ((r (degrees-to-radians (- angle))))
34 (set! x (+ x (* 4 (sin r))))
35 (set! y (+ y (* 4 (cos r)))))
36 (cond ((> x max-x) (set! x min-x))
37 ((< x min-x) (set! x max-x)))
38 (cond ((> y max-y) (set! y min-y))
39 ((< y min-y) (set! y max-y)))
46 (draw-texture (if moving ship2 ship1)))
48 (define-mob (shot (x 0) (y 0) (angle 0))
53 ;; (define (move-shots shots)
54 ;; (cond ((null? shots) '())
56 ;; (let* ((sh (car shots))
57 ;; (x (assoc-ref sh 'x)) (y (assoc-ref sh 'y))
58 ;; (angle (assoc-ref sh 'angle))
59 ;; (r (degrees-to-radians (- angle))))
60 ;; (set! x (+ x (* 10 (sin r))))
61 ;; (set! y (+ y (* 10 (cos r))))
62 ;; (cond ((and (<= x max-x)
66 ;; (cons `((x . ,x) (y . ,y) (angle . ,angle))
67 ;; (move-shots (cdr shots))))
69 ;; (move-shots (cdr shots))))))))
71 (show-mob (make-asteroid))
72 (show-mob (make-ship))
74 ;; (define (ship-shot s)
75 ;; (cond ((key-pressed? 'space)
76 ;; `((x . ,(assoc-ref s 'x)) (y . ,(assoc-ref s 'y)) (angle . ,(assoc-ref s 'angle))))
80 ;; (define (draw-shot sh)
82 ;; (translate (assoc-ref sh 'x) (assoc-ref sh 'y))
83 ;; (rotate (assoc-ref sh 'angle))
86 ;; (define (move-shots shots)
87 ;; (cond ((null? shots) '())
89 ;; (let* ((sh (car shots))
90 ;; (x (assoc-ref sh 'x)) (y (assoc-ref sh 'y))
91 ;; (angle (assoc-ref sh 'angle))
92 ;; (r (degrees-to-radians (- angle))))
93 ;; (set! x (+ x (* 10 (sin r))))
94 ;; (set! y (+ y (* 10 (cos r))))
95 ;; (cond ((and (<= x max-x)
99 ;; (cons `((x . ,x) (y . ,y) (angle . ,angle))
100 ;; (move-shots (cdr shots))))
102 ;; (move-shots (cdr shots))))))))
104 ;; (define (make-asteroids n)
106 ;; (let ((n2 (- (random (* n 2)) n)))
107 ;; (cond ((and (< n2 r) (>= n2 0)) r)
108 ;; ((and (> n2 (- r)) (< n2 0)) (- r))
111 ;; (cond ((= n 0) '())
113 ;; (cons `((x . ,(xy max-x 20)) (y . ,(xy max-y 20)) (angle . 0) (vx . 1) (vy . 1) (size . 95))
114 ;; (make-asteroids (- n 1))))))
116 ;; (define (killed-ship? s a)
117 ;; (cond ((null? a) #f)
119 ;; (or (< (distance-between-points (list (assoc-ref s 'x) (assoc-ref s 'y))
120 ;; (list (assoc-ref (car a) 'x) (assoc-ref (car a) 'y)))
121 ;; (assoc-ref (car a) 'size))
122 ;; (killed-ship? s (cdr a))))))
124 ;; (define (kill-asteroids s a)
129 ;; (let ((a1 (car a)))
130 ;; (cond ((< (distance-between-points (list (assoc-ref s1 'x) (assoc-ref s1 'y))
131 ;; (list (assoc-ref a1 'x) (assoc-ref a1 'y)))
132 ;; (assoc-ref a1 'size))
133 ;; (values (cdr a) #t))
135 ;; (receive (an k) (f1 s1 (cdr a))
136 ;; (values (cons a1 an) k))))))))
141 ;; (let ((s1 (car s)))
142 ;; (receive (an k) (f1 s1 a)
144 ;; (kill-asteroids (cdr s) an))
146 ;; (receive (sn an) (kill-asteroids (cdr s) an)
147 ;; (values (cons s1 sn) an)))))))))
150 ;; (let ((asteroids #f) (ship #f) (shots #f))
151 ;; (define (new-game n)
152 ;; (set! asteroids (make-asteroids n))
153 ;; (set! ship '((x . 0) (y . 0) (angle . 0) (moving . #f)))
159 ;; (cond ((killed-ship? ship asteroids)
161 ;; (receive (s a) (kill-asteroids shots asteroids)
163 ;; (set! asteroids a))
164 ;; (set! asteroids (map move-asteroid asteroids))
165 ;; (set! ship (move-ship (alist-copy ship)))
166 ;; (let ((shot (ship-shot ship)))
168 ;; (set! shots (cons shot shots)))))
169 ;; (set! shots (move-shots shots))
170 ;; (for-each draw-asteroid asteroids)
171 ;; (for-each draw-shot shots)
172 ;; (draw-ship ship)))