- (set! res (apply ,pwc param))
- (into-cache key res)
- res)))))))
-
-(use-cache-with (gacela video) load-texture)
-(use-cache-with (gacela video) load-font)
-
-
-;;; GaCeLa Functions
-
-(define set-game-properties! #f)
-(define get-game-properties #f)
-
-(let ((ptitle *title*) (pwidth *width-screen*) (pheight *height-screen*) (pbpp *bpp-screen*) (pfps *frames-per-second*) (pmode *mode*))
- (set! set-game-properties!
- (lambda* (#:key title width height bpp fps mode)
-; (init-video-mode)
- (if title
- (begin
- (set! ptitle title)
- (if (video-mode-on?) (SDL_WM_SetCaption title ""))))
- (if (or width height bpp)
- (begin
- (if width (set! pwidth width))
- (if height (set! pheight height))
- (if bpp (set! pbpp bpp))
- (if (video-mode-on?) (resize-screen pwidth pheight pbpp))))
- (if fps
- (begin
- (set! pfps fps)
- (set-frames-per-second fps)))
- (if mode
- (begin
- (set! pmode mode)
- (if (video-mode-on?)
- (if (eq? mode '3d) (set-3d-mode) (set-2d-mode)))))
- (get-game-properties)))
-
- (set! get-game-properties
- (lambda ()
- `((title . ,ptitle) (width . ,pwidth) (height . ,pheight) (bpp . ,pbpp) (fps . ,pfps) (mode . ,pmode)))))
-
-
-(define-macro (run-game . code)
- `(let ((game-function ,(if (null? code)
- `(lambda () #f)
- `(lambda () ,@code))))
- (init-video-mode)
- (set-game-code game-function)
- (cond ((not (game-running?))
- (game-loop)))))
-
-(define game-loop #f)
-(define game-running? #f)
-(define set-game-code #f)
-
-(let ((running #f) (game-code #f))
- (set! game-loop
- (lambda ()
- (refresh-active-mobs)
- (set! running #t)
- (quit! #f)
- (do () ((quit?))
- (init-frame-time)
- (check-connections)
- (eval-from-clients)
- (process-events)
- (cond ((not (quit?))
- (cond ((video-mode-on?)
- (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT))
- (to-origin)))
- (refresh-active-mobs)
- (if (procedure? game-code)
- (catch #t
- (lambda () (game-code))
- (lambda (key . args) #f)))
- (cond ((video-mode-on?)
- (run-mobs)
- (SDL_GL_SwapBuffers)))
- (delay-frame))))
- (set! running #f)))
-
- (set! game-running?
- (lambda ()
- running))
-
- (set! set-game-code
- (lambda (game-function)
- (set! game-code game-function))))
+ (set! ,mob-id-z-index (+ ,mob-id-z-index z))
+ (translate-mob x y))))
+ (let* ,attr
+ ,@(map
+ (lambda (a)
+ `(let ((val (assoc-ref ,data-symbol ',(car a))))
+ (cond (val (set! ,(car a) val)))))
+ attr)
+ (catch #t
+ (lambda* () ,@body)
+ (lambda (key . args) #f))
+ (list ,mob-id-z-index (list ,@(map (lambda (a) `(cons ',(car a) ,(car a))) attr))))))))
+
+(define-macro (define-mob mob-head . body)
+ (let* ((name (car mob-head))
+ (attr (cdr mob-head))
+ (make-fun-symbol (gensym))
+ (mob-fun-symbol (gensym))
+ (params-symbol (gensym)))
+ `(define (,name . ,params-symbol)
+ (define ,make-fun-symbol
+ (lambda* ,(if (null? attr) '() `(#:key ,@attr))
+ (the-mob ,name (list ,@(map (lambda (a) `(cons ',(car a) ,(car a))) attr)))))
+ (define ,mob-fun-symbol
+ (define-mob-function ,attr ,@body))
+ (cond ((or (null? ,params-symbol) (keyword? (car ,params-symbol)))
+ (apply ,make-fun-symbol ,params-symbol))
+ (else
+ (apply ,mob-fun-symbol ,params-symbol))))))
+
+(define-macro (lambda-mob attr . body)
+ (let ((fun-name (gensym)))
+ `(begin
+ (define-mob-function ,(cons fun-name attr) ,@body)
+ (the-mob 'undefined '() ,fun-name))))
+
+
+;;; Functions for checking mobs (collisions and more)
+
+(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))))
+
+
+;;; Scenes
+
+(define-macro (define-scene name . body)
+ `(define (,name)
+ ,@body))
+
+
+(module-map (lambda (sym var)
+ (if (not (eq? sym '%module-public-interface))
+ (module-export! (current-module) (list sym))))
+ (current-module))