]> git.jsancho.org Git - gacela.git/blobdiff - games/asteroids/asteroids.scm
(no commit message)
[gacela.git] / games / asteroids / asteroids.scm
index 84c0ac4d795c65ec9cfa97ff1d2304bb4932889d..2b70db1de94ec9f38e1e1bc890e5b979363dabfb 100644 (file)
   (rotate angle)
   (draw-texture image))
 
+;; (define (killed-ship? s a)
+;;   (cond ((null? a) #f)
+;;     (else
+;;      (or (< (distance-between-points (list (assoc-ref s 'x) (assoc-ref s 'y))
+;;                                      (list (assoc-ref (car a) 'x) (assoc-ref (car a) 'y)))
+;;             (assoc-ref (car a) 'size))
+;;          (killed-ship? s (cdr a))))))
+
+(define-macro (killed-ship?)
+  `(
+    (map-mobs
+     (lambda (m)
+       
 (define-mob (ship
             (ship1 (load-texture "Ship1.png"))
             (ship2 (load-texture "Ship2.png"))
 
 
 (define (init-asteroids n)
-  (define (xy n m)
-    (let ((n2 (- (random (* (- n m) 2)) (- n m))))
-      (if (> n2 0) (+ n2 m) (- n2 m))))
-
   (cond ((> n 0)
-        (let ((x (xy max-x 100)) (y (xy max-y 100))
-              (angle (random 360)) (dir (- (random 360) 180)))
-          (show-mob (make-asteroid #:x x #:y y #:angle angle #:dir dir)))
-        (init-asteroids (- n 1)))))
+        (let ((x (- (random (* max-x 2)) max-x))
+              (y (- (random (* max-y 2)) max-y)))
+          (cond ((< (distance-between-points (list x y) '(0 0)) 120)
+                 (init-asteroids n))
+                (else
+                 (let ((angle (random 360)) (dir (- (random 360) 180)))
+                   (show-mob (make-asteroid #:x x #:y y #:angle angle #:dir dir)))
+                 (init-asteroids (- n 1))))))))
+
 
-;(show-mob (make-asteroid))
 (init-asteroids 2)
 (show-mob (make-ship))
+     
+(let ((font (load-font "../tetris/lazy.ttf" #:size 20)))
+  (run-game
+   (render-text (format #f "Mobs: ~a" (length (get-active-mobs))) font)))
 
-;;   (define (xy n r)
-;;     (let ((n2 (- (random (* n 2)) n)))
-;;       (cond ((and (< n2 r) (>= n2 0)) r)
-;;         ((and (> n2 (- r)) (< n2 0)) (- r))
-;;         (else n2))))
-
-;;   (cond ((= n 0) '())
-;;     (else
-;;      (cons `((x . ,(xy max-x 20)) (y . ,(xy max-y 20)) (angle . 0) (vx . 1) (vy . 1) (size . 95))
-;;            (make-asteroids (- n 1))))))
 
 ;;   (define (new-game n)
 ;;     (set! asteroids (make-asteroids n))