X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fgacela_mobs.scm;h=c0507f5af6eb529a4a61a44f6fe1ac060cc8cb5a;hb=25092276a1f3e86b9681fe155b7050da730a3514;hp=8120e0369b649f089e7508dcdb83a5e3adbd2f5f;hpb=03149b3e627438a3dd317e62aba2befce52cc324;p=gacela.git diff --git a/src/gacela_mobs.scm b/src/gacela_mobs.scm index 8120e03..c0507f5 100755 --- a/src/gacela_mobs.scm +++ b/src/gacela_mobs.scm @@ -51,6 +51,35 @@ (define (process-mobs mobs) (for-each (lambda (m) (m #:render)) mobs)) + +;;; Actions and looks for mobs + +(defmacro make-behaviour (name attr &rest code) + `(defun ,(get-behaviour-fun-name name) (object-attr) + (let ,(mapcar #'attribute-definition attr) + ,@code + ,(cons 'progn (mapcar #'attribute-save (reverse attr))) + object-attr))) + +(defun get-behaviour-fun-name (name) + (intern (concatenate 'string "BEHAVIOUR-" (string-upcase (string name))) 'gacela)) + +(defun attribute-name (attribute) + (intern (string attribute) 'keyword)) + +(define (attribute-definition attribute) + (let* ((name (cond ((list? attribute) (car attribute)) + (else attribute))) + (pname (attribute-name name)) + (value (cond ((listp attribute) (cadr attribute))))) + `(,name (getf object-attr ,pname ,value)))) + +(defun attribute-save (attribute) + (let* ((name (cond ((listp attribute) (car attribute)) + (t attribute))) + (pname (attribute-name name))) + `(setf (getf object-attr ,pname) ,name))) + (define-macro (lambda-look . look) (define (process-look look) (cond ((null? look) (values '() '())) @@ -72,6 +101,9 @@ ,@look-lines (glPopMatrix))))) + +;;; Making mobs + (define-macro (define-mob mob-head . look) (let ((name (car mob-head)) (attr (cdr mob-head))) `(define ,name @@ -86,7 +118,15 @@ ((get-attr) attr) ((set-attr) - (if (not (null? params)) (set! attr (car params)))))))) + (if (not (null? params)) (set! attr (car params)))) + ((get-actions) + actions) + ((set-actions) + (if (not (null? params)) (set! actions (car params)))) + ((get-renders) + renders) + ((set-renders) + (if (not (null? params)) (set! renders (car params)))))))) (cond ((not (null? ',look)) (display ',look) (newline)))