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)))
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 (show-mob (make-asteroid))
66 (show-mob (make-ship))
68 ;; (define (make-asteroids n)
70 ;; (let ((n2 (- (random (* n 2)) n)))
71 ;; (cond ((and (< n2 r) (>= n2 0)) r)
72 ;; ((and (> n2 (- r)) (< n2 0)) (- r))
75 ;; (cond ((= n 0) '())
77 ;; (cons `((x . ,(xy max-x 20)) (y . ,(xy max-y 20)) (angle . 0) (vx . 1) (vy . 1) (size . 95))
78 ;; (make-asteroids (- n 1))))))
80 ;; (define (killed-ship? s a)
81 ;; (cond ((null? a) #f)
83 ;; (or (< (distance-between-points (list (assoc-ref s 'x) (assoc-ref s 'y))
84 ;; (list (assoc-ref (car a) 'x) (assoc-ref (car a) 'y)))
85 ;; (assoc-ref (car a) 'size))
86 ;; (killed-ship? s (cdr a))))))
88 ;; (define (kill-asteroids s a)
93 ;; (let ((a1 (car a)))
94 ;; (cond ((< (distance-between-points (list (assoc-ref s1 'x) (assoc-ref s1 'y))
95 ;; (list (assoc-ref a1 'x) (assoc-ref a1 'y)))
96 ;; (assoc-ref a1 'size))
97 ;; (values (cdr a) #t))
99 ;; (receive (an k) (f1 s1 (cdr a))
100 ;; (values (cons a1 an) k))))))))
105 ;; (let ((s1 (car s)))
106 ;; (receive (an k) (f1 s1 a)
108 ;; (kill-asteroids (cdr s) an))
110 ;; (receive (sn an) (kill-asteroids (cdr s) an)
111 ;; (values (cons s1 sn) an)))))))))
114 ;; (let ((asteroids #f) (ship #f) (shots #f))
115 ;; (define (new-game n)
116 ;; (set! asteroids (make-asteroids n))
117 ;; (set! ship '((x . 0) (y . 0) (angle . 0) (moving . #f)))
123 ;; (cond ((killed-ship? ship asteroids)
125 ;; (receive (s a) (kill-asteroids shots asteroids)
127 ;; (set! asteroids a))
128 ;; (set! asteroids (map move-asteroid asteroids))
129 ;; (set! ship (move-ship (alist-copy ship)))
130 ;; (let ((shot (ship-shot ship)))
132 ;; (set! shots (cons shot shots)))))
133 ;; (set! shots (move-shots shots))
134 ;; (for-each draw-asteroid asteroids)
135 ;; (for-each draw-shot shots)
136 ;; (draw-ship ship)))