aboutsummaryrefslogtreecommitdiff
path: root/animation.scm
diff options
context:
space:
mode:
Diffstat (limited to 'animation.scm')
-rw-r--r--animation.scm48
1 files changed, 27 insertions, 21 deletions
diff --git a/animation.scm b/animation.scm
index 468f7f0..c8f4497 100644
--- a/animation.scm
+++ b/animation.scm
@@ -1,17 +1,17 @@
(module downstroke-animation *
- (import scheme
- (chicken base)
- (chicken keyword)
- (only srfi-1 filter)
- downstroke-entity
- downstroke-world)
+(import scheme
+ (chicken base)
+ (chicken keyword)
+ (only srfi-1 filter)
+ downstroke-entity
+ downstroke-world)
- ;; ---- Animation data accessors ----
+;; ---- Animation data accessors ----
- (define (animation-frames anim)
- (get-keyword #:frames anim))
- (define (animation-duration anim)
- (get-keyword #:duration anim))
+(define (animation-frames anim)
+ (get-keyword #:frames anim))
+(define (animation-duration anim)
+ (get-keyword #:duration anim))
(define (frame-by-idx frames frame-idx)
(list-ref frames (modulo frame-idx (length frames))))
@@ -19,9 +19,9 @@
;; The tile ID is 1-indexed.
(define (frame->tile-id frames frame-idx)
(let ((frame-def (frame-by-idx frames frame-idx)))
- (+ 1 (if (list? frame-def)
- (car frame-def)
- frame-def))))
+ (if (list? frame-def)
+ (car frame-def)
+ frame-def)))
(define (frame->duration frames frame-idx)
(let ((frame-def (frame-by-idx frames frame-idx)))
@@ -42,7 +42,7 @@
(define (animation-by-name animations name)
- (let ((matching-anims (filter (lambda (anim) (eq? (get-keyword #:name anim) 'walk)) animations)))
+ (let ((matching-anims (filter (lambda (anim) (eq? (get-keyword #:name anim) name)) animations)))
(if matching-anims
(car matching-anims)
#f)))
@@ -68,10 +68,16 @@
(list (cons #:anim-tick tick)
(cons #:tile-id (frame->tile-id frames frame)))))))
- (define (animate-entity entity animations)
- (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)
- entity)))
+(define (animate-entity entity animations)
+ (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)
+ 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)))
+
) ;; End of animation module