aboutsummaryrefslogtreecommitdiff
path: root/animation.scm
diff options
context:
space:
mode:
Diffstat (limited to 'animation.scm')
-rw-r--r--animation.scm39
1 files changed, 20 insertions, 19 deletions
diff --git a/animation.scm b/animation.scm
index a152753..4caf1fe 100644
--- a/animation.scm
+++ b/animation.scm
@@ -32,24 +32,25 @@
;; 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))
+ (frames (animation-frames anim))
+ (frame (entity-ref entity #:anim-frame 0)))
+ (if (>= tick duration)
+ (let ((new-frame (modulo (+ frame 1) (length frames))))
+ (entity-set (entity-set (entity-set entity
+ #:anim-tick 0)
+ #:anim-frame new-frame)
+ #:tile-id (frame->tile-id frames new-frame)))
+ (entity-set (entity-set entity #:anim-tick tick)
+ #:tile-id (frame->tile-id frames frame)))))
+
(define (animate-entity entity animations)
- (let ((anim-name (entity-ref entity #:anim-name #f)))
- (if (not anim-name)
- entity
- (let* ((entry (assq anim-name animations))
- (anim (and entry (cdr entry))))
- (if (not anim)
- entity
- (let* ((tick (+ 1 (entity-ref entity #:anim-tick 0)))
- (duration (animation-duration anim))
- (frames (animation-frames anim))
- (frame (entity-ref entity #:anim-frame 0)))
- (if (>= tick duration)
- (let ((new-frame (modulo (+ frame 1) (length frames))))
- (entity-set (entity-set (entity-set entity
- #:anim-tick 0)
- #:anim-frame new-frame)
- #:tile-id (frame->tile-id frames new-frame)))
- (entity-set (entity-set entity #:anim-tick tick)
- #:tile-id (frame->tile-id frames frame)))))))))
+ (let* ((anim-name (entity-ref entity #:anim-name #f))
+ (entry (and anim-name (assq anim-name animations)))
+ (anim (and entry (cdr entry))))
+ (if anim
+ (advance-animation entity anim)
+ entity)))
) ;; End of animation module