(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)
(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)))
;;; 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