From: jsancho Date: Sat, 28 Jan 2012 09:27:43 +0000 (+0000) Subject: Collision support X-Git-Url: https://git.jsancho.org/?p=gacela.git;a=commitdiff_plain;h=eba2c1bb47b19f0f5dcf96a4ee2a0544f6111d80 Collision support --- diff --git a/src/gacela.scm b/src/gacela.scm index 6c109da..6f14848 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -262,11 +262,6 @@ (cond ((not (= time mob-time)) (set! mob-time time) (set! saved-data mob-data))))) -; (define (filter-mobs type fun) -; #t) -; (define (map-mobs fun type) -; (let ((mobs (filter (lambda (m) (and (eq? (m 'get-type) type) (not (eq? (m 'get-mob-id) ,mob-id-symbol)))) (get-active-mobs)))) -; (map (lambda (m) (fun (m 'get-data))) mobs))) (case option ((get-mob-id) mob-id) @@ -316,19 +311,15 @@ ;;; Functions for checking mobs (collisions and more) -(define (map-mobs fun) - (let ((mobs (filter (lambda (m) (not (eq? (m 'get-mob-id) (get-current-mob-id)))) (get-active-mobs)))) - (map fun mobs))) - -(define-macro (define-checking-mobs head mob-attr . body) - `(define ,head - -;; (define-macro (lambda-mob-data attr . body) -;; `(lambda ,attr ,@body)) - -;; (define-macro (define-collision-check name mobs . body) -;; `(defmacro* ,name (#:optional m) -;; `(let ,(cond (m `((mob-id (,m 'get-mob-id)) (mob-type (,m 'get-type)))) -;; (else `())) - -;; mob-id))) +(define (map-mobs fun type) + (let ((mobs (filter (lambda (m) (and (eq? (m 'get-type) type) (not (eq? (m 'get-mob-id) (get-current-mob-id))))) (get-active-mobs)))) + (map (lambda (m) (fun (m 'get-data))) mobs))) + +(define-macro (define-checking-mobs head mob-def . body) + (let ((type (car mob-def)) (attr (cdr mob-def))) + `(define ,head + (map-mobs + (lambda (m) + (let ,(map (lambda (a) `(,(car a) (assoc-ref m ',(cadr a)))) attr) + ,@body)) + ',type))))