diff options
Diffstat (limited to 'animation.scm')
| -rw-r--r-- | animation.scm | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/animation.scm b/animation.scm index ea13125..2466cc8 100644 --- a/animation.scm +++ b/animation.scm @@ -1,6 +1,7 @@ (module (downstroke animation) * (import scheme (chicken base) + (chicken pretty-print) (only srfi-1 filter) (downstroke entity) (downstroke world)) @@ -17,7 +18,7 @@ ((procedure? default) (default)) (else default))) -(define +default-anim-duration+ 10) +(define +default-anim-duration+ 100) ; 100ms (define (animation-frames anim) (animation-ref anim #:frames 1)) (define (animation-duration anim) (animation-ref anim #:duration +default-anim-duration+)) @@ -32,11 +33,11 @@ (car frame-def) frame-def))) -(define (frame->duration frames frame-idx) - (let ((frame-def (frame-by-idx frames frame-idx))) +(define (frame->duration animation frame-idx) + (let ((frame-def (frame-by-idx (animation-frames animation) frame-idx))) (if (list? frame-def) (cadr frame-def) - 10))) + (animation-ref animation #:duration +default-anim-duration+)))) ;; ---- set-animation ---- ;; Switch to a new animation, resetting frame and tick counters. @@ -63,9 +64,9 @@ ;; Pass the animation table for this entity's type. ;; Entities without #:anim-name are returned unchanged. -(define (advance-animation entity anim) - (let ((tick (+ 1 (entity-ref entity #:anim-tick 0))) - (duration (animation-duration anim)) +(define (advance-animation entity anim dt) + (let ((tick (+ dt (entity-ref entity #:anim-tick 0))) + (duration (entity-ref entity #:duration +default-anim-duration+)) (frames (animation-frames anim)) (frame (entity-ref entity #:anim-frame 0))) (if (>= tick duration) @@ -74,21 +75,24 @@ `((#:anim-tick . 0) (#:anim-frame . ,new-frame-id) (#:tile-id . ,(frame->tile-id frames new-frame-id)) - (#:duration . ,(frame->duration frames new-frame-id))))) + (#:duration . ,(frame->duration anim new-frame-id))))) (entity-set-many entity `((#:anim-tick . ,tick) (#:tile-id . ,(frame->tile-id frames frame))))))) -(define (animate-entity entity animations) +(define (animate-entity entity animations dt) (let* ((anim-name (entity-ref entity #:anim-name #f)) (anim (and anim-name (animation-by-name animations anim-name)))) (if anim - (advance-animation entity anim) + (advance-animation entity anim dt) entity))) (define-pipeline (apply-animation animation) (scene entity dt) guard: (entity-ref entity #:animations #f) - (let ((animations (entity-ref entity #:animations #f))) - (animate-entity entity animations))) + (let* ((animations (entity-ref entity #:animations #f)) + (updated-entity (animate-entity entity animations dt))) + (when (eq? (entity-ref entity #:type) 'timed-frames) + (pp (list (entity-ref updated-entity #:tile-id) (entity-ref updated-entity #:duration) (entity-ref entity #:anim-tick)))) + updated-entity)) ) ;; End of animation module |
