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