From: jsancho Date: Fri, 10 Jun 2011 18:33:21 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=44cea6ad0255b8bda0cd3ea74441d47d8efc5eb5;p=gacela.git --- diff --git a/src/gacela.scm b/src/gacela.scm index b03440a..6be5ee8 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -220,7 +220,7 @@ (define game-running? #f) (define set-game-code #f) -(let ((running #f) (game-code #f)) +(let ((running #f) (game-code #f) (mobs-function (lambda () #f))) (set! game-loop (lambda () (set! running #t) @@ -233,9 +233,11 @@ (cond ((not (quit?)) (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT)) (to-origin) -; (refresh-active-objects) + (cond ((reload-mobs?) + (set! mobs-function (get-mobs-function)) + (mobs-reloaded))) (if (procedure? game-code) (game-code)) -; (render-objects) + (mobs-function) (SDL_GL_SwapBuffers) (delay-frame)))) (set! running #f))) diff --git a/src/gacela_mobs.scm b/src/gacela_mobs.scm index 497e827..3e3e17a 100755 --- a/src/gacela_mobs.scm +++ b/src/gacela_mobs.scm @@ -17,38 +17,50 @@ ;;; Mobs Factory -(define add-mob #f) -(define kill-mob #f) +(define add-mob-symbol #f) +(define kill-mob-symbol #f) (define get-active-mobs #f) (define reload-mobs? #f) +(define mobs-reloaded #f) -(let ((active-mobs '(m1 m2)) (reload #f)) - (set! add-mob +(let ((active-mobs '()) (reload #f)) + (set! add-mob-symbol (lambda (mob) - (pushnew (procedure-name mob) active-mobs) + (pushnew mob active-mobs) (set! reload #t))) - (set! kill-mob + (set! kill-mob-symbol (lambda (mob) - (set! active-mobs (lset-difference eq? active-mobs (list (procedure-name mob)))) + (set! active-mobs (lset-difference eq? active-mobs (list mob))) (set! reload #t))) (set! get-active-mobs (lambda () active-mobs)) (set! reload-mobs? - (lambda () reload))) + (lambda () reload)) + (set! mobs-reloaded + (lambda () (set! reload #f)))) + +(define-macro (add-mob mob) + `(add-mob-symbol ',mob)) + +(define-macro (kill-mob mob) + `(kill-mob-symbol ',mob)) (define-macro (get-mobs-function) (let ((mobs (get-active-mobs))) - `(lambda () ,@(map (lambda (mob) `(,mob)) mobs)))) + (cond ((null? mobs) + `(lambda () #f)) + (else + `(lambda () ,@(map (lambda (mob) `(,mob #:render)) mobs)))))) (define-macro (define-mob mob-head . look) (let ((name (car mob-head)) (attr (cdr mob-head))) `(begin (define ,name #f) - (let ((attr ,attr)) + (let ((attr ',attr)) (set! ,name (lambda (option) (case option