From: jsancho Date: Thu, 15 Sep 2011 19:31:02 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=91dd14e8cb97624a3f7e0515afbff4d7143f514e;p=gacela.git --- diff --git a/emacs/emacs_conf.lisp b/emacs/emacs_conf.lisp index 5cde2b1..29dcc20 100644 --- a/emacs/emacs_conf.lisp +++ b/emacs/emacs_conf.lisp @@ -14,7 +14,7 @@ (t (process-send-string "gacela" "(run-game) (clear-active-mobs)") (process-send-region "gacela" (point-min-marker) (point-max-marker)))) - (process-send-string "gacela" ")\n")) + (process-send-string "gacela" "\n)\n")) (define-key global-map [(ctrl x) (ctrl g)] 'send-to-gacela) diff --git a/games/asteroids/asteroids.scm b/games/asteroids/asteroids.scm index b18b7f6..92b03c4 100644 --- a/games/asteroids/asteroids.scm +++ b/games/asteroids/asteroids.scm @@ -40,67 +40,31 @@ (set! moving #t)) (else (set! moving #f))) + (cond ((key-pressed? 'space) + (show-mob (make-shot #:x x #:y y #:angle angle)))) (translate x y) (rotate angle) (draw-texture (if moving ship2 ship1))) (define-mob (shot (x 0) (y 0) (angle 0)) + (let ((r (degrees-to-radians (- angle)))) + (set! x (+ x (* 10 (sin r)))) + (set! y (+ y (* 10 (cos r)))) + (cond ((or (> x max-x) + (< x min-x) + (> y max-y) + (< y min-y)) + (kill-me)))) + (translate x y) (rotate angle) (draw-line 10)) -;; (define (move-shots shots) -;; (cond ((null? shots) '()) -;; (else -;; (let* ((sh (car shots)) -;; (x (assoc-ref sh 'x)) (y (assoc-ref sh 'y)) -;; (angle (assoc-ref sh 'angle)) -;; (r (degrees-to-radians (- angle)))) -;; (set! x (+ x (* 10 (sin r)))) -;; (set! y (+ y (* 10 (cos r)))) -;; (cond ((and (<= x max-x) -;; (>= x min-x) -;; (<= y max-y) -;; (>= y min-y)) -;; (cons `((x . ,x) (y . ,y) (angle . ,angle)) -;; (move-shots (cdr shots)))) -;; (else -;; (move-shots (cdr shots)))))))) (show-mob (make-asteroid)) (show-mob (make-ship)) -;; (define (ship-shot s) -;; (cond ((key-pressed? 'space) -;; `((x . ,(assoc-ref s 'x)) (y . ,(assoc-ref s 'y)) (angle . ,(assoc-ref s 'angle)))) -;; (else -;; #f))) - -;; (define (draw-shot sh) -;; (to-origin) -;; (translate (assoc-ref sh 'x) (assoc-ref sh 'y)) -;; (rotate (assoc-ref sh 'angle)) -;; (draw-line 10)) - -;; (define (move-shots shots) -;; (cond ((null? shots) '()) -;; (else -;; (let* ((sh (car shots)) -;; (x (assoc-ref sh 'x)) (y (assoc-ref sh 'y)) -;; (angle (assoc-ref sh 'angle)) -;; (r (degrees-to-radians (- angle)))) -;; (set! x (+ x (* 10 (sin r)))) -;; (set! y (+ y (* 10 (cos r)))) -;; (cond ((and (<= x max-x) -;; (>= x min-x) -;; (<= y max-y) -;; (>= y min-y)) -;; (cons `((x . ,x) (y . ,y) (angle . ,angle)) -;; (move-shots (cdr shots)))) -;; (else -;; (move-shots (cdr shots)))))))) - ;; (define (make-asteroids n) ;; (define (xy n r) ;; (let ((n2 (- (random (* n 2)) n))) diff --git a/src/gacela_mobs.scm b/src/gacela_mobs.scm index e0e2edd..ca4d5d3 100755 --- a/src/gacela_mobs.scm +++ b/src/gacela_mobs.scm @@ -56,7 +56,14 @@ `(show-mob-hash (,mob 'get-mob-id) (lambda () (,mob)))))) (define-macro (hide-mob mob) - `(hide-mob-hash ',mob)) + (cond ((list? mob) + `(let ((m ,mob)) + (hide-mob-hash (m 'get-mob-id) m))) + (else + `(hide-mob-hash (,mob 'get-mob-id) (lambda () (,mob)))))) + +(define-macro (kill-me) + `(hide-mob-hash mob-id)) (define (run-mobs mobs) (for-each @@ -72,8 +79,8 @@ (define-macro (define-mob mob-head . body) (let ((name (car mob-head)) (attr (cdr mob-head))) `(define ,(string->symbol (string-concatenate (list "make-" (symbol->string name)))) - (lambda () - (lambda-mob ,attr ,@body))))) + (lambda* (#:key ,@attr) + (lambda-mob () ,@body))))) (define-macro (lambda-mob attr . body) `(let ,(cons '(mob-id (gensym)) attr)