From: jsancho Date: Sun, 18 Sep 2011 08:13:22 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=6ae59c90c15804096c9b738953bb78bc75d21e19;p=gacela.git --- diff --git a/games/asteroids/asteroids.scm b/games/asteroids/asteroids.scm index 756dd73..8f1c911 100644 --- a/games/asteroids/asteroids.scm +++ b/games/asteroids/asteroids.scm @@ -77,6 +77,11 @@ (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 (new-game n) ;; (set! asteroids (make-asteroids n)) ;; (set! ship '((x . 0) (y . 0) (angle . 0) (moving . #f))) diff --git a/src/gacela_mobs.scm b/src/gacela_mobs.scm index ca4d5d3..dabb9dc 100755 --- a/src/gacela_mobs.scm +++ b/src/gacela_mobs.scm @@ -31,7 +31,7 @@ (set! hide-mob-hash (lambda (key) - (hash-remove! key) + (hash-remove! active-mobs key) (set! changed #t))) (set! get-active-mobs @@ -58,12 +58,9 @@ (define-macro (hide-mob mob) (cond ((list? mob) `(let ((m ,mob)) - (hide-mob-hash (m 'get-mob-id) m))) + (hide-mob-hash (m 'get-mob-id)))) (else - `(hide-mob-hash (,mob 'get-mob-id) (lambda () (,mob)))))) - -(define-macro (kill-me) - `(hide-mob-hash mob-id)) + `(hide-mob-hash (,mob 'get-mob-id))))) (define (run-mobs mobs) (for-each @@ -79,16 +76,20 @@ (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* (#:key ,@attr) + (lambda* ,(if (null? attr) '() `(#:key ,@attr)) (lambda-mob () ,@body))))) (define-macro (lambda-mob attr . body) - `(let ,(cons '(mob-id (gensym)) attr) - (lambda* (#:optional (option #f)) - (case option - ((get-mob-id) - mob-id) - (else - (catch #t - (lambda () ,@body) - (lambda (key . args) #f))))))) + (let ((mob-id-symbol (gensym)) + (type-mob + `(let ,(cons `(,mob-id-symbol (gensym)) attr) + (lambda* (#:optional (option #f)) + (define (kill-me) + (hide-mob-hash ,mob-id-symbol)) + (case option + ((get-mob-id) + ,mob-id-symbol) + (else + (catch #t + (lambda () ,@body) + (lambda (key . args) #f))))))))