From: Javier Sancho Date: Mon, 17 Oct 2016 16:09:08 +0000 (+0200) Subject: Images in development X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=2a08d93dcd9a52442e59c185ac85d4344e716650;p=gacela.git Images in development --- diff --git a/examples/fran.scm b/examples/fran.scm index 9b18db8..964bbbc 100644 --- a/examples/fran.scm +++ b/examples/fran.scm @@ -22,9 +22,9 @@ ;;; Reactive positions -(define (waggle) (cos (* pi (current-time)))) -(define (wiggle) (sin (* pi (current-time)))) - +(define (tick) (* 3000000 (get-internal-real-time))) +(define (waggle) (* 200 (+ 1 (cos (* pi (tick)))))) +(define (wiggle) (* 300 (+ 1 (sin (* pi (tick)))))) ;;; First example diff --git a/gacela/image.scm b/gacela/image.scm index 1fdeaf6..370bbd1 100644 --- a/gacela/image.scm +++ b/gacela/image.scm @@ -18,28 +18,32 @@ (define-module (gacela image) #:use-module (gacela scene) #:use-module (gacela game) + #:use-module ((sdl2) #:prefix sdl2:) #:use-module ((sdl2 image) #:prefix sdl2:) #:use-module ((sdl2 render) #:prefix sdl2:) + #:use-module ((sdl2 surface) #:prefix sdl2:) #:export (import-bitmap move-xy)) -(define-syntax-rule (import-bitmap filename) +(define (import-bitmap filename) (make-scene "bitmap" (let ((image (sdl2:load-image filename)) (texture #f)) (let ((a 0)) - (lambda () + (lambda* (#:key (xy '(0 0))) (if (not texture) (set! texture (sdl2:surface->texture %sdl-renderer image))) - ;; (set! a (+ a 1)) - ;; (format #t "~a steps with texture ~a~%" a texture)))))) (sdl2:clear-renderer %sdl-renderer) - (sdl2:render-copy %sdl-renderer texture) + (sdl2:render-copy %sdl-renderer texture #:dest-rect (sdl2:make-rect (car xy) (cadr xy) (sdl2:surface-width image) (sdl2:surface-height image))) (sdl2:present-renderer %sdl-renderer)))))) -(define-syntax-rule (move-xy x y scene) +(define (move-xy x y scene) + (define (to-integer n) + (inexact->exact (round n))) (make-scene "move-xy" (lambda () - (display-scene scene)))) + (let ((xy (list (to-integer (if (procedure? x) (x) x)) + (to-integer (if (procedure? y) (y) y))))) + (display-scene scene #:xy xy))))) diff --git a/gacela/scene.scm b/gacela/scene.scm index 62b1a1e..e620480 100644 --- a/gacela/scene.scm +++ b/gacela/scene.scm @@ -39,8 +39,8 @@ ;;; Scene Procedures -(define (display-scene scene) - ((scene-procedure scene))) +(define (display-scene scene . args) + (apply (scene-procedure scene) args)) (define (run-scene scene) (play-game