From: jsancho Date: Fri, 3 Jun 2011 16:04:12 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=75d1bbb394aa23715811cac3da7ad6b202df26cf;p=gacela.git --- diff --git a/src/gacela_misc.scm b/src/gacela_misc.scm index b75a44e..d486b26 100644 --- a/src/gacela_misc.scm +++ b/src/gacela_misc.scm @@ -20,3 +20,7 @@ (cond ((> (* p 2) n) p) (else (power (* p 2) n)))) (power 1 n)) + +(define-macro (pushnew elem list) + `(cond ((not (find (lambda (e) (eq? e ,elem)) ,list)) + (set! ,list (cons ,elem ,list))))) diff --git a/src/gacela_mobs.scm b/src/gacela_mobs.scm index 12a0ef1..9e971b9 100755 --- a/src/gacela_mobs.scm +++ b/src/gacela_mobs.scm @@ -38,6 +38,50 @@ ;;; Mob Factory +(define add-mob #f) +(define kill-mob #f) +(define kill-all-mobs #f) +(define refresh-active-mobs #f) +(define action-mobs #f) +(define render-mobs #f) + +(let ((active-mobs '()) (mobs-to-add '()) (mobs-to-kill '()) + (set! add-mob + (lambda (mob) + (pushnew mob mobs-to-add))) + + (set! kill-mob + (lambda (mob) + (pushnew mob mobs-to-kill)) + + (set! kill-all-mobs + (lambda () + (set! active-mobs '()) + (set! mobs-to-add '()) + (set! mobs-to-kill '()))) + + (set! refresh-active-mobs + (lambda () + (define (add active to-add) + (cond ((null? to-add) active) + (else + (pushnew (car to-add) active) + (add active (cdr to-add))))) + + (add active-mobs mobs-to-add) + (set! mobs-to-add '()) + (set! active-mobs (reverse (lset-difference eq? active-mobs mobs-to-kill))) + (set! mobs-to-kill '()))) + + (set! action-mobs + (lambda () + (map (lambda (m) (m #:action)) active-mobs))) + + (set! render-mobs + (lambda () + (map (lambda (m) (m #:render)) active-mobs)))) + + (define-macro (makemob name . methods) `(define* (,name . args) (let ((option (car args)))