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 (let ((r (degrees-to-radians (- dir))))
19 (set! x (+ x (sin r)))
20 (set! y (+ y (cos r))))
21 (set! angle (+ angle 1))
23 (cond ((or (> x max-x) (< x min-x))
24 (set! dir (* -1 dir))))
25 (cond ((or (> y max-y) (< y min-y))
26 (set! dir (- 180 dir))))
28 (if (asteroid-killed?) (kill-me))
34 (ship1 (load-texture "Ship1.png"))
35 (ship2 (load-texture "Ship2.png"))
38 (cond ((key? 'left) (set! angle (+ angle 5)))
39 ((key? 'right) (set! angle (- angle 5))))
41 (let ((r (degrees-to-radians (- angle))))
42 (set! x (+ x (* 4 (sin r))))
43 (set! y (+ y (* 4 (cos r)))))
44 (cond ((> x max-x) (set! x min-x))
45 ((< x min-x) (set! x max-x)))
46 (cond ((> y max-y) (set! y min-y))
47 ((< y min-y) (set! y max-y)))
51 (cond ((key-pressed? 'space)
52 (show-mob (make-shot #:x x #:y y #:angle angle))))
56 (draw-texture (if moving ship2 ship1)))
58 (define-mob (shot (x 0) (y 0) (angle 0))
59 (let ((r (degrees-to-radians (- angle))))
60 (set! x (+ x (* 10 (sin r))))
61 (set! y (+ y (* 10 (cos r))))
62 (cond ((or (> x max-x)
73 (define (init-asteroids n)
75 (let ((x (- (random (* max-x 2)) max-x))
76 (y (- (random (* max-y 2)) max-y)))
77 (cond ((< (distance-between-points (list x y) '(0 0)) 120)
80 (let ((angle (random 360)) (dir (- (random 360) 180)))
81 (show-mob (make-asteroid #:x x #:y y #:angle angle #:dir dir)))
82 (init-asteroids (- n 1))))))))
86 (show-mob (make-ship))
88 (let ((font (load-font "../tetris/lazy.ttf" #:size 20)))
90 (render-text (format #f "Mobs: ~a" (length (get-active-mobs))) font)))
93 ;; (define (new-game n)
94 ;; (set! asteroids (make-asteroids n))
95 ;; (set! ship '((x . 0) (y . 0) (angle . 0) (moving . #f)))
100 ;; (define (killed-ship? s a)
101 ;; (cond ((null? a) #f)
103 ;; (or (< (distance-between-points (list (assoc-ref s 'x) (assoc-ref s 'y))
104 ;; (list (assoc-ref (car a) 'x) (assoc-ref (car a) 'y)))
105 ;; (assoc-ref (car a) 'size))
106 ;; (killed-ship? s (cdr a))))))
109 ;; (let ((asteroids #f) (ship #f) (shots #f))
112 ;; (cond ((killed-ship? ship asteroids)
114 ;; (receive (s a) (kill-asteroids shots asteroids)
116 ;; (set! asteroids a))
117 ;; (set! asteroids (map move-asteroid asteroids))
118 ;; (set! ship (move-ship (alist-copy ship)))
119 ;; (let ((shot (ship-shot ship)))
121 ;; (set! shots (cons shot shots)))))
122 ;; (set! shots (move-shots shots))
123 ;; (for-each draw-asteroid asteroids)
124 ;; (for-each draw-shot shots)
125 ;; (draw-ship ship)))