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 ((x (- (random (* max-x 2)) max-x))
68 (y (- (random (* max-y 2)) max-y)))
69 (cond ((< (distance-between-points (list x y) '(0 0)) 120)
72 (let ((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))))))))
78 (show-mob (make-ship))
80 ;; (define (new-game n)
81 ;; (set! asteroids (make-asteroids n))
82 ;; (set! ship '((x . 0) (y . 0) (angle . 0) (moving . #f)))
87 ;; (define (killed-ship? s a)
88 ;; (cond ((null? a) #f)
90 ;; (or (< (distance-between-points (list (assoc-ref s 'x) (assoc-ref s 'y))
91 ;; (list (assoc-ref (car a) 'x) (assoc-ref (car a) 'y)))
92 ;; (assoc-ref (car a) 'size))
93 ;; (killed-ship? s (cdr a))))))
95 ;; (define (kill-asteroids s a)
100 ;; (let ((a1 (car a)))
101 ;; (cond ((< (distance-between-points (list (assoc-ref s1 'x) (assoc-ref s1 'y))
102 ;; (list (assoc-ref a1 'x) (assoc-ref a1 'y)))
103 ;; (assoc-ref a1 'size))
104 ;; (values (cdr a) #t))
106 ;; (receive (an k) (f1 s1 (cdr a))
107 ;; (values (cons a1 an) k))))))))
112 ;; (let ((s1 (car s)))
113 ;; (receive (an k) (f1 s1 a)
115 ;; (kill-asteroids (cdr s) an))
117 ;; (receive (sn an) (kill-asteroids (cdr s) an)
118 ;; (values (cons s1 sn) an)))))))))
121 ;; (let ((asteroids #f) (ship #f) (shots #f))
124 ;; (cond ((killed-ship? ship asteroids)
126 ;; (receive (s a) (kill-asteroids shots asteroids)
128 ;; (set! asteroids a))
129 ;; (set! asteroids (map move-asteroid asteroids))
130 ;; (set! ship (move-ship (alist-copy ship)))
131 ;; (let ((shot (ship-shot ship)))
133 ;; (set! shots (cons shot shots)))))
134 ;; (set! shots (move-shots shots))
135 ;; (for-each draw-asteroid asteroids)
136 ;; (for-each draw-shot shots)
137 ;; (draw-ship ship)))