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))))
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)))
43 (cond ((key-pressed? 'space)
44 (show-mob (make-shot #:x x #:y y #:angle angle))))
48 (draw-texture (if moving ship2 ship1)))
50 (define-mob (shot (x 0) (y 0) (angle 0))
51 (let ((r (degrees-to-radians (- angle))))
52 (set! x (+ x (* 10 (sin r))))
53 (set! y (+ y (* 10 (cos r))))
54 (cond ((or (> x max-x)
65 (define (init-asteroids n)
67 (let ((n2 (- (random (* (- n m) 2)) (- n m))))
68 (if (> n2 0) (+ n2 m) (- n2 m))))
71 (let ((x (xy max-x 100)) (y (xy max-y 100))
72 (angle (random 360)) (dir (- (random 360) 180)))
73 (show-mob (make-asteroid #:x x #:y y #:angle angle #:dir dir)))
74 (init-asteroids (- n 1)))))
76 ;(show-mob (make-asteroid))
78 (show-mob (make-ship))
81 ;; (let ((n2 (- (random (* n 2)) n)))
82 ;; (cond ((and (< n2 r) (>= n2 0)) r)
83 ;; ((and (> n2 (- r)) (< n2 0)) (- r))
86 ;; (cond ((= n 0) '())
88 ;; (cons `((x . ,(xy max-x 20)) (y . ,(xy max-y 20)) (angle . 0) (vx . 1) (vy . 1) (size . 95))
89 ;; (make-asteroids (- n 1))))))
91 ;; (define (new-game n)
92 ;; (set! asteroids (make-asteroids n))
93 ;; (set! ship '((x . 0) (y . 0) (angle . 0) (moving . #f)))
98 ;; (define (killed-ship? s a)
99 ;; (cond ((null? a) #f)
101 ;; (or (< (distance-between-points (list (assoc-ref s 'x) (assoc-ref s 'y))
102 ;; (list (assoc-ref (car a) 'x) (assoc-ref (car a) 'y)))
103 ;; (assoc-ref (car a) 'size))
104 ;; (killed-ship? s (cdr a))))))
106 ;; (define (kill-asteroids s a)
111 ;; (let ((a1 (car a)))
112 ;; (cond ((< (distance-between-points (list (assoc-ref s1 'x) (assoc-ref s1 'y))
113 ;; (list (assoc-ref a1 'x) (assoc-ref a1 'y)))
114 ;; (assoc-ref a1 'size))
115 ;; (values (cdr a) #t))
117 ;; (receive (an k) (f1 s1 (cdr a))
118 ;; (values (cons a1 an) k))))))))
123 ;; (let ((s1 (car s)))
124 ;; (receive (an k) (f1 s1 a)
126 ;; (kill-asteroids (cdr s) an))
128 ;; (receive (sn an) (kill-asteroids (cdr s) an)
129 ;; (values (cons s1 sn) an)))))))))
132 ;; (let ((asteroids #f) (ship #f) (shots #f))
135 ;; (cond ((killed-ship? ship asteroids)
137 ;; (receive (s a) (kill-asteroids shots asteroids)
139 ;; (set! asteroids a))
140 ;; (set! asteroids (map move-asteroid asteroids))
141 ;; (set! ship (move-ship (alist-copy ship)))
142 ;; (let ((shot (ship-shot ship)))
144 ;; (set! shots (cons shot shots)))))
145 ;; (set! shots (move-shots shots))
146 ;; (for-each draw-asteroid asteroids)
147 ;; (for-each draw-shot shots)
148 ;; (draw-ship ship)))