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))
8 (define-macro (asteroid-killed?)
11 (lambda (s) (if (< (distance-between-points (list (assoc-ref s 'x) (assoc-ref s 'y)) (list x y)) size) 1 0))
16 (image (load-texture "Asteroid.png"))
17 (x 0) (y 0) (angle 0) (dir 0) (size 100))
18 (cond ((asteroid-killed?)
21 (let ((r (degrees-to-radians (- dir))))
22 (set! x (+ x (sin r)))
23 (set! y (+ y (cos r))))
24 (set! angle (+ angle 1))
26 (cond ((or (> x max-x) (< x min-x))
27 (set! dir (* -1 dir))))
28 (cond ((or (> y max-y) (< y min-y))
29 (set! dir (- 180 dir))))))
36 (ship1 (load-texture "Ship1.png"))
37 (ship2 (load-texture "Ship2.png"))
40 (cond ((key? 'left) (set! angle (+ angle 5)))
41 ((key? 'right) (set! angle (- angle 5))))
43 (let ((r (degrees-to-radians (- angle))))
44 (set! x (+ x (* 4 (sin r))))
45 (set! y (+ y (* 4 (cos r)))))
46 (cond ((> x max-x) (set! x min-x))
47 ((< x min-x) (set! x max-x)))
48 (cond ((> y max-y) (set! y min-y))
49 ((< y min-y) (set! y max-y)))
53 (cond ((key-pressed? 'space)
54 (show-mob (make-shot #:x x #:y y #:angle angle))))
58 (draw-texture (if moving ship2 ship1)))
60 (define-macro (shot-killed?)
63 (lambda (a) (if (< (distance-between-points (list (assoc-ref a 'x) (assoc-ref a 'y)) (list x y)) (assoc-ref a 'size)) 1 0))
67 (define-mob (shot (x 0) (y 0) (angle 0))
71 (let ((r (degrees-to-radians (- angle))))
72 (set! x (+ x (* 10 (sin r))))
73 (set! y (+ y (* 10 (cos r))))
74 (cond ((or (> x max-x)
85 (define (init-asteroids n)
87 (let ((x (- (random (* max-x 2)) max-x))
88 (y (- (random (* max-y 2)) max-y)))
89 (cond ((< (distance-between-points (list x y) '(0 0)) 120)
92 (let ((angle (random 360)) (dir (- (random 360) 180)))
93 (show-mob (make-asteroid #:x x #:y y #:angle angle #:dir dir)))
94 (init-asteroids (- n 1))))))))
98 (show-mob (make-ship))
100 (let ((font (load-font "../tetris/lazy.ttf" #:size 20)))
102 (render-text (format #f "Mobs: ~a" (length (get-active-mobs))) font)))
105 ;; (define (new-game n)
106 ;; (set! asteroids (make-asteroids n))
107 ;; (set! ship '((x . 0) (y . 0) (angle . 0) (moving . #f)))
112 ;; (define (killed-ship? s a)
113 ;; (cond ((null? a) #f)
115 ;; (or (< (distance-between-points (list (assoc-ref s 'x) (assoc-ref s 'y))
116 ;; (list (assoc-ref (car a) 'x) (assoc-ref (car a) 'y)))
117 ;; (assoc-ref (car a) 'size))
118 ;; (killed-ship? s (cdr a))))))
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)))